summaryrefslogtreecommitdiff
path: root/arch/arm/imx-common/sci/svc/timer/rpc_clnt.c
blob: 6e11d3782d62af2c744ce7cbf97647a514ea4a1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
 * Copyright (C) 2016 Freescale Semiconductor, Inc.
 * Copyright 2017 NXP
 *
 * SPDX-License-Identifier:     GPL-2.0+
 */

/*!
 * File containing client-side RPC functions for the TIMER service. These
 * functions are ported to clients that communicate to the SC.
 *
 * @addtogroup TIMER_SVC
 * @{
 */

/* Includes */

#include <asm/imx-common/sci/types.h>
#include <asm/imx-common/sci/svc/rm/api.h>
#include <asm/imx-common/sci/svc/timer/api.h>
#include <asm/imx-common/sci/rpc.h>
#include "rpc.h"

/* Local Defines */

/* Local Types */

/* Local Functions */

sc_err_t sc_timer_set_wdog_timeout(sc_ipc_t ipc,
    sc_timer_wdog_time_t timeout)
{
    sc_rpc_msg_t msg;
    uint8_t result;

    RPC_VER(&msg) = SC_RPC_VERSION;
    RPC_SVC(&msg) = SC_RPC_SVC_TIMER;
    RPC_FUNC(&msg) = TIMER_FUNC_SET_WDOG_TIMEOUT;
    RPC_U32(&msg, 0) = timeout;
    RPC_SIZE(&msg) = 2;

    sc_call_rpc(ipc, &msg, false);

    result = RPC_R8(&msg);
    return (sc_err_t) result;
}

sc_err_t sc_timer_start_wdog(sc_ipc_t ipc, bool lock)
{
    sc_rpc_msg_t msg;
    uint8_t result;

    RPC_VER(&msg) = SC_RPC_VERSION;
    RPC_SVC(&msg) = SC_RPC_SVC_TIMER;
    RPC_FUNC(&msg) = TIMER_FUNC_START_WDOG;
    RPC_U8(&msg, 0) = lock;
    RPC_SIZE(&msg) = 2;

    sc_call_rpc(ipc, &msg, false);

    result = RPC_R8(&msg);
    return (sc_err_t) result;
}

sc_err_t sc_timer_stop_wdog(sc_ipc_t ipc)
{
    sc_rpc_msg_t msg;
    uint8_t result;

    RPC_VER(&msg) = SC_RPC_VERSION;
    RPC_SVC(&msg) = SC_RPC_SVC_TIMER;
    RPC_FUNC(&msg) = TIMER_FUNC_STOP_WDOG;
    RPC_SIZE(&msg) = 1;

    sc_call_rpc(ipc, &msg, false);

    result = RPC_R8(&msg);
    return (sc_err_t) result;
}

sc_err_t sc_timer_ping_wdog(sc_ipc_t ipc)
{
    sc_rpc_msg_t msg;
    uint8_t result;

    RPC_VER(&msg) = SC_RPC_VERSION;
    RPC_SVC(&msg) = SC_RPC_SVC_TIMER;
    RPC_FUNC(&msg) = TIMER_FUNC_PING_WDOG;
    RPC_SIZE(&msg) = 1;

    sc_call_rpc(ipc, &msg, false);

    result = RPC_R8(&msg);
    return (sc_err_t) result;
}

sc_err_t sc_timer_get_wdog_status(sc_ipc_t ipc,
    sc_timer_wdog_time_t *timeout, sc_timer_wdog_time_t *max_timeout,
    sc_timer_wdog_time_t *remaining_time)
{
    sc_rpc_msg_t msg;
    uint8_t result;

    RPC_VER(&msg) = SC_RPC_VERSION;
    RPC_SVC(&msg) = SC_RPC_SVC_TIMER;
    RPC_FUNC(&msg) = TIMER_FUNC_GET_WDOG_STATUS;
    RPC_SIZE(&msg) = 1;

    sc_call_rpc(ipc, &msg, false);

    if (timeout != NULL)
        *timeout = RPC_U32(&msg, 0);
    if (max_timeout != NULL)
        *max_timeout = RPC_U32(&msg, 4);
    if (remaining_time != NULL)
        *remaining_time = RPC_U32(&msg, 8);
    result = RPC_R8(&msg);
    return (sc_err_t) result;
}

