AM64x MCU+ SDK  10.01.00
GPTIMER

The General-Purpose Timer driver provides APIs to configure the available timer modules in multiple modes.

Features Supported

  • Interrupts generated on overflow, compare, and capture
  • Free-running 32-bit upward counter
  • Compare and capture modes
  • Autoreload mode
  • Start/stop mode
  • Programmable divider clock source (2 exponent n, where n = [0-8])
  • Dedicated input trigger for capture mode and dedicated output trigger/PWM signal
  • On-the-fly read/write register

SysConfig Features

Note
It is strongly recommend to use SysConfig where it is available instead of using direct SW API calls. This will help simplify the SW application and also catch common mistakes early in the development cycle.
  • Set mode of operation of the timer
  • Enable/Disable and Set counter Prescaler
  • Enable/Disable Auto reload Mode and set Auto reload Value
  • Enable Interrupt and Assign User Callback
  • Set Compare value when Compare Match mode is set
  • Set Counter mode and Capture event when Timer configured to capture input
  • Set PWM output Trigger mode and Compare Value in PWM mode
  • Set Default Output Polarity in PWM mode
  • Set Output Pin Modulation in PWM mode

Features NOT Supported

  • Atomic 64-bit timer value read of cascaded timers
  • Smart-idle with wake-up mode

Example Usage

Include the below file to access the APIs

Instance Open Example

/* Initialize parameters */
params.enablePrescaler = false,
params.cntPrescaler = 0,
params.oneShotMode = false,
params.cntReloadVal = 0,
params.overflowMaskCount = 0,
params.counterInitVal = 0,
/* Update object Parameters mode settings */
gGpTimerObjects[CONFIG_GPTIMER0].timerConfigMode = GPTIMER_MODE_CONFIG_FREE_RUN;
gGpTimerObjects[CONFIG_GPTIMER0].overflowCallbackFunction = NULL,
gGpTimerObjects[CONFIG_GPTIMER0].compareMatchCallbackFunction = NULL,
gGpTimerObjects[CONFIG_GPTIMER0].captureCallbackFunction = NULL,
gGpTimerHandle = GPTIMER_open(CONFIG_GPTIMER0, &params);
DebugP_assert(gGpTimerHandle != NULL);

Instance Close Example

GPTIMER_close(gGpTimerHandle);

GPTIMER configuration in Free Running Mode without interrupt

void gptimer_free_run_no_interrupt(void)
{
uint32_t conifgMode;
GPTIMER_setTimerConfigMode(gGpTimerHandle, conifgMode,
(void *)NULL);
/* Start the Timer */
GPTIMER_start(gGpTimerHandle);
}

GPTIMER configuration in Free Running Mode with interrupt

void overflowCallback(GPTIMER_Handle handle)
{
/* Post Semaphore */
SemaphoreP_post(&overflowSemObj);
}
void gptimer_free_run_interrupt(void)
{
uint32_t conifgMode;
SemaphoreP_constructBinary(&overflowSemObj, 0);
GPTIMER_setTimerConfigMode(gGpTimerHandle, conifgMode,
(void *)NULL);
/* Add Callback */
GPTIMER_setCallbackFxn(gGpTimerHandle, overflowCallback, NULL, NULL);
/* Start the Timer */
GPTIMER_start(gGpTimerHandle);
/* Pend Semaphore */
SemaphoreP_destruct(&overflowSemObj);
}

GPTIMER configuration in Output Compare Mode

void compareMatchCallback(GPTIMER_Handle handle)
{
/* Post Semaphore */
SemaphoreP_post(&compareMatchSemObj);
}
void gptimer_output_compare_interrupt(void)
{
SemaphoreP_constructBinary(&compareMatchSemObj, 0);
uint32_t conifgMode;
compareConfig.cntCompareValComp = (0x017D7840U);
GPTIMER_setTimerConfigMode(gGpTimerHandle, conifgMode,
(void *)(&compareConfig));
/* Add Callback */
GPTIMER_setCallbackFxn(gGpTimerHandle, NULL, compareMatchCallback, NULL);
/* Start the TImer */
GPTIMER_start(gGpTimerHandle);
/* Pend Semaphore */
SemaphoreP_pend(&compareMatchSemObj, SystemP_WAIT_FOREVER);
SemaphoreP_destruct(&compareMatchSemObj);
}

GPTIMER configuration in Input Capture Mode

void CaptureCallbackUser(GPTIMER_Handle handle)
{
/* Post Semaphore */
SemaphoreP_post(&captureSemObj);
}
void gptimer_input_capture_interrupt(void)
{
SemaphoreP_constructBinary(&captureSemObj, 0);
uint32_t conifgMode;
inputCaptureConfig.captureMode = GPTIMER_INPUT_CAPTURE_MODE_SECOND;
inputCaptureConfig.captureEventMode = GPTIMER_INPUT_CAPTURE_EVENT_EDGE;
GPTIMER_setTimerConfigMode(gGpTimerHandle, conifgMode,
(void *)(&inputCaptureConfig));
/* Add Callback */
GPTIMER_setCallbackFxn(gGpTimerHandle, NULL, NULL, CaptureCallbackUser);
/* Start the Timer */
GPTIMER_start(gGpTimerHandle);
/* Pend Semaphore */
SemaphoreP_destruct(&captureSemObj);
}

GPTIMER configuration in PWM Generation Mode

