]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil/driverlib/timer32.h
Final V8.2.1 release ready for tagging:
[freertos] / FreeRTOS / Demo / CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil / driverlib / timer32.h
1 /*
2  * -------------------------------------------
3  *    MSP432 DriverLib - v01_04_00_18 
4  * -------------------------------------------
5  *
6  * --COPYRIGHT--,BSD,BSD
7  * Copyright (c) 2015, Texas Instruments Incorporated
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * *  Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  *
17  * *  Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  *
21  * *  Neither the name of Texas Instruments Incorporated nor the names of
22  *    its contributors may be used to endorse or promote products derived
23  *    from this software without 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,
27  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
32  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  * --/COPYRIGHT--*/
37 #ifndef TIMER32_H_
38 #define TIMER32_H_
39
40 //*****************************************************************************
41 //
42 //! \addtogroup timer32_api
43 //! @{
44 //
45 //*****************************************************************************
46
47 //*****************************************************************************
48 //
49 // If building with a C++ compiler, make all of the definitions in this header
50 // have a C binding.
51 //
52 //*****************************************************************************
53 #ifdef __cplusplus
54 extern "C"
55 {
56 #endif
57 #include <stdint.h>
58 #include <stdbool.h>
59 #include <msp.h>
60
61 //*****************************************************************************
62 //
63 // Control specific variables
64 //
65 //*****************************************************************************
66 #define TIMER_OFFSET    0x020
67
68 #define TIMER32_0_MODULE   TIMER32_BASE
69 #define TIMER32_1_MODULE   (TIMER32_BASE + OFS_TIMER32_LOAD2)
70
71 #define TIMER32_0_INTERRUPT         INT_T32_INT1
72 #define TIMER32_1_INTERRUPT         INT_T32_INT2
73 #define TIMER32_COMBINED_INTERRUPT  INT_T32_INTC
74
75 #define TIMER32_1_MODULE6BIT           0x00
76 #define TIMER32_32BIT           0x01
77
78 #define TIMER32_PRESCALER_1      0x00
79 #define TIMER32_PRESCALER_16     0x04
80 #define TIMER32_PRESCALER_256    0x08
81
82 #define TIMER32_FREE_RUN_MODE   0x00
83 #define TIMER32_PERIODIC_MODE   0x01
84
85 //*****************************************************************************
86 //
87 // API Function prototypes
88 //
89 //*****************************************************************************
90
91 //*****************************************************************************
92 //
93 //! Initializes the Timer32 module
94 //!
95 //! \param timer is the instance of the Timer32 module.
96 //! Valid parameters must be one of the following values:
97 //!         - \b TIMER32_0_MODULE
98 //!         - \b TIMER32_1_MODULE
99 //!
100 //! \param preScaler is the prescaler (or divider) to apply to the clock
101 //! source given to the Timer32 module.
102 //!         Valid values are
103 //!         - \b TIMER32_PRESCALER_1 [DEFAULT]
104 //!         - \b TIMER32_PRESCALER_16
105 //!         - \b TIMER32_PRESCALER_256
106 //! \param resolution is the bit resolution of the Timer32 module.
107 //!         Valid values are
108 //!         - \b TIMER32_1_MODULE6BIT [DEFAULT]
109 //!         - \b TIMER32_32BIT
110 //! \param mode selects between free run and periodic mode. In free run
111 //! mode, the value of the timer is reset to UINT16_MAX (for 16-bit mode) or
112 //! UINT32_MAX (for 16-bit mode) when the timer reaches zero. In periodic mode,
113 //! the timer is reset to the value set by the Timer32_setCount function.
114 //!         Valid values are
115 //!         - \b TIMER32_FREE_RUN_MODE [DEFAULT]
116 //!         - \b TIMER32_PERIODIC_MODE
117 //!
118 //!
119 //! \return None.
120 //
121 //*****************************************************************************
122 extern void Timer32_initModule(uint32_t timer, uint32_t preScaler,
123         uint32_t resolution, uint32_t mode);
124
125 //*****************************************************************************
126 //
127 //! Sets the count of the timer and resets the current value to the value
128 //! passed. This value is set on the next rising edge of the clock provided to
129 //! the timer module
130 //!
131 //! \param timer is the instance of the Timer32 module.
132 //! Valid parameters must be one of the following values:
133 //!         - \b TIMER32_0_MODULE
134 //!         - \b TIMER32_1_MODULE
135 //! \param count Value of the timer to set. Note that
136 //! if the timer is in 16-bit mode and a value is passed in that exceeds
137 //! UINT16_MAX, the value will be truncated to UINT16_MAX.
138 //!
139 //! Also note that if the timer is operating in periodic mode, the value passed
140 //! into this function will represent the new period of the timer (the value
141 //! which is reloaded into the timer each time it reaches a zero value).
142 //!
143 //! \return None
144 //
145 //*****************************************************************************
146 extern void Timer32_setCount(uint32_t timer, uint32_t count);
147
148 //*****************************************************************************
149 //
150 //! Sets the count of the timer without resetting the current value. When the
151 //! current value of the timer reaches zero, the value passed into this function
152 //! will be set as the new count value.
153 //!
154 //! \param timer is the instance of the Timer32 module.
155 //! Valid parameters must be one of the following values:
156 //!         - \b TIMER32_0_MODULE
157 //!         - \b TIMER32_1_MODULE
158 //! \param count Value of the timer to set in the background. Note that
159 //! if the timer is in 16-bit mode and a value is passed in that exceeds
160 //! UINT16_MAX, the value will be truncated to UINT16_MAX.
161 //!
162 //! Also note that if the timer is operating in periodic mode, the value passed
163 //! into this function will represent the new period of the timer (the value
164 //! which is reloaded into the timer each time it reaches a zero value).
165 //!
166 //! \return None
167 //
168 //*****************************************************************************
169 extern void Timer32_setCountInBackground(uint32_t timer, uint32_t count);
170
171 //*****************************************************************************
172 //
173 //! Returns the current value of the timer.
174 //!
175 //! \param timer is the instance of the Timer32 module.
176 //! Valid parameters must be one of the following values:
177 //!         - \b TIMER32_0_MODULE
178 //!         - \b TIMER32_1_MODULE
179 //!
180 //! \return The current count of the timer.
181 //
182 //*****************************************************************************
183 extern uint32_t Timer32_getValue(uint32_t timer);
184
185 //*****************************************************************************
186 //
187 //! Starts the timer. The Timer32_initModule function should be called (in
188 //! conjunction with Timer32_setCount if periodic mode is desired) prior to
189 //  starting the timer.
190 //!
191 //! \param timer is the instance of the Timer32 module.
192 //! Valid parameters must be one of the following values:
193 //!         - \b TIMER32_0_MODULE
194 //!         - \b TIMER32_1_MODULE
195 //!
196 //! \param oneShot sets whether the Timer32 module operates in one shot
197 //!  or continuous mode. In one shot mode, the timer will halt when a zero is
198 //!  reached and stay halted until either:
199 //!         - The user calls the Timer32PeriodSet function
200 //!         - The Timer32_initModule is called to reinitialize the timer with one-shot
201 //!             mode disabled.
202 //!
203 //! A true value will cause the timer to operate in one shot mode while a false
204 //! value will cause the timer to operate in continuous mode
205 //!
206 //! \return None
207 //
208 //*****************************************************************************
209 extern void Timer32_startTimer(uint32_t timer, bool oneShot);
210
211 //*****************************************************************************
212 //
213 //! Halts the timer. Current count and setting values are preserved.
214 //!
215 //! \param timer is the instance of the Timer32 module.
216 //! Valid parameters must be one of the following values:
217 //!         - \b TIMER32_0_MODULE
218 //!         - \b TIMER32_1_MODULE
219 //!
220 //! \return None
221 //
222 //*****************************************************************************
223 extern void Timer32_haltTimer(uint32_t timer);
224
225 //*****************************************************************************
226 //
227 //! Enables a Timer32 interrupt source.
228 //!
229 //! \param timer is the instance of the Timer32 module.
230 //! Valid parameters must be one of the following values:
231 //!         - \b TIMER32_0_MODULE
232 //!         - \b TIMER32_1_MODULE
233 //!
234 //! Enables the indicated Timer32 interrupt source.
235 //!
236 //! \return None.
237 //
238 //*****************************************************************************
239 extern void Timer32_enableInterrupt(uint32_t timer);
240
241 //*****************************************************************************
242 //
243 //! Disables a Timer32 interrupt source.
244 //!
245 //! \param timer is the instance of the Timer32 module.
246 //! Valid parameters must be one of the following values:
247 //!         - \b TIMER32_0_MODULE
248 //!         - \b TIMER32_1_MODULE
249 //!
250 //! Disables the indicated Timer32 interrupt source.
251 //!
252 //! \return None.
253 //
254 //*****************************************************************************
255 extern void Timer32_disableInterrupt(uint32_t timer);
256
257 //*****************************************************************************
258 //
259 //! Clears Timer32 interrupt source.
260 //!
261 //! \param timer is the instance of the Timer32 module.
262 //! Valid parameters must be one of the following values:
263 //!         - \b TIMER32_0_MODULE
264 //!         - \b TIMER32_1_MODULE
265 //!
266 //! The Timer32 interrupt source is cleared, so that it no longer asserts.
267 //!
268 //! \return None.
269 //
270 //*****************************************************************************
271 extern void Timer32_clearInterruptFlag(uint32_t timer);
272
273 //*****************************************************************************
274 //
275 //! Gets the current Timer32 interrupt status.
276 //!
277 //! \param timer is the instance of the Timer32 module.
278 //! Valid parameters must be one of the following values:
279 //!         - \b TIMER32_0_MODULE
280 //!         - \b TIMER32_1_MODULE
281 //!
282 //! This returns the interrupt status for the Timer32 module. A positive value
283 //! will indicate that an interrupt is pending while a zero value will indicate
284 //! that no interrupt is pending.
285 //!
286 //! \return The current interrupt status
287 //
288 //*****************************************************************************
289 extern uint32_t Timer32_getInterruptStatus(uint32_t timer);
290
291 //*****************************************************************************
292 //
293 //! Registers an interrupt handler for Timer32 interrupts.
294 //!
295 //! \param timerInterrupt is the specific interrupt to register. For the
296 //! Timer32 module, there are a total of three different interrupts: one
297 //! interrupt for each two Timer32 modules, and a "combined" interrupt which
298 //! is a logical OR of each individual Timer32 interrupt.
299 //!         - \b TIMER32_0_INTERRUPT
300 //!         - \b TIMER32_1_INTERRUPT
301 //!         - \b TIMER32_COMBINED_INTERRUPT
302 //!
303 //! \param intHandler is a pointer to the function to be called when the
304 //! Timer32 interrupt occurs.
305 //!
306 //! This function registers the handler to be called when an Timer32
307 //! interrupt occurs. This function enables the global interrupt in the
308 //! interrupt controller; specific Timer32 interrupts must be enabled
309 //! via Timer32_enableInterrupt().  It is the interrupt handler's
310 //! responsibility to clear the interrupt source
311 //! via Timer32_clearInterruptFlag().
312 //!
313 //! \return None.
314 //
315 //*****************************************************************************
316 extern void Timer32_registerInterrupt(uint32_t timerInterrupt,
317         void (*intHandler)(void));
318
319 //*****************************************************************************
320 //
321 //! Unregisters the interrupt handler for the Timer32 interrupt.
322 //!
323 //! \param timerInterrupt is the specific interrupt to register. For the
324 //! Timer32 module, there are a total of three different interrupts: one
325 //! interrupt for each two Timer32 modules, and a "combined" interrupt which
326 //! is a logical OR of each individual Timer32 interrupt.
327 //!         - \b TIMER32_0_INTERRUPT
328 //!         - \b TIMER32_1_INTERRUPT
329 //!         - \b TIMER32_COMBINED_INTERRUPT
330 //!
331 //! This function unregisters the handler to be called when a Timer32
332 //! interrupt occurs.  This function also masks off the interrupt in the
333 //! interrupt controller so that the interrupt handler no longer is called.
334 //!
335 //! \sa Interrupt_registerInterrupt() for important information about
336 //! registering interrupt handlers.
337 //!
338 //! \return None.
339 //
340 //*****************************************************************************
341 extern void Timer32_unregisterInterrupt(uint32_t timerInterrupt);
342
343 //*****************************************************************************
344 //
345 // Mark the end of the C bindings section for C++ compilers.
346 //
347 //*****************************************************************************
348 #ifdef __cplusplus
349 }
350 #endif
351
352 //*****************************************************************************
353 //
354 // Close the Doxygen group.
355 //! @}
356 //
357 //*****************************************************************************
358
359 #endif /* TIMER32_H_ */