sc_err_t sc_timer_set_wdog_action(sc_ipc_t ipc,
    sc_rm_pt_t pt, sc_timer_wdog_action_t action)
{
    sc_rpc_msg_t msg;
    uint8_t result;

    RPC_VER(&msg) = SC_RPC_VERSION;
    RPC_SVC(&msg) = SC_RPC_SVC_TIMER;
    RPC_FUNC(&msg) = TIMER_FUNC_SET_WDOG_ACTION;
    RPC_U8(&msg, 0) = pt;
    RPC_U8(&msg, 1) = action;
    RPC_SIZE(&msg) = 2;

    sc_call_rpc(ipc, &msg, false);

    result = RPC_R8(&msg);
    return (sc_err_t) result;
}

sc_err_t sc_timer_set_rtc_time(sc_ipc_t ipc, uint16_t year, uint8_t mon,
    uint8_t day, uint8_t hour, uint8_t min, uint8_t sec)
{
    sc_rpc_msg_t msg;
    uint8_t result;

    RPC_VER(&msg) = SC_RPC_VERSION;
    RPC_SVC(&msg) = SC_RPC_SVC_TIMER;
    RPC_FUNC(&msg) = TIMER_FUNC_SET_RTC_TIME;
    RPC_U16(&msg, 0) = year;
    RPC_U8(&msg, 2) = mon;
    RPC_U8(&msg, 3) = day;
    RPC_U8(&msg, 4) = hour;
    RPC_U8(&msg, 5) = min;
    RPC_U8(&msg, 6) = sec;
    RPC_SIZE(&msg) = 3;

    sc_call_rpc(ipc, &msg, false);

    result = RPC_R8(&msg);
    return (sc_err_t) result;
}

sc_err_t sc_timer_get_rtc_time(sc_ipc_t ipc, uint16_t *year, uint8_t *mon,
    uint8_t *day, uint8_t *hour, uint8_t *min, uint8_t *sec)
{
    sc_rpc_msg_t msg;
    uint8_t result;

    RPC_VER(&msg) = SC_RPC_VERSION;
    RPC_SVC(&msg) = SC_RPC_SVC_TIMER;
    RPC_FUNC(&msg) = TIMER_FUNC_GET_RTC_TIME;
    RPC_SIZE(&msg) = 1;

    sc_call_rpc(ipc, &msg, false);

    if (year != NULL)
        *year = RPC_U16(&msg, 0);
    result = RPC_R8(&msg);
    if (mon != NULL)
        *mon = RPC_U8(&msg, 2);
    if (day != NULL)
        *day = RPC_U8(&msg, 3);
    if (hour != NULL)
        *hour = RPC_U8(&msg, 4);
    if (min != NULL)
        *min = RPC_U8(&msg, 5);
    if (sec != NULL)
        *sec = RPC_U8(&msg, 6);
    return (sc_err_t) result;
}

sc_err_t sc_timer_get_rtc_sec1970(sc_ipc_t ipc, uint32_t *sec)
{
    sc_rpc_msg_t msg;
    uint8_t result;

    RPC_VER(&msg) = SC_RPC_VERSION;
    RPC_SVC(&msg) = SC_RPC_SVC_TIMER;
    RPC_FUNC(&msg) = TIMER_FUNC_GET_RTC_SEC1970;
    RPC_SIZE(&msg) = 1;

    sc_call_rpc(ipc, &msg, false);

    if (sec != NULL)
        *sec = RPC_U32(&msg, 0);
    result = RPC_R8(&msg);
    return (sc_err_t) result;
}

sc_err_t sc_timer_set_rtc_alarm(sc_ipc_t ipc, uint16_t year, uint8_t mon,
    uint8_t day, uint8_t hour, uint8_t min, uint8_t sec)
{
    sc_rpc_msg_t msg;
    uint8_t result;

    RPC_VER(&msg) = SC_RPC_VERSION;
    RPC_SVC(&msg) = SC_RPC_SVC_TIMER;
    RPC_FUNC(&msg) = TIMER_FUNC_SET_RTC_ALARM;
    RPC_U16(&msg, 0) = year;
    RPC_U8(&msg, 2) = mon;
    RPC_U8(&msg, 3) = day;
    RPC_U8(&msg, 4) = hour;
    RPC_U8(&msg, 5) = min;
    RPC_U8(&msg, 6) = sec;
    RPC_SIZE(&msg) = 3;

    sc_call_rpc(ipc, &msg, false);

    result = RPC_R8(&msg);
    return (sc_err_t) result;
}

/**@}*/