MSP430 DriverLib for MSP430FR2xx_4xx Devices  2.91.13.01
rtc.h
1 //*****************************************************************************
2 //
3 // rtc.h - Driver for the RTC Module.
4 //
5 //*****************************************************************************
6 
7 #ifndef __MSP430WARE_RTC_H__
8 #define __MSP430WARE_RTC_H__
9 
10 #include "inc/hw_memmap.h"
11 
12 #ifdef __MSP430_HAS_RTC__
13 
14 //*****************************************************************************
15 //
16 // If building with a C++ compiler, make all of the definitions in this header
17 // have a C binding.
18 //
19 //*****************************************************************************
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif
24 
25 //*****************************************************************************
26 //
27 // The following are values that can be passed to the clockSource parameter for
28 // functions: RTC_start().
29 //
30 //*****************************************************************************
31 #define RTC_CLOCKSOURCE_DISABLED (RTCSS_0)
32 #define RTC_CLOCKSOURCE_SMCLK (RTCSS_1)
33 #define RTC_CLOCKSOURCE_XT1CLK (RTCSS_2)
34 #define RTC_CLOCKSOURCE_VLOCLK (RTCSS_3)
35 #define RTC_CLOCKSOURCE_ACLK (0x4000)
36 
37 //*****************************************************************************
38 //
39 // The following are values that can be passed to the clockPredivider parameter
40 // for functions: RTC_init().
41 //
42 //*****************************************************************************
43 #define RTC_CLOCKPREDIVIDER_1 (RTCPS_0)
44 #define RTC_CLOCKPREDIVIDER_10 (RTCPS_1)
45 #define RTC_CLOCKPREDIVIDER_100 (RTCPS_2)
46 #define RTC_CLOCKPREDIVIDER_1000 (RTCPS_3)
47 #define RTC_CLOCKPREDIVIDER_16 (RTCPS_4)
48 #define RTC_CLOCKPREDIVIDER_64 (RTCPS_5)
49 #define RTC_CLOCKPREDIVIDER_256 (RTCPS_6)
50 #define RTC_CLOCKPREDIVIDER_1024 (RTCPS_7)
51 
52 //*****************************************************************************
53 //
54 // The following are values that can be passed to the interruptMask parameter
55 // for functions: RTC_enableInterrupt(), and RTC_disableInterrupt().
56 //
57 //*****************************************************************************
58 #define RTC_OVERFLOW_INTERRUPT (RTCIE)
59 
60 //*****************************************************************************
61 //
62 // The following are values that can be passed to the interruptFlagMask
63 // parameter for functions: RTC_getInterruptStatus(), and RTC_clearInterrupt().
64 //
65 //*****************************************************************************
66 #define RTC_OVERFLOW_INTERRUPT_FLAG (RTCIF)
67 
68 //*****************************************************************************
69 //
70 // Prototypes for the APIs.
71 //
72 //*****************************************************************************
73 
74 //*****************************************************************************
75 //
76 //! \brief Initializes the RTC.
77 //!
78 //! This function initializes the RTC for clock source and clock pre-divider.
79 //!
80 //! \param baseAddress is the base address of the RTC module.
81 //! \param modulo is the modulo value to set to RTC.
82 //! \n Modified bits of \b RTCMOD register.
83 //! \param clockPredivider is the clock pre-divider select for RTC.
84 //! Valid values are:
85 //! - \b RTC_CLOCKPREDIVIDER_1 [Default]
86 //! - \b RTC_CLOCKPREDIVIDER_10
87 //! - \b RTC_CLOCKPREDIVIDER_100
88 //! - \b RTC_CLOCKPREDIVIDER_1000
89 //! - \b RTC_CLOCKPREDIVIDER_16
90 //! - \b RTC_CLOCKPREDIVIDER_64
91 //! - \b RTC_CLOCKPREDIVIDER_256
92 //! - \b RTC_CLOCKPREDIVIDER_1024
93 //! \n Modified bits are \b RTCPS of \b RTCCTL register.
94 //!
95 //! \return None
96 //
97 //*****************************************************************************
98 extern void RTC_init(uint16_t baseAddress,
99  uint16_t modulo,
100  uint16_t clockPredivider);
101 
102 //*****************************************************************************
103 //
104 //! \brief Starts RTC running.
105 //!
106 //! This function starts the RTC by setting the clock source field (RTCSS).
107 //! When started, the RTC counter will begin counting at the rate described by
108 //! the clock source and pre-divider value. When the RTC counter reaches the
109 //! value in the modulo register, the RTC hardware sets the RTC's interrupt
110 //! flag bit (RTCIF). Please note, that the RTC actually compares the RTC
111 //! counter to the modulo shadow register. Since the RTC_start() function sets
112 //! the RTCSR (RTC software reset) bit, this forces the RTC to copy the value
113 //! from the Modulo register into the shadow register.
114 //!
115 //! \param baseAddress is the base address of the RTC module.
116 //! \param clockSource is the clock source select for RTC.
117 //! Valid values are:
118 //! - \b RTC_CLOCKSOURCE_DISABLED [Default]
119 //! - \b RTC_CLOCKSOURCE_SMCLK
120 //! - \b RTC_CLOCKSOURCE_XT1CLK
121 //! - \b RTC_CLOCKSOURCE_VLOCLK
122 //! - \b RTC_CLOCKSOURCE_ACLK
123 //! \n Modified bits are \b RTCSS of \b RTCCTL register.
124 //!
125 //! Modified bits are \b RTCSR of \b RTCCTL register.
126 //!
127 //! \return None
128 //
129 //*****************************************************************************
130 extern void RTC_start(uint16_t baseAddress,
131  uint16_t clockSource);
132 
133 //*****************************************************************************
134 //
135 //! \brief Stops RTC running.
136 //!
137 //! This function does software reset for RTC.
138 //!
139 //! \param baseAddress is the base address of the RTC module.
140 //!
141 //! \return None
142 //
143 //*****************************************************************************
144 extern void RTC_stop(uint16_t baseAddress);
145 
146 //*****************************************************************************
147 //
148 //! \brief Sets the modulo value.
149 //!
150 //! This function does software reset for RTC.
151 //!
152 //! \param baseAddress is the base address of the RTC module.
153 //! \param modulo is the modulo value to set to RTC.
154 //! \n Modified bits of \b RTCMOD register.
155 //!
156 //! \return None
157 //
158 //*****************************************************************************
159 extern void RTC_setModulo(uint16_t baseAddress,
160  uint16_t modulo);
161 
162 //*****************************************************************************
163 //
164 //! \brief Enables selected RTC interrupt sources.
165 //!
166 //! This function enables the selected RTC interrupt source. Only the sources
167 //! that are enabled can be reflected to the processor interrupt; disabled
168 //! sources have no effect on the processor. Does not clear interrupt flags.
169 //!
170 //! \param baseAddress is the base address of the RTC module.
171 //! \param interruptMask is a bit mask of the interrupts to enable.
172 //! Valid values are:
173 //! - \b RTC_OVERFLOW_INTERRUPT - counter overflow interrupt
174 //!
175 //! Modified bits are \b RTCIE of \b RTCCTL register.
176 //!
177 //! \return None
178 //
179 //*****************************************************************************
180 extern void RTC_enableInterrupt(uint16_t baseAddress,
181  uint8_t interruptMask);
182 
183 //*****************************************************************************
184 //
185 //! \brief Disables selected RTC interrupt sources.
186 //!
187 //! This function disables the selected RTC interrupt source. Only the sources
188 //! that are enabled can be reflected to the processor interrupt; disabled
189 //! sources have no effect on the processor.
190 //!
191 //! \param baseAddress is the base address of the RTC module.
192 //! \param interruptMask is a bit mask of the interrupts to disable.
193 //! Valid values are:
194 //! - \b RTC_OVERFLOW_INTERRUPT - counter overflow interrupt
195 //!
196 //! Modified bits are \b RTCIE of \b RTCCTL register.
197 //!
198 //! \return None
199 //
200 //*****************************************************************************
201 extern void RTC_disableInterrupt(uint16_t baseAddress,
202  uint8_t interruptMask);
203 
204 //*****************************************************************************
205 //
206 //! \brief Returns the status of the selected interrupts flags.
207 //!
208 //! This function returns the status of the interrupt flag for the selected
209 //! channel.
210 //!
211 //! \param baseAddress is the base address of the RTC module.
212 //! \param interruptFlagMask is a bit mask of the interrupt flags to return the
213 //! status of.
214 //! Valid values are:
215 //! - \b RTC_OVERFLOW_INTERRUPT_FLAG - asserts when counter overflows
216 //!
217 //! \return A bit mask of the selected interrupt flag's status.
218 //
219 //*****************************************************************************
220 extern uint8_t RTC_getInterruptStatus(uint16_t baseAddress,
221  uint8_t interruptFlagMask);
222 
223 //*****************************************************************************
224 //
225 //! \brief Clears selected RTC interrupt flags.
226 //!
227 //! This function clears the RTC interrupt flag is cleared, so that it no
228 //! longer asserts.
229 //!
230 //! \param baseAddress is the base address of the RTC module.
231 //! \param interruptFlagMask is a bit mask of the interrupt flags to clear
232 //! Valid values are:
233 //! - \b RTC_OVERFLOW_INTERRUPT_FLAG - asserts when counter overflows
234 //!
235 //! Modified bits are \b RTCIF of \b RTCCTL register.
236 //!
237 //! \return None
238 //
239 //*****************************************************************************
240 extern void RTC_clearInterrupt(uint16_t baseAddress,
241  int8_t interruptFlagMask);
242 
243 //*****************************************************************************
244 //
245 // Mark the end of the C bindings section for C++ compilers.
246 //
247 //*****************************************************************************
248 #ifdef __cplusplus
249 }
250 #endif
251 
252 #endif
253 #endif // __MSP430WARE_RTC_H__
void RTC_start(uint16_t baseAddress, uint16_t clockSource)
Starts RTC running.
Definition: rtc.c:31
void RTC_clearInterrupt(uint16_t baseAddress, int8_t interruptFlagMask)
Clears selected RTC interrupt flags.
Definition: rtc.c:90
void RTC_setModulo(uint16_t baseAddress, uint16_t modulo)
Sets the modulo value.
Definition: rtc.c:56
void RTC_enableInterrupt(uint16_t baseAddress, uint8_t interruptMask)
Enables selected RTC interrupt sources.
Definition: rtc.c:62
void RTC_disableInterrupt(uint16_t baseAddress, uint8_t interruptMask)
Disables selected RTC interrupt sources.
Definition: rtc.c:70
void RTC_init(uint16_t baseAddress, uint16_t modulo, uint16_t clockPredivider)
Initializes the RTC.
Definition: rtc.c:21
uint8_t RTC_getInterruptStatus(uint16_t baseAddress, uint8_t interruptFlagMask)
Returns the status of the selected interrupts flags.
Definition: rtc.c:78
void RTC_stop(uint16_t baseAddress)
Stops RTC running.
Definition: rtc.c:51

Copyright 2020, Texas Instruments Incorporated