LGPTimerLPF3.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023, 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 LGPTimerLPF3.h
34  * @brief LGPTimer driver implementation for Low Power F3 devices
35  *
36  * @anchor ti_drivers_LGPTimer_Overview
37  * # Overview #
38  * The LGPTimer driver allows you to measure elapsed time with simple and
39  * portable APIs. It also allows for asynchronous callbacks after a
40  * certain amount of time has elapsed.
41  *
42  * The LGPTimer driver also handles the general purpose timer resource allocation.
43  * For each driver that requires use of a general purpose timer, it calls
44  * LGPTimerLPF3_open() to occupy the specified timer, and calls
45  * LGPTimerLPF3_close() to release the occupied timer resource.
46  *
47  * @anchor ti_drivers_LGPTimer_PeripheralProperties
48  * # LGPT peripheral properties #
49  * The LGPT peripherals support different timer counter widths depending
50  * on the peripheral instance number (LGPT0, LGPT1, ..). The table below
51  * lists supported counter widths for each peripheral instance number on
52  * available device types.
53  * The timer counter clock is sourced from the internal prescaler stage which
54  * has the high frequency clock (CLKSVT) as input.
55  * The prescaler can be configured to divide the input system clock, effectively
56  * extending the maximal time interval for the timer counter while reducing the
57  * timer resolution.
58  *
59  * | Device type | LGPT0 | LGPT1 | LGPT2 | LGPT3 |
60  * |---------------|---------|---------|---------|---------|
61  * | CC2340R2 | 16 bits | 16 bits | N.A | N.A |
62  * | CC2340R5 | 16 bits | 16 bits | 16 bits | 24 bits |
63  * | CC27X5 | 16 bits | 16 bits | 16 bits | 24 bits |
64  *
65  * @anchor ti_drivers_LGPTimer_CounterModes
66  * # Counter Modes #
67  * The LGPTimer driver supports the following timer counter modes:
68  * - Oneshot mode counting upwards. When the counter reaches the target value, the
69  * timer is stopped automatically and the TGT interrupt status flag
70  * (@ref LGPTimerLPF3_INT_TGT) is set.
71  * - Periodic mode counting upwards. When the counter reaches target value it wraps
72  * and restarts counting from 0 again. The TGT interrupt status flag is set each
73  * time the target value is reached. The ZERO interrupt status flag
74  * (@ref LGPTimerLPF3_INT_ZERO) is set each time the counter restarts from 0.
75  * - Periodic mode counting upwards/downwads. When the counter reaches target value
76  * while counting upwards the TGT interrupt flag is set and it starts counting
77  * downwards to 0. When 0 is reached the ZERO insterrupt status flag is set
78  * and the sequence is repeated.
79  *
80  * @anchor ti_drivers_LGPTimer_UnsupportedFeatures
81  * # Unsupported Features #
82  * - Use of the three configurable capture/compare channels is not supported
83  * - PWM signal generation is not supported
84  * - DMA usage is not supported
85  * - ADC trigger is not supported
86  * - QDEC mode where the timer functions as a quadrature decoder is not supported
87  * - Timer synchronization is not supported
88  * - Prescaler counter clock sourced from events is not supported
89  *
90  * @anchor ti_drivers_LGPTimer_PowerManagement
91  * # Power Management #
92  * The power management framework will try to put the device into the most
93  * power efficient mode whenever possible. Please see the technical reference
94  * manual for further details on each power mode.
95  *
96  * The LGPTimer driver will set constraints on disallowed power modes when
97  * needed, removing the need for the application to handle this.
98  * The following statements are valid:
99  * - After LGPTimerLPF3_open():
100  * The device is still allowed to enter Standby. When the device is
101  * active, the corresponding LGPT peripheral will be enabled and clocked.
102  * Note that a configured counter target will not be retained when going
103  * in and out of Standby. The counter target is set by the functions
104  * LGPTimerLPF3_setInitialCounterTarget() and LGPTimerLPF3_setNextCounterTarget().
105  * - After LGPTimerLPF3_start():
106  * The device will only go to Idle power mode since the high frequency
107  * clock (CLKSVT) is needed for timer operation.
108  * - After LGPTimerLPF3_stop():
109  * The device is still allowed to enter Standby. When the device is
110  * active, the corresponding LGPT peripheral will be enabled and clocked.
111  * - After LGPTimerLPF3_close():
112  * The underlying LGPT peripheral is turned off. The device is allowed to
113  * enter Standby.
114  *
115  * @anchor ti_drivers_LGPTimer_Accuracy
116  * # Accuracy #
117  * The timer clock of the LGPT peripheral is dependent on the high frequency clock (CLKSVT).
118  *
119  * @anchor ti_drivers_LGPTimer_Usage
120  * # Usage #
121  *
122  * This documentation provides a basic @ref ti_drivers_LGPTimer_Example "example"
123  * in the form of a commented code fragment.
124  *
125  * @anchor ti_drivers_LGPTimer_Example
126  * ## Periodic timer example##
127  * The code example below will generate an interrupt using the LGPTimer every 1 ms.
128  *
129  * @anchor ti_drivers_LGPTimer_Code
130  * @code
131  * LGPTimerLPF3_Handle hTimer;
132  * void timerCallback(LGPTimerLPF3_Handle lgptHandle, LGPTimerLPF3_IntMask interruptMask) {
133  * // interrupt callback code goes here. Minimize processing in interrupt.
134  * }
135  *
136  * void taskFxn(uintptr_t a0, uintptr_t a1) {
137  * uint32_t counterTarget;
138  *
139  * lgptHandle = NULL;
140  * LGPTimerLPF3_Params params;
141  * LGPTimerLPF3_Params_init(&params);
142  * params.hwiCallbackFxn = timerCallback;
143  * lgptHandle = LGPTimerLPF3_open(0, &params);
144  * if(lgptHandle == NULL) {
145  * Log_error0("Failed to open LGPTimer");
146  * Task_exit();
147  * }
148  *
149  * counterTarget = 48000; // 1 ms with a system clock of 48 MHz
150  * LGPTimerLPF3_setInitialCounterTarget(lgptHandle, counterTarget, true);
151  * LGPTimerLPF3_enableInterrupt(lgptHandle, LGPTimerLPF3_INT_TGT);
152  *
153  * LGPTimerLPF3_start(lgptHandle, LGPTimerLPF3_CTL_MODE_UP_PER);
154  *
155  * while(1) {
156  * vTaskSuspend(lgptHandle);
157  * }
158  * }
159  * @endcode
160  *
161  *
162  * <hr>
163  * @anchor ti_drivers_LGPT_Configuration
164  * # Configuration
165  *
166  * Refer to the @ref driver_configuration "Driver's Configuration" section
167  * for driver configuration information.
168  * <hr>
169  *
170  * ============================================================================
171  */
172 
173 #ifndef ti_drivers_timer_LGPTimerLPF3__include
174 #define ti_drivers_timer_LGPTimerLPF3__include
175 
176 #include <stdint.h>
177 #include <stdbool.h>
178 #include <stddef.h>
179 
180 #include <ti/drivers/dpl/HwiP.h>
181 #include <ti/drivers/Power.h>
182 
183 #include <ti/devices/DeviceFamily.h>
184 #include DeviceFamily_constructPath(inc/hw_lgpt.h)
185 
186 #ifdef __cplusplus
187 extern "C" {
188 #endif
189 
199 typedef enum
200 {
202  LGPTimerLPF3_CTL_MODE_DIS = LGPT_CTL_MODE_DIS,
206  LGPTimerLPF3_CTL_MODE_UP_ONCE = LGPT_CTL_MODE_UP_ONCE,
208  LGPTimerLPF3_CTL_MODE_UP_PER = LGPT_CTL_MODE_UP_PER,
210  LGPTimerLPF3_CTL_MODE_UPDWN_PER = LGPT_CTL_MODE_UPDWN_PER,
212 
218 typedef enum
219 {
221  LGPTimerLPF3_INT_TGT = 1 << LGPT_RIS_TGT_S,
223  LGPTimerLPF3_INT_ZERO = 1 << LGPT_RIS_ZERO_S,
225 
230 typedef enum
231 {
233  LGPTimerLPF3_DEBUG_STALL_OFF = LGPT_EMU_HALT_DIS,
235  LGPTimerLPF3_DEBUG_STALL_IMMEDIATE = (LGPT_EMU_HALT_EN | LGPT_EMU_CTL_IMMEDIATE),
237  LGPTimerLPF3_DEBUG_STALL_ON_ZERO = (LGPT_EMU_HALT_EN | LGPT_EMU_CTL_ZERCOND),
239 
240 /* Forward declaration of LGPTimer configuration */
242 
243 /* LGPTimer handle is pointer to configuration structure */
245 
246 /* Interrupt bit vector. See LGPTimerLPF3_Interrupt for available interrupts */
247 typedef uint16_t LGPTimerLPF3_IntMask;
248 
257 typedef void (*LGPTimerLPF3_HwiFxn)(LGPTimerLPF3_Handle handle, LGPTimerLPF3_IntMask interruptMask);
258 
267 typedef struct LGPTimerLPF3_Params
268 {
275  uint8_t prescalerDiv;
279 
298 typedef struct LGPTimerLPF3_HWAttrs
299 {
301  uint32_t baseAddr;
303  uint8_t intNum;
305  uint8_t intPriority;
307  uint8_t powerID;
309 
324 typedef struct LGPTimerLPF3_Object
325 {
326  HwiP_Struct hwi;
329  uint32_t arg;
330  bool isOpen;
332  uint8_t prescalerDiv;
335 
353 {
356 };
357 
371 
387 extern LGPTimerLPF3_Handle LGPTimerLPF3_open(uint_least8_t index, const LGPTimerLPF3_Params *params);
388 
403 extern void LGPTimerLPF3_close(LGPTimerLPF3_Handle handle);
404 
419 extern void LGPTimerLPF3_start(LGPTimerLPF3_Handle handle, LGPTimerLPF3_Mode mode);
420 
431 extern void LGPTimerLPF3_stop(LGPTimerLPF3_Handle handle);
432 
451 extern void LGPTimerLPF3_setInitialCounterTarget(LGPTimerLPF3_Handle handle, uint32_t value, bool intFlagClr);
452 
476 extern void LGPTimerLPF3_setNextCounterTarget(LGPTimerLPF3_Handle handle, uint32_t value, bool intFlagClr);
477 
489 extern uint32_t LGPTimerLPF3_getCounter(LGPTimerLPF3_Handle handle);
490 
504 extern uint32_t LGPTimerLPF3_getArg(LGPTimerLPF3_Handle handle);
505 
517 extern void LGPTimerLPF3_setArg(LGPTimerLPF3_Handle handle, void *arg);
518 
528 void LGPTimerLPF3_enableInterrupt(LGPTimerLPF3_Handle handle, LGPTimerLPF3_IntMask intMask);
529 
540 void LGPTimerLPF3_disableInterrupt(LGPTimerLPF3_Handle handle, LGPTimerLPF3_IntMask intMask);
541 
542 #ifdef __cplusplus
543 }
544 #endif
545 #endif /* ti_drivers_timer_LGPTimerLPF3__include */
ADC_Params params
Definition: Driver_Init.h:11
LGPTimer Global configuration.
Definition: LGPTimerLPF3.h:352
HwiP_Struct hwi
Definition: LGPTimerLPF3.h:326
Definition: LGPTimerLPF3.h:206
LGPTimerLPF3_DebugMode
Definitions for controlling timer debug stall mode.
Definition: LGPTimerLPF3.h:230
struct LGPTimerLPF3_Object LGPTimerLPF3_Object
LGPTimerLPF3 Object.
LGPTimerLPF3_Object * object
Definition: LGPTimerLPF3.h:354
uint32_t LGPTimerLPF3_getCounter(LGPTimerLPF3_Handle handle)
Function that returns the current timer counter value.
Definition: LGPTimerLPF3.h:202
Definition: LGPTimerLPF3.h:208
LGPTimerLPF3_Mode
Definitions for supported LGPTimer counting modes.
Definition: LGPTimerLPF3.h:199
void LGPTimerLPF3_enableInterrupt(LGPTimerLPF3_Handle handle, LGPTimerLPF3_IntMask intMask)
Enable interrupt source for the LGPTimer handle.
Definition: LGPTimerLPF3.h:221
struct LGPTimerLPF3_Params LGPTimerLPF3_Params
LGPTimerLPF3 Parameters.
LGPTimerLPF3_Config * LGPTimerLPF3_Handle
Definition: LGPTimerLPF3.h:244
void LGPTimerLPF3_setArg(LGPTimerLPF3_Handle handle, void *arg)
Function to set a custom argument.
uint32_t arg
Definition: LGPTimerLPF3.h:329
Power Manager.
LGPTimerLPF3_Interrupt
Definitions for supported LGPTimer interrupts. LGPTimerLPF3_IntMask arguments should be a bit vector ...
Definition: LGPTimerLPF3.h:218
uint32_t LGPTimerLPF3_getArg(LGPTimerLPF3_Handle handle)
Function to get a custom argument.
uint32_t baseAddr
Definition: LGPTimerLPF3.h:301
bool intPhaseLate
Definition: LGPTimerLPF3.h:331
uint8_t prescalerDiv
Definition: LGPTimerLPF3.h:275
LGPTimerLPF3 Parameters.
Definition: LGPTimerLPF3.h:267
Definition: LGPTimerLPF3.h:233
void LGPTimerLPF3_start(LGPTimerLPF3_Handle handle, LGPTimerLPF3_Mode mode)
Function that starts the timer counter of the specified LGPTimer handle with current settings and spe...
uint8_t powerID
Definition: LGPTimerLPF3.h:307
LGPTimerLPF3 Object.
Definition: LGPTimerLPF3.h:324
uint8_t intPriority
Definition: LGPTimerLPF3.h:305
LGPTimerLPF3 Hardware attributes.
Definition: LGPTimerLPF3.h:298
void(* LGPTimerLPF3_HwiFxn)(LGPTimerLPF3_Handle handle, LGPTimerLPF3_IntMask interruptMask)
The definition of a callback function used by the LGPTimer driver.
Definition: LGPTimerLPF3.h:257
Definition: LGPTimerLPF3.h:210
Power_NotifyObj postNotify
Definition: LGPTimerLPF3.h:328
uint8_t prescalerDiv
Definition: LGPTimerLPF3.h:332
Definition: LGPTimerLPF3.h:223
void LGPTimerLPF3_Params_init(LGPTimerLPF3_Params *params)
Function that initializes the LGPTimerLPF3_Params struct to its default values.
uint8_t intNum
Definition: LGPTimerLPF3.h:303
const LGPTimerLPF3_HWAttrs * hwAttrs
Definition: LGPTimerLPF3.h:355
Power notify object structure.
Definition: Power.h:445
struct LGPTimerLPF3_HWAttrs LGPTimerLPF3_HWAttrs
LGPTimerLPF3 Hardware attributes.
Definition: LGPTimerLPF3.h:235
LGPTimerLPF3_DebugMode debugStallMode
Definition: LGPTimerLPF3.h:333
LGPTimerLPF3_HwiFxn hwiCallbackFxn
Definition: LGPTimerLPF3.h:271
void LGPTimerLPF3_setNextCounterTarget(LGPTimerLPF3_Handle handle, uint32_t value, bool intFlagClr)
Function that sets the next timer counter target on the specified LGPTimer. The specified target valu...
LGPTimerLPF3_Handle LGPTimerLPF3_open(uint_least8_t index, const LGPTimerLPF3_Params *params)
Function that opens a driver for the given LGPT peripheral. Will set power dependency on timer and co...
LGPTimerLPF3_DebugMode debugStallMode
Definition: LGPTimerLPF3.h:277
bool isOpen
Definition: LGPTimerLPF3.h:330
void LGPTimerLPF3_disableInterrupt(LGPTimerLPF3_Handle handle, LGPTimerLPF3_IntMask intMask)
Disable interrupt source for the LGPTimer handle.
void LGPTimerLPF3_setInitialCounterTarget(LGPTimerLPF3_Handle handle, uint32_t value, bool intFlagClr)
Function that sets the initial timer counter target on the specified LGPTimer. This function must be ...
LGPTimerLPF3_HwiFxn hwiCallbackFxn
Definition: LGPTimerLPF3.h:327
void LGPTimerLPF3_stop(LGPTimerLPF3_Handle handle)
Function that stops the timer counter of the specified LGPTimer driver.
uint16_t LGPTimerLPF3_IntMask
Definition: LGPTimerLPF3.h:247
void LGPTimerLPF3_close(LGPTimerLPF3_Handle handle)
Function that closes a LGPTimer driver specified by the LGPTimer handle. Closing LGPTimer driver will...
bool intPhaseLate
Definition: LGPTimerLPF3.h:273
Definition: LGPTimerLPF3.h:237
© Copyright 1995-2023, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale