AM243x MCU+ SDK  11.00.00
gp_timer/v0/gp_timer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2024 Texas Instruments Incorporated
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * 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
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
48 #ifndef GP_TIMER_H_
49 #define GP_TIMER_H_
50 
51 /* ========================================================================== */
52 /* Include Files */
53 /* ========================================================================== */
54 #include <stdint.h>
55 #include <stdbool.h>
56 #include <kernel/dpl/SemaphoreP.h>
57 #include <kernel/dpl/HwiP.h>
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 
63 /* ========================================================================== */
64 /* Macros & Typedefs */
65 /* ========================================================================== */
66 
74 #define GPTIMER_MODE_CONFIG_FREE_RUN ((uint8_t) 0U)
75 
76 #define GPTIMER_MODE_CONFIG_INPUT_CAPTURE ((uint8_t) 1U)
77 
78 #define GPTIMER_MODE_CONFIG_OUTPUT_COMPARE ((uint8_t) 2U)
79 
80 #define GPTIMER_MODE_CONFIG_PWM_GEN ((uint8_t) 3U)
81 
91 #define GPTIMER_INPUT_CAPTURE_MODE_SINGLE ((uint32_t) 0U)
92 
93 #define GPTIMER_INPUT_CAPTURE_MODE_SECOND ((uint32_t) 1U)
94 
104 #define GPTIMER_INPUT_CAPTURE_EVENT_NO_CAPTURE ((uint32_t) 0U)
105 
106 #define GPTIMER_INPUT_CAPTURE_EVENT_RISING ((uint32_t) 1U)
107 
108 #define GPTIMER_INPUT_CAPTURE_EVENT_FALLING ((uint32_t) 2U)
109 
110 #define GPTIMER_INPUT_CAPTURE_EVENT_EDGE ((uint32_t) 3U)
111 
121 #define GPTIMER_PWM_OUT_NO_TRIGGER ((uint32_t) 0U)
122 
123 #define GPTIMER_PWM_OUT_OVERFLOW_TRIGGER ((uint32_t) 1U)
124 
125 #define GPTIMER_PWM_OUT_OVERFLOW_MATCH_TRIGGER ((uint32_t) 2U)
126 
136 #define GPTIMER_PWM_OUT_PIN_DEFAULT_0 ((uint32_t) 0U)
137 
138 #define GPTIMER_PWM_OUT_PIN_DEFAULT_1 ((uint32_t) 1U)
139 
153 #define GPTIMER_PWM_OUT_PIN_MODULATION_PULSE ((uint32_t) 0U)
154 
155 #define GPTIMER_PWM_OUT_PIN_MODULATION_TOGGLE ((uint32_t) 1U)
156 
165 #define TIMER_IRQ_TCAR_IT_FLAG_MASK (uint32_t)0x04U
166 #define TIMER_IRQ_OVF_IT_FLAG_MASK (uint32_t)0x02U
167 #define TIMER_IRQ_MAT_IT_FLAG_MASK (uint32_t)0x01U
168 
171 /* ========================================================================== */
172 /* Structure Declarations */
173 /* ========================================================================== */
174 
178 typedef struct GPTIMER_Config_s *GPTIMER_Handle;
179 
180 /* ========================================================================== */
181 /* Function pointers Declarations */
182 /* ========================================================================== */
183 
196 
209 
222 
223 /* ========================================================================== */
224 /* Structure Declarations */
225 /* ========================================================================== */
226 
230 typedef struct GPTIMER_HwAttrs_s {
231 
233  uint32_t baseAddr;
235  uint32_t intNum;
237  uint16_t eventId;
239  uint32_t inputClk;
243  uint8_t intrPriority;
244 
246 
253 typedef struct GPTIMER_Params_s {
254 
258  uint32_t cntPrescaler;
262  uint32_t cntReloadVal;
266  uint32_t counterInitVal;
267 
269 
273 typedef struct GPTIMER_Compare_Config_s
274 {
277 
279 
283 typedef struct GPTIMER_Capture_Config_s
284 {
286  uint32_t captureMode;
289 
291 
295 typedef struct GPTIMER_PWM_Config_s
296 {
305 
307 
311 typedef struct GPTIMER_Object_s
312 {
318  bool isOpen;
321 
334 
345 
347 
357 typedef struct GPTIMER_Config_s {
363 
364 /* ========================================================================== */
365 /* Function Declarations */
366 /* ========================================================================== */
367 
371 void GPTIMER_init(void);
372 
376 void GPTIMER_deinit(void);
377 
384 
393 GPTIMER_Handle GPTIMER_open(uint32_t idx, const GPTIMER_Params *params);
394 
405 
412 
419 
428 
436 void GPTIMER_setCount(GPTIMER_Handle handle, uint32_t value);
437 
446 
455 
464 
476  uint32_t timerConfigMode, void *config);
477 
488  GPTIMER_OverflowCallbackFxn overflowCbFxn,
489  GPTIMER_CompareMatchCallbackFxn compMatchCbFxn,
490  GPTIMER_CaptureCallbackFxn captureCbFxn);
491 
499 
507 void GPTIMER_clearIRQStatus(GPTIMER_Handle handle, uint32_t irqMask);
508 
518 void GPTIMER_enableInterruptStatus(GPTIMER_Handle handle, uint32_t irqMask);
519 
527 void GPTIMER_disableInterruptStatus(GPTIMER_Handle handle, uint32_t irqMask);
528 
529 #ifdef __cplusplus
530 }
531 #endif
532 #endif /* #ifndef GP_TIMER_H_ */
533 
GPTIMER_stop
void GPTIMER_stop(GPTIMER_Handle handle)
Stop the TImer.
GPTIMER_clearIRQStatus
void GPTIMER_clearIRQStatus(GPTIMER_Handle handle, uint32_t irqMask)
Clear IRQ status bit.
GPTIMER_setTimerConfigMode
int32_t GPTIMER_setTimerConfigMode(GPTIMER_Handle handle, uint32_t timerConfigMode, void *config)
Change Timer Configuration.
GPTIMER_init
void GPTIMER_init(void)
Initialize the GPTIMER module.
GPTIMER_Config
GPTIMER Global Configuration.
Definition: gp_timer/v0/gp_timer.h:357
GPTIMER_setCallbackFxn
void GPTIMER_setCallbackFxn(GPTIMER_Handle handle, GPTIMER_OverflowCallbackFxn overflowCbFxn, GPTIMER_CompareMatchCallbackFxn compMatchCbFxn, GPTIMER_CaptureCallbackFxn captureCbFxn)
Update Callback Functions.
GPTIMER_HwAttrs::enableIntr
bool enableIntr
Definition: gp_timer/v0/gp_timer.h:241
GPTIMER_Object::pwmConfig
GPTIMER_PWM_Config pwmConfig
Definition: gp_timer/v0/gp_timer.h:333
GPTIMER_Object::isOpen
bool isOpen
Definition: gp_timer/v0/gp_timer.h:318
GPTIMER_HwAttrs::intNum
uint32_t intNum
Definition: gp_timer/v0/gp_timer.h:235
GPTIMER_Object::timerConfigMode
uint8_t timerConfigMode
Definition: gp_timer/v0/gp_timer.h:327
GPTIMER_setCount
void GPTIMER_setCount(GPTIMER_Handle handle, uint32_t value)
Set timer counter value.
GPTIMER_PWM_Config::defaultPWMOutSetting
uint32_t defaultPWMOutSetting
Definition: gp_timer/v0/gp_timer.h:300
GPTIMER_Handle
struct GPTIMER_Config_s * GPTIMER_Handle
A handle that is returned from a GPTIMER_open() call.
Definition: gp_timer/v0/gp_timer.h:178
GPTIMER_Object::hwiObj
HwiP_Object hwiObj
Definition: gp_timer/v0/gp_timer.h:316
GPTIMER_Object::mutex
SemaphoreP_Object mutex
Definition: gp_timer/v0/gp_timer.h:314
GPTIMER_Capture_Config::captureEventMode
uint32_t captureEventMode
Definition: gp_timer/v0/gp_timer.h:288
GPTIMER_OverflowCallbackFxn
void(* GPTIMER_OverflowCallbackFxn)(GPTIMER_Handle handle)
GPTIMER Overflow Callback Function.
Definition: gp_timer/v0/gp_timer.h:195
GPTIMER_start
void GPTIMER_start(GPTIMER_Handle handle)
Start the Timer.
GPTIMER_Capture_Config::captureMode
uint32_t captureMode
Definition: gp_timer/v0/gp_timer.h:286
GPTIMER_PWM_Config::outputModulationType
uint32_t outputModulationType
Definition: gp_timer/v0/gp_timer.h:304
SemaphoreP.h
GPTIMER_Compare_Config::cntCompareValComp
uint32_t cntCompareValComp
Definition: gp_timer/v0/gp_timer.h:276
GPTIMER_Params::oneShotMode
bool oneShotMode
Definition: gp_timer/v0/gp_timer.h:260
GPTIMER_getTimerCaptureVal1
uint32_t GPTIMER_getTimerCaptureVal1(GPTIMER_Handle handle)
Get Timer Capture Value 1.
GPTIMER_deinit
void GPTIMER_deinit(void)
De-initialize the GPTIMER module.
GPTIMER_Object::compareConfig
GPTIMER_Compare_Config compareConfig
Definition: gp_timer/v0/gp_timer.h:329
GPTIMER_Params::overflowMaskCount
uint32_t overflowMaskCount
Definition: gp_timer/v0/gp_timer.h:264
GPTIMER_HwAttrs::eventId
uint16_t eventId
Definition: gp_timer/v0/gp_timer.h:237
value
uint32_t value
Definition: tisci_otp_revision.h:2
GPTIMER_Object::compareMatchCallbackFunction
GPTIMER_CompareMatchCallbackFxn compareMatchCallbackFunction
Definition: gp_timer/v0/gp_timer.h:342
HwiP.h
GPTIMER_Object::captureCallbackFunction
GPTIMER_CaptureCallbackFxn captureCallbackFunction
Definition: gp_timer/v0/gp_timer.h:344
GPTIMER_Params::enablePrescaler
bool enablePrescaler
Definition: gp_timer/v0/gp_timer.h:256
GPTIMER_Params_init
void GPTIMER_Params_init(GPTIMER_Params *params)
Function to set default values of GPTIMER_Params in params.
GPTIMER_PWM_Config::trigOutputPWMMode
uint32_t trigOutputPWMMode
Definition: gp_timer/v0/gp_timer.h:298
GPTIMER_Compare_Config
GPTIMER Compare Mode Configuration Parameters.
Definition: gp_timer/v0/gp_timer.h:274
GPTIMER_Config::hwAttrs
GPTIMER_HwAttrs const * hwAttrs
Definition: gp_timer/v0/gp_timer.h:361
GPTIMER_getCount
uint32_t GPTIMER_getCount(GPTIMER_Handle handle)
Get timer counter value.
GPTIMER_HwAttrs::intrPriority
uint8_t intrPriority
Definition: gp_timer/v0/gp_timer.h:243
GPTIMER_getIRQStatus
uint32_t GPTIMER_getIRQStatus(GPTIMER_Handle handle)
Get IRQ status.
GPTIMER_Params::cntPrescaler
uint32_t cntPrescaler
Definition: gp_timer/v0/gp_timer.h:258
GPTIMER_setCompareVal
void GPTIMER_setCompareVal(GPTIMER_Handle handle, uint32_t value)
Set timer compare value.
GPTIMER_Object::overflowCallbackFunction
GPTIMER_OverflowCallbackFxn overflowCallbackFunction
Definition: gp_timer/v0/gp_timer.h:340
GPTIMER_CaptureCallbackFxn
void(* GPTIMER_CaptureCallbackFxn)(GPTIMER_Handle handle)
GPTIMER Capture Callback Function.
Definition: gp_timer/v0/gp_timer.h:221
GPTIMER_Object::gptimerParams
GPTIMER_Params gptimerParams
Definition: gp_timer/v0/gp_timer.h:320
GPTIMER_Params
GPTIMER Parameters.
Definition: gp_timer/v0/gp_timer.h:253
GPTIMER_Capture_Config
GPTIMER Capture Mode Configuration Parameters.
Definition: gp_timer/v0/gp_timer.h:284
HwiP_Object
Opaque Hwi object used with the Hwi APIs.
Definition: HwiP.h:93
GPTIMER_Object
GPTIMER driver object.
Definition: gp_timer/v0/gp_timer.h:312
GPTIMER_disableInterruptStatus
void GPTIMER_disableInterruptStatus(GPTIMER_Handle handle, uint32_t irqMask)
Disable IRQ Status.
GPTIMER_CompareMatchCallbackFxn
void(* GPTIMER_CompareMatchCallbackFxn)(GPTIMER_Handle handle)
GPTIMER Compare Match Callback Function.
Definition: gp_timer/v0/gp_timer.h:208
GPTIMER_Config::object
GPTIMER_Object * object
Definition: gp_timer/v0/gp_timer.h:359
GPTIMER_Params::counterInitVal
uint32_t counterInitVal
Definition: gp_timer/v0/gp_timer.h:266
SemaphoreP_Object
Opaque semaphore object used with the semaphore APIs.
Definition: SemaphoreP.h:59
GPTIMER_PWM_Config
GPTIMER PWM Generation Mode Configuration Parameters.
Definition: gp_timer/v0/gp_timer.h:296
GPTIMER_Params::cntReloadVal
uint32_t cntReloadVal
Definition: gp_timer/v0/gp_timer.h:262
GPTIMER_HwAttrs::inputClk
uint32_t inputClk
Definition: gp_timer/v0/gp_timer.h:239
GPTIMER_getTimerCaptureVal2
uint32_t GPTIMER_getTimerCaptureVal2(GPTIMER_Handle handle)
Get Timer Capture Value 2.
GPTIMER_close
void GPTIMER_close(GPTIMER_Handle handle)
Function to close the GPTIMER Peripheral specified by the handle.
GPTIMER_HwAttrs
GPTIMER Hardware attributes.
Definition: gp_timer/v0/gp_timer.h:230
GPTIMER_open
GPTIMER_Handle GPTIMER_open(uint32_t idx, const GPTIMER_Params *params)
Open the GPTIMER at index idx with parameters params.
GPTIMER_PWM_Config::cntCompareValPWM
uint32_t cntCompareValPWM
Definition: gp_timer/v0/gp_timer.h:302
GPTIMER_enableInterruptStatus
void GPTIMER_enableInterruptStatus(GPTIMER_Handle handle, uint32_t irqMask)
Enable IRQ Status, Corresponding status bit will be set in case of an event. Interrupt and callback w...
GPTIMER_HwAttrs::baseAddr
uint32_t baseAddr
Definition: gp_timer/v0/gp_timer.h:233
GPTIMER_Object::captureConfig
GPTIMER_Capture_Config captureConfig
Definition: gp_timer/v0/gp_timer.h:331