9.9 rtcounter.c File Reference

Includes

  1. xc.h
  2. stdio.h
  3. stdbool.h
  4. rtcounter.h
  5. tmr1.h

Functions

void
rtcount_isr (void)

This function is the handler that is called whenever the Timer peripheral overflows. The handler increments the RTCounter overflow counter.

Parameters:

none

Returns:

None

void
rtcount_initialize (void)

This function sets the RTCounter ISR handler as the the interrupt handler for the timer. Must be called while GIE = 0

Parameters:

none

Returns:

None

uint32_t
rtcount_getTickCount (void)

This function returns the 32-bit total tick count of the timer. This means concatenating the hardware timer value to the overflow counter

Parameters:

none

Returns:

None

uint32_t
rtcount_makeAbsolute (uint32_t period)

This function returns a number of ticks and returns the total number of timer ticks since the last overflow occurred or the timer module was started.

Parameters:

period

Type: uint32_t

- timer period

Returns:

bool
rtcount_sortedInsert (rtcountStruct_t *timer)

This function figures out where the specific timer will be placed on the queue.

Parameters:

timer

Type: rtcountStruct_t *

- instance of a timer being inserted to the queue

Returns:

void
rebase (void)

This function adjusts the time base so that the timer can be in the lower half of the range

Parameters:

none

Returns:

None

void
rtcount_create (rtcountStruct_t *timer, int32_t timeout)

This function adds a new timer to the list of serviced timers. The user supplies the memory for the timer and initializes it. This method simply updates absoluteTime and adds the timer to the list of serviced timers.

Parameters:

*timer

Type: rtcountStruct_t *

- timer instance to be created and added to the list

timeout

Type: int32_t

- number of timer ticks before this timer expires.

Returns:

None

void
rtcount_reschedule (rtcountStruct_t *timer, int32_t timeout)

This function adds time to previous ticks. We add it to the previous target and not to current time to ensure the cadence of the timer will be exact and no skidding is possible.

Parameters:

*timer

Type: rtcountStruct_t *

- timer instance to be added to

timeout

Type: int32_t

- number of timer ticks to be added.

Returns:

None

void
rtcount_delete (rtcountStruct_t *volatile timer)

This function cancels and removes a running timer

Parameters:

*timer

Type: rtcountStruct_t *volatile

- timer instance to be removed

Returns:

None

void
rtcount_callNextCallback (void)

This function checks the list of expired timers and calls the first one in the list if the list is not empty. It also reschedules the timer if the callback returned a value greater than 0.It is recommended that this is called from the main superloop (while(1)) in your code but by design this can also be called from the timer ISR. If you wish callbacks to happen from the ISR context you can call this as the last action in timeout_isr instead.

Parameters:

none

Returns:

None

void
stopTimeouts (void)

This function stops all timers

Parameters:

none

Returns:

None

void
rtcount_startTimer (rtcountStruct_t *timer)

This function is specifically used in Stopwatch mode for calculating the elapsed time in stopwatch mode. It will start a timer with maximum timeout length.

Parameters:

*timer

Type: rtcountStruct_t *

- timer instance.

Returns:

None

uint32_t
rtcount_stopTimer (rtcountStruct_t *timer)

This function will stop the running timer and return the number of ticks it counted.

Parameters:

*timer

Type: rtcountStruct_t *

- timer instance.

Returns:

void
rtcount_flushAll (void)

This function cancels and removes all timers in the queue

Parameters:

none

Returns:

None

int
rtcount_printList (void)

This function prints the times for each of the timer for each timer on the queue.

Parameters:

none

Returns:

None