ADuCM4x50 Device Drivers API Reference Manual  Release 4.0.0.0
Timer Driver

General Purpose and RGB Timer Driver. More...

Modules

 Static Configuration
 

Data Structures

struct  ADI_TMR_CONFIG
 
struct  ADI_TMR_EVENT_CONFIG
 
struct  ADI_TMR_PWM_CONFIG
 

Macros

#define ADI_TMR_NUM_EVENTS   (40u)
 

Enumerations

enum  ADI_TMR_RESULT {
  ADI_TMR_SUCCESS,
  ADI_TMR_BAD_DEVICE_NUM,
  ADI_TMR_BAD_PWM_NUM,
  ADI_TMR_BAD_EVENT_ID,
  ADI_TMR_BAD_RELOAD_CONFIGURATION,
  ADI_TMR_OPERATION_NOT_ALLOWED,
  ADI_TMR_DEVICE_BUSY,
  ADI_TMR_RELOAD_DISABLED,
  ADI_TMR_NULL_POINTER
}
 
enum  ADI_TMR_DEVICE {
  ADI_TMR_DEVICE_GP0 = 0u,
  ADI_TMR_DEVICE_GP1 = 1u,
  ADI_TMR_DEVICE_GP2 = 2u,
  ADI_TMR_DEVICE_RGB = 3u,
  ADI_TMR_DEVICE_NUM = 4u
}
 
enum  ADI_TMR_EVENT {
  ADI_TMR_EVENT_TIMEOUT = 0x01,
  ADI_TMR_EVENT_CAPTURE = 0x02
}
 
enum  ADI_TMR_PRESCALER {
  ADI_TMR_PRESCALER_1 = 0u,
  ADI_TMR_PRESCALER_16 = 1u,
  ADI_TMR_PRESCALER_64 = 2u,
  ADI_TMR_PRESCALER_256 = 3u
}
 
enum  ADI_TMR_CLOCK_SOURCE {
  ADI_TMR_CLOCK_PCLK = 0u,
  ADI_TMR_CLOCK_HFOSC = 1u,
  ADI_TMR_CLOCK_LFOSC = 2u,
  ADI_TMR_CLOCK_LFXTAL = 3u
}
 
enum  ADI_TMR_PWM_OUTPUT {
  ADI_TMR_PWM_OUTPUT_0 = 0u,
  ADI_TMR_PWM_OUTPUT_1 = 1u,
  ADI_TMR_PWM_OUTPUT_2 = 2u,
  ADI_TMR_PWM_OUTPUT_NUM = 3u
}
 

Functions

ADI_TMR_RESULT adi_tmr_Init (ADI_TMR_DEVICE const eDevice, ADI_CALLBACK const pfCallback, void *const pCBParam, bool bEnableInt)
 Initialize GP or RGB Timer. More...
 
ADI_TMR_RESULT adi_tmr_ConfigTimer (ADI_TMR_DEVICE const eDevice, ADI_TMR_CONFIG *timerConfig)
 Configure GP or RGB Timer. More...
 
ADI_TMR_RESULT adi_tmr_ConfigEvent (ADI_TMR_DEVICE const eDevice, ADI_TMR_EVENT_CONFIG *eventConfig)
 Setup GP or RGB Timer Event Capture. More...
 
ADI_TMR_RESULT adi_tmr_ConfigPwm (ADI_TMR_DEVICE const eDevice, ADI_TMR_PWM_CONFIG *pwmConfig)
 Setup GP or RGB Timer Pulse Width Modulation. More...
 
ADI_TMR_RESULT adi_tmr_Enable (ADI_TMR_DEVICE const eDevice, bool bEnable)
 Enable or Disable the GP or RGB Timer. More...
 
ADI_TMR_RESULT adi_tmr_GetCurrentCount (ADI_TMR_DEVICE const eDevice, uint16_t *pCount)
 Get GP or RGB Timer Current Count. More...
 
ADI_TMR_RESULT adi_tmr_GetCaptureCount (ADI_TMR_DEVICE const eDevice, uint16_t *pCount)
 Get GP or RGB Timer Captured Count. More...
 
ADI_TMR_RESULT adi_tmr_Reload (ADI_TMR_DEVICE const eDevice)
 Reload GP or RGB Timer. More...
 

Detailed Description

General Purpose and RGB Timer Driver.

The timer driver controls the timer period, event capture, and pulse width modulation (PWM) features of the General Purpose (GP) Timers and the RGB Timer.

