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

Copyright 2015, Texas Instruments Incorporated