void gptimer_pwm_gen(void)
{
uint32_t conifgMode;
pwmConfig.trigOutputPWMMode = GPTIMER_PWM_OUT_OVERFLOW_MATCH_TRIGGER,
pwmConfig.defaultPWMOutSetting = GPTIMER_PWM_OUT_PIN_DEFAULT_0,
pwmConfig.cntCompareValPWM = 4294954795,
pwmConfig.outputModulationType = GPTIMER_PWM_OUT_PIN_MODULATION_TOGGLE,
GPTIMER_setTimerConfigMode(gGpTimerHandle, conifgMode,
(void *)(&pwmConfig));
/* Start the Timer */
GPTIMER_start(gGpTimerHandle);
}

API

APIs for GPTIMER

GPTIMER_INPUT_CAPTURE_MODE_SECOND
#define GPTIMER_INPUT_CAPTURE_MODE_SECOND
Capture Two Events.
Definition: gp_timer/v0/gp_timer.h:93
GPTIMER_setTimerConfigMode
int32_t GPTIMER_setTimerConfigMode(GPTIMER_Handle handle, uint32_t timerConfigMode, void *config)
Change Timer Configuration.
GPTIMER_setCallbackFxn
void GPTIMER_setCallbackFxn(GPTIMER_Handle handle, GPTIMER_OverflowCallbackFxn overflowCbFxn, GPTIMER_CompareMatchCallbackFxn compMatchCbFxn, GPTIMER_CaptureCallbackFxn captureCbFxn)
Update Callback Functions.
GPTIMER_MODE_CONFIG_OUTPUT_COMPARE
#define GPTIMER_MODE_CONFIG_OUTPUT_COMPARE
Output Compare Mode.
Definition: gp_timer/v0/gp_timer.h:78
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_PWM_OUT_PIN_DEFAULT_0
#define GPTIMER_PWM_OUT_PIN_DEFAULT_0
Pin Default value 0.
Definition: gp_timer/v0/gp_timer.h:136
GPTIMER_MODE_CONFIG_PWM_GEN
#define GPTIMER_MODE_CONFIG_PWM_GEN
PWM Generation Mode.
Definition: gp_timer/v0/gp_timer.h:80
GPTIMER_PWM_OUT_OVERFLOW_MATCH_TRIGGER
#define GPTIMER_PWM_OUT_OVERFLOW_MATCH_TRIGGER
PWM uses overflow and compare match as a trigger.
Definition: gp_timer/v0/gp_timer.h:125
GPTIMER_start
void GPTIMER_start(GPTIMER_Handle handle)
Start the Timer.
SystemP_WAIT_FOREVER
#define SystemP_WAIT_FOREVER
Value to use when needing a timeout of infinity or wait forver until resource is available.
Definition: SystemP.h:83
GPTIMER_MODE_CONFIG_FREE_RUN
#define GPTIMER_MODE_CONFIG_FREE_RUN
Free Running Mode.
Definition: gp_timer/v0/gp_timer.h:74
GPTIMER_Params::oneShotMode
bool oneShotMode
Definition: gp_timer/v0/gp_timer.h:260
GPTIMER_Params::overflowMaskCount
uint32_t overflowMaskCount
Definition: gp_timer/v0/gp_timer.h:264
SemaphoreP_destruct
void SemaphoreP_destruct(SemaphoreP_Object *obj)
Cleanup, delete, destruct a semaphore object.
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_OUT_PIN_MODULATION_TOGGLE
#define GPTIMER_PWM_OUT_PIN_MODULATION_TOGGLE
Pin Modulation type Toggle.
Definition: gp_timer/v0/gp_timer.h:155
GPTIMER_Params::cntPrescaler
uint32_t cntPrescaler
Definition: gp_timer/v0/gp_timer.h:258
gp_timer.h
GPTIMER_Params
GPTIMER Parameters.
Definition: gp_timer/v0/gp_timer.h:253
SemaphoreP_post
void SemaphoreP_post(SemaphoreP_Object *obj)
Post a semaphore object or unlock a mutex.
GPTIMER_Params::counterInitVal
uint32_t counterInitVal
Definition: gp_timer/v0/gp_timer.h:266
GPTIMER_INPUT_CAPTURE_EVENT_EDGE
#define GPTIMER_INPUT_CAPTURE_EVENT_EDGE
Capture Event on both rising and falling edge.
Definition: gp_timer/v0/gp_timer.h:110
SemaphoreP_constructBinary
int32_t SemaphoreP_constructBinary(SemaphoreP_Object *obj, uint32_t initValue)
Create a binary semaphore object.
GPTIMER_MODE_CONFIG_INPUT_CAPTURE
#define GPTIMER_MODE_CONFIG_INPUT_CAPTURE
Input Capture Mode.
Definition: gp_timer/v0/gp_timer.h:76
GPTIMER_Params::cntReloadVal
uint32_t cntReloadVal
Definition: gp_timer/v0/gp_timer.h:262
GPTIMER_close
void GPTIMER_close(GPTIMER_Handle handle)
Function to close the GPTIMER Peripheral specified by the handle.
DebugP_assert
#define DebugP_assert(expression)
Function to call for assert check.
Definition: DebugP.h:177
GPTIMER_open
GPTIMER_Handle GPTIMER_open(uint32_t idx, const GPTIMER_Params *params)
Open the GPTIMER at index idx with parameters params.
SemaphoreP_pend
int32_t SemaphoreP_pend(SemaphoreP_Object *obj, uint32_t timeToWaitInTicks)
Pend on a semaphore object or lock a mutex.