Note
The application must include drivers/tmr/adi_tmr.h to use this driver

Macro Definition Documentation

◆ ADI_TMR_NUM_EVENTS

#define ADI_TMR_NUM_EVENTS   (40u)

Number of events that can be captured

Definition at line 75 of file adi_tmr.c.

Enumeration Type Documentation

◆ ADI_TMR_RESULT

Enumeration for result code returned from the timer device driver functions. The return value of all timer APIs returning ADI_TMR_RESULT should always be tested at the application level for success or failure.

Enumerator
ADI_TMR_SUCCESS 

Successful operation

ADI_TMR_BAD_DEVICE_NUM 

Bad device number supplied by user

ADI_TMR_BAD_PWM_NUM 

Bad PWM output number supplied by user to adi_tmr_ConfigPwm

ADI_TMR_BAD_EVENT_ID 

Bad event number supplied by user to adi_tmr_ConfigEvent

ADI_TMR_BAD_RELOAD_CONFIGURATION 

Bad timer configuration, reloading and free running are mutually exclusive options

ADI_TMR_OPERATION_NOT_ALLOWED 

Setup or enable function called while the timer is running

ADI_TMR_DEVICE_BUSY 

Timeout while waiting for busy bit to clear before writing control register

ADI_TMR_RELOAD_DISABLED 

User attempts to reload the timer when reloading has not been enabled

ADI_TMR_NULL_POINTER 

User attempts to read the current or captured count with a NULL pointer

Definition at line 39 of file adi_tmr.h.

◆ ADI_TMR_DEVICE

Enumeration for the hardware peripheral being used during the API call

Enumerator
ADI_TMR_DEVICE_GP0 

General purpose timer 0

ADI_TMR_DEVICE_GP1 

General purpose timer 1

ADI_TMR_DEVICE_GP2 

General purpose timer 2

ADI_TMR_DEVICE_RGB 

RGB timer

ADI_TMR_DEVICE_NUM 

Total number of devices (private)

Definition at line 65 of file adi_tmr.h.

◆ ADI_TMR_EVENT

Enumeration of events notified in the application provided callback.

Enumerator
ADI_TMR_EVENT_TIMEOUT 

Timeout event occurred

ADI_TMR_EVENT_CAPTURE 

Event capture event occurred

Definition at line 90 of file adi_tmr.h.

◆ ADI_TMR_PRESCALER

Prescale options when configuring the timer

Enumerator
ADI_TMR_PRESCALER_1 

Count every 1 source clock periods

ADI_TMR_PRESCALER_16 

Count every 16 source clock periods

ADI_TMR_PRESCALER_64 

Count every 64 source clock periods

ADI_TMR_PRESCALER_256 

Count every 256 source clock periods

Definition at line 102 of file adi_tmr.h.

◆ ADI_TMR_CLOCK_SOURCE

Source clock options when configuring the timer

Enumerator
ADI_TMR_CLOCK_PCLK 

Use periphreal clock (PCLK)

ADI_TMR_CLOCK_HFOSC 

Use internal high frequency clock (HFOSC)

ADI_TMR_CLOCK_LFOSC 

Use internal low frequency clock (LFOSC)

ADI_TMR_CLOCK_LFXTAL 

Use external low frequency clock (LFXTAL)

Definition at line 118 of file adi_tmr.h.

◆ ADI_TMR_PWM_OUTPUT

RGB PWM outputs, used to specify which PWM output to configure. For the GP timers only ADI_TMR_PWM_OUTPUT_0 is allowed. The RGB timer has all three outputs.

Enumerator
ADI_TMR_PWM_OUTPUT_0 

PWM output 0

ADI_TMR_PWM_OUTPUT_1 

PWM output 1

ADI_TMR_PWM_OUTPUT_2 

PWM output 2

ADI_TMR_PWM_OUTPUT_NUM 

Total number of outputs (private)

Definition at line 136 of file adi_tmr.h.

Function Documentation

◆ adi_tmr_Init()

ADI_TMR_RESULT adi_tmr_Init ( ADI_TMR_DEVICE const  eDevice,
ADI_CALLBACK const  pfCallback,
void *const  pCBParam,
bool  bEnableInt 
)

Initialize GP or RGB Timer.

Setup callback function, device interrupt, and perform static configuration (if applicable).

Note
This function can only be called when the timer is disabled. This function should be called before any other functions are called.
Parameters
[in]eDevice: Device number
[in]pfCallback: Callback function
[in]pCBParam: Callback function parameter
[in]bEnableInt: True to enable the device interrupt, false to disable it
Returns
ADI_TMR_RESULT

Definition at line 143 of file adi_tmr.c.

◆ adi_tmr_ConfigTimer()

ADI_TMR_RESULT adi_tmr_ConfigTimer ( ADI_TMR_DEVICE const  eDevice,
ADI_TMR_CONFIG timerConfig 
)

Configure GP or RGB Timer.

Configure the basic hardware timer parameters.

Note
This function can only be called when the timer is disabled.
Parameters
[in]eDevice: Device number
[in]timerConfig: Timer configuration structure, filled by user prior to function call
Returns
ADI_TMR_RESULT

Definition at line 209 of file adi_tmr.c.

◆ adi_tmr_ConfigEvent()

ADI_TMR_RESULT adi_tmr_ConfigEvent ( ADI_TMR_DEVICE const  eDevice,
ADI_TMR_EVENT_CONFIG eventConfig 
)

Setup GP or RGB Timer Event Capture.

The timer can be configured to capture the timer value when a specific event occurs. The list of events can be found in the hardware reference manual. The callback function specified in adi_tmr_Init will be supplied ADI_TMR_EVENT_CAPTURE to indicate the event occured. The user can then read the captured value by calling adi_tmr_GetCaptureCount.

Note
This function can only be called when the timer is disabled.
Parameters
[in]eDevice: Device number
[in]eventConfig: Event configuration structure, filled by user prior to function call
Returns
ADI_TMR_RESULT

Definition at line 291 of file adi_tmr.c.

◆ adi_tmr_ConfigPwm()

ADI_TMR_RESULT adi_tmr_ConfigPwm ( ADI_TMR_DEVICE const  eDevice,
ADI_TMR_PWM_CONFIG pwmConfig 
)

Setup GP or RGB Timer Pulse Width Modulation.

The timer can be configured to generate a pulse width modulation output signal. The period of this signal is simply determined by the period of timer. The duty cycle will be 50% in toggle mode, or can be configured by the user for a different value using the match value. The pulse will toggle when the timer count matches the match value. The user can also specify the polarity of the signal by choosing if the signal idles low or high. GPIO muxing will be required to use the PWM output.

Note
This function can only be called when the timer is disabled.
Parameters
[in]eDevice: Device number
[in]pwmConfig: PWM configuration structure, filled by user prior to function call
Returns
ADI_TMR_RESULT

Definition at line 362 of file adi_tmr.c.

◆ adi_tmr_Enable()

ADI_TMR_RESULT adi_tmr_Enable ( ADI_TMR_DEVICE const  eDevice,
bool  bEnable 
)

Enable or Disable the GP or RGB Timer.

Start or stop the timer.

Parameters
[in]eDevice: Device number
[in]bEnable: True to enable, false to disable
Returns
ADI_TMR_RESULT

Definition at line 425 of file adi_tmr.c.

◆ adi_tmr_GetCurrentCount()

ADI_TMR_RESULT adi_tmr_GetCurrentCount ( ADI_TMR_DEVICE const  eDevice,
uint16_t *  pCount 
)

Get GP or RGB Timer Current Count.

Read the timer.

Parameters
[in]eDevice: Device number
[out]pCount: Pointer to the result.
Returns
ADI_TMR_RESULT

Definition at line 464 of file adi_tmr.c.

◆ adi_tmr_GetCaptureCount()

ADI_TMR_RESULT adi_tmr_GetCaptureCount ( ADI_TMR_DEVICE const  eDevice,
uint16_t *  pCount 
)

Get GP or RGB Timer Captured Count.

Read the captured timer value. This should be called after the callback function is called with ADI_TMR_EVENT_CAPTURE in the Event field.

Parameters
[in]eDevice: Device number
[out]pCount: Pointer to the result.
Returns
ADI_TMR_RESULT

Definition at line 496 of file adi_tmr.c.

◆ adi_tmr_Reload()

ADI_TMR_RESULT adi_tmr_Reload ( ADI_TMR_DEVICE const  eDevice)

Reload GP or RGB Timer.

Only relevent in peridic mode and when bReloading was set to true when configuring the timer. Calling this function will reload (i.e. reset) the timer to the LOAD value.

Parameters
[in]eDevice: Device number
Returns
ADI_TMR_RESULT

Definition at line 528 of file adi_tmr.c.