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.
38 #include <interrupt.h>
41 void Timer32_initModule(uint32_t timer, uint32_t preScaler, uint32_t resolution,
44 /* Setting up one shot or continuous mode */
45 if (mode == TIMER32_PERIODIC_MODE)
46 BITBAND_PERI(TIMER32_CMSIS(timer)->CONTROL, TIMER32_CONTROL_MODE_OFS)
48 else if (mode == TIMER32_FREE_RUN_MODE)
49 BITBAND_PERI(TIMER32_CMSIS(timer)->CONTROL, TIMER32_CONTROL_MODE_OFS)
54 /* Setting the resolution of the timer */
55 if (resolution == TIMER32_1_MODULE6BIT)
56 BITBAND_PERI(TIMER32_CMSIS(timer)->CONTROL, TIMER32_CONTROL_SIZE_OFS)
58 else if (resolution == TIMER32_32BIT)
59 BITBAND_PERI(TIMER32_CMSIS(timer)->CONTROL, TIMER32_CONTROL_SIZE_OFS)
64 /* Setting the PreScaler */
66 resolution == TIMER32_PRESCALER_1
67 || resolution == TIMER32_PRESCALER_16
68 || resolution == TIMER32_PRESCALER_256);
70 TIMER32_CMSIS(timer)->CONTROL = TIMER32_CMSIS(timer)->CONTROL
71 & (~TIMER32_CONTROL_PRESCALE_MASK) | preScaler;
75 void Timer32_setCount(uint32_t timer, uint32_t count)
77 if (!BITBAND_PERI(TIMER32_CMSIS(timer)->CONTROL, TIMER32_CONTROL_SIZE_OFS)
78 && (count > UINT16_MAX))
79 TIMER32_CMSIS(timer)->LOAD = UINT16_MAX;
81 TIMER32_CMSIS(timer)->LOAD = count;
84 void Timer32_setCountInBackground(uint32_t timer, uint32_t count)
86 if (!BITBAND_PERI(TIMER32_CMSIS(timer)->CONTROL, TIMER32_CONTROL_SIZE_OFS)
87 && (count > UINT16_MAX))
88 TIMER32_CMSIS(timer)->BGLOAD = UINT16_MAX;
90 TIMER32_CMSIS(timer)->BGLOAD = count;
93 uint32_t Timer32_getValue(uint32_t timer)
95 return TIMER32_CMSIS(timer)->VALUE;
98 void Timer32_startTimer(uint32_t timer, bool oneShot)
100 ASSERT(timer == TIMER32_0_MODULE || timer == TIMER32_1_MODULE);
103 BITBAND_PERI(TIMER32_CMSIS(timer)->CONTROL, TIMER32_CONTROL_ONESHOT_OFS)
106 BITBAND_PERI(TIMER32_CMSIS(timer)->CONTROL, TIMER32_CONTROL_ONESHOT_OFS)
109 TIMER32_CMSIS(timer)->CONTROL |= TIMER32_CONTROL_ENABLE;
112 void Timer32_haltTimer(uint32_t timer)
114 ASSERT(timer == TIMER32_0_MODULE || timer == TIMER32_1_MODULE);
116 TIMER32_CMSIS(timer)->CONTROL &= ~TIMER32_CONTROL_ENABLE;
119 void Timer32_enableInterrupt(uint32_t timer)
121 TIMER32_CMSIS(timer)->CONTROL |= TIMER32_CONTROL_IE;
124 void Timer32_disableInterrupt(uint32_t timer)
126 TIMER32_CMSIS(timer)->CONTROL &= ~TIMER32_CONTROL_IE;
129 void Timer32_clearInterruptFlag(uint32_t timer)
131 TIMER32_CMSIS(timer)->INTCLR |= 0x01;
134 uint32_t Timer32_getInterruptStatus(uint32_t timer)
136 return TIMER32_CMSIS(timer)->MIS;
139 void Timer32_registerInterrupt(uint32_t timerInterrupt,
140 void (*intHandler)(void))
142 Interrupt_registerInterrupt(timerInterrupt, intHandler);
143 Interrupt_enableInterrupt(timerInterrupt);
146 void Timer32_unregisterInterrupt(uint32_t timerInterrupt)
148 Interrupt_disableInterrupt(timerInterrupt);
149 Interrupt_unregisterInterrupt(timerInterrupt);