TimerMSP432.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2019, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*!****************************************************************************
33  * @file TimerMSP432.h
34  * @brief Timer driver interface for MSP432 devices
35  *
36  * # Operation #
37  * This driver implements two independent hardware peripherals on the
38  * MSP432: Timer_A and Timer32. The Timer_A implementation supports two clock
39  * sources, SMCLK and ACLCK, with multiple clock dividers. The Timer32
40  * implementation supports a single clock source, MCLK, with 3 clock
41  * dividers. For each driver instance, the configuration of the clock dividers
42  * is determined using the clock source, period, and period units. Note that
43  * the SMCLK and MCLK frequencies can change after Timer_open().
44  *
45  * ### MPS432 Timer Driver Configuration #
46  *
47  * In order to use the Timer APIs, the application is required to define
48  * 4 configuration items in the application ti_drivers_config.c file:
49  *
50  * 1. An array of TimerMSP432_Object elements, which will be used by
51  * by the driver to maintain instance state.
52  * Below is an example TimerMSP432_Object array appropriate for the MSP432
53  * LaunchPad board:
54  * @code
55  * #include <ti/drivers/Timer.h>
56  * #include <ti/drivers/timer/TimerMSP432.h>
57  *
58  * TimerMSP432_Object timerMSP432Objects[3];
59  * @endcode
60  *
61  * 2. An array of TimerMSP432_HWAttrs elements that defines which
62  *
63  * Below is an example TimerMSP432_HWAttrs array appropriate for the MSP432
64  * LaunchPad board:
65  * @code
66  * const TimerMSP432_HWAttrs timerMSP432HWAttrs[3] =
67  * {
68  * {
69  * .timerBaseAddress = TIMER32_0_BASE,
70  * .clockSource = TIMER_A_CLOCKSOURCE_SMCLK,
71  * .intNum = INT_T32_INT1,
72  * .intPriority = ~0,
73  * },
74  * {
75  * .timerBaseAddress = TIMER_A1_BASE,
76  * .clockSource = TIMER_A_CLOCKSOURCE_SMCLK,
77  * .intNum = INT_TA1_0,
78  * .intPriority = ~0,
79  * },
80  * {
81  * .timerBaseAddress = TIMER_A2_BASE,
82  * .clockSource = TIMER_A_CLOCKSOURCE_ACLK,
83  * .intNum = INT_TA2_0,
84  * .intPriority = ~0,
85  * },
86  * };
87  * @endcode
88  *
89  * 3. An array of @ref Timer_Config elements, one for each Timer instance.
90  * Each element of this array identifies the device-specific API function
91  * table, the device specific timer object instance, and the device specific
92  * Hardware Attributes to be used for each timer instance.
93  * Below is an example @ref Timer_Config array appropriate for the MSP432
94  * LaunchPad board:
95  * @code
96  * const Timer_Config Timer_config[3] = {
97  * {
98  * .fxnTablePtr = &TimerMSP432_Timer32_fxnTable,
99  * .object = &timerMSP432Objects[0],
100  * .hwAttrs = &timerMSP432HWAttrs[0]
101  * },
102  * {
103  * .fxnTablePtr = &TimerMSP432_Timer_A_fxnTable,
104  * .object = &timerMSP432Objects[1],
105  * .hwAttrs = &timerMSP432HWAttrs[1]
106  * }
107  * {
108  * .fxnTablePtr = &TimerMSP432_Timer_A_fxnTable,
109  * .object = &timerMSP432Objects[2],
110  * .hwAttrs = &timerMSP432HWAttrs[2]
111  * }
112  * };
113  * @endcode
114  *
115  * 4. A global variable, Timer_count, that informs the driver how many
116  * timer instances are defined:
117  * @code
118  * const uint_least8_t Timer_count = 3;
119  * @endcode
120  *
121  * # Resource Allocation #
122  * Allocation of each timer peripheral is managed through a set of resource
123  * allocation APIs. For example, the TimerMSP432_allocateTimerResource API
124  * will allocate a timer for exclusive use. Any attempt to allocate this
125  * resource in the future will result in a false value being returned from the
126  * allocation API. To free a timer resource, the TimerMSP432_freeTimerResource
127  * is used. The application is not responsible for calling these allocation
128  * APIs directly.
129  *
130  * ### Power Management #
131  * The TI-RTOS power management framework will try to put the device into the
132  * most power efficient mode whenever possible. Please see the technical
133  * reference manual for further details on each power mode.
134  *
135  * This driver supports dynamic power performance levels. The driver will
136  * determine which power performance levels are compatible with the desired
137  * period and period units. The driver prevents transitions to performance
138  * levels in which the period cannot be generated.
139  *
140  * After a performance level change, the period is recalculated such that the
141  * generated period will remain the same. The exact period may vary after a
142  * performance level transition. This is due to a change in clock frequency and
143  * hence period per clock cycle.
144  *
145  * The following statements are valid:
146  * - After Timer_open(): Clocks are enabled to the timer resource.
147  * Dynamic performance level changes are allowed.
148  * - After Timer_start(): DEEPSLEEP mode is disabled. The device can only go
149  * to Idle power mode. Performance level changes are not allowed.
150  * - After Timer_stop(): Conditions are equal as for after Timer_open.
151  * - After Timer_close(): The underlying GPTimer is turned off, and the
152  * clock to the timer and pin are disabled.
153  ******************************************************************************
154  */
155 #ifndef ti_drivers_timer_TimerMSP432__include
156 #define ti_drivers_timer_TimerMSP432__include
157 
158 #include <stdbool.h>
159 #include <stdint.h>
160 
161 #include <ti/drivers/Power.h>
162 #include <ti/drivers/Timer.h>
163 #include <ti/drivers/dpl/HwiP.h>
164 #include <ti/drivers/dpl/SemaphoreP.h>
165 
166 #ifdef __cplusplus
167 extern "C"
168 {
169 #endif
170 
173 
208 typedef struct {
211 
213  uint32_t clockSource;
214 
216  uint32_t intNum;
217 
219  uint32_t intPriority;
221 
227 typedef struct {
228  HwiP_Handle hwiHandle;
229  SemaphoreP_Handle timerSem;
235  uint32_t rawPeriod;
236  uint32_t period;
237  bool isRunning;
239 
254 extern bool TimerMSP432_allocateTimerResource(uint32_t baseAddress);
255 
270 extern void TimerMSP432_freeTimerResource(uint32_t baseAddress);
271 
272 #ifdef __cplusplus
273 }
274 #endif
275 
276 #endif /* ti_drivers_timer_TimerMSP432__include */
bool TimerMSP432_allocateTimerResource(uint32_t baseAddress)
Function to allocate a timer peripheral.
const Timer_FxnTable TimerMSP432_Timer32_fxnTable
Timer_PeriodUnits units
Definition: TimerMSP432.h:234
SemaphoreP_Handle timerSem
Definition: TimerMSP432.h:229
uint32_t timerBaseAddress
Definition: TimerMSP432.h:210
Timer_PeriodUnits
Timer period unit enum.
Definition: Timer.h:282
uint32_t intPriority
Definition: TimerMSP432.h:219
uint32_t perfConstraintMask
Definition: TimerMSP432.h:231
Power Manager.
Timer_CallBackFxn callBack
Definition: TimerMSP432.h:232
uint32_t intNum
Definition: TimerMSP432.h:216
void TimerMSP432_freeTimerResource(uint32_t baseAddress)
Function to de-allocate a timer peripheral.
Timer_Mode mode
Definition: TimerMSP432.h:233
Timer driver.
uint32_t rawPeriod
Definition: TimerMSP432.h:235
uint32_t period
Definition: TimerMSP432.h:236
TimerMSP432 Hardware Attributes.
Definition: TimerMSP432.h:208
Power notify object structure.
Definition: Power.h:443
TimerMSP432 Object.
Definition: TimerMSP432.h:227
uint32_t clockSource
Definition: TimerMSP432.h:213
Timer_Mode
Timer mode settings.
Definition: Timer.h:239
The definition of a timer function table that contains the required set of functions to control a spe...
Definition: Timer.h:379
Power_NotifyObj perfChangeNotify
Definition: TimerMSP432.h:230
HwiP_Handle hwiHandle
Definition: TimerMSP432.h:228
bool isRunning
Definition: TimerMSP432.h:237
void(* Timer_CallBackFxn)(Timer_Handle handle)
Timer callback function.
Definition: Timer.h:299
const Timer_FxnTable TimerMSP432_Timer_A_fxnTable
© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale