Timer

Features Supported

  • APIs to setup timer configuration

  • APIs to start and stop the timer

  • APIs to get the current timer count

  • APIs to check for counter overflow and clear timer overflow interrupt

Features NOT Supported

NA

Important Usage Guidelines

  • Supports continues and oneshot mode

  • When configuring the timer period in micro second the ‘periodInNsec’ should be set to 0

Attention

Timer(TIMER2) is used for the system tick functionality in c7x is also availbale to uses as a timer peripheral for a53 core. Hence use TIMER2 for single purpose either system tick functionality in c7x or timer peripheral for a53 core

Example Usage

Include the below file to access the APIs,


//! [include]
#include <kernel/dpl/TimerP.h>
//! [include]

void samples(uint32_t timerBaseAddr)
{
{
//! [initialize]
    TimerP_Params timerParams;

Example usage to initialize the timer:

    TimerP_Params_init(&timerParams);
    timerParams.inputPreScaler    = 1u;
    timerParams.inputClkHz        = 250u*1000u*1000u;
    timerParams.periodInUsec      = 10u*1000u;
    timerParams.oneshotMode       = 0;
    timerParams.enableOverflowInt = 1;
    TimerP_setup(timerBaseAddr, &timerParams);
//! [initialize]
}
{
//! [start]
    /* start the tick timer */
    TimerP_start(timerBaseAddr);
//! [start]
}
{
//! [curCount]
    uint32_t count;

    /* start the tick timer */
    count = TimerP_getCount(timerBaseAddr);
    (void) count; /* kill warning of variable set but not used */
//! [curCount]
}
{
//! [stop]
    /* stop the tick timer */
    TimerP_stop(timerBaseAddr);
//! [stop]

Example usage to start the timer:

}
{
//! [start]
    /* start the tick timer */
    TimerP_start(timerBaseAddr);
//! [start]

Example usage to get the current count value:

//! [curCount]
    uint32_t count;

    /* start the tick timer */
    count = TimerP_getCount(timerBaseAddr);
    (void) count; /* kill warning of variable set but not used */
//! [curCount]

Example usage to stop the timer:

//! [stop]
    /* stop the tick timer */
    TimerP_stop(timerBaseAddr);
//! [stop]

API Reference

Defines

TIME_IN_MICRO_SECONDS

Macro defines the time in micro seconds

MAX_TIMER_COUNT_VALUE

Macro defines the maximum timer count value

TIME_IN_MILLI_SECONDS

Macro defines the time in milli seconds

TIME_IN_NANO_SECONDS

Macro defines the time in nano seconds

TIMERP_SHIFT_BY_EIGHT

Macro defines the shift by eight

MAX_NUMBER_OF_CYCLES

Macro defines the maximum number of cycles

Functions

void TimerP_Params_init(TimerP_Params *params)

Set default value for TimerP_Params.

Parameters:

params – [out] timer parameters initalized to default

int32_t TimerP_setup(uint32_t baseAddr, TimerP_Params *params)

Setup timer but does not start it.

Parameters:
  • baseAddr – [in] HW timer base addresss

  • params – [in] timer parameters

Returns:

SystemP_SUCCESS on success, SystemP_FAILURE if baseAddr is 0, params is NULL, or any parameter value is invalid

int32_t TimerP_start(uint32_t baseAddr)

Start timer.

Parameters:

baseAddr – [in] HW timer base addresss

int32_t TimerP_stop(uint32_t baseAddr)

Stop timer.

Parameters:

baseAddr – [in] HW timer base addresss

uint32_t TimerP_getCount(uint32_t baseAddr)

Get timer current count.

Parameters:

baseAddr – [in] HW timer base addresss

Returns:

current timer count value

uint32_t TimerP_getReloadCount(uint32_t baseAddr)

Get timer reload count.

Parameters:

baseAddr – [in] HW timer base addresss

Returns:

reload count value

int32_t TimerP_clearOverflowInt(uint32_t baseAddr)

Clear timer overflow interrupt.

Parameters:

baseAddr – [in] HW timer base addresss

uint32_t TimerP_isOverflowed(uint32_t baseAddr)

Check if timer is overflowed.

Note

make sure to clear overflow status TimerP_clearOverflowInt

Parameters:

baseAddr – [in] HW timer base addresss

struct TimerP_Params
#include <TimerP.h>

Parameters for TimerP_setup.

Public Members

uint32_t inputPreScaler

input pre-scaler divisor ro apply

Note

MUST be power of 2 and between 1 and 256 for GP Timer

Note

MAKE sure this value is not 0

Note

This field is valid only when underlying timer is DM Timer.

Note

This field is not valid when underlying timer is RTI Timer. Set to 1 in this case.

uint32_t inputClkHz

Timer input clock in unit of Hz before pre-scaler, system initialization MUST make any system level muxes, PLLs, power required to input this clock are setup properly

Note

MAKE sure this value is not 0

uint32_t periodInUsec

Timer period in units of usecs, internally TimerP_Params::inputClkHz and TimerP_Params.inputPreScaler is used to compute the value to be put inside the timer HW register

Note

When value is 0, periodInNsec is used instead

Note

When both periodInUsec and periodInNsec are non-zero, periodInNsec is used

uint64_t periodInNsec

Timer period in units of nsecs, internally TimerP_Params::inputClkHz and TimerP_Params.inputPreScaler is used to compute the value to be put inside the timer HW register

Note

When value is 0, periodInUsec is used instead

Note

When both periodInUsec and periodInNsec are non-zero, periodInNsec is used

uint32_t oneshotMode

0: continuous mode of operation, 1: oneshot mode of operation

Note

NOT supported for RTI timer, always set to 0 in this case.

uint32_t enableOverflowInt

0: Do not enable timer overflow interrupt, 1: enable timer overflow interrupt

uint32_t enableDmaTrigger

0: Do not enable DMA trigger from timer, 1: enable DMA trigger from timer