sci_timer_api.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. /*
  2. * Copyright (C) 2016 Freescale Semiconductor, Inc.
  3. * Copyright 2017-2019 NXP
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. /*!
  8. * Header file containing the public API for the System Controller (SC)
  9. * Timer function.
  10. *
  11. * @addtogroup TIMER_SVC (SVC) Timer Service
  12. *
  13. * Module for the Timer service. This includes support for the watchdog, RTC,
  14. * and system counter. Note every resource partition has a watchdog it can
  15. * use.
  16. *
  17. * @{
  18. */
  19. #ifndef SC_TIMER_API_H
  20. #define SC_TIMER_API_H
  21. /* Includes */
  22. #include <sci/sci_types.h>
  23. /* Defines */
  24. /*!
  25. * @name Defines for type widths
  26. */
  27. /*@{*/
  28. #define SC_TIMER_ACTION_W 3U /* Width of sc_timer_wdog_action_t */
  29. /*@}*/
  30. /*!
  31. * @name Defines for sc_timer_wdog_action_t
  32. */
  33. /*@{*/
  34. #define SC_TIMER_WDOG_ACTION_PARTITION 0U /* Reset partition */
  35. #define SC_TIMER_WDOG_ACTION_WARM 1U /* Warm reset system */
  36. #define SC_TIMER_WDOG_ACTION_COLD 2U /* Cold reset system */
  37. #define SC_TIMER_WDOG_ACTION_BOARD 3U /* Reset board */
  38. #define SC_TIMER_WDOG_ACTION_IRQ 4U /* Only generate IRQs */
  39. /*@}*/
  40. /* Types */
  41. /*!
  42. * This type is used to configure the watchdog action.
  43. */
  44. typedef uint8_t sc_timer_wdog_action_t;
  45. /*!
  46. * This type is used to declare a watchdog time value in milliseconds.
  47. */
  48. typedef uint32_t sc_timer_wdog_time_t;
  49. /* Functions */
  50. /*!
  51. * @name Watchdog Functions
  52. * @{
  53. */
  54. /*!
  55. * This function sets the watchdog timeout in milliseconds. If not
  56. * set then the timeout defaults to the max. Once locked this value
  57. * cannot be changed.
  58. *
  59. * @param[in] ipc IPC handle
  60. * @param[in] timeout timeout period for the watchdog
  61. *
  62. * @return Returns an error code (SC_ERR_NONE = success, SC_ERR_LOCKED
  63. * = locked).
  64. */
  65. sc_err_t sc_timer_set_wdog_timeout(sc_ipc_t ipc, sc_timer_wdog_time_t timeout);
  66. /*!
  67. * This function sets the watchdog pre-timeout in milliseconds. If not
  68. * set then the pre-timeout defaults to the max. Once locked this value
  69. * cannot be changed.
  70. *
  71. * @param[in] ipc IPC handle
  72. * @param[in] pre_timeout pre-timeout period for the watchdog
  73. *
  74. * When the pre-timeout expires an IRQ will be generated. Note this timeout
  75. * clears when the IRQ is triggered. An IRQ is generated for the failing
  76. * partition and all of its child partitions.
  77. *
  78. * @return Returns an error code (SC_ERR_NONE = success).
  79. */
  80. sc_err_t sc_timer_set_wdog_pre_timeout(sc_ipc_t ipc,
  81. sc_timer_wdog_time_t pre_timeout);
  82. /*!
  83. * This function starts the watchdog.
  84. *
  85. * @param[in] ipc IPC handle
  86. * @param[in] lock boolean indicating the lock status
  87. *
  88. * @return Returns an error code (SC_ERR_NONE = success).
  89. *
  90. * If \a lock is set then the watchdog cannot be stopped or the timeout
  91. * period changed.
  92. */
  93. sc_err_t sc_timer_start_wdog(sc_ipc_t ipc, sc_bool_t lock);
  94. /*!
  95. * This function stops the watchdog if it is not locked.
  96. *
  97. * @param[in] ipc IPC handle
  98. *
  99. * @return Returns an error code (SC_ERR_NONE = success, SC_ERR_LOCKED
  100. * = locked).
  101. */
  102. sc_err_t sc_timer_stop_wdog(sc_ipc_t ipc);
  103. /*!
  104. * This function pings (services, kicks) the watchdog resetting the time
  105. * before expiration back to the timeout.
  106. *
  107. * @param[in] ipc IPC handle
  108. *
  109. * @return Returns an error code (SC_ERR_NONE = success).
  110. */
  111. sc_err_t sc_timer_ping_wdog(sc_ipc_t ipc);
  112. /*!
  113. * This function gets the status of the watchdog. All arguments are
  114. * in milliseconds.
  115. *
  116. * @param[in] ipc IPC handle
  117. * @param[out] timeout pointer to return the timeout
  118. * @param[out] max_timeout pointer to return the max timeout
  119. * @param[out] remaining_time pointer to return the time remaining
  120. * until trigger
  121. *
  122. * @return Returns an error code (SC_ERR_NONE = success).
  123. */
  124. sc_err_t sc_timer_get_wdog_status(sc_ipc_t ipc,
  125. sc_timer_wdog_time_t *timeout,
  126. sc_timer_wdog_time_t *max_timeout,
  127. sc_timer_wdog_time_t *remaining_time);
  128. /*!
  129. * This function gets the status of the watchdog of a partition. All
  130. * arguments are in milliseconds.
  131. *
  132. * @param[in] ipc IPC handle
  133. * @param[in] pt partition to query
  134. * @param[out] enb pointer to return enable status
  135. * @param[out] timeout pointer to return the timeout
  136. * @param[out] remaining_time pointer to return the time remaining
  137. * until trigger
  138. *
  139. * @return Returns an error code (SC_ERR_NONE = success).
  140. */
  141. sc_err_t sc_timer_pt_get_wdog_status(sc_ipc_t ipc, sc_rm_pt_t pt,
  142. sc_bool_t *enb,
  143. sc_timer_wdog_time_t *timeout,
  144. sc_timer_wdog_time_t *remaining_time);
  145. /*!
  146. * This function configures the action to be taken when a watchdog
  147. * expires.
  148. *
  149. * @param[in] ipc IPC handle
  150. * @param[in] pt partition to affect
  151. * @param[in] action action to take
  152. *
  153. * Default action is inherited from the parent.
  154. *
  155. * @return Returns an error code (SC_ERR_NONE = success).
  156. *
  157. * Return errors:
  158. * - SC_ERR_PARM if invalid parameters,
  159. * - SC_ERR_NOACCESS if caller's partition is not the SYSTEM owner,
  160. * - SC_ERR_LOCKED if the watchdog is locked
  161. */
  162. sc_err_t sc_timer_set_wdog_action(sc_ipc_t ipc,
  163. sc_rm_pt_t pt, sc_timer_wdog_action_t action);
  164. /* @} */
  165. /*!
  166. * @name Real-Time Clock (RTC) Functions
  167. * @{
  168. */
  169. /*!
  170. * This function sets the RTC time. Only the owner of the SC_R_SYSTEM
  171. * resource can set the time.
  172. *
  173. * @param[in] ipc IPC handle
  174. * @param[in] year year (min 1970)
  175. * @param[in] mon month (1-12)
  176. * @param[in] day day of the month (1-31)
  177. * @param[in] hour hour (0-23)
  178. * @param[in] min minute (0-59)
  179. * @param[in] sec second (0-59)
  180. *
  181. * @return Returns an error code (SC_ERR_NONE = success).
  182. *
  183. * Return errors:
  184. * - SC_ERR_PARM if invalid time/date parameters,
  185. * - SC_ERR_NOACCESS if caller's partition is not the SYSTEM owner
  186. */
  187. sc_err_t sc_timer_set_rtc_time(sc_ipc_t ipc, uint16_t year, uint8_t mon,
  188. uint8_t day, uint8_t hour, uint8_t min,
  189. uint8_t sec);
  190. /*!
  191. * This function gets the RTC time.
  192. *
  193. * @param[in] ipc IPC handle
  194. * @param[out] year pointer to return year (min 1970)
  195. * @param[out] mon pointer to return month (1-12)
  196. * @param[out] day pointer to return day of the month (1-31)
  197. * @param[out] hour pointer to return hour (0-23)
  198. * @param[out] min pointer to return minute (0-59)
  199. * @param[out] sec pointer to return second (0-59)
  200. *
  201. * @return Returns an error code (SC_ERR_NONE = success).
  202. */
  203. sc_err_t sc_timer_get_rtc_time(sc_ipc_t ipc, uint16_t *year, uint8_t *mon,
  204. uint8_t *day, uint8_t *hour, uint8_t *min,
  205. uint8_t *sec);
  206. /*!
  207. * This function gets the RTC time in seconds since 1/1/1970.
  208. *
  209. * @param[in] ipc IPC handle
  210. * @param[out] sec pointer to return second
  211. *
  212. * @return Returns an error code (SC_ERR_NONE = success).
  213. */
  214. sc_err_t sc_timer_get_rtc_sec1970(sc_ipc_t ipc, uint32_t *sec);
  215. /*!
  216. * This function sets the RTC alarm.
  217. *
  218. * @param[in] ipc IPC handle
  219. * @param[in] year year (min 1970)
  220. * @param[in] mon month (1-12)
  221. * @param[in] day day of the month (1-31)
  222. * @param[in] hour hour (0-23)
  223. * @param[in] min minute (0-59)
  224. * @param[in] sec second (0-59)
  225. *
  226. * Note this alarm setting clears when the alarm is triggered.
  227. *
  228. * @return Returns an error code (SC_ERR_NONE = success).
  229. *
  230. * Return errors:
  231. * - SC_ERR_PARM if invalid time/date parameters
  232. */
  233. sc_err_t sc_timer_set_rtc_alarm(sc_ipc_t ipc, uint16_t year, uint8_t mon,
  234. uint8_t day, uint8_t hour, uint8_t min,
  235. uint8_t sec);
  236. /*!
  237. * This function sets the RTC alarm (periodic mode).
  238. *
  239. * @param[in] ipc IPC handle
  240. * @param[in] sec period in seconds
  241. *
  242. * @return Returns an error code (SC_ERR_NONE = success).
  243. *
  244. * Return errors:
  245. * - SC_ERR_PARM if invalid time/date parameters
  246. */
  247. sc_err_t sc_timer_set_rtc_periodic_alarm(sc_ipc_t ipc, uint32_t sec);
  248. /*!
  249. * This function cancels the RTC alarm.
  250. *
  251. * @param[in] ipc IPC handle
  252. *
  253. * Note this alarm setting clears when the alarm is triggered.
  254. *
  255. * @return Returns an error code (SC_ERR_NONE = success).
  256. *
  257. * Return errors:
  258. * - SC_ERR_PARM if invalid time/date parameters
  259. */
  260. sc_err_t sc_timer_cancel_rtc_alarm(sc_ipc_t ipc);
  261. /*!
  262. * This function sets the RTC calibration value. Only the owner of the SC_R_SYSTEM
  263. * resource can set the calibration.
  264. *
  265. * @param[in] ipc IPC handle
  266. * @param[in] count calbration count (-16 to 15)
  267. *
  268. * The calibration value is a 5-bit value including the sign bit, which is
  269. * implemented in 2's complement. It is added or subtracted from the RTC on
  270. * a perdiodic basis, once per 32768 cycles of the RTC clock.
  271. *
  272. * @return Returns an error code (SC_ERR_NONE = success).
  273. */
  274. sc_err_t sc_timer_set_rtc_calb(sc_ipc_t ipc, int8_t count);
  275. /* @} */
  276. /*!
  277. * @name System Counter (SYSCTR) Functions
  278. * @{
  279. */
  280. /*!
  281. * This function sets the SYSCTR alarm.
  282. *
  283. * @param[in] ipc IPC handle
  284. * @param[in] ticks number of 8MHz cycles
  285. *
  286. * Note this alarm setting clears when the alarm is triggered.
  287. *
  288. * @return Returns an error code (SC_ERR_NONE = success).
  289. *
  290. * Return errors:
  291. * - SC_ERR_PARM if invalid time/date parameters
  292. */
  293. sc_err_t sc_timer_set_sysctr_alarm(sc_ipc_t ipc, uint64_t ticks);
  294. /*!
  295. * This function sets the SYSCTR alarm (periodic mode).
  296. *
  297. * @param[in] ipc IPC handle
  298. * @param[in] ticks number of 8MHz cycles
  299. *
  300. * @return Returns an error code (SC_ERR_NONE = success).
  301. *
  302. * Return errors:
  303. * - SC_ERR_PARM if invalid time/date parameters
  304. */
  305. sc_err_t sc_timer_set_sysctr_periodic_alarm(sc_ipc_t ipc, uint64_t ticks);
  306. /*!
  307. * This function cancels the SYSCTR alarm.
  308. *
  309. * @param[in] ipc IPC handle
  310. *
  311. * Note this alarm setting clears when the alarm is triggered.
  312. *
  313. * @return Returns an error code (SC_ERR_NONE = success).
  314. *
  315. * Return errors:
  316. * - SC_ERR_PARM if invalid time/date parameters
  317. */
  318. sc_err_t sc_timer_cancel_sysctr_alarm(sc_ipc_t ipc);
  319. /* @} */
  320. #endif /* SC_TIMER_API_H */
  321. /**@}*/