csl_rtc.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. /**
  2. * @file csl_rtc.h
  3. *
  4. * @brief
  5. * This is the main header file for the RTC Module which defines
  6. * all the data structures and exported API.
  7. *
  8. * \par
  9. * ============================================================================
  10. * @n (C) Copyright 2002-2011, Texas Instruments, Inc.
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. *
  16. * Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * Redistributions in binary form must reproduce the above copyright
  20. * notice, this list of conditions and the following disclaimer in the
  21. * documentation and/or other materials provided with the
  22. * distribution.
  23. *
  24. * Neither the name of Texas Instruments Incorporated nor the names of
  25. * its contributors may be used to endorse or promote products derived
  26. * from this software without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  29. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  30. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  31. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  32. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  33. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  34. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  35. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  36. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  37. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  38. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. */
  41. /** @defgroup CSL_RTC_API RTC
  42. *
  43. */
  44. #ifndef CSL_RTC_H_
  45. #define CSL_RTC_H_
  46. #ifdef __cplusplus
  47. extern "C" {
  48. #endif
  49. #include <ti/csl/soc.h>
  50. #include <ti/csl/csl.h>
  51. #include <ti/csl/cslr_rtc.h>
  52. /**
  53. @defgroup CSL_RTC_SYMBOL RTC Symbols Defined
  54. @ingroup CSL_RTC_API
  55. */
  56. /**
  57. @defgroup CSL_RTC_DATASTRUCT RTC Data Structures
  58. @ingroup CSL_RTC_API
  59. */
  60. /**
  61. @defgroup CSL_RTC_FUNCTION RTC Functions
  62. @ingroup CSL_RTC_API
  63. */
  64. /**
  65. @defgroup CSL_RTC_ENUM RTC Enumerated Data Types
  66. @ingroup CSL_RTC_API
  67. */
  68. /** @{ */
  69. /** @brief RTC KICK0 register UNLOCK key used to disable Write Protection. */
  70. #define CSL_RTC_KICK0_UNLOCK_KEY (0x83E70B13U)
  71. /** @brief RTC KICK0 register UNLOCK key used to disable Write Protection. */
  72. #define CSL_RTC_KICK1_UNLOCK_KEY (0x95A4F1E0U)
  73. /** @brief RTC KICK0 register LOCK key used to enable Write Protection. */
  74. #define CSL_RTC_KICK0_LOCK_KEY (0xFFFFFFFFU)
  75. /** @brief RTC KICK1 register LOCK key used to enable Write Protection. */
  76. #define CSL_RTC_KICK1_LOCK_KEY (0xFFFFFFFFU)
  77. /** @} */
  78. /** @brief Macro to wait till the RTC registers are free to access.
  79. Loops continuously till the RTC is busy updating an event. */
  80. #define CSL_RTC_WAIT_FOR_WRITE while(0x1U == \
  81. (CSL_FEXT(hRtc->STS, \
  82. RTC_STS_BUSY))){}
  83. /** @brief Macro to identify the correct Alarm Seconds register based on Alarm
  84. Number passed. */
  85. #define CSL_RTC_MAKE_ALARM_SECONDS(alarmNum) ((1U == (alarmNum)) ? \
  86. hRtc->ALARM_SECONDS: hRtc->ALARM2_SECONDS)
  87. /** @brief Macro to identify the correct Alarm Minutes register based on Alarm
  88. Number passed. */
  89. #define CSL_RTC_MAKE_ALARM_MINUTES(alarmNum) ((1U == (alarmNum)) ? \
  90. hRtc->ALARM_MINUTES: hRtc->ALARM2_MINUTES)
  91. /** @brief Macro to identify the correct Alarm Hours register based on Alarm
  92. Number passed. */
  93. #define CSL_RTC_MAKE_ALARM_HOURS(alarmNum) (((alarmNum) == 1) ? \
  94. hRtc->ALARM_HOURS: hRtc->ALARM2_HOURS)
  95. /** @brief Macro to identify the correct Alarm Days register based on Alarm
  96. Number passed. */
  97. #define CSL_RTC_MAKE_ALARM_DAYS(alarmNum) (((alarmNum) == 1) ? \
  98. hRtc->ALARM_DAYS: hRtc->ALARM2_DAYS)
  99. /** @brief Macro to identify the correct Alarm Months register based on Alarm
  100. Number passed. */
  101. #define CSL_RTC_MAKE_ALARM_MONTHS(alarmNum) (((alarmNum) == 1) ? \
  102. hRtc->ALARM_MONTHS: hRtc->ALARM2_MONTHS)
  103. /** @brief Macro to identify the correct Alarm Years register based on Alarm
  104. Number passed. */
  105. #define CSL_RTC_MAKE_ALARM_YEARS(alarmNum) (((alarmNum) == 1) ? \
  106. hRtc->ALARM_YEARS: hRtc->ALARM2_YEARS)
  107. /**
  108. @addtogroup CSL_RTC_ENUM
  109. @{
  110. */
  111. /**
  112. * General purpose global type def declarations
  113. */
  114. /** @brief Enumerates the different clock sources for RTC */
  115. typedef enum
  116. {
  117. /**
  118. * @brief External Clock source for the RTC module
  119. */
  120. CSL_RTC_CLK_SRC_INTERNAL = 0x0U,
  121. /**
  122. * @brief Internal clock source for the RTC module
  123. */
  124. CSL_RTC_CLK_SRC_EXTERNAL = 0x1U
  125. } CSL_rtcClkSrc;
  126. /** @brief Enumerates the different possible Timer Interrupt types */
  127. typedef enum
  128. {
  129. /**
  130. * @brief Periodic Timer Interrupt for Every Second
  131. */
  132. CSL_RTC_TIMER_INTR_MASK_EVERY_SEC = 0x0U,
  133. /**
  134. * @brief Periodic Timer Interrupt for Every Minute
  135. */
  136. CSL_RTC_TIMER_INTR_MASK_EVERY_MIN = 0x1U,
  137. /**
  138. * @brief Periodic Timer Interrupt for Every Hour
  139. */
  140. CSL_RTC_TIMER_INTR_MASK_EVERY_HR = 0x2U,
  141. /**
  142. * @brief Periodic Timer Interrupt for Every Day
  143. */
  144. CSL_RTC_TIMER_INTR_MASK_EVERY_DAY = 0x3U
  145. } CSL_rtcTimerIntrMask;
  146. /** @brief Enumerates the RTC Timer Interrupt Status. */
  147. typedef enum
  148. {
  149. /**
  150. * @brief Indicates 1 Day Interrupt Status
  151. */
  152. CSL_RTC_TIMER_INTR_STS_ONE_DAY = CSL_RTC_STS_EVT_1D_MASK,
  153. /**
  154. * @brief Indicates 1 Hour Interrupt Status
  155. */
  156. CSL_RTC_TIMER_INTR_STS_ONE_HR = CSL_RTC_STS_EVT_1H_MASK,
  157. /**
  158. * @brief Indicates 1 Minute Interrupt Status
  159. */
  160. CSL_RTC_TIMER_INTR_STS_ONE_MIN = CSL_RTC_STS_EVT_1M_MASK,
  161. /**
  162. * @brief Indicates 1 Second Interrupt Status
  163. */
  164. CSL_RTC_TIMER_INTR_STS_ONE_SEC = CSL_RTC_STS_EVT_1S_MASK,
  165. /**
  166. * @brief Mask value to determine occurrence of a Timer event
  167. */
  168. CSL_RTC_TIMER_INTR_STS_ALL = (CSL_RTC_STS_EVT_1D_MASK |
  169. CSL_RTC_STS_EVT_1H_MASK |
  170. CSL_RTC_STS_EVT_1M_MASK |
  171. CSL_RTC_STS_EVT_1S_MASK)
  172. } CSL_rtcTimerIntrSts;
  173. /** @brief Enumerates the RTC Alarm Interrupt Status. */
  174. typedef enum
  175. {
  176. /**
  177. * @brief Indicates the ALARM Interrupt has occurred
  178. */
  179. CSL_RTC_ALARM_INTR_STS_ALARM = CSL_RTC_STS_ALARM_MASK,
  180. /**
  181. * @brief Indicates ALARM2 Interrupt has occurred
  182. */
  183. CSL_RTC_ALARM_INTR_STS_ALARM2 = CSL_RTC_STS_ALARM2_MASK,
  184. /**
  185. * @brief Mask value to determine occurrence of an alarm event
  186. */
  187. CSL_RTC_ALARM_INTR_STS_ALL = (CSL_RTC_STS_ALARM_MASK |
  188. CSL_RTC_STS_ALARM2_MASK)
  189. } CSL_rtcAlarmIntrSts;
  190. /** @brief Enumerates the different Alarm events */
  191. typedef enum
  192. {
  193. /**
  194. * @brief Minimum Alarm Event Number
  195. */
  196. CSL_RTC_ALARM_NUM_MIN = 1U,
  197. /**
  198. * @brief Alarm Event number 1
  199. */
  200. CSL_RTC_ALARM_NUM_1 = CSL_RTC_ALARM_NUM_MIN,
  201. /**
  202. * @brief Alarm Event number 2
  203. */
  204. CSL_RTC_ALARM_NUM_2 = CSL_RTC_ALARM_NUM_1 + 1U,
  205. /**
  206. * @brief Maximum Alarm Event Number
  207. */
  208. CSL_RTC_ALARM_NUM_MAX = CSL_RTC_ALARM_NUM_2
  209. } CSL_rtcAlarmNum;
  210. /** @brief Enumerates the different idle modes supported */
  211. typedef enum
  212. {
  213. /**
  214. * @brief Force Idle mode
  215. */
  216. CSL_RTC_IDLE_MODE_FORCE_IDLE = 0x0U,
  217. /**
  218. * @brief No idle mode
  219. */
  220. CSL_RTC_IDLE_MODE_NO_IDLE = 0x1U,
  221. /**
  222. * @brief Smart idle mode
  223. */
  224. CSL_RTC_IDLE_MODE_SMART_IDLE = 0x2U,
  225. /**
  226. * @brief Smart idle Wakeup mode
  227. */
  228. CSL_RTC_IDLE_MODE_SMART_IDLE_WAKEUP = 0x3U
  229. } CSL_rtcIdleMode;
  230. /** @brief Enumerates the different wakeup sources for RTC. */
  231. typedef enum
  232. {
  233. /**
  234. * @brief Minimum Wakeup event source used for validation
  235. */
  236. CSL_RTC_WAKEUP_EVT_SRC_MIN = 0U,
  237. /**
  238. * @brief Timer Wakeup event source
  239. */
  240. CSL_RTC_WAKEUP_EVT_SRC_TIMER = CSL_RTC_WAKEUP_EVT_SRC_MIN,
  241. /**
  242. * @brief Alarm Wakeup event source
  243. */
  244. CSL_RTC_WAKEUP_EVT_SRC_ALARM = CSL_RTC_WAKEUP_EVT_SRC_TIMER + 1U,
  245. /**
  246. * @brief Minimum Wakeup event source used for validation
  247. */
  248. CSL_RTC_WAKEUP_EVT_SRC_MAX = CSL_RTC_WAKEUP_EVT_SRC_ALARM
  249. } CSL_rtcWakeupEvtSrc;
  250. /** @brief Enumerates the different external Wakeup event sources which
  251. can be used to wakeup the RTC module. */
  252. typedef enum
  253. {
  254. /**
  255. * @brief Minimum External Wakeup Source
  256. */
  257. CSL_RTC_EXT_WAKEUP_SRC_MIN = 0U,
  258. /**
  259. * @brief External Wakeup Source 0 used to wakeup RTC
  260. */
  261. CSL_RTC_EXT_WAKEUP_SRC_0 = CSL_RTC_EXT_WAKEUP_SRC_MIN,
  262. /**
  263. * @brief External Wakeup Source 1 used to wakeup RTC
  264. */
  265. CSL_RTC_EXT_WAKEUP_SRC_1 = CSL_RTC_EXT_WAKEUP_SRC_0 + 1U,
  266. /**
  267. * @brief External Wakeup Source 2 used to wakeup RTC
  268. */
  269. CSL_RTC_EXT_WAKEUP_SRC_2 = CSL_RTC_EXT_WAKEUP_SRC_1 + 1U,
  270. /**
  271. * @brief External Wakeup Source 3 used to wakeup RTC
  272. */
  273. CSL_RTC_EXT_WAKEUP_SRC_3 = CSL_RTC_EXT_WAKEUP_SRC_2 + 1U,
  274. /**
  275. * @brief Maximum External Wakeup Source
  276. */
  277. CSL_RTC_EXT_WAKEUP_SRC_MAX = CSL_RTC_EXT_WAKEUP_SRC_3
  278. } CSL_rtcExtWakeupSrc;
  279. /** @brief Enumerates the external event polarity */
  280. typedef enum
  281. {
  282. /**
  283. * @brief RTC WAKEUP EVENT POLARITY ACTIVE HIGH
  284. */
  285. CSL_RTC_WAKEUP_EVT_POL_ACTV_HIGH = 0x0U,
  286. /**
  287. * @brief RTC WAKEUP EVENT POLARITY ACTIVE LOW
  288. */
  289. CSL_RTC_WAKEUP_EVT_POL_ACTV_LOW = 0x1U
  290. } CSL_rtcWakeupEvtPol;
  291. /** @brief Enumerates the different scratch pad registers. */
  292. typedef enum
  293. {
  294. /**
  295. * @brief Minimum Scratch pad register number
  296. */
  297. CSL_RTC_SCRATCH_PAD_MIN = 0U,
  298. /**
  299. * @brief Scratch pad register number 0
  300. */
  301. CSL_RTC_SCRATCH_PAD_0 = CSL_RTC_SCRATCH_PAD_MIN,
  302. /**
  303. * @brief Scratch pad register number 1
  304. */
  305. CSL_RTC_SCRATCH_PAD_1 = CSL_RTC_SCRATCH_PAD_0 + 1U,
  306. /**
  307. * @brief Scratch pad register number 2
  308. */
  309. CSL_RTC_SCRATCH_PAD_2 = CSL_RTC_SCRATCH_PAD_1 + 1U,
  310. /**
  311. * @brief Maximum Scratch pad register number
  312. */
  313. CSL_RTC_SCRATCH_PAD_MAX = CSL_RTC_SCRATCH_PAD_2
  314. } CSL_rtcScratchPadReg;
  315. /** @brief Enumerates the Feedback resistor types */
  316. typedef enum
  317. {
  318. /**
  319. * @brief Internal oscillator feedback resistor
  320. */
  321. CSL_RTC_FEEDBACK_RESISTOR_INTERNAL = 0x0U,
  322. /**
  323. * @brief External oscillator feedback resistor
  324. */
  325. CSL_RTC_FEEDBACK_RESISTOR_EXTERNAL = 0x1U
  326. } CSL_rtcFeedbackResistor;
  327. /** @brief Enumerates the different Time modes. */
  328. typedef enum
  329. {
  330. /**
  331. * @brief Minimum time mode used for input validation
  332. */
  333. CSL_RTC_TIME_MODE_MIN = 0U,
  334. /**
  335. * @brief 24 Hour Time mode
  336. */
  337. CSL_RTC_TIME_MODE_24_HR = CSL_RTC_TIME_MODE_MIN,
  338. /**
  339. * @brief 24 Hour Time mode
  340. */
  341. CSL_RTC_TIME_MODE_12_HR = CSL_RTC_TIME_MODE_24_HR + 1U,
  342. /**
  343. * @brief Maximum time mode used for input validation
  344. */
  345. CSL_RTC_TIME_MODE_MAX = CSL_RTC_TIME_MODE_24_HR
  346. } CSL_rtcTimeMode;
  347. /** @brief Enumerates the different Time Meridiem formats. */
  348. typedef enum
  349. {
  350. /**
  351. * @brief Minimum Time meridiem mode
  352. */
  353. CSL_RTC_TIME_MERIDIEM_MIN = 0U,
  354. /**
  355. * @brief AM (Ante-Meridiem) Time Format
  356. */
  357. CSL_RTC_TIME_MERIDIEM_AM = CSL_RTC_TIME_MERIDIEM_MIN,
  358. /**
  359. * @brief PM (Post-Meridiem) Time Format
  360. */
  361. CSL_RTC_TIME_MERIDIEM_PM = CSL_RTC_TIME_MERIDIEM_AM + 1U,
  362. /**
  363. * @brief Maximum Time meridiem mode
  364. */
  365. CSL_RTC_TIME_MERIDIEM_MAX = CSL_RTC_TIME_MERIDIEM_PM
  366. } CSL_rtcTimeMeridiem;
  367. /** @brief enumerates the different day of the week */
  368. typedef enum
  369. {
  370. /**
  371. * @brief Minimum value of the Week Day
  372. */
  373. CSL_RTC_WEEK_DAY_MIN = 0U,
  374. /**
  375. * @brief Indicates Sunday
  376. */
  377. CSL_RTC_WEEK_DAY_SUNDAY = CSL_RTC_WEEK_DAY_MIN,
  378. /**
  379. * @brief Indicates Monday
  380. */
  381. CSL_RTC_WEEK_DAY_MONDAY = CSL_RTC_WEEK_DAY_SUNDAY + 1U,
  382. /**
  383. * @brief Indicates Tuesday
  384. */
  385. CSL_RTC_WEEK_DAY_TUESDAY = CSL_RTC_WEEK_DAY_MONDAY + 1U,
  386. /**
  387. * @brief Indicates Wednesday
  388. */
  389. CSL_RTC_WEEK_DAY_WEDNESDAY = CSL_RTC_WEEK_DAY_TUESDAY + 1U,
  390. /**
  391. * @brief Indicates Thursday
  392. */
  393. CSL_RTC_WEEK_DAY_THURSDAY = CSL_RTC_WEEK_DAY_WEDNESDAY + 1U,
  394. /**
  395. * @brief Indicates Friday
  396. */
  397. CSL_RTC_WEEK_DAY_FRIDAY = CSL_RTC_WEEK_DAY_THURSDAY + 1U,
  398. /**
  399. * @brief Indicates Saturday
  400. */
  401. CSL_RTC_WEEK_DAY_SATURDAY = CSL_RTC_WEEK_DAY_FRIDAY + 1U,
  402. /**
  403. * @brief Maximum value of the Week Day
  404. */
  405. CSL_RTC_WEEK_DAY_MAX = CSL_RTC_WEEK_DAY_SATURDAY
  406. } CSL_rtcWeekDay;
  407. /**
  408. @}
  409. */
  410. /** @addtogroup CSL_RTC_DATASTRUCT
  411. @{ */
  412. /** @brief Structure representing the Time information. */
  413. typedef struct
  414. {
  415. /** Time value in hours. */
  416. Uint32 hours;
  417. /** Time value in minutes. */
  418. Uint32 minutes;
  419. /** Time value in seconds */
  420. Uint32 seconds;
  421. /** Time value in nano seconds */
  422. Uint32 nanoSec;
  423. /** Hour Mode which can take any of the two values
  424. from the enum #CSL_rtcTimeMode to represent either
  425. 12 Hour mode or 24 Hour mode. */
  426. CSL_rtcTimeMode timeMode;
  427. /** Meridiem type to indicate either AM mode or PM mode which
  428. can take any of the values from the following enum
  429. #CSL_rtcTimeMeridiem */
  430. CSL_rtcTimeMeridiem meridiemMode;
  431. } CSL_rtcTimeObj;
  432. /** @brief Structure representing the Date information. */
  433. typedef struct
  434. {
  435. /** Value to represent the Day. */
  436. Uint32 day;
  437. /** Value to represent the Month. */
  438. Uint32 month;
  439. /** Value to represent the Year. */
  440. Uint32 year;
  441. /** Value to represent the day of the week which can
  442. can take any of the values from the following enum
  443. #CSL_rtcWeekDay */
  444. CSL_rtcWeekDay weekDay;
  445. } CSL_rtcDateObj;
  446. /**
  447. * @brief This data type is the handle to the CSL of the RTC
  448. */
  449. typedef CSL_RtcRegs *CSL_rtcHandle;
  450. /**
  451. @}
  452. */
  453. /**
  454. @addtogroup CSL_RTC_SYMBOL
  455. @{
  456. */
  457. /**
  458. @}
  459. */
  460. /** @addtogroup CSL_RTC_FUNCTION
  461. @{ */
  462. /*******************************************************************************
  463. * Timer global function declarations
  464. ******************************************************************************/
  465. /**
  466. @}
  467. */
  468. #ifdef __cplusplus
  469. }
  470. #endif
  471. #endif /* CSL_RTC_H_ */