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.
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 HWREGBIT8(timer + OFS_TIMER32_CONTROL1, TIMER32_CONTROL1_MODE_OFS) = 1;
47 else if (mode == TIMER32_FREE_RUN_MODE)
48 HWREGBIT8(timer + OFS_TIMER32_CONTROL1, TIMER32_CONTROL1_MODE_OFS) = 0;
52 /* Setting the resolution of the timer */
53 if (resolution == TIMER32_1_MODULE6BIT)
54 HWREGBIT8(timer + OFS_TIMER32_CONTROL1, TIMER32_CONTROL1_SIZE_OFS) = 0;
55 else if (resolution == TIMER32_32BIT)
56 HWREGBIT8(timer + OFS_TIMER32_CONTROL1, TIMER32_CONTROL1_SIZE_OFS) = 1;
60 /* Setting the PreScaler */
62 resolution == TIMER32_PRESCALER_1
63 || resolution == TIMER32_PRESCALER_16
64 || resolution == TIMER32_PRESCALER_256);
66 HWREG32(timer + OFS_TIMER32_CONTROL1) =
67 (HWREG32(timer + OFS_TIMER32_CONTROL1)
68 & ~TIMER32_CONTROL1_PRESCALE_M) | preScaler;
72 void Timer32_setCount(uint32_t timer, uint32_t count)
74 if (!HWREGBIT32(timer + OFS_TIMER32_CONTROL1,
75 TIMER32_CONTROL1_SIZE_OFS) && (count > UINT16_MAX))
76 HWREG32(timer + OFS_TIMER32_LOAD1) = UINT16_MAX;
78 HWREG32(timer + OFS_TIMER32_LOAD1) = count;
81 void Timer32_setCountInBackground(uint32_t timer, uint32_t count)
83 if (!HWREGBIT32(timer + OFS_TIMER32_CONTROL1,
84 TIMER32_CONTROL1_SIZE_OFS) && (count > UINT16_MAX))
85 HWREG32(timer + OFS_TIMER32_BGLOAD1) = UINT16_MAX;
87 HWREG32(timer + OFS_TIMER32_BGLOAD1) = count;
90 uint32_t Timer32_getValue(uint32_t timer)
92 return HWREG32(timer + OFS_TIMER32_VALUE1);
95 void Timer32_startTimer(uint32_t timer, bool oneShot)
97 ASSERT(timer == TIMER32_0_MODULE || timer == TIMER32_1_MODULE);
100 HWREGBIT8(timer + OFS_TIMER32_CONTROL1, TIMER32_CONTROL1_ONESHOT_OFS) =
103 HWREGBIT8(timer + OFS_TIMER32_CONTROL1, TIMER32_CONTROL1_ONESHOT_OFS) =
106 HWREG32(timer + OFS_TIMER32_CONTROL1) |= TIMER32_CONTROL1_ENABLE;
109 void Timer32_haltTimer(uint32_t timer)
111 ASSERT(timer == TIMER32_0_MODULE || timer == TIMER32_1_MODULE);
113 HWREG32(timer + OFS_TIMER32_CONTROL1) &= ~TIMER32_CONTROL1_ENABLE;
116 void Timer32_enableInterrupt(uint32_t timer)
118 HWREG32(timer + OFS_TIMER32_CONTROL1) |= TIMER32_CONTROL1_IE;
121 void Timer32_disableInterrupt(uint32_t timer)
123 HWREG32(timer + OFS_TIMER32_CONTROL1) &= ~TIMER32_CONTROL1_IE;
126 void Timer32_clearInterruptFlag(uint32_t timer)
128 HWREG32(timer + OFS_TIMER32_INTCLR1) |= 0x01;
131 uint32_t Timer32_getInterruptStatus(uint32_t timer)
133 return HWREG32(timer + OFS_TIMER32_MIS1);
136 void Timer32_registerInterrupt(uint32_t timerInterrupt,
137 void (*intHandler)(void))
139 Interrupt_registerInterrupt(timerInterrupt, intHandler);
140 Interrupt_enableInterrupt(timerInterrupt);
143 void Timer32_unregisterInterrupt(uint32_t timerInterrupt)
145 Interrupt_disableInterrupt(timerInterrupt);
146 Interrupt_unregisterInterrupt(timerInterrupt);