csl_rtcAux.h 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461
  1. /**
  2. * @file csl_rtcAux.h
  3. *
  4. * @brief
  5. * This is the RTC Auxilary Header File which exposes the various
  6. * CSL Functional Layer API's to configure the RTC Module.
  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. #ifndef CSL_RTCAUX_H
  42. #define CSL_RTCAUX_H
  43. #include <ti/csl/csl_rtc.h>
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. /******************************************************************************\
  48. * global macro declarations
  49. \******************************************************************************/
  50. /** @addtogroup CSL_RTC_ENUM
  51. @{ */
  52. /**
  53. @}
  54. */
  55. /** @addtogroup CSL_RTC_FUNCTION
  56. @{ */
  57. /** ============================================================================
  58. * @n@b CSL_rtcBcdToDec
  59. *
  60. * @b Description
  61. * @n This API converts the input BCD number to its decimal equivalent number.
  62. *
  63. * @b Arguments
  64. @verbatim
  65. bcdNum The value that holds the number in BCD format.
  66. @endverbatim
  67. *
  68. * <b> Return Value </b>
  69. * @n None
  70. *
  71. * <b> Pre Condition </b>
  72. * @n None
  73. *
  74. * <b> Post Condition </b>
  75. * @n None
  76. *
  77. * @b Example
  78. * @verbatim
  79. bdcToDec = CSL_rtcBcdToDec(hRtc); // Convert BDC to decimal
  80. @endverbatim
  81. * =============================================================================
  82. */
  83. static inline Uint32 CSL_rtcBcdToDec(Uint32 bcdNum)
  84. {
  85. Uint32 decNum = 0U;
  86. Uint32 multiplier = 1U;
  87. while(bcdNum > 0U)
  88. {
  89. decNum += (bcdNum & 0x0FU) * multiplier;
  90. multiplier = multiplier * 10U;
  91. bcdNum = bcdNum >> 0x4U;
  92. }
  93. return decNum;
  94. }
  95. /** ============================================================================
  96. * @n@b CSL_rtcDecToBcd
  97. *
  98. * @b Description
  99. * @n This API converts the input decimal number to its BCD equivalent number.
  100. *
  101. * @b Arguments
  102. @verbatim
  103. decNum The value that holds the number in Hexadecimal format.
  104. @endverbatim
  105. *
  106. * <b> Return Value </b>
  107. * @n None
  108. *
  109. * <b> Pre Condition </b>
  110. * @n None
  111. *
  112. * <b> Post Condition </b>
  113. * @n None
  114. *
  115. * @b Example
  116. * @verbatim
  117. decToBcd = CSL_rtcDecToBcd(hRtc); // Convert decimal to BCD
  118. @endverbatim
  119. * =============================================================================
  120. */
  121. static inline Uint32 CSL_rtcDecToBcd(Uint32 decNum)
  122. {
  123. Uint32 bcdNum = 0U;
  124. Uint32 digit = 0U;
  125. Uint32 count = 0U;
  126. while(decNum > 0U)
  127. {
  128. digit = (decNum % 10U);
  129. bcdNum += (digit << (0x4U * count));
  130. count++;
  131. decNum = (decNum/10U);
  132. }
  133. return bcdNum;
  134. }
  135. /** ============================================================================
  136. * @n@b CSL_rtcGetRevision
  137. *
  138. * @b Description
  139. * @n This function returns the revision Id of the module.
  140. *
  141. * @b Arguments
  142. @verbatim
  143. hRtc The handle of the RTC module.
  144. @endverbatim
  145. *
  146. * <b> Return Value </b>
  147. * @n The revision number of the RTC module. This will give the information
  148. regarding the major and minor revisions.
  149. - Bits[10:8] Major revision
  150. - Bits[7:6] Custom revision for a particular device
  151. - Bits[5:0] Minor revision
  152. *
  153. * <b> Pre Condition </b>
  154. * @n None
  155. *
  156. * <b> Post Condition </b>
  157. * @n None
  158. *
  159. * @b Writes
  160. * @n CSL_RTC_REVISION;
  161. *
  162. * @b Example
  163. * @verbatim
  164. CSL_rtcGetRevision(hRtc); // Read RTC revision
  165. @endverbatim
  166. * =============================================================================
  167. */
  168. static inline Uint32 CSL_rtcGetRevision(CSL_rtcHandle hRtc)
  169. {
  170. Uint32 revision = 0U;
  171. revision = hRtc->REVISION;
  172. return revision;
  173. }
  174. /** ============================================================================
  175. * @n@b CSL_rtcWriteProtectEnable
  176. *
  177. * @b Description
  178. * @n This function enables/disables the write-protection for RTC registers.
  179. *
  180. * @b Arguments
  181. @verbatim
  182. hRtc The handle of the RTC module.
  183. enableWriteProtect Value to specify whether write protection
  184. feature has to be enabled/disabled.
  185. 'enableWriteProtect' can take any of the two values
  186. - TRUE to enable write protection the register
  187. are locked from spurious writes.
  188. - FALSE to disable write protection to allow write
  189. access to RTC registers.
  190. @endverbatim
  191. *
  192. * <b> Return Value </b>
  193. * @n None
  194. *
  195. * <b> Pre Condition </b>
  196. * @n None
  197. *
  198. * <b> Post Condition </b>
  199. * @n None
  200. *
  201. * @b Writes
  202. * @n CSL_RTC_KICK0;
  203. * CSL_RTC_KICK1;
  204. *
  205. * @b Example
  206. * @verbatim
  207. CSL_rtcWriteProtectEnable(hRtc, enableWriteProtect);
  208. // Enables/Disables the write-protection for RTC registers.
  209. @endverbatim
  210. * =============================================================================
  211. */
  212. static inline void CSL_rtcWriteProtectEnable(CSL_rtcHandle hRtc,
  213. Uint32 enableWriteProtect)
  214. {
  215. if(TRUE == enableWriteProtect)
  216. {
  217. CSL_FINS(hRtc->KICK0, RTC_KICK0_KICK0, CSL_RTC_KICK0_LOCK_KEY);
  218. CSL_FINS(hRtc->KICK1, RTC_KICK1_KICK1, CSL_RTC_KICK1_LOCK_KEY);
  219. }
  220. else
  221. {
  222. CSL_FINS(hRtc->KICK0, RTC_KICK0_KICK0, CSL_RTC_KICK0_UNLOCK_KEY);
  223. CSL_FINS(hRtc->KICK1, RTC_KICK1_KICK1, CSL_RTC_KICK1_UNLOCK_KEY);
  224. }
  225. }
  226. /** ============================================================================
  227. * @n@b CSL_rtcClkSrcSelect
  228. *
  229. * @b Description
  230. * @n This API selects the clock source for the RTC module.
  231. *
  232. * @b Arguments
  233. @verbatim
  234. hRtc The handle of the RTC module.
  235. clkSrc This specifies the RTC Clock source to be selected 'clkSrc'
  236. can take one of the values from the following enum
  237. - #CSL_rtcClkSrc
  238. @endverbatim
  239. *
  240. * <b> Return Value </b>
  241. * @n None
  242. *
  243. * <b> Pre Condition </b>
  244. * @n None
  245. *
  246. * <b> Post Condition </b>
  247. * @n None
  248. *
  249. * @b Writes
  250. * @n CSL_RTC_OSC;
  251. *
  252. * @b Example
  253. * @verbatim
  254. CSL_rtcClkSrcSelect(hRtc, clkSrc); // Select the clock source
  255. @endverbatim
  256. * =============================================================================
  257. */
  258. static inline void CSL_rtcClkSrcSelect(CSL_rtcHandle hRtc,
  259. CSL_rtcClkSrc clkSrc)
  260. {
  261. /* Select the correct Clock Source */
  262. CSL_FINS(hRtc->OSC, RTC_OSC_K32CLK_SEL,
  263. clkSrc);
  264. if(CSL_RTC_CLK_SRC_INTERNAL == clkSrc)
  265. {
  266. /* Disable the XTAL Pins and apply high impedance. */
  267. CSL_FINS(hRtc->OSC, RTC_OSC_OSC32K_GZ, ((uint32_t)0x1U));
  268. }
  269. else
  270. {
  271. /* Enable the XTAL Pins to connect it to the external Clk source. */
  272. CSL_FINS(hRtc->OSC, RTC_OSC_OSC32K_GZ, ((uint32_t)0x0U));
  273. }
  274. }
  275. /** ============================================================================
  276. * @n@b CSL_rtcEnable
  277. *
  278. * @b Description
  279. * @n This API enables/disables the RTC module.
  280. *
  281. * @b Arguments
  282. @verbatim
  283. hRtc The handle of the RTC module.
  284. enableModule Value to indicate enabling/disabling of the module.
  285. 'enableModule' can take any of the two values:
  286. - TRUE to enable the module.
  287. - FALSE to disable the module.
  288. @endverbatim
  289. *
  290. * <b> Return Value </b>
  291. * @n None
  292. *
  293. * <b> Pre Condition </b>
  294. * @n None
  295. *
  296. * <b> Post Condition </b>
  297. * @n None
  298. *
  299. * @b Writes
  300. * @n CSL_RTC_CTRL;
  301. * @n CSL_RTC_OSC;
  302. *
  303. * @b Example
  304. * @verbatim
  305. CSL_rtcEnable(hRtc, enableModule); // Enable/Disable the RTC module.
  306. @endverbatim
  307. * =============================================================================
  308. */
  309. static inline void CSL_rtcEnable(CSL_rtcHandle hRtc, Uint32 enableModule)
  310. {
  311. if(TRUE == enableModule)
  312. {
  313. CSL_FINS(hRtc->CTRL, RTC_CTRL_RTC_DISABLE, ((uint32_t)0x0U));
  314. /* Enable the 32kHz clocks */
  315. CSL_FINS(hRtc->OSC, RTC_OSC_K32CLK_EN, ((uint32_t)0x1U));
  316. }
  317. else
  318. {
  319. CSL_FINS(hRtc->CTRL, RTC_CTRL_RTC_DISABLE, ((uint32_t)0x01U));
  320. /* Disable the 32kHz clocks */
  321. CSL_FINS(hRtc->OSC, RTC_OSC_K32CLK_EN, ((uint32_t)0x0U));
  322. }
  323. }
  324. /** ============================================================================
  325. * @n@b CSL_rtcRun
  326. *
  327. * @b Description
  328. * @n This function sets the RTC to run with the programmed date and time information.
  329. *
  330. * @b Arguments
  331. @verbatim
  332. hRtc The handle of the RTC module.
  333. @endverbatim
  334. *
  335. * <b> Return Value </b>
  336. * @n None
  337. *
  338. * <b> Pre Condition </b>
  339. * @n None
  340. *
  341. * <b> Post Condition </b>
  342. * @n None
  343. *
  344. * @b Writes
  345. * @n CSL_RTC_CTRL;
  346. *
  347. * @b Example
  348. * @verbatim
  349. CSL_rtcRun(hRtc); // Run RTC
  350. @endverbatim
  351. * =============================================================================
  352. */
  353. static inline void CSL_rtcRun(CSL_rtcHandle hRtc)
  354. {
  355. CSL_FINS(hRtc->CTRL, RTC_CTRL_STOP_RTC, ((uint32_t)0x1U));
  356. }
  357. /** ============================================================================
  358. * @n@b CSL_rtcStop
  359. *
  360. * @b Description
  361. * @n This function stops the RTC.
  362. *
  363. * @b Arguments
  364. @verbatim
  365. hRtc The handle of the RTC module.
  366. @endverbatim
  367. *
  368. * <b> Return Value </b>
  369. * @n None
  370. *
  371. * <b> Pre Condition </b>
  372. * @n None
  373. *
  374. * <b> Post Condition </b>
  375. * @n None
  376. *
  377. * @b Writes
  378. * @n CSL_RTC_CTRL;
  379. *
  380. * @b Example
  381. * @verbatim
  382. CSL_rtcStop(hRtc); // Stop RTC
  383. @endverbatim
  384. * =============================================================================
  385. */
  386. static inline void CSL_rtcStop(CSL_rtcHandle hRtc)
  387. {
  388. CSL_FINS(hRtc->CTRL, RTC_CTRL_STOP_RTC, ((uint32_t)0x0U));
  389. }
  390. /** ============================================================================
  391. * @n@b CSL_rtcTimerIntrEnable
  392. *
  393. * @b Description
  394. * @n This function enables the periodic timer interrupt.
  395. *
  396. * @b Arguments
  397. @verbatim
  398. hRtc The handle of the RTC module.
  399. intrMask This specifies the period between two consecutive Timer
  400. interrupts. 'intrMask' can take one of the following values
  401. from the following enum
  402. - #CSL_rtcTimerIntrMask
  403. @endverbatim
  404. *
  405. * <b> Return Value </b>
  406. * @n None
  407. *
  408. * <b> Pre Condition </b>
  409. * @n None
  410. *
  411. * <b> Post Condition </b>
  412. * @n None
  413. *
  414. * @b Writes
  415. * @n CSL_RTC_INTRS;
  416. *
  417. * @b Example
  418. * @verbatim
  419. CSL_rtcTimerIntrEnable(hRtc, intrMask); // Enable timer interrupt
  420. @endverbatim
  421. * =============================================================================
  422. */
  423. static inline void CSL_rtcTimerIntrEnable(CSL_rtcHandle hRtc,
  424. CSL_rtcTimerIntrMask intrMask)
  425. {
  426. /* Poll the status register flag until the BUSY bit equals zero */
  427. CSL_RTC_WAIT_FOR_WRITE
  428. /* Enable Periodic Timer interrupts */
  429. CSL_FINS(hRtc->INTRS, RTC_INTRS_IT_TIMER, ((uint32_t)0x1U));
  430. /* Set the Timer interrupt period. */
  431. CSL_FINS(hRtc->INTRS, RTC_INTRS_EVERY, intrMask);
  432. }
  433. /** ============================================================================
  434. * @n@b CSL_rtcTimerIntrDisable
  435. *
  436. * @b Description
  437. * @n This function disables the periodic timer interrupts.
  438. *
  439. * @b Arguments
  440. @verbatim
  441. hRtc The handle of the RTC module.
  442. @endverbatim
  443. *
  444. * <b> Return Value </b>
  445. * @n None
  446. *
  447. * <b> Pre Condition </b>
  448. * @n None
  449. *
  450. * <b> Post Condition </b>
  451. * @n None
  452. *
  453. * @b Writes
  454. * @n CSL_RTC_INTRS;
  455. *
  456. * @b Example
  457. * @verbatim
  458. CSL_rtcTimerIntrDisable(hRtc); // Disable timer interrupt
  459. @endverbatim
  460. * =============================================================================
  461. */
  462. static inline void CSL_rtcTimerIntrDisable(CSL_rtcHandle hRtc)
  463. {
  464. /* Poll the status register flag until the BUSY bit equals zero */
  465. CSL_RTC_WAIT_FOR_WRITE
  466. /* Disable Periodic Timer interrupts */
  467. CSL_FINS(hRtc->INTRS, RTC_INTRS_IT_TIMER, ((uint32_t)0x0U));
  468. }
  469. /** ============================================================================
  470. * @n@b CSL_rtcTimerIntrStatus
  471. *
  472. * @b Description
  473. * @n This function returns the status of TIMER interrupt events.
  474. *
  475. * @b Arguments
  476. @verbatim
  477. hRtc The handle of the RTC module.
  478. @endverbatim
  479. *
  480. * <b> Return Value </b>
  481. * @n None
  482. *
  483. * <b> Pre Condition </b>
  484. * @n None
  485. *
  486. * <b> Post Condition </b>
  487. * @n None
  488. *
  489. * @b Writes
  490. * @n CSL_RTC_STS;
  491. *
  492. * @b Example
  493. * @verbatim
  494. CSL_rtcTimerIntrStatus(hRtc); // Get RTC timer interrupt sttaus
  495. @endverbatim
  496. * =============================================================================
  497. */
  498. static inline Uint32 CSL_rtcTimerIntrStatus(CSL_rtcHandle hRtc)
  499. {
  500. Uint32 regVal = 0U;
  501. regVal = hRtc->STS;
  502. regVal = (regVal & (CSL_RTC_STS_EVT_1S_MASK |
  503. CSL_RTC_STS_EVT_1M_MASK | CSL_RTC_STS_EVT_1H_MASK |
  504. CSL_RTC_STS_EVT_1D_MASK));
  505. return regVal;
  506. }
  507. /** ============================================================================
  508. * @n@b CSL_rtcAlarmIntrEnable
  509. *
  510. * @b Description
  511. * @n This function enables ALARM interrupts.
  512. *
  513. * @b Arguments
  514. @verbatim
  515. hRtc The handle of the RTC module.
  516. alarmNum The value identifies the alarm register for which the
  517. Interrupts have to be enabled. 'alarmNum' can take one of
  518. the following values from the following enum
  519. - #CSL_rtcAlarmNum
  520. @endverbatim
  521. *
  522. * <b> Return Value </b>
  523. * @n None
  524. *
  525. * <b> Pre Condition </b>
  526. * @n None
  527. *
  528. * <b> Post Condition </b>
  529. * @n None
  530. *
  531. * @b Writes
  532. * @n CSL_RTC_INTRS;
  533. *
  534. * @b Example
  535. * @verbatim
  536. CSL_rtcAlarmIntrEnable(hRtc, alarmNum); // Enable the Alarm interrupt
  537. @endverbatim
  538. * =============================================================================
  539. */
  540. static inline void CSL_rtcAlarmIntrEnable(CSL_rtcHandle hRtc,
  541. CSL_rtcAlarmNum alarmNum)
  542. {
  543. /* Poll the status register flag until the BUSY bit equals zero */
  544. CSL_RTC_WAIT_FOR_WRITE
  545. if(CSL_RTC_ALARM_NUM_1 == alarmNum)
  546. {
  547. /* Enable ALARM1 interrupts */
  548. CSL_FINS(hRtc->INTRS, RTC_INTRS_IT_ALARM, ((uint32_t)0x1U));
  549. }
  550. else if(CSL_RTC_ALARM_NUM_2 == alarmNum)
  551. {
  552. /* Enable ALARM1 interrupts */
  553. CSL_FINS(hRtc->INTRS, RTC_INTRS_IT_ALARM2, ((uint32_t)0x1U));
  554. }
  555. else
  556. {
  557. /*
  558. ** It is expected of application to pass proper value as
  559. ** this function doesn't return error.
  560. */
  561. }
  562. }
  563. /** ============================================================================
  564. * @n@b CSL_rtcAlarmIntrDisable
  565. *
  566. * @b Description
  567. * @n This function disables the ALARM interrupts.
  568. *
  569. * @b Arguments
  570. @verbatim
  571. hRtc The handle of the RTC module.
  572. alarmNum The value identifies the alarm register for which the
  573. Interrupts have to be enabled. 'alarmNum' can take one of
  574. the following values from the following enum
  575. - #CSL_rtcAlarmNum
  576. @endverbatim
  577. *
  578. * <b> Return Value </b>
  579. * @n None
  580. *
  581. * <b> Pre Condition </b>
  582. * @n None
  583. *
  584. * <b> Post Condition </b>
  585. * @n None
  586. *
  587. * @b Writes
  588. * @n CSL_RTC_INTRS;
  589. *
  590. * @b Example
  591. * @verbatim
  592. CSL_rtcAlarmIntrDisable(hRtc, alarmNum); // Disable the Alarm interrupt
  593. @endverbatim
  594. * =============================================================================
  595. */
  596. static inline void CSL_rtcAlarmIntrDisable(CSL_rtcHandle hRtc,
  597. CSL_rtcAlarmNum alarmNum)
  598. {
  599. /* Poll the status register flag until the BUSY bit equals zero */
  600. CSL_RTC_WAIT_FOR_WRITE
  601. if(CSL_RTC_ALARM_NUM_1 == alarmNum)
  602. {
  603. /* Enable ALARM1 interrupts */
  604. CSL_FINS(hRtc->INTRS, RTC_INTRS_IT_ALARM, ((uint32_t)0x0U));
  605. }
  606. else if(CSL_RTC_ALARM_NUM_2 == alarmNum)
  607. {
  608. /* Enable ALARM1 interrupts */
  609. CSL_FINS(hRtc->INTRS, RTC_INTRS_IT_ALARM2, ((uint32_t)0x0U));
  610. }
  611. else
  612. {
  613. /*
  614. ** It is expected of application to pass proper value as
  615. ** this function doesn't return error.
  616. */
  617. }
  618. }
  619. /** ============================================================================
  620. * @n@b CSL_rtcAlarmIntrStatus
  621. *
  622. * @b Description
  623. * @n This function returns the status of ALARM interrupt events.
  624. *
  625. * @b Arguments
  626. @verbatim
  627. hRtc The handle of the RTC module.
  628. @endverbatim
  629. *
  630. * <b> Return Value </b>
  631. * @n None
  632. *
  633. * <b> Pre Condition </b>
  634. * @n None
  635. *
  636. * <b> Post Condition </b>
  637. * @n None
  638. *
  639. * @b Writes
  640. * @n CSL_RTC_STS;
  641. *
  642. * @b Example
  643. * @verbatim
  644. CSL_rtcAlarmIntrStatus(hRtc); // Get the alarm interrupt status
  645. @endverbatim
  646. * =============================================================================
  647. */
  648. static inline Uint32 CSL_rtcAlarmIntrStatus(CSL_rtcHandle hRtc)
  649. {
  650. Uint32 regVal = 0U;
  651. regVal = hRtc->STS;
  652. regVal = (regVal & (CSL_RTC_STS_ALARM_MASK | CSL_RTC_STS_ALARM2_MASK));
  653. return regVal;
  654. }
  655. /** ============================================================================
  656. * @n@b CSL_rtcAlarmIntrClear
  657. *
  658. * @b Description
  659. * @n This function clears the ALARM interrupt status.
  660. *
  661. * @b Arguments
  662. @verbatim
  663. hRtc The handle of the RTC module.
  664. alarmNum The value identifies the alarm register for which the
  665. Interrupts have to be enabled. 'alarmNum' can take one of
  666. the following values from the following enum
  667. - #CSL_rtcAlarmNum
  668. @endverbatim
  669. *
  670. * <b> Return Value </b>
  671. * @n None
  672. *
  673. * <b> Pre Condition </b>
  674. * @n None
  675. *
  676. * <b> Post Condition </b>
  677. * @n None
  678. *
  679. * @b Writes
  680. * @n CSL_RTC_STS;
  681. *
  682. * @b Example
  683. * @verbatim
  684. CSL_rtcAlarmIntrClear(hRtc, alarmNum); // Clear the alarm interrupt
  685. @endverbatim
  686. * =============================================================================
  687. */
  688. static inline void CSL_rtcAlarmIntrClear(CSL_rtcHandle hRtc,
  689. CSL_rtcAlarmNum alarmNum)
  690. {
  691. Uint32 regVal = 0U;
  692. regVal = hRtc->STS;
  693. if(CSL_RTC_ALARM_NUM_1 == alarmNum)
  694. {
  695. regVal = (regVal & ~CSL_RTC_STS_ALARM_MASK);
  696. regVal |= (((uint32_t)0x1U) << CSL_RTC_STS_ALARM_SHIFT);
  697. }
  698. else if(CSL_RTC_ALARM_NUM_2 == alarmNum)
  699. {
  700. regVal = (regVal & ~CSL_RTC_STS_ALARM2_MASK);
  701. regVal |= (((uint32_t)0x1U) << CSL_RTC_STS_ALARM2_SHIFT);
  702. }
  703. else
  704. {
  705. /*
  706. ** It is expected of application to pass proper value as
  707. ** this function doesn't return error.
  708. */
  709. }
  710. /* Write the updated value back to the register. */
  711. hRtc->STS = regVal;
  712. }
  713. /** ============================================================================
  714. * @n@b CSL_rtcIsBusy
  715. *
  716. * @b Description
  717. * @n This function returns the status of RTC module.
  718. *
  719. * @b Arguments
  720. @verbatim
  721. hRtc The handle of the RTC module.
  722. @endverbatim
  723. *
  724. * <b> Return Value </b>
  725. * @n TRUE indicating RTC is busy updating an event.
  726. * @n FALSE indicating RTC event update is more than 15 seconds from the current time.
  727. *
  728. * <b> Pre Condition </b>
  729. * @n None
  730. *
  731. * <b> Post Condition </b>
  732. * @n None
  733. *
  734. * @b Writes
  735. * @n CSL_RTC_STS;
  736. *
  737. * @b Example
  738. * @verbatim
  739. CSL_rtcIsBusy(hRtc); // Enable the MMU
  740. @endverbatim
  741. * =============================================================================
  742. */
  743. static inline Uint32 CSL_rtcIsBusy(CSL_rtcHandle hRtc)
  744. {
  745. Uint32 status = FALSE;
  746. if(0x1U ==
  747. CSL_FEXT(hRtc->STS, RTC_STS_BUSY))
  748. {
  749. status = TRUE;
  750. }
  751. return status;
  752. }
  753. /** ============================================================================
  754. * @n@b CSL_rtcRoundingEnable
  755. *
  756. * @b Description
  757. * @n This function Enables/Disables the feature of minute rounding.
  758. *
  759. * @b Arguments
  760. @verbatim
  761. hRtc The handle of the RTC module.
  762. enableRounding value to specify whether the Rounding feature
  763. has to be enabled/disabled. 'enableRounding' can
  764. take any of the two values:
  765. - TRUE to indicate enabling Rounding off feature
  766. - FALSE to indicate disabling Rounding off feature
  767. @endverbatim
  768. *
  769. * <b> Return Value </b>
  770. * @n None
  771. *
  772. * <b> Pre Condition </b>
  773. * @n None
  774. *
  775. * <b> Post Condition </b>
  776. * @n None
  777. *
  778. * @b Writes
  779. * @n CSL_RTC_CTRL;
  780. *
  781. * @b Example
  782. * @verbatim
  783. CSL_rtcRoundingEnable(hRtc, enableRounding);
  784. // Enable/Disable the minutes rounding
  785. @endverbatim
  786. * =============================================================================
  787. */
  788. static inline void CSL_rtcRoundingEnable(CSL_rtcHandle hRtc,
  789. Uint32 enableRounding)
  790. {
  791. if(enableRounding == TRUE)
  792. {
  793. CSL_FINS(hRtc->CTRL, RTC_CTRL_ROUND_30S, ((uint32_t)0x1U));
  794. }
  795. else
  796. {
  797. CSL_FINS(hRtc->CTRL, RTC_CTRL_ROUND_30S, ((uint32_t)0x0U));
  798. }
  799. }
  800. /** ============================================================================
  801. * @n@b CSL_rtcSetTime
  802. *
  803. * @b Description
  804. * @n This function programs the specified time information in the Time registers.
  805. *
  806. * @b Arguments
  807. @verbatim
  808. hRtc The handle of the RTC module.
  809. pTime pointer to the structure CSL_rtcTimeObj which contains the
  810. variables representing the Time to be set in the RTC.
  811. @endverbatim
  812. *
  813. * <b> Return Value </b>
  814. * @n None
  815. *
  816. * <b> Pre Condition </b>
  817. * @n None
  818. *
  819. * <b> Post Condition </b>
  820. * @n None
  821. *
  822. * @b Writes
  823. * @n CSL_RTC_SECONDS;
  824. * @n CSL_RTC_MINUTES;
  825. * @n CSL_RTC_HOURS;
  826. * @n CSL_RTC_CTRL;
  827. * @n CSL_RTC_HOURS_PM_NAM;
  828. *
  829. * @b Example
  830. * @verbatim
  831. CSL_rtcSetTime(hRtc, &time); // Set current time
  832. @endverbatim
  833. * =============================================================================
  834. */
  835. static inline void CSL_rtcSetTime(CSL_rtcHandle hRtc, CSL_rtcTimeObj *pTime)
  836. {
  837. Uint32 timeVal = 0U;
  838. Uint32 regVal = 0U;
  839. /* Get The BCD equivalent of the seconds value */
  840. timeVal = CSL_rtcDecToBcd(pTime->seconds);
  841. regVal = hRtc->SECONDS;
  842. /* Clear the Seconds field */
  843. regVal &= ~(CSL_RTC_SECONDS_SEC0_MASK | CSL_RTC_SECONDS_SEC1_MASK);
  844. regVal |= timeVal;
  845. /* Check if RTC is busy updating its registers. */
  846. CSL_RTC_WAIT_FOR_WRITE
  847. /* Write the seconds value */
  848. hRtc->SECONDS = regVal;
  849. /* Get The BCD equivalent of the minutes value */
  850. timeVal = CSL_rtcDecToBcd(pTime->minutes);
  851. regVal = hRtc->MINUTES;
  852. /* Clear the Minutes field */
  853. regVal &= ~(CSL_RTC_MINUTES_MIN0_MASK | CSL_RTC_MINUTES_MIN1_MASK);
  854. regVal |= timeVal;
  855. /* Check if RTC is busy updating its registers. */
  856. CSL_RTC_WAIT_FOR_WRITE
  857. /* Write the seconds value */
  858. hRtc->MINUTES = regVal;
  859. /* Get the Time mode. */
  860. timeVal = pTime->timeMode;
  861. CSL_FINS(hRtc->CTRL, RTC_CTRL_MODE_12_24, timeVal);
  862. /* Get The BCD equivalent of the hours value*/
  863. timeVal = CSL_rtcDecToBcd(pTime->hours);
  864. /* Get the Hours value. */
  865. regVal = hRtc->HOURS;
  866. /* Clear the Hours field */
  867. regVal &= ~(CSL_RTC_HOURS_HOUR0_MASK | CSL_RTC_HOURS_HOUR1_MASK);
  868. regVal |= timeVal;
  869. if(CSL_RTC_TIME_MODE_12_HR == pTime->timeMode)
  870. {
  871. timeVal = pTime->meridiemMode;
  872. CSL_FINS(regVal, RTC_HOURS_PM_NAM, timeVal);
  873. }
  874. /* Check if RTC is busy updating its registers. */
  875. CSL_RTC_WAIT_FOR_WRITE
  876. /* Write the Hours value. */
  877. hRtc->HOURS = regVal;
  878. }
  879. /** ============================================================================
  880. * @n@b CSL_rtcGetTime
  881. *
  882. * @b Description
  883. * @n This function reads the current time from the registers holding time information.
  884. *
  885. * @b Arguments
  886. @verbatim
  887. hRtc The handle of the RTC module.
  888. pTime Pointer to the structure CSL_rtcTimeObj which contains the
  889. variables representing the Time through which the time
  890. set in the RTC will be returned.
  891. @endverbatim
  892. *
  893. * <b> Return Value </b>
  894. * @n None
  895. *
  896. * <b> Pre Condition </b>
  897. * @n None
  898. *
  899. * <b> Post Condition </b>
  900. * @n None
  901. *
  902. * @b Writes
  903. * @n CSL_RTC_SECONDS;
  904. * @n CSL_RTC_MINUTES;
  905. * @n CSL_RTC_HOURS;
  906. * @n CSL_RTC_CTRL;
  907. * @n CSL_RTC_HOURS_PM_NAM;
  908. *
  909. * @b Example
  910. * @verbatim
  911. CSL_rtcGetTime(hRtc, &time); // Get current time
  912. @endverbatim
  913. * =============================================================================
  914. */
  915. static inline void CSL_rtcGetTime(CSL_rtcHandle hRtc, CSL_rtcTimeObj *pTime)
  916. {
  917. Uint32 timeVal = 0U;
  918. /* Check if RTC is busy updating its registers. */
  919. CSL_RTC_WAIT_FOR_WRITE
  920. /* Read the Seconds value. */
  921. timeVal = hRtc->SECONDS;
  922. timeVal &= (CSL_RTC_SECONDS_SEC0_MASK | CSL_RTC_SECONDS_SEC1_MASK);
  923. /* Get the Decimal equivalent of the seconds value in BCD */
  924. pTime->seconds = CSL_rtcBcdToDec(timeVal);
  925. /* Read the Minutes value. */
  926. timeVal = hRtc->MINUTES;
  927. timeVal &= (CSL_RTC_MINUTES_MIN0_MASK | CSL_RTC_MINUTES_MIN1_MASK);
  928. /* Get the Decimal equivalent of the minutes value in BCD */
  929. pTime->minutes = CSL_rtcBcdToDec(timeVal);
  930. /* Read the Time mode */
  931. timeVal = CSL_FEXT(hRtc->CTRL, RTC_CTRL_MODE_12_24);
  932. pTime->timeMode = (CSL_rtcTimeMode) timeVal;
  933. /* Read the Hours value. */
  934. timeVal = hRtc->HOURS;
  935. /*
  936. ** If the Time mode is in 12 hour format get the meridiem mode of the
  937. ** current time set.
  938. */
  939. if(CSL_RTC_TIME_MODE_12_HR == pTime->timeMode)
  940. {
  941. pTime->meridiemMode = (CSL_rtcTimeMeridiem) CSL_FEXT(timeVal, RTC_HOURS_PM_NAM);
  942. }
  943. timeVal &= (CSL_RTC_HOURS_HOUR0_MASK | CSL_RTC_HOURS_HOUR1_MASK);
  944. /* Get the Decimal equivalent of the hours value in BCD */
  945. pTime->hours = CSL_rtcBcdToDec(timeVal);
  946. }
  947. /** ============================================================================
  948. * @n@b CSL_rtcSetDate
  949. *
  950. * @b Description
  951. * @n This function sets the specified date information in registers holding date information.
  952. *
  953. * @b Arguments
  954. @verbatim
  955. hRtc The handle of the RTC module.
  956. pDate pointer to the structure CSL_rtcDateObj which contains the
  957. variables representing the Date to be set in the RTC.
  958. @endverbatim
  959. *
  960. * <b> Return Value </b>
  961. * @n None
  962. *
  963. * <b> Pre Condition </b>
  964. * @n None
  965. *
  966. * <b> Post Condition </b>
  967. * @n None
  968. *
  969. * @b Writes
  970. * @n CSL_RTC_YEARS;
  971. * @n CSL_RTC_MONTHS;
  972. * @n CSL_RTC_DAYS;
  973. * @n CSL_RTC_WEEKS;
  974. *
  975. * @b Example
  976. * @verbatim
  977. CSL_rtcSetDate(hRtc, &date); // Set current date
  978. @endverbatim
  979. * =============================================================================
  980. */
  981. static inline void CSL_rtcSetDate(CSL_rtcHandle hRtc, CSL_rtcDateObj *pDate)
  982. {
  983. Uint32 dateVal = 0U;
  984. Uint32 regVal = 0U;
  985. /* Get The BCD equivalent of the years value*/
  986. dateVal = CSL_rtcDecToBcd(pDate->year);
  987. regVal = hRtc->YEARS;
  988. /* Clear the years field */
  989. regVal &= ~(CSL_RTC_YEARS_YEAR0_MASK | CSL_RTC_YEARS_YEAR1_MASK);
  990. regVal |= dateVal;
  991. /* Check if RTC is busy updating its registers. */
  992. CSL_RTC_WAIT_FOR_WRITE
  993. /* Set the years value */
  994. hRtc->YEARS = regVal;
  995. /* Get the BCD equivalent of the month value. */
  996. dateVal = CSL_rtcDecToBcd(pDate->month);
  997. regVal = hRtc->MONTHS;
  998. /* Clear the month field */
  999. regVal &= ~(CSL_RTC_MONTHS_MONTH0_MASK | CSL_RTC_MONTHS_MONTH1_MASK);
  1000. regVal |= dateVal;
  1001. /* Check if RTC is busy updating its registers. */
  1002. CSL_RTC_WAIT_FOR_WRITE
  1003. /* Set the month value */
  1004. hRtc->MONTHS = regVal;
  1005. /* Get the BCD equivalent of the Day value. */
  1006. dateVal = CSL_rtcDecToBcd(pDate->day);
  1007. regVal = hRtc->DAYS;
  1008. /* Clear the years field */
  1009. regVal &= ~(CSL_RTC_DAYS_DAY0_MASK | CSL_RTC_DAYS_DAY1_MASK);
  1010. regVal |= dateVal;
  1011. /* Check if RTC is busy updating its registers. */
  1012. CSL_RTC_WAIT_FOR_WRITE
  1013. /* Set the Day value */
  1014. hRtc->DAYS = regVal;
  1015. /* Get the Day of the Week. */
  1016. dateVal = CSL_rtcDecToBcd(pDate->weekDay);
  1017. /* Check if RTC is busy updating its registers. */
  1018. CSL_RTC_WAIT_FOR_WRITE
  1019. /* Set the Day of the Week value */
  1020. CSL_FINS(hRtc->WEEKS, RTC_WEEKS_WEEK, dateVal);
  1021. }
  1022. /** ============================================================================
  1023. * @n@b CSL_rtcGetDate
  1024. *
  1025. * @b Description
  1026. * @n This function reads the calendar information from relevant registers holding date information.
  1027. *
  1028. * @b Arguments
  1029. @verbatim
  1030. hRtc The handle of the RTC module.
  1031. pDate pointer to the structure CSL_rtcDateObj holding the variables
  1032. representing the Date through which the date set in the RTC
  1033. will be returned.
  1034. @endverbatim
  1035. *
  1036. * <b> Return Value </b>
  1037. * @n None
  1038. *
  1039. * <b> Pre Condition </b>
  1040. * @n None
  1041. *
  1042. * <b> Post Condition </b>
  1043. * @n None
  1044. *
  1045. * @b Writes
  1046. * @n CSL_RTC_YEARS;
  1047. * @n CSL_RTC_MONTHS;
  1048. * @n CSL_RTC_DAYS;
  1049. * @n CSL_RTC_WEEKS;
  1050. *
  1051. * @b Example
  1052. * @verbatim
  1053. CSL_rtcGetDate(hRtc, &date); // Get current date
  1054. @endverbatim
  1055. * =============================================================================
  1056. */
  1057. static inline void CSL_rtcGetDate(CSL_rtcHandle hRtc, CSL_rtcDateObj *pDate)
  1058. {
  1059. Uint32 dateVal = 0U;
  1060. /* Check if RTC is busy updating its registers. */
  1061. CSL_RTC_WAIT_FOR_WRITE
  1062. /*
  1063. ** Doing a dummy read of seconds register which internally
  1064. ** fetches all the Time and Date register into shadow register.
  1065. ** This ensures the same date and time is read when the last second read
  1066. ** register was done.
  1067. */
  1068. hRtc->SECONDS;
  1069. /* Read the Year value */
  1070. dateVal = hRtc->YEARS;
  1071. dateVal &= (CSL_RTC_YEARS_YEAR0_MASK | CSL_RTC_YEARS_YEAR1_MASK);
  1072. /* Get the decimal equivalent of the year value in BCD */
  1073. pDate->year = CSL_rtcBcdToDec(dateVal);
  1074. /* Read the Month value */
  1075. dateVal = hRtc->MONTHS;
  1076. dateVal &= (CSL_RTC_MONTHS_MONTH0_MASK | CSL_RTC_MONTHS_MONTH1_MASK);
  1077. /* Get the decimal equivalent of the month value in BCD */
  1078. pDate->month = CSL_rtcBcdToDec(dateVal);
  1079. /* Read the Day value */
  1080. dateVal = hRtc->DAYS;
  1081. dateVal &= (CSL_RTC_DAYS_DAY0_MASK | CSL_RTC_DAYS_DAY1_MASK);
  1082. /* Get the decimal equivalent of the date value in BCD */
  1083. pDate->day = CSL_rtcBcdToDec(dateVal);
  1084. /* Read the Days of the Week Value. */
  1085. dateVal = CSL_FEXT(hRtc->WEEKS, RTC_WEEKS_WEEK);
  1086. /* Get the decimal equivalent of the date value in BCD */
  1087. pDate->weekDay = (CSL_rtcWeekDay) CSL_rtcBcdToDec(dateVal);
  1088. }
  1089. /** ============================================================================
  1090. * @n@b CSL_rtcSetAlarm
  1091. *
  1092. * @b Description
  1093. * @n This function sets the specified alarm register with Alarm information including Time and Date.
  1094. *
  1095. * @b Arguments
  1096. @verbatim
  1097. hRtc The handle of the RTC module.
  1098. alarmNum The value identifies the alarm register for which the
  1099. Interrupts have to be enabled. 'alarmNum' can take one of
  1100. the following values from the following enum
  1101. - #CSL_rtcAlarmNum
  1102. pAlarmTime Pointer to the structure CSL_rtcTimeObj which contains the
  1103. variables representing Alarm Time to be set in the RTC.
  1104. pAlarmDate Pointer to the structure dateObj which contains the
  1105. variables representing Alarm Date to be set in the RTC.
  1106. @endverbatim
  1107. *
  1108. * <b> Return Value </b>
  1109. * @n None
  1110. *
  1111. * <b> Pre Condition </b>
  1112. * @n None
  1113. *
  1114. * <b> Post Condition </b>
  1115. * @n None
  1116. *
  1117. * @b Writes
  1118. * @n CSL_RTC_INTRS;
  1119. *
  1120. * @b Example
  1121. * @verbatim
  1122. CSL_rtcSetAlarm(hRtc, alarmNum, &alarmTime, &alarmDate); // Configure alarm
  1123. @endverbatim
  1124. * =============================================================================
  1125. */
  1126. static inline void CSL_rtcSetAlarm(CSL_rtcHandle hRtc,
  1127. CSL_rtcAlarmNum alarmNum,
  1128. CSL_rtcTimeObj *pAlarmTime,
  1129. CSL_rtcDateObj *pAlarmDate)
  1130. {
  1131. Uint32 timeVal = 0U;
  1132. Uint32 regVal = 0U;
  1133. /* Get the BCD equivalent of the seconds value. */
  1134. timeVal = CSL_rtcDecToBcd(pAlarmTime->seconds);
  1135. regVal = CSL_RTC_MAKE_ALARM_SECONDS(alarmNum);
  1136. /* Clear the Seconds field */
  1137. regVal &= ~(CSL_RTC_ALARM_SECONDS_ALARM_SEC0_MASK |
  1138. CSL_RTC_ALARM_SECONDS_ALARM_SEC1_MASK);
  1139. regVal |= timeVal;
  1140. /* Check if RTC is busy updating its registers. */
  1141. CSL_RTC_WAIT_FOR_WRITE
  1142. /* Write the seconds value */
  1143. if(CSL_RTC_ALARM_NUM_1 == alarmNum)
  1144. {
  1145. hRtc->ALARM_SECONDS = regVal;
  1146. }
  1147. else if(CSL_RTC_ALARM_NUM_2 == alarmNum)
  1148. {
  1149. hRtc->ALARM2_SECONDS = regVal;
  1150. }
  1151. else
  1152. {
  1153. /*
  1154. ** It is expected of application to pass proper value as
  1155. ** this function doesn't return error.
  1156. */
  1157. }
  1158. /* Get BCD equivalent of the minutes value. */
  1159. timeVal = CSL_rtcDecToBcd(pAlarmTime->minutes);
  1160. regVal = CSL_RTC_MAKE_ALARM_MINUTES(alarmNum);
  1161. /* Clear the Seconds field */
  1162. regVal &= ~(CSL_RTC_ALARM_MINUTES_ALARM_MIN0_MASK |
  1163. CSL_RTC_ALARM_MINUTES_ALARM_MIN1_MASK);
  1164. regVal |= timeVal;
  1165. /* Check if RTC is busy updating its registers. */
  1166. CSL_RTC_WAIT_FOR_WRITE
  1167. /* Write the seconds value */
  1168. if(CSL_RTC_ALARM_NUM_1 == alarmNum)
  1169. {
  1170. hRtc->ALARM_MINUTES = regVal;
  1171. }
  1172. else if(CSL_RTC_ALARM_NUM_2 == alarmNum)
  1173. {
  1174. hRtc->ALARM2_MINUTES = regVal;
  1175. }
  1176. else
  1177. {
  1178. /*
  1179. ** It is expected of application to pass proper value as
  1180. ** this function doesn't return error.
  1181. */
  1182. }
  1183. /* Get the Time mode format. */
  1184. timeVal = pAlarmTime->timeMode;
  1185. CSL_FINS(hRtc->CTRL, RTC_CTRL_MODE_12_24, timeVal);
  1186. /* Get the BCD equivalent of the Hours Value */
  1187. timeVal = CSL_rtcDecToBcd(pAlarmTime->hours);
  1188. regVal = CSL_RTC_MAKE_ALARM_HOURS(alarmNum);
  1189. /* Clear the Hours field */
  1190. regVal &= ~(CSL_RTC_ALARM_HOURS_ALARM_HOUR0_MASK |
  1191. CSL_RTC_ALARM_HOURS_ALARM_HOUR1_MASK);
  1192. regVal |= timeVal;
  1193. if(CSL_RTC_TIME_MODE_12_HR == pAlarmTime->timeMode)
  1194. {
  1195. timeVal = pAlarmTime->meridiemMode;
  1196. CSL_FINS(regVal, RTC_ALARM_HOURS_ALARM_PM_NAM, timeVal);
  1197. }
  1198. /* Check if RTC is busy updating its registers. */
  1199. CSL_RTC_WAIT_FOR_WRITE
  1200. /* Write the hours value */
  1201. if(CSL_RTC_ALARM_NUM_1 == alarmNum)
  1202. {
  1203. hRtc->ALARM_HOURS = regVal;
  1204. }
  1205. else if(CSL_RTC_ALARM_NUM_2 == alarmNum)
  1206. {
  1207. hRtc->ALARM2_HOURS = regVal;
  1208. }
  1209. else
  1210. {
  1211. /*
  1212. ** It is expected of application to pass proper value as
  1213. ** this function doesn't return error.
  1214. */
  1215. }
  1216. /* Get the BCD equivalent of the year value. */
  1217. timeVal = CSL_rtcDecToBcd(pAlarmDate->year);
  1218. regVal = CSL_RTC_MAKE_ALARM_YEARS(alarmNum);
  1219. /* Clear the year field */
  1220. regVal &= ~(CSL_RTC_ALARM_YEARS_ALARM_YEAR0_MASK |
  1221. CSL_RTC_ALARM_YEARS_ALARM_YEAR1_MASK);
  1222. regVal |= timeVal;
  1223. /* Check if RTC is busy updating its registers. */
  1224. CSL_RTC_WAIT_FOR_WRITE
  1225. /* Write the year value */
  1226. if(CSL_RTC_ALARM_NUM_1 == alarmNum)
  1227. {
  1228. hRtc->ALARM_YEARS = regVal;
  1229. }
  1230. else if(CSL_RTC_ALARM_NUM_2 == alarmNum)
  1231. {
  1232. hRtc->ALARM2_YEARS = regVal;
  1233. }
  1234. else
  1235. {
  1236. /*
  1237. ** It is expected of application to pass proper value as
  1238. ** this function doesn't return error.
  1239. */
  1240. }
  1241. /* Get the BCD equivalent of the month value. */
  1242. timeVal = CSL_rtcDecToBcd(pAlarmDate->month);
  1243. regVal = CSL_RTC_MAKE_ALARM_MONTHS(alarmNum);
  1244. /* Clear the months field */
  1245. regVal &= ~(CSL_RTC_ALARM_MONTHS_ALARM_MONTH0_MASK |
  1246. CSL_RTC_ALARM_MONTHS_ALARM_MONTH1_MASK);
  1247. regVal |= timeVal;
  1248. /* Check if RTC is busy updating its registers. */
  1249. CSL_RTC_WAIT_FOR_WRITE
  1250. /* Write the months value */
  1251. if(CSL_RTC_ALARM_NUM_1 == alarmNum)
  1252. {
  1253. hRtc->ALARM_MONTHS = regVal;
  1254. }
  1255. else if(CSL_RTC_ALARM_NUM_2 == alarmNum)
  1256. {
  1257. hRtc->ALARM2_MONTHS = regVal;
  1258. }
  1259. else
  1260. {
  1261. /*
  1262. ** It is expected of application to pass proper value as
  1263. ** this function doesn't return error.
  1264. */
  1265. }
  1266. /* Get the BCD equivalent of the day value. */
  1267. timeVal = CSL_rtcDecToBcd(pAlarmDate->day);
  1268. regVal = CSL_RTC_MAKE_ALARM_DAYS(alarmNum);
  1269. /* Clear the day field */
  1270. regVal &= ~(CSL_RTC_ALARM_DAYS_ALARM_DAY0_MASK |
  1271. CSL_RTC_ALARM_DAYS_ALARM_DAY1_MASK);
  1272. regVal |= timeVal;
  1273. /* Check if RTC is busy updating its registers. */
  1274. CSL_RTC_WAIT_FOR_WRITE
  1275. /* Write the day value */
  1276. if(CSL_RTC_ALARM_NUM_1 == alarmNum)
  1277. {
  1278. hRtc->ALARM_DAYS = regVal;
  1279. }
  1280. else if(CSL_RTC_ALARM_NUM_2 == alarmNum)
  1281. {
  1282. hRtc->ALARM2_DAYS = regVal;
  1283. }
  1284. else
  1285. {
  1286. /*
  1287. ** It is expected of application to pass proper value as
  1288. ** this function doesn't return error.
  1289. */
  1290. }
  1291. }
  1292. /** ============================================================================
  1293. * @n@b CSL_rtcGetAlarm
  1294. *
  1295. * @b Description
  1296. * @n This function reads the programmed Alarm information including Time and Date from the specified alarm register.
  1297. *
  1298. * @b Arguments
  1299. @verbatim
  1300. hRtc The handle of the RTC module.
  1301. alarmNum The value identifies the alarm register for which the
  1302. Interrupts have to be enabled. 'alarmNum' can take one of
  1303. the following values from the following enum
  1304. - #CSL_rtcAlarmNum
  1305. pAlarmTime Pointer to the structure CSL_rtcTimeObj which contains the
  1306. variables representing Alarm Time to be set in the RTC.
  1307. pAlarmDate Pointer to the structure CSL_rtcDateObj which contains the
  1308. variables representing Alarm Date to be set in the RTC.
  1309. @endverbatim
  1310. *
  1311. * <b> Return Value </b>
  1312. * @n None
  1313. *
  1314. * <b> Pre Condition </b>
  1315. * @n None
  1316. *
  1317. * <b> Post Condition </b>
  1318. * @n None
  1319. *
  1320. * @b Writes
  1321. * @n CSL_RTC_INTRS;
  1322. *
  1323. * @b Example
  1324. * @verbatim
  1325. CSL_rtcGetAlarm(hRtc, alarmNum, &alarmTime, &alarmDate); // Read alarm configuration
  1326. @endverbatim
  1327. * =============================================================================
  1328. */
  1329. static inline void CSL_rtcGetAlarm(CSL_rtcHandle hRtc,
  1330. CSL_rtcAlarmNum alarmNum,
  1331. CSL_rtcTimeObj *pAlarmTime,
  1332. CSL_rtcDateObj *pAlarmDate)
  1333. {
  1334. Uint32 regVal = 0U;
  1335. /* Read the Seconds value. */
  1336. regVal = CSL_RTC_MAKE_ALARM_SECONDS(alarmNum);
  1337. regVal &= (CSL_RTC_ALARM_SECONDS_ALARM_SEC0_MASK |
  1338. CSL_RTC_ALARM_SECONDS_ALARM_SEC1_MASK);
  1339. /* Get the decimal equivalent of the seconds value in BCD */
  1340. pAlarmTime->seconds = CSL_rtcBcdToDec(regVal);
  1341. /* Read the minutes value. */
  1342. regVal = CSL_RTC_MAKE_ALARM_MINUTES(alarmNum);
  1343. regVal &= (CSL_RTC_ALARM_MINUTES_ALARM_MIN0_MASK |
  1344. CSL_RTC_ALARM_MINUTES_ALARM_MIN1_MASK);
  1345. /* Get the decimal equivalent of the minutes value in BCD */
  1346. pAlarmTime->minutes = CSL_rtcBcdToDec(regVal);
  1347. /* Read the Hours value. */
  1348. regVal = CSL_RTC_MAKE_ALARM_HOURS(alarmNum);
  1349. regVal &= (CSL_RTC_ALARM_HOURS_ALARM_HOUR0_MASK |
  1350. CSL_RTC_ALARM_HOURS_ALARM_HOUR1_MASK);
  1351. /* Get the decimal equivalent of the hours value in BCD */
  1352. pAlarmTime->hours = CSL_rtcBcdToDec(regVal);
  1353. regVal = CSL_FEXT(hRtc->CTRL, RTC_CTRL_MODE_12_24);
  1354. pAlarmTime->timeMode = (CSL_rtcTimeMode) regVal;
  1355. /*
  1356. ** If the Time mode is in 12 hour format get the meridiem mode of the
  1357. ** current time set.
  1358. */
  1359. if(CSL_RTC_TIME_MODE_12_HR == pAlarmTime->timeMode)
  1360. {
  1361. pAlarmTime->meridiemMode = (CSL_rtcTimeMeridiem)CSL_FEXT(regVal, RTC_ALARM_HOURS_ALARM_PM_NAM);
  1362. }
  1363. /* Read the Year value */
  1364. regVal = CSL_RTC_MAKE_ALARM_YEARS(alarmNum);
  1365. regVal &= (CSL_RTC_ALARM_YEARS_ALARM_YEAR0_MASK |
  1366. CSL_RTC_ALARM_YEARS_ALARM_YEAR1_MASK);
  1367. /* Get the Decimal equivalent of the year value */
  1368. pAlarmDate->year = CSL_rtcBcdToDec(regVal);
  1369. /* Read the Month value */
  1370. regVal = CSL_RTC_MAKE_ALARM_MONTHS(alarmNum);
  1371. regVal &= (CSL_RTC_ALARM_MONTHS_ALARM_MONTH0_MASK |
  1372. CSL_RTC_ALARM_MONTHS_ALARM_MONTH1_MASK);
  1373. /* Get the decimal equivalent of the month value */
  1374. pAlarmDate->month = CSL_rtcBcdToDec(regVal);
  1375. /* Read the Day value */
  1376. regVal = CSL_RTC_MAKE_ALARM_DAYS(alarmNum);
  1377. regVal &= (CSL_RTC_ALARM_DAYS_ALARM_DAY0_MASK |
  1378. CSL_RTC_ALARM_DAYS_ALARM_DAY1_MASK);
  1379. /* Get the decimal equivalent of the day value */
  1380. pAlarmDate->day = CSL_rtcBcdToDec(regVal);
  1381. }
  1382. /** ============================================================================
  1383. * @n@b CSL_rtcSetScratchPadVal
  1384. *
  1385. * @b Description
  1386. * @n This function writes the specified arbitrary value to the specified scratch register.
  1387. *
  1388. * @b Arguments
  1389. @verbatim
  1390. hRtc The handle of the RTC module.
  1391. regNum Specifies the scratch register number to be accessed. This
  1392. can take the values from the following enum
  1393. - #CSL_rtcScratchPadReg
  1394. scratchVal Refers to the value to be written to the scratch registers.
  1395. @endverbatim
  1396. *
  1397. * <b> Return Value </b>
  1398. * @n None
  1399. *
  1400. * <b> Pre Condition </b>
  1401. * @n None
  1402. *
  1403. * <b> Post Condition </b>
  1404. * @n None
  1405. *
  1406. * @b Writes
  1407. * @n CSL_RTC_SCRATCH0;
  1408. *
  1409. * @b Example
  1410. * @verbatim
  1411. CSL_rtcSetScratchPadVal(hRtc, regNum, scratchVal);
  1412. // Write given value to scratchpad register
  1413. @endverbatim
  1414. * =============================================================================
  1415. */
  1416. static inline void CSL_rtcSetScratchPadVal(CSL_rtcHandle hRtc,
  1417. CSL_rtcScratchPadReg regNum,
  1418. Uint32 scratchVal)
  1419. {
  1420. if(CSL_RTC_SCRATCH_PAD_0 == regNum)
  1421. {
  1422. hRtc->SCRATCH0 = scratchVal;
  1423. }
  1424. else if(CSL_RTC_SCRATCH_PAD_1 == regNum)
  1425. {
  1426. hRtc->SCRATCH1 = scratchVal;
  1427. }
  1428. else if(CSL_RTC_SCRATCH_PAD_2 == regNum)
  1429. {
  1430. hRtc->SCRATCH2 = scratchVal;
  1431. }
  1432. else
  1433. {
  1434. /*
  1435. ** It is expected of application to pass proper value as
  1436. ** this function doesn't return error.
  1437. */
  1438. }
  1439. }
  1440. /** ============================================================================
  1441. * @n@b CSL_rtcGetScratchPadVal
  1442. *
  1443. * @b Description
  1444. * @n This function is used to enable the MMU.
  1445. *
  1446. * @b Arguments
  1447. @verbatim
  1448. hRtc The handle of the RTC module.
  1449. @endverbatim
  1450. *
  1451. * <b> Return Value </b>
  1452. * @n None
  1453. *
  1454. * <b> Pre Condition </b>
  1455. * @n None
  1456. *
  1457. * <b> Post Condition </b>
  1458. * @n None
  1459. *
  1460. * @b Reads
  1461. * @n CSL_RTC_SCRATCH0;
  1462. *
  1463. * @b Example
  1464. * @verbatim
  1465. CSL_rtcGetScratchPadVal(hRtc, regNum); // Enable the MMU
  1466. @endverbatim
  1467. * =============================================================================
  1468. */
  1469. static inline Uint32 CSL_rtcGetScratchPadVal(CSL_rtcHandle hRtc, Uint32 regNum)
  1470. {
  1471. Uint32 scratchVal = 0U;
  1472. if(CSL_RTC_SCRATCH_PAD_0 == regNum)
  1473. {
  1474. scratchVal = hRtc->SCRATCH0;
  1475. }
  1476. else if(CSL_RTC_SCRATCH_PAD_1 == regNum)
  1477. {
  1478. scratchVal = hRtc->SCRATCH1;
  1479. }
  1480. else if(CSL_RTC_SCRATCH_PAD_2 == regNum)
  1481. {
  1482. scratchVal = hRtc->SCRATCH2;
  1483. }
  1484. else
  1485. {
  1486. /*
  1487. ** It is expected of application to pass proper value as
  1488. ** this function doesn't return error.
  1489. */
  1490. }
  1491. return scratchVal;
  1492. }
  1493. /** ============================================================================
  1494. * @n@b CSL_rtcSetIdleMode
  1495. *
  1496. * @b Description
  1497. * @n This API configures the Idle Mode for the RTC.
  1498. *
  1499. * @b Arguments
  1500. @verbatim
  1501. hRtc The handle of the RTC module.
  1502. idleMode This specifies the idle mode that is to be enabled. 'idleMode'
  1503. can take any of the values from the following enum
  1504. - #CSL_rtcIdleMode
  1505. @endverbatim
  1506. *
  1507. * <b> Return Value </b>
  1508. * @n None
  1509. *
  1510. * <b> Pre Condition </b>
  1511. * @n None
  1512. *
  1513. * <b> Post Condition </b>
  1514. * @n None
  1515. *
  1516. * @b Writes
  1517. * @n CSL_RTC_SYSCONFIG;
  1518. *
  1519. * @b Example
  1520. * @verbatim
  1521. CSL_rtcSetIdleMode(hRtc, idleMode); // Configure idle mode
  1522. @endverbatim
  1523. * =============================================================================
  1524. */
  1525. static inline void CSL_rtcSetIdleMode(CSL_rtcHandle hRtc,
  1526. CSL_rtcIdleMode idleMode)
  1527. {
  1528. /* Set the Idle mode in the SYS Config register */
  1529. CSL_FINS(hRtc->SYSCONFIG, RTC_SYSCONFIG_IDLEMODE, idleMode);
  1530. }
  1531. /** ============================================================================
  1532. * @n@b CSL_rtcWakeupEnable
  1533. *
  1534. * @b Description
  1535. * @n This API is used to Enable the Alarm and Timer event Wakeup signal to the CPU.
  1536. *
  1537. * @b Arguments
  1538. @verbatim
  1539. hRtc The handle of the RTC module.
  1540. wakeupSrc Value to specify the wakeup event source to disable
  1541. i.e. either the timer or the alarm based wakeup.
  1542. wakeupSrc' can take any of the values from the following enum
  1543. - #CSL_rtcWakeupEvtSrc
  1544. @endverbatim
  1545. *
  1546. * <b> Return Value </b>
  1547. * @n None
  1548. *
  1549. * <b> Pre Condition </b>
  1550. * @n None
  1551. *
  1552. * <b> Post Condition </b>
  1553. * @n None
  1554. *
  1555. * @b Writes
  1556. * @n CSL_RTC_IRQWAKEEN;
  1557. *
  1558. * @b Example
  1559. * @verbatim
  1560. CSL_rtcWakeupEnable(hRtc, wakeupSrc); // Enable the wakeup signal
  1561. @endverbatim
  1562. * =============================================================================
  1563. */
  1564. static inline void CSL_rtcWakeupEnable(CSL_rtcHandle hRtc,
  1565. CSL_rtcWakeupEvtSrc wakeupSrc)
  1566. {
  1567. if(CSL_RTC_WAKEUP_EVT_SRC_TIMER == wakeupSrc)
  1568. {
  1569. CSL_FINS(hRtc->IRQWAKEEN, RTC_IRQWAKEEN_TIMMER_WAKEEN, ((uint32_t)0x1U));
  1570. }
  1571. else if(CSL_RTC_WAKEUP_EVT_SRC_ALARM == wakeupSrc)
  1572. {
  1573. CSL_FINS(hRtc->IRQWAKEEN, RTC_IRQWAKEEN_ALARM_WAKEEN, ((uint32_t)0x1U));
  1574. }
  1575. else
  1576. {
  1577. /*
  1578. ** It is expected of application to pass proper value as
  1579. ** this function doesn't return error.
  1580. */
  1581. }
  1582. }
  1583. /** ============================================================================
  1584. * @n@b CSL_rtcWakeupDisable
  1585. *
  1586. * @b Description
  1587. * @n This API controls the PMIC power enable signal which can be used to control an external PMIC.
  1588. *
  1589. * @b Arguments
  1590. @verbatim
  1591. hRtc The handle of the RTC module.
  1592. wakeupSrc Value to specify the wakeup event source to disable
  1593. i.e. either the timer or the alarm based wakeup.
  1594. wakeupSrc' can take any of the values from the following enum
  1595. - #CSL_rtcWakeupEvtSrc
  1596. @endverbatim
  1597. *
  1598. * <b> Return Value </b>
  1599. * @n None
  1600. *
  1601. * <b> Pre Condition </b>
  1602. * @n None
  1603. *
  1604. * <b> Post Condition </b>
  1605. * @n None
  1606. *
  1607. * @b Writes
  1608. * @n CSL_RTC_IRQWAKEEN;
  1609. *
  1610. * @b Example
  1611. * @verbatim
  1612. CSL_rtcWakeupDisable(hRtc, wakeupSrc); // Disable the wakeup signal
  1613. @endverbatim
  1614. * =============================================================================
  1615. */
  1616. static inline void CSL_rtcWakeupDisable(CSL_rtcHandle hRtc,
  1617. CSL_rtcWakeupEvtSrc wakeupSrc)
  1618. {
  1619. if(CSL_RTC_WAKEUP_EVT_SRC_TIMER == wakeupSrc)
  1620. {
  1621. CSL_FINS(hRtc->IRQWAKEEN, RTC_IRQWAKEEN_TIMMER_WAKEEN, ((uint32_t)0x0U));
  1622. }
  1623. else if(CSL_RTC_WAKEUP_EVT_SRC_ALARM == wakeupSrc)
  1624. {
  1625. CSL_FINS(hRtc->IRQWAKEEN, RTC_IRQWAKEEN_ALARM_WAKEEN, ((uint32_t)0x0U));
  1626. }
  1627. else
  1628. {
  1629. /*
  1630. ** It is expected of application to pass proper value as
  1631. ** this function doesn't return error.
  1632. */
  1633. }
  1634. }
  1635. /** ============================================================================
  1636. * @n@b CSL_rtcPmicPowerEnable
  1637. *
  1638. * @b Description
  1639. * @n This API controls the PMIC power enable signal which can be used to control an external PMIC.
  1640. *
  1641. * @b Arguments
  1642. @verbatim
  1643. hRtc The handle of the RTC module.
  1644. enablePmicPower This specifies whether the PMIC power enable signal
  1645. has to be pulled low or high. 'enablePmicPower'
  1646. can take any of the two values:
  1647. - TRUE to enable PMIC power enable signal
  1648. - FALSE to disable PMIC power enable signal
  1649. @endverbatim
  1650. *
  1651. * <b> Return Value </b>
  1652. * @n None
  1653. *
  1654. * <b> Pre Condition </b>
  1655. * @n None
  1656. *
  1657. * <b> Post Condition </b>
  1658. * @n None
  1659. *
  1660. * @b Writes
  1661. * @n CSL_RTC_RTC_PMIC_REG;
  1662. *
  1663. * @b Example
  1664. * @verbatim
  1665. CSL_rtcPmicPowerEnable(hRtc, enablePmicPower);
  1666. // Control the PMIC power enable signal
  1667. @endverbatim
  1668. * =============================================================================
  1669. */
  1670. static inline void CSL_rtcPmicPowerEnable(CSL_rtcHandle hRtc,
  1671. Uint32 enablePmicPower)
  1672. {
  1673. if(TRUE == enablePmicPower)
  1674. {
  1675. CSL_FINS(hRtc->RTC_PMIC_REG, RTC_RTC_PMIC_REG_PWR_EN, ((uint32_t)0x1U));
  1676. }
  1677. else
  1678. {
  1679. CSL_FINS(hRtc->RTC_PMIC_REG, RTC_RTC_PMIC_REG_PWR_EN, ((uint32_t)0x0U));
  1680. }
  1681. }
  1682. /** ============================================================================
  1683. * @n@b CSL_rtcPmicExtWakeupEnable
  1684. *
  1685. * @b Description
  1686. * @n This API Enables the PMIC External Wakeup feature.
  1687. *
  1688. * @b Arguments
  1689. @verbatim
  1690. hRtc The handle of the RTC module.
  1691. extWakeupSrc The external Input pin to be configured 'extWakeupSrc'
  1692. can take any of the values from the following enum
  1693. - #CSL_rtcExtWakeupSrc
  1694. @endverbatim
  1695. *
  1696. * <b> Return Value </b>
  1697. * @n None
  1698. *
  1699. * <b> Pre Condition </b>
  1700. * @n None
  1701. *
  1702. * <b> Post Condition </b>
  1703. * @n None
  1704. *
  1705. * @b Writes
  1706. * @n CSL_RTC_RTC_PMIC_REG;
  1707. *
  1708. * @b Example
  1709. * @verbatim
  1710. CSL_rtcPmicExtWakeupEnable(hRtc, extWakeupSrc); // Enable the PMIC external wakeup
  1711. @endverbatim
  1712. * =============================================================================
  1713. */
  1714. static inline void CSL_rtcPmicExtWakeupEnable(CSL_rtcHandle hRtc,
  1715. CSL_rtcExtWakeupSrc extWakeupSrc)
  1716. {
  1717. Uint32 regVal = 0U;
  1718. /* Enable external wakeup inputs */
  1719. regVal = hRtc->RTC_PMIC_REG;
  1720. regVal |= (((uint32_t)0x1U) << (extWakeupSrc +
  1721. CSL_RTC_RTC_PMIC_REG_EXT_WAKEUP_EN_SHIFT));
  1722. hRtc->RTC_PMIC_REG = regVal;
  1723. }
  1724. /** ============================================================================
  1725. * @n@b CSL_rtcPmicExtWakeupDisable
  1726. *
  1727. * @b Description
  1728. * @n This API Disables the PMIC External Wakeup feature.
  1729. *
  1730. * @b Arguments
  1731. @verbatim
  1732. hRtc The handle of the RTC module.
  1733. extWakeupSrc The external Input pin to be configured 'extWakeupSrc'
  1734. can take any of the values from the following enum
  1735. - #CSL_rtcExtWakeupSrc
  1736. @endverbatim
  1737. *
  1738. * <b> Return Value </b>
  1739. * @n None
  1740. *
  1741. * <b> Pre Condition </b>
  1742. * @n None
  1743. *
  1744. * <b> Post Condition </b>
  1745. * @n None
  1746. *
  1747. * @b Writes
  1748. * @n CSL_RTC_RTC_PMIC_REG;
  1749. *
  1750. * @b Example
  1751. * @verbatim
  1752. CSL_rtcPmicExtWakeupDisable(hRtc, extWakeupSrc); // Disable the PMIC external wakeup
  1753. @endverbatim
  1754. * =============================================================================
  1755. */
  1756. static inline void CSL_rtcPmicExtWakeupDisable(CSL_rtcHandle hRtc,
  1757. CSL_rtcExtWakeupSrc extWakeupSrc)
  1758. {
  1759. Uint32 regVal = 0U;
  1760. /* Disable external wakeup inputs */
  1761. regVal = hRtc->RTC_PMIC_REG;
  1762. regVal &= ~(((uint32_t)0x1U) << (extWakeupSrc +
  1763. CSL_RTC_RTC_PMIC_REG_EXT_WAKEUP_EN_SHIFT));
  1764. hRtc->RTC_PMIC_REG = regVal;
  1765. }
  1766. /** ============================================================================
  1767. * @n@b CSL_rtcPmicExtWakeupPol
  1768. *
  1769. * @b Description
  1770. * @n This API configures the Polarity of PMIC External Wakeup Pin
  1771. *
  1772. * @b Arguments
  1773. @verbatim
  1774. hRtc The handle of the RTC module.
  1775. extWakeupSrc The external Input pin to be configured. 'extWakeupSrc'
  1776. can take any of the values from the following enum
  1777. - #CSL_rtcExtWakeupSrc
  1778. wakeupEvtPol This specifies whether the PMIC External Wakeup.
  1779. Polarity to be low or high. 'wakeupEvtPol'
  1780. can take any of the values from the following enum
  1781. - #CSL_rtcWakeupEvtPol
  1782. @endverbatim
  1783. *
  1784. * <b> Return Value </b>
  1785. * @n None
  1786. *
  1787. * <b> Pre Condition </b>
  1788. * @n None
  1789. *
  1790. * <b> Post Condition </b>
  1791. * @n None
  1792. *
  1793. * @b Writes
  1794. * @n CSL_RTC_RTC_PMIC_REG;
  1795. *
  1796. * @b Example
  1797. * @verbatim
  1798. CSL_rtcPmicExtWakeupPol(hRtc, extWakeupSrc, wakeupEvtPol);
  1799. // Configures the Polarity of PMIC External Wakeup Pin
  1800. @endverbatim
  1801. * =============================================================================
  1802. */
  1803. static inline void CSL_rtcPmicExtWakeupPol(CSL_rtcHandle hRtc,
  1804. CSL_rtcExtWakeupSrc extWakeupSrc,
  1805. CSL_rtcWakeupEvtPol wakeupEvtPol)
  1806. {
  1807. Uint32 regVal = 0U;
  1808. /* Configure the polarity of external wakeup inputs */
  1809. regVal = hRtc->RTC_PMIC_REG;
  1810. regVal &= ~(((uint32_t)0x1U) << (extWakeupSrc +
  1811. CSL_RTC_RTC_PMIC_REG_EXT_WAKEUP_POL_SHIFT));
  1812. regVal |= (wakeupEvtPol << (extWakeupSrc + CSL_RTC_RTC_PMIC_REG_EXT_WAKEUP_POL_SHIFT));
  1813. hRtc->RTC_PMIC_REG = regVal;
  1814. }
  1815. /** ============================================================================
  1816. * @n@b CSL_rtcPmicExtWakeupClear
  1817. *
  1818. * @b Description
  1819. * @n This API clears the PMIC External Wakeup Status
  1820. *
  1821. * @b Arguments
  1822. @verbatim
  1823. hRtc The handle of the RTC module.
  1824. extWakeupSrc The external Input pin to be configured 'extWakeupSrc'
  1825. can take any of the values from following enum
  1826. - #CSL_rtcExtWakeupSrc
  1827. @endverbatim
  1828. *
  1829. * <b> Return Value </b>
  1830. * @n None
  1831. *
  1832. * <b> Pre Condition </b>
  1833. * @n None
  1834. *
  1835. * <b> Post Condition </b>
  1836. * @n None
  1837. *
  1838. * @b Writes
  1839. * @n CSL_RTC_RTC_PMIC_REG;
  1840. *
  1841. * @b Example
  1842. * @verbatim
  1843. CSL_rtcPmicExtWakeupClear(hRtc, extWakeupSrc);
  1844. // Clears the PMIC External Wakeup Status
  1845. @endverbatim
  1846. * =============================================================================
  1847. */
  1848. static inline void CSL_rtcPmicExtWakeupClear(CSL_rtcHandle hRtc,
  1849. CSL_rtcExtWakeupSrc extWakeupSrc)
  1850. {
  1851. Uint32 regVal = 0U;
  1852. /* Clears the external wakeup pin status */
  1853. regVal = hRtc->RTC_PMIC_REG;
  1854. regVal |= (((uint32_t)0x1U) << (extWakeupSrc +
  1855. CSL_RTC_RTC_PMIC_REG_EXT_WAKEUP_STS_SHIFT));
  1856. hRtc->RTC_PMIC_REG = regVal;
  1857. }
  1858. /** ============================================================================
  1859. * @n@b CSL_rtcFeedbackResistorSel
  1860. *
  1861. * @b Description
  1862. * @n This API selects the mode of the Oscillator Feedback resistor to either internal or external of the SOC.
  1863. *
  1864. * @b Arguments
  1865. @verbatim
  1866. hRtc The handle of the RTC module.
  1867. resistorSel This specifies whether the Oscillator Feedback resistor
  1868. to be used should be either external or internal to the
  1869. SoC. 'resistorSel' can take one of the following two
  1870. values from the following enum
  1871. - #CSL_rtcFeedbackResistor
  1872. @endverbatim
  1873. *
  1874. * <b> Return Value </b>
  1875. * @n None
  1876. *
  1877. * <b> Pre Condition </b>
  1878. * @n None
  1879. *
  1880. * <b> Post Condition </b>
  1881. * @n None
  1882. *
  1883. * @b Writes
  1884. * @n CSL_RTC_OSC;
  1885. *
  1886. * @b Example
  1887. * @verbatim
  1888. CSL_rtcFeedbackResistorSel(hRtc, resistorSel);
  1889. // Select the mode of Oscillator Feedback resistor
  1890. @endverbatim
  1891. * =============================================================================
  1892. */
  1893. static inline void CSL_rtcFeedbackResistorSel(CSL_rtcHandle hRtc,
  1894. CSL_rtcFeedbackResistor resistorSel)
  1895. {
  1896. /* Select the Feedback resistor type to either external or internal */
  1897. CSL_FINS(hRtc->OSC, RTC_OSC_RES_SELECT, resistorSel);
  1898. }
  1899. /** ============================================================================
  1900. * @n@b CSL_rtcPmicExtWakeupDebounceEnable
  1901. *
  1902. * @b Description
  1903. * @n This API Enables the External Wakeup Debounce feature.
  1904. *
  1905. * @b Arguments
  1906. @verbatim
  1907. hRtc The handle of the RTC module.
  1908. extWakeupSrc The external Input pin to be configured 'extWakeupSrc'
  1909. can take any of the values from following enum
  1910. - #CSL_rtcExtWakeupSrc
  1911. @endverbatim
  1912. *
  1913. * <b> Return Value </b>
  1914. * @n None
  1915. *
  1916. * <b> Pre Condition </b>
  1917. * @n None
  1918. *
  1919. * <b> Post Condition </b>
  1920. * @n None
  1921. *
  1922. * @b Writes
  1923. * @n CSL_RTC_RTC_PMIC_REG;
  1924. *
  1925. * @b Example
  1926. * @verbatim
  1927. CSL_rtcPmicExtWakeupDebounceEnable(hRtc, extWakeupSrc);
  1928. // Enable the External Wakeup Debounce
  1929. @endverbatim
  1930. * =============================================================================
  1931. */
  1932. static inline void CSL_rtcPmicExtWakeupDebounceEnable(CSL_rtcHandle hRtc,
  1933. CSL_rtcExtWakeupSrc extWakeupSrc)
  1934. {
  1935. Uint32 regVal = 0U;
  1936. /* Enable external wakeup inputs */
  1937. regVal = hRtc->RTC_PMIC_REG;
  1938. regVal |= (((uint32_t)0x1U) << (extWakeupSrc +
  1939. CSL_RTC_RTC_PMIC_REG_EXT_WAKEUP_DB_EN_SHIFT));
  1940. hRtc->RTC_PMIC_REG = regVal;
  1941. }
  1942. /** ============================================================================
  1943. * @n@b CSL_rtcPmicExtWakeupDebounceDisable
  1944. *
  1945. * @b Description
  1946. * @n This API Disables the External Wakeup Debounce feature.
  1947. *
  1948. * @b Arguments
  1949. @verbatim
  1950. hRtc The handle of the RTC module.
  1951. extWakeupSrc The external Input pin to be configured 'extWakeupSrc'
  1952. can take any of the values from following enum
  1953. - #CSL_rtcExtWakeupSrc
  1954. @endverbatim
  1955. *
  1956. * <b> Return Value </b>
  1957. * @n None
  1958. *
  1959. * <b> Pre Condition </b>
  1960. * @n None
  1961. *
  1962. * <b> Post Condition </b>
  1963. * @n None
  1964. *
  1965. * @b Writes
  1966. * @n CSL_RTC_RTC_PMIC_REG;
  1967. *
  1968. * @b Example
  1969. * @verbatim
  1970. CSL_rtcPmicExtWakeupDebounceDisable(hRtc, extWakeupSrc);
  1971. // Disable the External Wakeup Debounce
  1972. @endverbatim
  1973. * =============================================================================
  1974. */
  1975. static inline void CSL_rtcPmicExtWakeupDebounceDisable(CSL_rtcHandle hRtc,
  1976. CSL_rtcExtWakeupSrc extWakeupSrc)
  1977. {
  1978. Uint32 regVal = 0U;
  1979. /* Disable external wakeup inputs */
  1980. regVal = hRtc->RTC_PMIC_REG;
  1981. regVal &= ~(((uint32_t)0x1U) << (extWakeupSrc +
  1982. CSL_RTC_RTC_PMIC_REG_EXT_WAKEUP_DB_EN_SHIFT));
  1983. hRtc->RTC_PMIC_REG = regVal;
  1984. }
  1985. /** ============================================================================
  1986. * @n@b CSL_rtcSetDebounceTime
  1987. *
  1988. * @b Description
  1989. * @n This API sets the debounce time for the RTC module.
  1990. *
  1991. * @b Arguments
  1992. @verbatim
  1993. hRtc The handle of the RTC module.
  1994. debounceTime The value to specify the debounce time.
  1995. @endverbatim
  1996. *
  1997. * <b> Return Value </b>
  1998. * @n None
  1999. *
  2000. * <b> Pre Condition </b>
  2001. * @n None
  2002. *
  2003. * <b> Post Condition </b>
  2004. * @n None
  2005. *
  2006. * @b Writes
  2007. * @n CSL_RTC_RTL_DEBOUNCE;
  2008. *
  2009. * @b Example
  2010. * @verbatim
  2011. CSL_rtcSetDebounceTime(hRtc, debounceTime); // Set debounce time
  2012. @endverbatim
  2013. * =============================================================================
  2014. */
  2015. static inline void CSL_rtcSetDebounceTime(CSL_rtcHandle hRtc,
  2016. Uint32 debounceTime)
  2017. {
  2018. /* Set the Debounce Time */
  2019. CSL_FINS(hRtc->RTL_DEBOUNCE, RTC_RTL_DEBOUNCE_DEBOUNCE_REG, debounceTime);
  2020. }
  2021. /** ============================================================================
  2022. * @n@b CSL_rtcTestModeEnable
  2023. *
  2024. * @b Description
  2025. * @n This function is used to enable the MMU.
  2026. *
  2027. * @b Arguments
  2028. @verbatim
  2029. hRtc The handle of the RTC module.
  2030. enableTestMode Value to specify enabling/disabling of the Test
  2031. Mode. 'enableTestMode' can take one of the following values:
  2032. - TRUE to enable a Test mode of the RTC
  2033. - FALSE to disable Test mode and switch back to functional mode.
  2034. @endverbatim
  2035. *
  2036. * <b> Return Value </b>
  2037. * @n None
  2038. *
  2039. * <b> Pre Condition </b>
  2040. * @n None
  2041. *
  2042. * <b> Post Condition </b>
  2043. * @n None
  2044. *
  2045. * @b Writes
  2046. * @n CSL_RTC_CTRL;
  2047. *
  2048. * @b Example
  2049. * @verbatim
  2050. CSL_rtcTestModeEnable(hRtc, enableTestMode); // Enable the test mode
  2051. @endverbatim
  2052. * =============================================================================
  2053. */
  2054. static inline void CSL_rtcTestModeEnable(CSL_rtcHandle hRtc,
  2055. Uint32 enableTestMode)
  2056. {
  2057. if(TRUE == enableTestMode)
  2058. {
  2059. CSL_FINS(hRtc->CTRL, RTC_CTRL_TEST_MODE, ((uint32_t)0x1U));
  2060. }
  2061. else
  2062. {
  2063. CSL_FINS(hRtc->CTRL, RTC_CTRL_TEST_MODE, ((uint32_t)0x0U));
  2064. }
  2065. }
  2066. /** ============================================================================
  2067. * @n@b CSL_rtcCompensationEnable
  2068. *
  2069. * @b Description
  2070. * @n This API is used to Enable/Disable Crystal Compensation feature
  2071. to account for any inaccuracy in 32K oscillator.
  2072. *
  2073. * @b Arguments
  2074. @verbatim
  2075. hRtc The handle of the RTC module.
  2076. enableCompensation Value to specify enabling/disabling of the Test
  2077. Mode. 'enableCompensation' can take one of the
  2078. following values:
  2079. - TRUE to enable oscillator compensation feature
  2080. - FALSE to disable oscillator compensation feature
  2081. @endverbatim
  2082. *
  2083. * <b> Return Value </b>
  2084. * @n None
  2085. *
  2086. * <b> Pre Condition </b>
  2087. * @n None
  2088. *
  2089. * <b> Post Condition </b>
  2090. * @n None
  2091. *
  2092. * @b Writes
  2093. * @n CSL_RTC_CTRL;
  2094. *
  2095. * @b Example
  2096. * @verbatim
  2097. CSL_rtcCompensationEnable(hRtc, enableCompensation); // Enable compensation
  2098. @endverbatim
  2099. * =============================================================================
  2100. */
  2101. static inline void CSL_rtcCompensationEnable(CSL_rtcHandle hRtc,
  2102. Uint32 enableCompensation)
  2103. {
  2104. if(TRUE == enableCompensation)
  2105. {
  2106. CSL_FINS(hRtc->CTRL, RTC_CTRL_AUTO_COMP, ((uint32_t)0x1U));
  2107. }
  2108. else
  2109. {
  2110. CSL_FINS(hRtc->CTRL, RTC_CTRL_AUTO_COMP, ((uint32_t)0x0U));
  2111. }
  2112. }
  2113. /** ============================================================================
  2114. * @n@b CSL_rtcSetCompensationVal
  2115. *
  2116. * @b Description
  2117. * @n This function sets the compensation registers with the
  2118. specified drift compensation value versus one hour period of the
  2119. oscillator frequency.
  2120. *
  2121. * @b Arguments
  2122. @verbatim
  2123. hRtc The handle of the RTC module.
  2124. compVal The drift compensation value.
  2125. @endverbatim
  2126. *
  2127. * <b> Return Value </b>
  2128. * @n None
  2129. *
  2130. * <b> Pre Condition </b>
  2131. * @n None
  2132. *
  2133. * <b> Post Condition </b>
  2134. * @n None
  2135. *
  2136. * @b Writes
  2137. * @n CSL_RTC_COMP_LSB;
  2138. * @n CSL_RTC_COMP_MSB;
  2139. *
  2140. * @b Example
  2141. * @verbatim
  2142. CSL_rtcSetCompensationVal(hRtc, compVal); // Set compensation value
  2143. @endverbatim
  2144. * =============================================================================
  2145. */
  2146. static inline void CSL_rtcSetCompensationVal(CSL_rtcHandle hRtc, Int32 compVal)
  2147. {
  2148. Uint32 lsbVal = 0U;
  2149. Uint32 msbVal = 0U;
  2150. uint32_t tempVal = (uint32_t)compVal;
  2151. /* Get the 2's complement Value of the compensation value. */
  2152. tempVal = ~(tempVal);
  2153. compVal = (int32_t)(tempVal) + 1;
  2154. lsbVal = (((uint32_t)compVal) & CSL_RTC_COMP_LSB_RTC_COMP_LSB_MASK);
  2155. msbVal = ((((uint32_t)compVal) >> CSL_RTC_COMP_MSB_RTC_COMP_MSB_SHIFT) &
  2156. CSL_RTC_COMP_MSB_RTC_COMP_MSB_MASK);
  2157. /* Poll the status register flag until the BUSY bit equals zero */
  2158. CSL_RTC_WAIT_FOR_WRITE
  2159. /* Set the compensation value to account for oscillator drift. */
  2160. hRtc->COMP_LSB = lsbVal;
  2161. hRtc->COMP_MSB = msbVal;
  2162. }
  2163. /** ============================================================================
  2164. * @n@b CSL_rtcGetCompensationVal
  2165. *
  2166. * @b Description
  2167. * @n This function reads the compensation value being set in the compensation registers.
  2168. *
  2169. * @b Arguments
  2170. @verbatim
  2171. hRtc The handle of the RTC module.
  2172. @endverbatim
  2173. *
  2174. * <b> Return Value </b>
  2175. * @n None
  2176. *
  2177. * <b> Pre Condition </b>
  2178. * @n None
  2179. *
  2180. * <b> Post Condition </b>
  2181. * @n None
  2182. *
  2183. * @b Reads
  2184. * @n CSL_RTC_COMP_LSB;
  2185. * @n CSL_RTC_COMP_MSB;
  2186. *
  2187. * @b Example
  2188. * @verbatim
  2189. CSL_rtcGetCompensationVal(hRtc); // Read compensation value
  2190. @endverbatim
  2191. * =============================================================================
  2192. */
  2193. static inline Int32 CSL_rtcGetCompensationVal(CSL_rtcHandle hRtc)
  2194. {
  2195. Uint32 lsbVal = 0U;
  2196. Uint32 msbVal = 0U;
  2197. Int32 compVal = 0;
  2198. uint32_t tempVal = 0U;
  2199. lsbVal = hRtc->COMP_LSB;
  2200. msbVal = hRtc->COMP_MSB;
  2201. msbVal = ((msbVal << CSL_RTC_COMP_MSB_RTC_COMP_MSB_SHIFT) &
  2202. CSL_RTC_COMP_MSB_RTC_COMP_MSB_MASK);
  2203. tempVal = (msbVal | lsbVal);
  2204. tempVal = ~(tempVal);
  2205. compVal = (int32_t)(tempVal) + 1;
  2206. return compVal;
  2207. }
  2208. /**
  2209. @}
  2210. */
  2211. #ifdef __cplusplus
  2212. }
  2213. #endif
  2214. #endif /*CSL_RTCAUX_H*/