2 * -------------------------------------------
3 * MSP432 DriverLib - v3_10_00_09
4 * -------------------------------------------
6 * --COPYRIGHT--,BSD,BSD
7 * Copyright (c) 2014, Texas Instruments Incorporated
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
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.
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.
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.
40 //*****************************************************************************
42 //! \addtogroup timer32_api
45 //*****************************************************************************
47 //*****************************************************************************
49 // If building with a C++ compiler, make all of the definitions in this header
52 //*****************************************************************************
61 //*****************************************************************************
63 // Control specific variables
65 //*****************************************************************************
66 #define TIMER32_CMSIS(x) ((Timer32_Type *) x)
68 #define TIMER_OFFSET 0x020
70 #define TIMER32_0_BASE TIMER32_1
71 #define TIMER32_1_BASE TIMER32_2
73 #define TIMER32_0_INTERRUPT INT_T32_INT1
74 #define TIMER32_1_INTERRUPT INT_T32_INT2
75 #define TIMER32_COMBINED_INTERRUPT INT_T32_INTC
77 #define TIMER32_1_MODULE6BIT 0x00
78 #define TIMER32_32BIT 0x01
80 #define TIMER32_PRESCALER_1 0x00
81 #define TIMER32_PRESCALER_16 0x04
82 #define TIMER32_PRESCALER_256 0x08
84 #define TIMER32_FREE_RUN_MODE 0x00
85 #define TIMER32_PERIODIC_MODE 0x01
87 //*****************************************************************************
89 // API Function prototypes
91 //*****************************************************************************
93 //*****************************************************************************
95 //! Initializes the Timer32 module
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
102 //! \param preScaler is the prescaler (or divider) to apply to the clock
103 //! source given to the Timer32 module.
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.
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.
117 //! - \b TIMER32_FREE_RUN_MODE [DEFAULT]
118 //! - \b TIMER32_PERIODIC_MODE
123 //*****************************************************************************
124 extern void Timer32_initModule(uint32_t timer, uint32_t preScaler,
125 uint32_t resolution, uint32_t mode);
127 //*****************************************************************************
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
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.
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).
147 //*****************************************************************************
148 extern void Timer32_setCount(uint32_t timer, uint32_t count);
150 //*****************************************************************************
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.
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.
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).
170 //*****************************************************************************
171 extern void Timer32_setCountInBackground(uint32_t timer, uint32_t count);
173 //*****************************************************************************
175 //! Returns the current value of the timer.
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
182 //! \return The current count of the timer.
184 //*****************************************************************************
185 extern uint32_t Timer32_getValue(uint32_t timer);
187 //*****************************************************************************
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.
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
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
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
210 //*****************************************************************************
211 extern void Timer32_startTimer(uint32_t timer, bool oneShot);
213 //*****************************************************************************
215 //! Halts the timer. Current count and setting values are preserved.
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
224 //*****************************************************************************
225 extern void Timer32_haltTimer(uint32_t timer);
227 //*****************************************************************************
229 //! Enables a Timer32 interrupt source.
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
236 //! Enables the indicated Timer32 interrupt source.
240 //*****************************************************************************
241 extern void Timer32_enableInterrupt(uint32_t timer);
243 //*****************************************************************************
245 //! Disables a Timer32 interrupt source.
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
252 //! Disables the indicated Timer32 interrupt source.
256 //*****************************************************************************
257 extern void Timer32_disableInterrupt(uint32_t timer);
259 //*****************************************************************************
261 //! Clears Timer32 interrupt source.
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
268 //! The Timer32 interrupt source is cleared, so that it no longer asserts.
272 //*****************************************************************************
273 extern void Timer32_clearInterruptFlag(uint32_t timer);
275 //*****************************************************************************
277 //! Gets the current Timer32 interrupt status.
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
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.
288 //! \return The current interrupt status
290 //*****************************************************************************
291 extern uint32_t Timer32_getInterruptStatus(uint32_t timer);
293 //*****************************************************************************
295 //! Registers an interrupt handler for Timer32 interrupts.
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
305 //! \param intHandler is a pointer to the function to be called when the
306 //! Timer32 interrupt occurs.
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().
317 //*****************************************************************************
318 extern void Timer32_registerInterrupt(uint32_t timerInterrupt,
319 void (*intHandler)(void));
321 //*****************************************************************************
323 //! Unregisters the interrupt handler for the Timer32 interrupt.
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
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.
337 //! \sa Interrupt_registerInterrupt() for important information about
338 //! registering interrupt handlers.
342 //*****************************************************************************
343 extern void Timer32_unregisterInterrupt(uint32_t timerInterrupt);
345 //*****************************************************************************
347 // Mark the end of the C bindings section for C++ compilers.
349 //*****************************************************************************
354 //*****************************************************************************
356 // Close the Doxygen group.
359 //*****************************************************************************
361 #endif /* TIMER32_H_ */