Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

TIMER - Procedure for timer usage


Files

file  otTimer.h
 Timer Library for BF51x.

Modules

 Version History
 Timer - Code example

Defines

#define StartTimer(tim)   TimerSetAsCounter(tim); TimerEnable(tim, true)
 Simple macro to use the timer as counter.
#define ElapsedTimeMs(st, et)   (ElapsedTimeUs(st, et) / 1000)

Enumerations

enum  TimerId {
  TIMER0, TIMER1, TIMER2, TIMER3,
  TIMER4, TIMER5, TIMER6, TIMER7
}

Functions

void DelayUs (U32 dly)
 Delay. Not accurate!
void DelayMs (U32 dlyMs)
 Delay. Not accurate!
void CoreTimerSetInterruptService (int prescaler, U32 countValue, bool autoReload, void(*pCallback)())
 Set the interrupt service for the CORE timer.
The core timer is a programmable 32-bit interval timer which can generate periodic interrupts.
Unlike other peripherals, the core timer resides inside the Blackfin core and runs at the core clock (CCLK) rate.
Usage example:
// Prescaler action 400MHz / 40 (39+1) = 10MHz (100ns)
// Period: 5000000 * 100ns = 0.5s
CoreTimerSetInterruptService(39, 5000000, true, _coreTimerCallBack);
.
void CoreTimerEnable (bool ena)
 Enable CORE timer. Enable or disable CORE timer.
void TimerSetInterruptCallBack (int timer, void(*pCallback)())
 Change the callback of the specified timer.
TimerEnable(TIMER0, false);
TimerSetInterruptService(TIMER0, _newTimer0CallBack);
TimerEnable(TIMER0, true);
.
void TimerSetInterruptService (int timer, void(*pCallback)(), U32 countValue)
 Set the interrupt service for a timer. With this procedure is possible to set an interrupt service routine called at every terminal count of the timer.
Typical usage:
TimerSetInterruptService(TIMER0, _timer0CallBack, TimerRateMs(1000));
TimerEnable(TIMER0, true);
.
void TimerClrInterruptService (int timer)
 Clear the interrupt service for a timer.
void TimerSetSquareWave (int timer, U32 width, U32 period)
 TBD.
void TimerSetAsCounter (int timer)
 Period measure. Preset a timer to be used for elapsed time.
U32 TimerGetCounts (int timer)
 Return timer counts. Return the timer counts. Used for time measure.
// Init timer 0
TimerSetAsCounter(TIMER0);
TimerEnable(TIMER0, true);
U32 st = TimerGetCounts(TIMER0);    // Grab start time
// Do your process ...
U32 et = TimerGetCounts(TIMER0);    // Grab end time
printf("Elapsed time: %u mS\n", ElapsedTimeUs(st, et) / 1000);
.
void TimerEnable (int timer, bool ena)
 Timer enable. Enable or disable selected timer.
float CoreGetPeripheralClock ()
 Get peripheral clock as MHz. Return SCLCK frequency used by peripherals.
float CoreGetClock ()
 Get core clock as MHz. Return the CCLK frequency used by the core.
void WatchDogSetTimeout (U32 count)
 Preset watch dog timer. A software watchdog can improve system reliability by generating an event to the processor core if the watchdog expires before being updated by software. The 32-bit watchdog timer counts downward every SCLK cycle. If it becomes 0, an event requests can be issued (RESET).
void WatchDogEnable (bool enable)
 Enable or disable watch dog.
U32 ElapsedTime (U32 st, U32 et)
 Calculation of the elapsed time from the timer count values.
U32 ElapsedTimeUs (U32 st, U32 et)
 Calculation of the elapsed time from the timer count values.
U32 ElapsedTimeNs (U32 st, U32 et)
 Calculation of the elapsed time from the timer count values.
U32 TimerRateHz (double Hz)
 Calculates the count value of a timer to obtain the desired frequency (Hertz).
U32 TimerRateMs (double Ms)
 Calculates the count value of a timer to obtain the desired period (mS).
U32 TimerRateUs (double Us)
 Calculates the count value of a timer to obtain the desired period (uS).
void ElapsedTimeStart (int timer)
 starts the measurement of time (ms).
U32 ElapsedTimeEnd (int timer)
 Ends the measurement of time (ms).
U32 ElapsedTimeEndUs (int timer)
bool ElapsedTimeCheck (U32 target, int timer)
 Check if the "target" time has been reached.
bool ElapsedTimeCheckUs (U32 target, int timer)
 Check if the "target" time has been reached.
bool ElapsedTimeCheckUsMark (U32 target, int timer)
 Check if the "target" time has been reached and if it is done store a new value for next check.
void TimerDelayUs (int timer, U32 dly)
void LongTimerTick (U16 id)
U64 LongTimerTickValue (U16 id)
U64 LongTimerTickRead (U16 id)

Define Documentation

#define ElapsedTimeMs st,
et   )     (ElapsedTimeUs(st, et) / 1000)
 

#define StartTimer tim   )     TimerSetAsCounter(tim); TimerEnable(tim, true)
 


Enumeration Type Documentation

enum TimerId
 

