CC26xx Driver Library
aon_rtc.h
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: aon_rtc.h
3 * Revised: 2016-01-04 14:40:17 +0100 (Mon, 04 Jan 2016)
4 * Revision: 45350
5 *
6 * Description: Defines and prototypes for the AON RTC
7 *
8 * Copyright (c) 2015, Texas Instruments Incorporated
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 *
14 * 1) Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 *
17 * 2) Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 *
21 * 3) Neither the name of the ORGANIZATION nor the names of its contributors may
22 * be used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 *
37 ******************************************************************************/
38 
39 //*****************************************************************************
40 //
45 //
46 //*****************************************************************************
47 
48 #ifndef __AON_RTC_H__
49 #define __AON_RTC_H__
50 
51 //*****************************************************************************
52 //
53 // If building with a C++ compiler, make all of the definitions in this header
54 // have a C binding.
55 //
56 //*****************************************************************************
57 #ifdef __cplusplus
58 extern "C"
59 {
60 #endif
61 
62 #include <stdbool.h>
63 #include <stdint.h>
64 #include <inc/hw_types.h>
65 #include <inc/hw_memmap.h>
66 #include <inc/hw_aon_rtc.h>
67 #include <driverlib/debug.h>
68 
69 //*****************************************************************************
70 //
71 // Support for DriverLib in ROM:
72 // This section renames all functions that are not "static inline", so that
73 // calling these functions will default to implementation in flash. At the end
74 // of this file a second renaming will change the defaults to implementation in
75 // ROM for available functions.
76 //
77 // To force use of the implementation in flash, e.g. for debugging:
78 // - Globally: Define DRIVERLIB_NOROM at project level
79 // - Per function: Use prefix "NOROM_" when calling the function
80 //
81 //*****************************************************************************
82 #if !defined(DOXYGEN)
83  #define AONRTCCurrentCompareValueGet NOROM_AONRTCCurrentCompareValueGet
84  #define AONRTCCurrent64BitValueGet NOROM_AONRTCCurrent64BitValueGet
85 #endif
86 
87 //*****************************************************************************
88 //
89 // Values that can be passed to most of the AON_RTC APIs as the ui32Channel
90 // parameter.
91 //
92 //*****************************************************************************
93 #define AON_RTC_CH_NONE 0x0 // RTC No channel
94 #define AON_RTC_CH0 0x1 // RTC Channel 0
95 #define AON_RTC_CH1 0x2 // RTC Channel 1
96 #define AON_RTC_CH2 0x4 // RTC Channel 2
97 #define AON_RTC_ACTIVE 0x8 // RTC Active
98 
99 //*****************************************************************************
100 //
101 // Values that can be passed to AONRTCConfigDelay as the ui32Delay parameter.
102 //
103 //*****************************************************************************
104 #define AON_RTC_CONFIG_DELAY_NODELAY 0 // NO DELAY
105 #define AON_RTC_CONFIG_DELAY_1 1 // Delay of 1 clk cycle
106 #define AON_RTC_CONFIG_DELAY_2 2 // Delay of 2 clk cycles
107 #define AON_RTC_CONFIG_DELAY_4 3 // Delay of 4 clk cycles
108 #define AON_RTC_CONFIG_DELAY_8 4 // Delay of 8 clk cycles
109 #define AON_RTC_CONFIG_DELAY_16 5 // Delay of 16 clk cycles
110 #define AON_RTC_CONFIG_DELAY_32 6 // Delay of 32 clk cycles
111 #define AON_RTC_CONFIG_DELAY_48 7 // Delay of 48 clk cycles
112 #define AON_RTC_CONFIG_DELAY_64 8 // Delay of 64 clk cycles
113 #define AON_RTC_CONFIG_DELAY_80 9 // Delay of 80 clk cycles
114 #define AON_RTC_CONFIG_DELAY_96 10 // Delay of 96 clk cycles
115 #define AON_RTC_CONFIG_DELAY_112 11 // Delay of 112 clk cycles
116 #define AON_RTC_CONFIG_DELAY_128 12 // Delay of 128 clk cycles
117 #define AON_RTC_CONFIG_DELAY_144 13 // Delay of 144 clk cycles
118 
119 //*****************************************************************************
120 //
121 // Values that can be passed to AONRTCSetModeCH1 as the ui32Mode
122 // parameter.
123 //
124 //*****************************************************************************
125 #define AON_RTC_MODE_CH1_CAPTURE 1 // Capture mode
126 #define AON_RTC_MODE_CH1_COMPARE 0 // Compare Mode
127 
128 //*****************************************************************************
129 //
130 // Values that can be passed to AONRTCSetModeCH2 as the ui32Mode
131 // parameter.
132 //
133 //*****************************************************************************
134 #define AON_RTC_MODE_CH2_CONTINUOUS 1 // Continuous mode
135 #define AON_RTC_MODE_CH2_NORMALCOMPARE 0 // Normal compare mode
136 
137 //*****************************************************************************
138 //
139 // API Functions and prototypes
140 //
141 //*****************************************************************************
142 
143 //*****************************************************************************
144 //
155 //
156 //*****************************************************************************
157 __STATIC_INLINE void
159 {
160  //
161  // Enable RTC.
162  //
164 }
165 
166 //*****************************************************************************
167 //
178 //
179 //*****************************************************************************
180 __STATIC_INLINE void
182 {
183  //
184  // Disable RTC
185  //
187 }
188 
189 //*****************************************************************************
190 //
196 //
197 //*****************************************************************************
198 __STATIC_INLINE void
200 {
201  //
202  // Reset RTC.
203  //
205 }
206 
207 //*****************************************************************************
208 //
214 //
215 //*****************************************************************************
216 __STATIC_INLINE bool
218 {
219  // Read if RTC is enabled
220  return(HWREGBITW(AON_RTC_BASE + AON_RTC_O_CTL, AON_RTC_CTL_EN_BITN));
221 }
222 
223 //*****************************************************************************
224 //
236 //
237 //*****************************************************************************
238 __STATIC_INLINE bool
239 AONRTCChannelActive(uint32_t ui32Channel)
240 {
241  uint32_t uint32Status = 0;
242 
243  if(ui32Channel & AON_RTC_CH0)
244  {
245  uint32Status = HWREGBITW(AON_RTC_BASE + AON_RTC_O_CHCTL, AON_RTC_CHCTL_CH0_EN_BITN);
246  }
247 
248  if(ui32Channel & AON_RTC_CH1)
249  {
250  uint32Status = HWREGBITW(AON_RTC_BASE + AON_RTC_O_CHCTL, AON_RTC_CHCTL_CH1_EN_BITN);
251  }
252 
253  if(ui32Channel & AON_RTC_CH2)
254  {
255  uint32Status = HWREGBITW(AON_RTC_BASE + AON_RTC_O_CHCTL, AON_RTC_CHCTL_CH2_EN_BITN);
256  }
257 
258  return(uint32Status);
259 }
260 
261 //*****************************************************************************
262 //
289 //
290 //*****************************************************************************
291 __STATIC_INLINE void
292 AONRTCDelayConfig(uint32_t ui32Delay)
293 {
294  uint32_t ui32Cfg;
295 
296  //
297  // Check the arguments.
298  //
299  ASSERT(ui32Delay <= AON_RTC_CONFIG_DELAY_144);
300 
301 
302  ui32Cfg = HWREG(AON_RTC_BASE + AON_RTC_O_CTL);
303  ui32Cfg &= ~(AON_RTC_CTL_EV_DELAY_M);
304  ui32Cfg |= (ui32Delay << AON_RTC_CTL_EV_DELAY_S);
305 
306  HWREG(AON_RTC_BASE + AON_RTC_O_CTL) = ui32Cfg;
307 }
308 
309 //*****************************************************************************
310 //
326 //
327 //*****************************************************************************
328 __STATIC_INLINE void
329 AONRTCCombinedEventConfig(uint32_t ui32Channels)
330 {
331  uint32_t ui32Cfg;
332 
333  //
334  // Check the arguments.
335  //
336  ASSERT( (ui32Channels & (AON_RTC_CH0 | AON_RTC_CH1 | AON_RTC_CH2)) ||
337  (ui32Channels == AON_RTC_CH_NONE) );
338 
339  ui32Cfg = HWREG(AON_RTC_BASE + AON_RTC_O_CTL);
340  ui32Cfg &= ~(AON_RTC_CTL_COMB_EV_MASK_M);
341  ui32Cfg |= (ui32Channels << AON_RTC_CTL_COMB_EV_MASK_S);
342 
343  HWREG(AON_RTC_BASE + AON_RTC_O_CTL) = ui32Cfg;
344 }
345 
346 //*****************************************************************************
347 //
359 //
360 //*****************************************************************************
361 __STATIC_INLINE void
362 AONRTCEventClear(uint32_t ui32Channel)
363 {
364  // Check the arguments.
365  ASSERT((ui32Channel == AON_RTC_CH0) ||
366  (ui32Channel == AON_RTC_CH1) ||
367  (ui32Channel == AON_RTC_CH2));
368 
369  if(ui32Channel & AON_RTC_CH0)
370  {
372  }
373 
374  if(ui32Channel & AON_RTC_CH1)
375  {
377  }
378 
379  if(ui32Channel & AON_RTC_CH2)
380  {
382  }
383 }
384 
385 //*****************************************************************************
386 //
400 //
401 //*****************************************************************************
402 __STATIC_INLINE bool
403 AONRTCEventGet(uint32_t ui32Channel)
404 {
405  uint32_t uint32Event = 0;
406 
407  // Check the arguments.
408  ASSERT((ui32Channel == AON_RTC_CH0) ||
409  (ui32Channel == AON_RTC_CH1) ||
410  (ui32Channel == AON_RTC_CH2));
411 
412  if(ui32Channel & AON_RTC_CH0)
413  {
414  uint32Event = HWREGBITW(AON_RTC_BASE + AON_RTC_O_EVFLAGS, AON_RTC_EVFLAGS_CH0_BITN);
415  }
416 
417  if(ui32Channel & AON_RTC_CH1)
418  {
419  uint32Event = HWREGBITW(AON_RTC_BASE + AON_RTC_O_EVFLAGS, AON_RTC_EVFLAGS_CH1_BITN);
420  }
421 
422  if(ui32Channel & AON_RTC_CH2)
423  {
424  uint32Event = HWREGBITW(AON_RTC_BASE + AON_RTC_O_EVFLAGS, AON_RTC_EVFLAGS_CH2_BITN);
425  }
426 
427  return(uint32Event);
428 }
429 
430 //*****************************************************************************
431 //
448 //
449 //*****************************************************************************
450 __STATIC_INLINE uint32_t
452 {
453  //
454  // The following read gets the seconds, but also latches the fractional
455  // part.
456  //
457  return(HWREG(AON_RTC_BASE + AON_RTC_O_SEC));
458 }
459 
460 //*****************************************************************************
461 //
478 //
479 //*****************************************************************************
480 __STATIC_INLINE uint32_t
482 {
483  //
484  // Note1: It is recommended to use AON RTCCurrentCompareValueGet() instead
485  // of this function if the <16.16> format is sufficient.
486  // Note2: AONRTCSecGet() must be called before this function to get a
487  // consistent reading.
488  // Note3: Interrupts must be disabled between the call to AONRTCSecGet() and this
489  // call since there are interrupt functions that reads AON_RTC_O_SEC
490  //
491  return(HWREG(AON_RTC_BASE + AON_RTC_O_SUBSEC));
492 }
493 
494 //*****************************************************************************
495 //
510 //
511 //*****************************************************************************
512 __STATIC_INLINE uint32_t
514 {
515  return(HWREG(AON_RTC_BASE + AON_RTC_O_SUBSECINC));
516 }
517 
518 //*****************************************************************************
519 //
536 //
537 //*****************************************************************************
538 __STATIC_INLINE void
539 AONRTCModeCh1Set(uint32_t ui32Mode)
540 {
541  // Check the arguments.
542  ASSERT((ui32Mode == AON_RTC_MODE_CH1_CAPTURE) ||
543  (ui32Mode == AON_RTC_MODE_CH1_COMPARE));
544 
546 }
547 
548 //*****************************************************************************
549 //
561 //
562 //*****************************************************************************
563 __STATIC_INLINE uint32_t
565 {
567 }
568 
569 //*****************************************************************************
570 //
590 //
591 //*****************************************************************************
592 __STATIC_INLINE void
593 AONRTCModeCh2Set(uint32_t ui32Mode)
594 {
595  // Check the arguments.
596  ASSERT((ui32Mode == AON_RTC_MODE_CH2_CONTINUOUS) ||
597  (ui32Mode == AON_RTC_MODE_CH2_NORMALCOMPARE));
598 
600 }
601 
602 //*****************************************************************************
603 //
618 //
619 //*****************************************************************************
620 __STATIC_INLINE uint32_t
622 {
624 }
625 
626 //*****************************************************************************
627 //
643 //
644 //*****************************************************************************
645 __STATIC_INLINE void
646 AONRTCChannelEnable(uint32_t ui32Channel)
647 {
648  // Check the arguments.
649  ASSERT((ui32Channel == AON_RTC_CH0) ||
650  (ui32Channel == AON_RTC_CH1) ||
651  (ui32Channel == AON_RTC_CH2));
652 
653  if(ui32Channel & AON_RTC_CH0)
654  {
656  }
657 
658  if(ui32Channel & AON_RTC_CH1)
659  {
661  }
662 
663  if(ui32Channel & AON_RTC_CH2)
664  {
666  }
667 }
668 
669 //*****************************************************************************
670 //
686 //
687 //*****************************************************************************
688 __STATIC_INLINE void
689 AONRTCChannelDisable(uint32_t ui32Channel)
690 {
691  // Check the arguments.
692  ASSERT((ui32Channel == AON_RTC_CH0) ||
693  (ui32Channel == AON_RTC_CH1) ||
694  (ui32Channel == AON_RTC_CH2));
695 
696  if(ui32Channel & AON_RTC_CH0)
697  {
699  }
700 
701  if(ui32Channel & AON_RTC_CH1)
702  {
704  }
705 
706  if(ui32Channel & AON_RTC_CH2)
707  {
709  }
710 }
711 
712 //*****************************************************************************
713 //
733 //
734 //*****************************************************************************
735 __STATIC_INLINE void
736 AONRTCCompareValueSet(uint32_t ui32Channel, uint32_t ui32CompValue)
737 {
738  // Check the arguments.
739  ASSERT((ui32Channel == AON_RTC_CH0) ||
740  (ui32Channel == AON_RTC_CH1) ||
741  (ui32Channel == AON_RTC_CH2));
742 
743  if(ui32Channel & AON_RTC_CH0)
744  {
745  HWREG(AON_RTC_BASE + AON_RTC_O_CH0CMP) = ui32CompValue;
746  }
747 
748  if(ui32Channel & AON_RTC_CH1)
749  {
750  HWREG(AON_RTC_BASE + AON_RTC_O_CH1CMP) = ui32CompValue;
751  }
752 
753  if(ui32Channel & AON_RTC_CH2)
754  {
755  HWREG(AON_RTC_BASE + AON_RTC_O_CH2CMP) = ui32CompValue;
756  }
757 }
758 
759 //*****************************************************************************
760 //
772 //
773 //*****************************************************************************
774 __STATIC_INLINE uint32_t
775 AONRTCCompareValueGet(uint32_t ui32Channel)
776 {
777  uint32_t ui32Value = 0;
778 
779  // Check the arguments
780  ASSERT((ui32Channel == AON_RTC_CH0) ||
781  (ui32Channel == AON_RTC_CH1) ||
782  (ui32Channel == AON_RTC_CH2));
783 
784  if(ui32Channel & AON_RTC_CH0)
785  {
786  ui32Value = HWREG(AON_RTC_BASE + AON_RTC_O_CH0CMP);
787  }
788 
789  if(ui32Channel & AON_RTC_CH1)
790  {
791  ui32Value = HWREG(AON_RTC_BASE + AON_RTC_O_CH1CMP);
792  }
793 
794  if(ui32Channel & AON_RTC_CH2)
795  {
796  ui32Value = HWREG(AON_RTC_BASE + AON_RTC_O_CH2CMP);
797  }
798 
799  return(ui32Value);
800 }
801 
802 //*****************************************************************************
803 //
819 //
820 //*****************************************************************************
821 extern uint32_t AONRTCCurrentCompareValueGet(void);
822 
823 //*****************************************************************************
824 //
833 //
834 //*****************************************************************************
835 extern uint64_t AONRTCCurrent64BitValueGet(void);
836 
837 //*****************************************************************************
838 //
851 //
852 //*****************************************************************************
853 __STATIC_INLINE void
854 AONRTCIncValueCh2Set(uint32_t ui32IncValue)
855 {
856  HWREG(AON_RTC_BASE + AON_RTC_O_CH2CMPINC) = ui32IncValue;
857 }
858 
859 //*****************************************************************************
860 //
873 //
874 //*****************************************************************************
875 __STATIC_INLINE uint32_t
877 {
878  return(HWREG(AON_RTC_BASE + AON_RTC_O_CH2CMPINC));
879 }
880 
881 //*****************************************************************************
882 //
891 //
892 //*****************************************************************************
893 __STATIC_INLINE uint32_t
895 {
896  return(HWREG(AON_RTC_BASE + AON_RTC_O_CH1CAPT));
897 }
898 
899 //*****************************************************************************
900 //
901 // Support for DriverLib in ROM:
902 // Redirect to implementation in ROM when available.
903 //
904 //*****************************************************************************
905 #if !defined(DRIVERLIB_NOROM) && !defined(DOXYGEN)
906  #include <driverlib/rom.h>
907  #ifdef ROM_AONRTCCurrentCompareValueGet
908  #undef AONRTCCurrentCompareValueGet
909  #define AONRTCCurrentCompareValueGet ROM_AONRTCCurrentCompareValueGet
910  #endif
911  #ifdef ROM_AONRTCCurrent64BitValueGet
912  #undef AONRTCCurrent64BitValueGet
913  #define AONRTCCurrent64BitValueGet ROM_AONRTCCurrent64BitValueGet
914  #endif
915 #endif
916 
917 //*****************************************************************************
918 //
919 // Mark the end of the C bindings section for C++ compilers.
920 //
921 //*****************************************************************************
922 #ifdef __cplusplus
923 }
924 #endif
925 
926 #endif // __AON_RTC_H__
927 
928 //*****************************************************************************
929 //
933 //
934 //*****************************************************************************
#define AON_RTC_CH1
Definition: aon_rtc.h:95
static uint32_t AONRTCSubSecIncrGet(void)
Get the sub second increment of the RTC.
Definition: aon_rtc.h:513
static bool AONRTCChannelActive(uint32_t ui32Channel)
Check if an RTC channel is active (enabled).
Definition: aon_rtc.h:239
static void AONRTCEventClear(uint32_t ui32Channel)
Clear event from a specified channel.
Definition: aon_rtc.h:362
static void AONRTCModeCh1Set(uint32_t ui32Mode)
Set operational mode of channel 1.
Definition: aon_rtc.h:539
static void AONRTCModeCh2Set(uint32_t ui32Mode)
Set operational mode of channel 2.
Definition: aon_rtc.h:593
#define AON_RTC_CONFIG_DELAY_144
Definition: aon_rtc.h:117
#define AON_RTC_CH_NONE
Definition: aon_rtc.h:93
uint64_t AONRTCCurrent64BitValueGet(void)
Get the current 64-bit value of the RTC counter.
Definition: aon_rtc.c:87
static void AONRTCDisable(void)
Disable the RTC.
Definition: aon_rtc.h:181
static bool AONRTCActive(void)
Check if the RTC is active (enabled).
Definition: aon_rtc.h:217
#define AON_RTC_CH2
Definition: aon_rtc.h:96
static uint32_t AONRTCCompareValueGet(uint32_t ui32Channel)
Get the compare value for the given channel.
Definition: aon_rtc.h:775
static void AONRTCChannelDisable(uint32_t ui32Channel)
Disable event operation for the specified channel.
Definition: aon_rtc.h:689
#define AON_RTC_MODE_CH1_CAPTURE
Definition: aon_rtc.h:125
static void AONRTCCombinedEventConfig(uint32_t ui32Channels)
Configure the source of the combined event.
Definition: aon_rtc.h:329
static void AONRTCIncValueCh2Set(uint32_t ui32IncValue)
Set the channel 2 increment value when operating in continuous mode.
Definition: aon_rtc.h:854
static void AONRTCReset(void)
Reset the RTC.
Definition: aon_rtc.h:199
#define AON_RTC_CH0
Definition: aon_rtc.h:94
#define AON_RTC_MODE_CH2_NORMALCOMPARE
Definition: aon_rtc.h:135
#define ASSERT(expr)
Definition: debug.h:74
#define AON_RTC_MODE_CH1_COMPARE
Definition: aon_rtc.h:126
static void AONRTCEnable(void)
Enable the RTC.
Definition: aon_rtc.h:158
static void AONRTCDelayConfig(uint32_t ui32Delay)
Configure Event Delay for the RTC.
Definition: aon_rtc.h:292
static uint32_t AONRTCModeCh1Get(void)
Get operational mode of channel 1.
Definition: aon_rtc.h:564
static void AONRTCChannelEnable(uint32_t ui32Channel)
Enable event operation for the specified channel.
Definition: aon_rtc.h:646
#define AON_RTC_MODE_CH2_CONTINUOUS
Definition: aon_rtc.h:134
static uint32_t AONRTCCaptureValueCh1Get(void)
Get the channel 1 capture value.
Definition: aon_rtc.h:894
static uint32_t AONRTCModeCh2Get(void)
Get operational mode of channel 2.
Definition: aon_rtc.h:621
uint32_t AONRTCCurrentCompareValueGet(void)
Get the current value of the RTC counter in a format that matches RTC compare values.
Definition: aon_rtc.c:62
static uint32_t AONRTCFractionGet(void)
Get fractional part (sub-seconds) of RTC free-running timer.
Definition: aon_rtc.h:481
static void AONRTCCompareValueSet(uint32_t ui32Channel, uint32_t ui32CompValue)
Set the compare value for the given channel.
Definition: aon_rtc.h:736
static uint32_t AONRTCSecGet(void)
Get integer part (seconds) of RTC free-running timer.
Definition: aon_rtc.h:451
static bool AONRTCEventGet(uint32_t ui32Channel)
Get event status for a specified channel.
Definition: aon_rtc.h:403
static uint32_t AONRTCIncValueCh2Get(void)
Get the channel2 increment value when operating in continuous mode.
Definition: aon_rtc.h:876