2 * -------------------------------------------
3 * MSP432 DriverLib - v01_04_00_18
4 * -------------------------------------------
6 * --COPYRIGHT--,BSD,BSD
7 * Copyright (c) 2015, 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 TIMER_OFFSET 0x020
68 #define TIMER32_0_MODULE TIMER32_BASE
69 #define TIMER32_1_MODULE (TIMER32_BASE + OFS_TIMER32_LOAD2)
71 #define TIMER32_0_INTERRUPT INT_T32_INT1
72 #define TIMER32_1_INTERRUPT INT_T32_INT2
73 #define TIMER32_COMBINED_INTERRUPT INT_T32_INTC
75 #define TIMER32_1_MODULE6BIT 0x00
76 #define TIMER32_32BIT 0x01
78 #define TIMER32_PRESCALER_1 0x00
79 #define TIMER32_PRESCALER_16 0x04
80 #define TIMER32_PRESCALER_256 0x08
82 #define TIMER32_FREE_RUN_MODE 0x00
83 #define TIMER32_PERIODIC_MODE 0x01
85 //*****************************************************************************
87 // API Function prototypes
89 //*****************************************************************************
91 //*****************************************************************************
93 //! Initializes the Timer32 module
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
100 //! \param preScaler is the prescaler (or divider) to apply to the clock
101 //! source given to the Timer32 module.
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.
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.
115 //! - \b TIMER32_FREE_RUN_MODE [DEFAULT]
116 //! - \b TIMER32_PERIODIC_MODE
121 //*****************************************************************************
122 extern void Timer32_initModule(uint32_t timer, uint32_t preScaler,
123 uint32_t resolution, uint32_t mode);
125 //*****************************************************************************
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
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.
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).
145 //*****************************************************************************
146 extern void Timer32_setCount(uint32_t timer, uint32_t count);
148 //*****************************************************************************
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.
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.
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).
168 //*****************************************************************************
169 extern void Timer32_setCountInBackground(uint32_t timer, uint32_t count);
171 //*****************************************************************************
173 //! Returns the current value of the timer.
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
180 //! \return The current count of the timer.
182 //*****************************************************************************
183 extern uint32_t Timer32_getValue(uint32_t timer);
185 //*****************************************************************************
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.
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
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
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
208 //*****************************************************************************
209 extern void Timer32_startTimer(uint32_t timer, bool oneShot);
211 //*****************************************************************************
213 //! Halts the timer. Current count and setting values are preserved.
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
222 //*****************************************************************************
223 extern void Timer32_haltTimer(uint32_t timer);
225 //*****************************************************************************
227 //! Enables a Timer32 interrupt source.
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
234 //! Enables the indicated Timer32 interrupt source.
238 //*****************************************************************************
239 extern void Timer32_enableInterrupt(uint32_t timer);
241 //*****************************************************************************
243 //! Disables a Timer32 interrupt source.
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
250 //! Disables the indicated Timer32 interrupt source.
254 //*****************************************************************************
255 extern void Timer32_disableInterrupt(uint32_t timer);
257 //*****************************************************************************
259 //! Clears Timer32 interrupt source.
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
266 //! The Timer32 interrupt source is cleared, so that it no longer asserts.
270 //*****************************************************************************
271 extern void Timer32_clearInterruptFlag(uint32_t timer);
273 //*****************************************************************************
275 //! Gets the current Timer32 interrupt status.
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
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.
286 //! \return The current interrupt status
288 //*****************************************************************************
289 extern uint32_t Timer32_getInterruptStatus(uint32_t timer);
291 //*****************************************************************************
293 //! Registers an interrupt handler for Timer32 interrupts.
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
303 //! \param intHandler is a pointer to the function to be called when the
304 //! Timer32 interrupt occurs.
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().
315 //*****************************************************************************
316 extern void Timer32_registerInterrupt(uint32_t timerInterrupt,
317 void (*intHandler)(void));
319 //*****************************************************************************
321 //! Unregisters the interrupt handler for the Timer32 interrupt.
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
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.
335 //! \sa Interrupt_registerInterrupt() for important information about
336 //! registering interrupt handlers.
340 //*****************************************************************************
341 extern void Timer32_unregisterInterrupt(uint32_t timerInterrupt);
343 //*****************************************************************************
345 // Mark the end of the C bindings section for C++ compilers.
347 //*****************************************************************************
352 //*****************************************************************************
354 // Close the Doxygen group.
357 //*****************************************************************************
359 #endif /* TIMER32_H_ */