Enumeration values:
TIMER0  32 bit Timer 0
TIMER1  32 bit Timer 1
TIMER2  32 bit Timer 2
TIMER3  32 bit Timer 3
TIMER4  32 bit Timer 4
TIMER5  32 bit Timer 5
TIMER6  32 bit Timer 6
TIMER7  32 bit Timer 7


Function Documentation

float CoreGetClock  ) 
 

Returns:
Frequency as MHz

float CoreGetPeripheralClock  ) 
 

Returns:
Frequency as MHz

void CoreTimerEnable bool  ena  ) 
 

Parameters:
ena If true enable the CORE timer
See also:
CoreTimerSetInterruptService

void CoreTimerSetInterruptService int  prescaler,
U32  countValue,
bool  autoReload,
void(*)()  pCallback
 

Parameters:
prescaler (8bit) divider
countValue (32bit) divider
autoReload If true presetted value is reloaded
pCallback C callback procedure called at every terminal count
See also:
CoreTimerEnable

void DelayMs U32  dlyMs  ) 
 

Parameters:
dlyMs Delay in milliseconds

void DelayUs U32  dly  ) 
 

Parameters:
dly Delay in microseconds

U32 ElapsedTime U32  st,
U32  et
 

Parameters:
st Start count
et End count
Returns:
Elapsed time in timer counts
See also:
TimerGetCounts

bool ElapsedTimeCheck U32  target,
int  timer
 

Parameters:
target Elapsed time to be verified as ms
timer Id, see TimerId
Returns:
True If current time is >= target
See also:
ElapsedTimeStart

bool ElapsedTimeCheckUs U32  target,
int  timer
 

Parameters:
target Elapsed time to be verified
timer Id, see TimerId
See also:
ElapsedTimeStart

bool ElapsedTimeCheckUsMark U32  target,
int  timer
 

Parameters:
target Elapsed time to be verified
timer Id, see TimerId
See also:
ElapsedTimeStart

void ElapsedTimeEnd int  timer  ) 
 

Parameters:
timer Id, see TimerId
See also:
ElapsedTimeStart

U32 ElapsedTimeEndUs int  timer  ) 
 

U32 ElapsedTimeNs U32  st,
U32  et
 

Parameters:
st Start count
et End count
Returns:
Elapsed time in ns (10E-9 s). Minimum tick is 10ns
See also:
TimerGetCounts

void ElapsedTimeStart int  timer  ) 
 

Parameters:
timer Id, see TimerId
See also:
ElapsedTimeCheck

U32 ElapsedTimeUs U32  st,
U32  et
 

Parameters:
st Start count
et End count
Returns:
Elapsed time in us (10E-6 s).
See also:
TimerGetCounts

void LongTimerTick U16  id  ) 
 

void LongTimerTick(U16 id); Implement a 64-bit timer using a 32-bit one. An interrupt every second is generated. See also LongTimerTickValue

Parameters:
id Id, see TimerId
See also:
LongTimerTickValue

U64 LongTimerTickRead U16  id  ) 
 

U64 LongTimerTickValue U16  id  ) 
 

Parameters:
id Id, see TimerId
Returns:
64 bit counts
See also:
LongTimerTick

void TimerClrInterruptService int  timer  ) 
 

Parameters:
timer Id, see TimerId
See also:
TimerEnable, TimerSetInterruptService

void TimerDelayUs int  timer,
U32  dly
 

fn void TimerDelayUs(int timer, U32 dly); Execute a delay with specified timer for a specified delay. Blocking procedure.

Parameters:
timer Id, see TimerId
dly Delay as us

void TimerEnable int  timer,
bool  ena
 

Parameters:
timer Id, see TimerId
ena true enable selected timer

U32 TimerGetCounts int  timer  ) 
 

Parameters:
timer Id, see TimerId
Returns:
Timer counts as SCCLK ticks (10ns)

U32 TimerRateHz double  Hz  ) 
 

Parameters:
Hz Desidered frequency.

U32 TimerRateMs double  Ms  ) 
 

Parameters:
Ms Desidered period

U32 TimerRateUs double  Us  ) 
 

Parameters:
Us Desidered period

void TimerSetAsCounter int  timer  ) 
 

Parameters:
timer Id, see TimerId
See also:
TimerEnable, TimerGetCounts, ElapsedTimeUs

void TimerSetInterruptCallBack int  timer,
void(*)()  pCallback
 

Parameters:
timer Id, see TimerId
pCallback C callback procedure called at every terminal count
See also:
TimerSetInterruptService

void TimerSetInterruptService int  timer,
void(*)()  pCallback,
U32  countValue
 

Parameters:
timer Id, see TimerId
pCallback C callback procedure called at every terminal count
countValue 32 bit divider, input clock is SCLK tipically 100MHz.
See also:
TimerEnable, TimerClrInterruptService

void TimerSetSquareWave int  timer,
U32  width,
U32  period
 

Parameters:
timer Id, see TimerId
width 
period 

void WatchDogEnable bool  enable  ) 
 

Parameters:
enable if true anable watch dog

void WatchDogSetTimeout U32  count  ) 
 

Parameters:
count timeut value. Tipical value of SCLK is 10nS, maximum timeout value is 2^32 * 10 = 42949.67296 seconds
footer

otStudio - Library Reference - (C) 2020-23 Officina Turini, All Rights Reserved
Document built with Doxygen 1.4.0