1 /* 2 * Copyright (C) 2016 Freescale Semiconductor, Inc. 3 * Copyright 2017-2019 NXP 4 * 5 * SPDX-License-Identifier: BSD-3-Clause 6 */ 7 8 /*! 9 * File containing client-side RPC functions for the TIMER service. These 10 * functions are ported to clients that communicate to the SC. 11 * 12 * @addtogroup TIMER_SVC 13 * @{ 14 */ 15 16 /* Includes */ 17 18 #include <sci/sci_types.h> 19 #include <sci/svc/rm/sci_rm_api.h> 20 #include <sci/svc/timer/sci_timer_api.h> 21 #include <sci/sci_rpc.h> 22 #include <stdlib.h> 23 #include "sci_timer_rpc.h" 24 25 /* Local Defines */ 26 27 /* Local Types */ 28 29 /* Local Functions */ 30 31 sc_err_t sc_timer_set_wdog_timeout(sc_ipc_t ipc, sc_timer_wdog_time_t timeout) 32 { 33 sc_rpc_msg_t msg; 34 uint8_t result; 35 36 RPC_VER(&msg) = SC_RPC_VERSION; 37 RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_TIMER; 38 RPC_FUNC(&msg) = (uint8_t)TIMER_FUNC_SET_WDOG_TIMEOUT; 39 RPC_U32(&msg, 0U) = (uint32_t)timeout; 40 RPC_SIZE(&msg) = 2U; 41 42 sc_call_rpc(ipc, &msg, SC_FALSE); 43 44 result = RPC_R8(&msg); 45 return (sc_err_t)result; 46 } 47 48 sc_err_t sc_timer_set_wdog_pre_timeout(sc_ipc_t ipc, 49 sc_timer_wdog_time_t pre_timeout) 50 { 51 sc_rpc_msg_t msg; 52 uint8_t result; 53 54 RPC_VER(&msg) = SC_RPC_VERSION; 55 RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_TIMER; 56 RPC_FUNC(&msg) = (uint8_t)TIMER_FUNC_SET_WDOG_PRE_TIMEOUT; 57 RPC_U32(&msg, 0U) = (uint32_t)pre_timeout; 58 RPC_SIZE(&msg) = 2U; 59 60 sc_call_rpc(ipc, &msg, SC_FALSE); 61 62 result = RPC_R8(&msg); 63 return (sc_err_t)result; 64 } 65 66 sc_err_t sc_timer_start_wdog(sc_ipc_t ipc, sc_bool_t lock) 67 { 68 sc_rpc_msg_t msg; 69 uint8_t result; 70 71 RPC_VER(&msg) = SC_RPC_VERSION; 72 RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_TIMER; 73 RPC_FUNC(&msg) = (uint8_t)TIMER_FUNC_START_WDOG; 74 RPC_U8(&msg, 0U) = (uint8_t)lock; 75 RPC_SIZE(&msg) = 2U; 76 77 sc_call_rpc(ipc, &msg, SC_FALSE); 78 79 result = RPC_R8(&msg); 80 return (sc_err_t)result; 81 } 82 83 sc_err_t sc_timer_stop_wdog(sc_ipc_t ipc) 84 { 85 sc_rpc_msg_t msg; 86 uint8_t result; 87 88 RPC_VER(&msg) = SC_RPC_VERSION; 89 RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_TIMER; 90 RPC_FUNC(&msg) = (uint8_t)TIMER_FUNC_STOP_WDOG; 91 RPC_SIZE(&msg) = 1U; 92 93 sc_call_rpc(ipc, &msg, SC_FALSE); 94 95 result = RPC_R8(&msg); 96 return (sc_err_t)result; 97 } 98 99 sc_err_t sc_timer_ping_wdog(sc_ipc_t ipc) 100 { 101 sc_rpc_msg_t msg; 102 uint8_t result; 103 104 RPC_VER(&msg) = SC_RPC_VERSION; 105 RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_TIMER; 106 RPC_FUNC(&msg) = (uint8_t)TIMER_FUNC_PING_WDOG; 107 RPC_SIZE(&msg) = 1U; 108 109 sc_call_rpc(ipc, &msg, SC_FALSE); 110 111 result = RPC_R8(&msg); 112 return (sc_err_t)result; 113 } 114 115 sc_err_t sc_timer_get_wdog_status(sc_ipc_t ipc, 116 sc_timer_wdog_time_t *timeout, 117 sc_timer_wdog_time_t *max_timeout, 118 sc_timer_wdog_time_t *remaining_time) 119 { 120 sc_rpc_msg_t msg; 121 uint8_t result; 122 123 RPC_VER(&msg) = SC_RPC_VERSION; 124 RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_TIMER; 125 RPC_FUNC(&msg) = (uint8_t)TIMER_FUNC_GET_WDOG_STATUS; 126 RPC_SIZE(&msg) = 1U; 127 128 sc_call_rpc(ipc, &msg, SC_FALSE); 129 130 if (timeout != NULL) 131 *timeout = RPC_U32(&msg, 0U); 132 133 if (max_timeout != NULL) 134 *max_timeout = RPC_U32(&msg, 4U); 135 136 if (remaining_time != NULL) 137 *remaining_time = RPC_U32(&msg, 8U); 138 139 result = RPC_R8(&msg); 140 return (sc_err_t)result; 141 } 142 143 sc_err_t sc_timer_pt_get_wdog_status(sc_ipc_t ipc, sc_rm_pt_t pt, 144 sc_bool_t *enb, 145 sc_timer_wdog_time_t *timeout, 146 sc_timer_wdog_time_t *remaining_time) 147 { 148 sc_rpc_msg_t msg; 149 uint8_t result; 150 151 RPC_VER(&msg) = SC_RPC_VERSION; 152 RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_TIMER; 153 RPC_FUNC(&msg) = (uint8_t)TIMER_FUNC_PT_GET_WDOG_STATUS; 154 RPC_U8(&msg, 0U) = (uint8_t)pt; 155 RPC_SIZE(&msg) = 2U; 156 157 sc_call_rpc(ipc, &msg, SC_FALSE); 158 159 if (timeout != NULL) 160 *timeout = RPC_U32(&msg, 0U); 161 162 if (remaining_time != NULL) 163 *remaining_time = RPC_U32(&msg, 4U); 164 165 result = RPC_R8(&msg); 166 if (enb != NULL) 167 *enb = RPC_U8(&msg, 8U); 168 169 return (sc_err_t)result; 170 } 171 172 sc_err_t sc_timer_set_wdog_action(sc_ipc_t ipc, 173 sc_rm_pt_t pt, sc_timer_wdog_action_t action) 174 { 175 sc_rpc_msg_t msg; 176 uint8_t result; 177 178 RPC_VER(&msg) = SC_RPC_VERSION; 179 RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_TIMER; 180 RPC_FUNC(&msg) = (uint8_t)TIMER_FUNC_SET_WDOG_ACTION; 181 RPC_U8(&msg, 0U) = (uint8_t)pt; 182 RPC_U8(&msg, 1U) = (uint8_t)action; 183 RPC_SIZE(&msg) = 2U; 184 185 sc_call_rpc(ipc, &msg, SC_FALSE); 186 187 result = RPC_R8(&msg); 188 return (sc_err_t)result; 189 } 190 191 sc_err_t sc_timer_set_rtc_time(sc_ipc_t ipc, uint16_t year, uint8_t mon, 192 uint8_t day, uint8_t hour, uint8_t min, 193 uint8_t sec) 194 { 195 sc_rpc_msg_t msg; 196 uint8_t result; 197 198 RPC_VER(&msg) = SC_RPC_VERSION; 199 RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_TIMER; 200 RPC_FUNC(&msg) = (uint8_t)TIMER_FUNC_SET_RTC_TIME; 201 RPC_U16(&msg, 0U) = (uint16_t)year; 202 RPC_U8(&msg, 2U) = (uint8_t)mon; 203 RPC_U8(&msg, 3U) = (uint8_t)day; 204 RPC_U8(&msg, 4U) = (uint8_t)hour; 205 RPC_U8(&msg, 5U) = (uint8_t)min; 206 RPC_U8(&msg, 6U) = (uint8_t)sec; 207 RPC_SIZE(&msg) = 3U; 208 209 sc_call_rpc(ipc, &msg, SC_FALSE); 210 211 result = RPC_R8(&msg); 212 return (sc_err_t)result; 213 } 214 215 sc_err_t sc_timer_get_rtc_time(sc_ipc_t ipc, uint16_t *year, uint8_t *mon, 216 uint8_t *day, uint8_t *hour, uint8_t *min, 217 uint8_t *sec) 218 { 219 sc_rpc_msg_t msg; 220 uint8_t result; 221 222 RPC_VER(&msg) = SC_RPC_VERSION; 223 RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_TIMER; 224 RPC_FUNC(&msg) = (uint8_t)TIMER_FUNC_GET_RTC_TIME; 225 RPC_SIZE(&msg) = 1U; 226 227 sc_call_rpc(ipc, &msg, SC_FALSE); 228 229 if (year != NULL) 230 *year = RPC_U16(&msg, 0U); 231 232 result = RPC_R8(&msg); 233 if (mon != NULL) 234 *mon = RPC_U8(&msg, 2U); 235 236 if (day != NULL) 237 *day = RPC_U8(&msg, 3U); 238 239 if (hour != NULL) 240 *hour = RPC_U8(&msg, 4U); 241 242 if (min != NULL) 243 *min = RPC_U8(&msg, 5U); 244 245 if (sec != NULL) 246 *sec = RPC_U8(&msg, 6U); 247 248 return (sc_err_t)result; 249 } 250 251 sc_err_t sc_timer_get_rtc_sec1970(sc_ipc_t ipc, uint32_t *sec) 252 { 253 sc_rpc_msg_t msg; 254 uint8_t result; 255 256 RPC_VER(&msg) = SC_RPC_VERSION; 257 RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_TIMER; 258 RPC_FUNC(&msg) = (uint8_t)TIMER_FUNC_GET_RTC_SEC1970; 259 RPC_SIZE(&msg) = 1U; 260 261 sc_call_rpc(ipc, &msg, SC_FALSE); 262 263 if (sec != NULL) 264 *sec = RPC_U32(&msg, 0U); 265 266 result = RPC_R8(&msg); 267 return (sc_err_t)result; 268 } 269 270 sc_err_t sc_timer_set_rtc_alarm(sc_ipc_t ipc, uint16_t year, uint8_t mon, 271 uint8_t day, uint8_t hour, uint8_t min, 272 uint8_t sec) 273 { 274 sc_rpc_msg_t msg; 275 uint8_t result; 276 277 RPC_VER(&msg) = SC_RPC_VERSION; 278 RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_TIMER; 279 RPC_FUNC(&msg) = (uint8_t)TIMER_FUNC_SET_RTC_ALARM; 280 RPC_U16(&msg, 0U) = (uint16_t)year; 281 RPC_U8(&msg, 2U) = (uint8_t)mon; 282 RPC_U8(&msg, 3U) = (uint8_t)day; 283 RPC_U8(&msg, 4U) = (uint8_t)hour; 284 RPC_U8(&msg, 5U) = (uint8_t)min; 285 RPC_U8(&msg, 6U) = (uint8_t)sec; 286 RPC_SIZE(&msg) = 3U; 287 288 sc_call_rpc(ipc, &msg, SC_FALSE); 289 290 result = RPC_R8(&msg); 291 return (sc_err_t)result; 292 } 293 294 sc_err_t sc_timer_set_rtc_periodic_alarm(sc_ipc_t ipc, uint32_t sec) 295 { 296 sc_rpc_msg_t msg; 297 uint8_t result; 298 299 RPC_VER(&msg) = SC_RPC_VERSION; 300 RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_TIMER; 301 RPC_FUNC(&msg) = (uint8_t)TIMER_FUNC_SET_RTC_PERIODIC_ALARM; 302 RPC_U32(&msg, 0U) = (uint32_t)sec; 303 RPC_SIZE(&msg) = 2U; 304 305 sc_call_rpc(ipc, &msg, SC_FALSE); 306 307 result = RPC_R8(&msg); 308 return (sc_err_t)result; 309 } 310 311 sc_err_t sc_timer_cancel_rtc_alarm(sc_ipc_t ipc) 312 { 313 sc_rpc_msg_t msg; 314 uint8_t result; 315 316 RPC_VER(&msg) = SC_RPC_VERSION; 317 RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_TIMER; 318 RPC_FUNC(&msg) = (uint8_t)TIMER_FUNC_CANCEL_RTC_ALARM; 319 RPC_SIZE(&msg) = 1U; 320 321 sc_call_rpc(ipc, &msg, SC_FALSE); 322 323 result = RPC_R8(&msg); 324 return (sc_err_t)result; 325 } 326 327 sc_err_t sc_timer_set_rtc_calb(sc_ipc_t ipc, int8_t count) 328 { 329 sc_rpc_msg_t msg; 330 uint8_t result; 331 332 RPC_VER(&msg) = SC_RPC_VERSION; 333 RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_TIMER; 334 RPC_FUNC(&msg) = (uint8_t)TIMER_FUNC_SET_RTC_CALB; 335 RPC_I8(&msg, 0U) = (int8_t) count; 336 RPC_SIZE(&msg) = 2U; 337 338 sc_call_rpc(ipc, &msg, SC_FALSE); 339 340 result = RPC_R8(&msg); 341 return (sc_err_t)result; 342 } 343 344 sc_err_t sc_timer_set_sysctr_alarm(sc_ipc_t ipc, uint64_t ticks) 345 { 346 sc_rpc_msg_t msg; 347 uint8_t result; 348 349 RPC_VER(&msg) = SC_RPC_VERSION; 350 RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_TIMER; 351 RPC_FUNC(&msg) = (uint8_t)TIMER_FUNC_SET_SYSCTR_ALARM; 352 RPC_U32(&msg, 0U) = (uint32_t)(ticks >> 32U); 353 RPC_U32(&msg, 4U) = (uint32_t)ticks; 354 RPC_SIZE(&msg) = 3U; 355 356 sc_call_rpc(ipc, &msg, SC_FALSE); 357 358 result = RPC_R8(&msg); 359 return (sc_err_t)result; 360 } 361 362 sc_err_t sc_timer_set_sysctr_periodic_alarm(sc_ipc_t ipc, uint64_t ticks) 363 { 364 sc_rpc_msg_t msg; 365 uint8_t result; 366 367 RPC_VER(&msg) = SC_RPC_VERSION; 368 RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_TIMER; 369 RPC_FUNC(&msg) = (uint8_t)TIMER_FUNC_SET_SYSCTR_PERIODIC_ALARM; 370 RPC_U32(&msg, 0U) = (uint32_t)(ticks >> 32U); 371 RPC_U32(&msg, 4U) = (uint32_t)ticks; 372 RPC_SIZE(&msg) = 3U; 373 374 sc_call_rpc(ipc, &msg, SC_FALSE); 375 376 result = RPC_R8(&msg); 377 return (sc_err_t)result; 378 } 379 380 sc_err_t sc_timer_cancel_sysctr_alarm(sc_ipc_t ipc) 381 { 382 sc_rpc_msg_t msg; 383 uint8_t result; 384 385 RPC_VER(&msg) = SC_RPC_VERSION; 386 RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_TIMER; 387 RPC_FUNC(&msg) = (uint8_t)TIMER_FUNC_CANCEL_SYSCTR_ALARM; 388 RPC_SIZE(&msg) = 1U; 389 390 sc_call_rpc(ipc, &msg, SC_FALSE); 391 392 result = RPC_R8(&msg); 393 return (sc_err_t)result; 394 } 395 396 /**@}*/ 397