]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil/driverlib/timer32.h
commit 9f316c246baafa15c542a5aea81a94f26e3d6507
[freertos] / FreeRTOS / Demo / CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil / driverlib / timer32.h
1 /*
2  * -------------------------------------------
3  *    MSP432 DriverLib - v3_10_00_09 
4  * -------------------------------------------
5  *
6  * --COPYRIGHT--,BSD,BSD
7  * Copyright (c) 2014, 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 TIMER32_CMSIS(x) ((Timer32_Type *) x)
67
68 #define TIMER_OFFSET    0x020
69
70 #define TIMER32_0_BASE   TIMER32_1
71 #define TIMER32_1_BASE   TIMER32_2
72
73 #define TIMER32_0_INTERRUPT         INT_T32_INT1
74 #define TIMER32_1_INTERRUPT         INT_T32_INT2
75 #define TIMER32_COMBINED_INTERRUPT  INT_T32_INTC
76
77 #define TIMER32_1_MODULE6BIT           0x00
78 #define TIMER32_32BIT           0x01
79
80 #define TIMER32_PRESCALER_1      0x00
81 #define TIMER32_PRESCALER_16     0x04
82 #define TIMER32_PRESCALER_256    0x08
83
84 #define TIMER32_FREE_RUN_MODE   0x00
85 #define TIMER32_PERIODIC_MODE   0x01
86
87 //*****************************************************************************
88 //
89 // API Function prototypes
90 //
91 //*****************************************************************************
92
93 //*****************************************************************************
94 //
95 //! Initializes the Timer32 module
96 //!
97 //! \param timer is the instance of the Timer32 module.
98 //! Valid parameters must be one of the following values:
99 //!         - \b TIMER32_0_BASE
100 //!         - \b TIMER32_1_BASE
101 //!
102 //! \param preScaler is the prescaler (or divider) to apply to the clock
103 //! source given to the Timer32 module.
104 //!         Valid values are
105 //!         - \b TIMER32_PRESCALER_1 [DEFAULT]
106 //!         - \b TIMER32_PRESCALER_16
107 //!         - \b TIMER32_PRESCALER_256
108 //! \param resolution is the bit resolution of the Timer32 module.
109 //!         Valid values are
110 //!         - \b TIMER32_1_MODULE6BIT [DEFAULT]
111 //!         - \b TIMER32_32BIT
112 //! \param mode selects between free run and periodic mode. In free run
113 //! mode, the value of the timer is reset to UINT16_MAX (for 16-bit mode) or
114 //! UINT32_MAX (for 16-bit mode) when the timer reaches zero. In periodic mode,
115 //! the timer is reset to the value set by the Timer32_setCount function.
116 //!         Valid values are
117 //!         - \b TIMER32_FREE_RUN_MODE [DEFAULT]
118 //!         - \b TIMER32_PERIODIC_MODE
119 //!
120 //!
121 //! \return None.
122 //
123 //*****************************************************************************
124 extern void Timer32_initModule(uint32_t timer, uint32_t preScaler,
125         uint32_t resolution, uint32_t mode);
126
127 //*****************************************************************************
128 //
129 //! Sets the count of the timer and resets the current value to the value
130 //! passed. This value is set on the next rising edge of the clock provided to
131 //! the timer module
132 //!
133 //! \param timer is the instance of the Timer32 module.
134 //! Valid parameters must be one of the following values:
135 //!         - \b TIMER32_0_BASE
136 //!         - \b TIMER32_1_BASE
137 //! \param count Value of the timer to set. Note that
138 //! if the timer is in 16-bit mode and a value is passed in that exceeds
139 //! UINT16_MAX, the value will be truncated to UINT16_MAX.
140 //!
141 //! Also note that if the timer is operating in periodic mode, the value passed
142 //! into this function will represent the new period of the timer (the value
143 //! which is reloaded into the timer each time it reaches a zero value).
144 //!
145 //! \return None
146 //
147 //*****************************************************************************
148 extern void Timer32_setCount(uint32_t timer, uint32_t count);
149
150 //*****************************************************************************
151 //
152 //! Sets the count of the timer without resetting the current value. When the
153 //! current value of the timer reaches zero, the value passed into this function
154 //! will be set as the new count value.
155 //!
156 //! \param timer is the instance of the Timer32 module.
157 //! Valid parameters must be one of the following values:
158 //!         - \b TIMER32_0_BASE
159 //!         - \b TIMER32_1_BASE
160 //! \param count Value of the timer to set in the background. Note that
161 //! if the timer is in 16-bit mode and a value is passed in that exceeds
162 //! UINT16_MAX, the value will be truncated to UINT16_MAX.
163 //!
164 //! Also note that if the timer is operating in periodic mode, the value passed
165 //! into this function will represent the new period of the timer (the value
166 //! which is reloaded into the timer each time it reaches a zero value).
167 //!
168 //! \return None
169 //
170 //*****************************************************************************
171 extern void Timer32_setCountInBackground(uint32_t timer, uint32_t count);
172
173 //*****************************************************************************
174 //
175 //! Returns the current value of the timer.
176 //!
177 //! \param timer is the instance of the Timer32 module.
178 //! Valid parameters must be one of the following values:
179 //!         - \b TIMER32_0_BASE
180 //!         - \b TIMER32_1_BASE
181 //!
182 //! \return The current count of the timer.
183 //
184 //*****************************************************************************
185 extern uint32_t Timer32_getValue(uint32_t timer);
186
187 //*****************************************************************************
188 //
189 //! Starts the timer. The Timer32_initModule function should be called (in
190 //! conjunction with Timer32_setCount if periodic mode is desired) prior to
191 //  starting the timer.
192 //!
193 //! \param timer is the instance of the Timer32 module.
194 //! Valid parameters must be one of the following values:
195 //!         - \b TIMER32_0_BASE
196 //!         - \b TIMER32_1_BASE
197 //!
198 //! \param oneShot sets whether the Timer32 module operates in one shot
199 //!  or continuous mode. In one shot mode, the timer will halt when a zero is
200 //!  reached and stay halted until either:
201 //!         - The user calls the Timer32PeriodSet function
202 //!         - The Timer32_initModule is called to reinitialize the timer with one-shot
203 //!             mode disabled.
204 //!
205 //! A true value will cause the timer to operate in one shot mode while a false
206 //! value will cause the timer to operate in continuous mode
207 //!
208 //! \return None
209 //
210 //*****************************************************************************
211 extern void Timer32_startTimer(uint32_t timer, bool oneShot);
212
213 //*****************************************************************************
214 //
215 //! Halts the timer. Current count and setting values are preserved.
216 //!
217 //! \param timer is the instance of the Timer32 module.
218 //! Valid parameters must be one of the following values:
219 //!         - \b TIMER32_0_BASE
220 //!         - \b TIMER32_1_BASE
221 //!
222 //! \return None
223 //
224 //*****************************************************************************
225 extern void Timer32_haltTimer(uint32_t timer);
226
227 //*****************************************************************************
228 //
229 //! Enables a Timer32 interrupt source.
230 //!
231 //! \param timer is the instance of the Timer32 module.
232 //! Valid parameters must be one of the following values:
233 //!         - \b TIMER32_0_BASE
234 //!         - \b TIMER32_1_BASE
235 //!
236 //! Enables the indicated Timer32 interrupt source.
237 //!
238 //! \return None.
239 //
240 //*****************************************************************************
241 extern void Timer32_enableInterrupt(uint32_t timer);
242
243 //*****************************************************************************
244 //
245 //! Disables a Timer32 interrupt source.
246 //!
247 //! \param timer is the instance of the Timer32 module.
248 //! Valid parameters must be one of the following values:
249 //!         - \b TIMER32_0_BASE
250 //!         - \b TIMER32_1_BASE
251 //!
252 //! Disables the indicated Timer32 interrupt source.
253 //!
254 //! \return None.
255 //
256 //*****************************************************************************
257 extern void Timer32_disableInterrupt(uint32_t timer);
258
259 //*****************************************************************************
260 //
261 //! Clears Timer32 interrupt source.
262 //!
263 //! \param timer is the instance of the Timer32 module.
264 //! Valid parameters must be one of the following values:
265 //!         - \b TIMER32_0_BASE
266 //!         - \b TIMER32_1_BASE
267 //!
268 //! The Timer32 interrupt source is cleared, so that it no longer asserts.
269 //!
270 //! \return None.
271 //
272 //*****************************************************************************
273 extern void Timer32_clearInterruptFlag(uint32_t timer);
274
275 //*****************************************************************************
276 //
277 //! Gets the current Timer32 interrupt status.
278 //!
279 //! \param timer is the instance of the Timer32 module.
280 //! Valid parameters must be one of the following values:
281 //!         - \b TIMER32_0_BASE
282 //!         - \b TIMER32_1_BASE
283 //!
284 //! This returns the interrupt status for the Timer32 module. A positive value
285 //! will indicate that an interrupt is pending while a zero value will indicate
286 //! that no interrupt is pending.
287 //!
288 //! \return The current interrupt status
289 //
290 //*****************************************************************************
291 extern uint32_t Timer32_getInterruptStatus(uint32_t timer);
292
293 //*****************************************************************************
294 //
295 //! Registers an interrupt handler for Timer32 interrupts.
296 //!
297 //! \param timerInterrupt is the specific interrupt to register. For the
298 //! Timer32 module, there are a total of three different interrupts: one
299 //! interrupt for each two Timer32 modules, and a "combined" interrupt which
300 //! is a logical OR of each individual Timer32 interrupt.
301 //!         - \b TIMER32_0_INTERRUPT
302 //!         - \b TIMER32_1_INTERRUPT
303 //!         - \b TIMER32_COMBINED_INTERRUPT
304 //!
305 //! \param intHandler is a pointer to the function to be called when the
306 //! Timer32 interrupt occurs.
307 //!
308 //! This function registers the handler to be called when an Timer32
309 //! interrupt occurs. This function enables the global interrupt in the
310 //! interrupt controller; specific Timer32 interrupts must be enabled
311 //! via Timer32_enableInterrupt().  It is the interrupt handler's
312 //! responsibility to clear the interrupt source
313 //! via Timer32_clearInterruptFlag().
314 //!
315 //! \return None.
316 //
317 //*****************************************************************************
318 extern void Timer32_registerInterrupt(uint32_t timerInterrupt,
319         void (*intHandler)(void));
320
321 //*****************************************************************************
322 //
323 //! Unregisters the interrupt handler for the Timer32 interrupt.
324 //!
325 //! \param timerInterrupt is the specific interrupt to register. For the
326 //! Timer32 module, there are a total of three different interrupts: one
327 //! interrupt for each two Timer32 modules, and a "combined" interrupt which
328 //! is a logical OR of each individual Timer32 interrupt.
329 //!         - \b TIMER32_0_INTERRUPT
330 //!         - \b TIMER32_1_INTERRUPT
331 //!         - \b TIMER32_COMBINED_INTERRUPT
332 //!
333 //! This function unregisters the handler to be called when a Timer32
334 //! interrupt occurs.  This function also masks off the interrupt in the
335 //! interrupt controller so that the interrupt handler no longer is called.
336 //!
337 //! \sa Interrupt_registerInterrupt() for important information about
338 //! registering interrupt handlers.
339 //!
340 //! \return None.
341 //
342 //*****************************************************************************
343 extern void Timer32_unregisterInterrupt(uint32_t timerInterrupt);
344
345 //*****************************************************************************
346 //
347 // Mark the end of the C bindings section for C++ compilers.
348 //
349 //*****************************************************************************
350 #ifdef __cplusplus
351 }
352 #endif
353
354 //*****************************************************************************
355 //
356 // Close the Doxygen group.
357 //! @}
358 //
359 //*****************************************************************************
360
361 #endif /* TIMER32_H_ */