Microchip® Advanced Software Framework

timeout.c File Reference

Timeout service for XMEGA.

Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.

#include <asf.h>
#include <conf_timeout.h>
#include <rtc.h>

Data Structures

struct  timeout_struct
 Timeout timekeeping data. More...
 

Functions

static void tick_handler (uint32_t time)
 Callback function for RTC compare interrupt handler. More...
 
void timeout_init (void)
 Initialize timeout. More...
 
void timeout_start_offset (timeout_id_t id, uint16_t period, uint16_t offset)
 Start periodic timeout with a specific start timeout. More...
 
void timeout_start_periodic (timeout_id_t id, uint16_t period)
 Start periodic timeout. More...
 
void timeout_start_singleshot (timeout_id_t id, uint16_t timeout)
 Start singleshot timeout. More...
 
void timeout_stop (timeout_id_t id)
 Stop running timeout. More...
 
bool timeout_test_and_clear_expired (timeout_id_t id)
 Test and clear expired flag for running timeout. More...
 

Variables

static uint8_t timeout_active
 Bitmask of active timeouts. More...
 
static struct timeout_struct timeout_array [TIMEOUT_COUNT]
 Array of configurable timeout timekeeping data. More...
 
static uint8_t timeout_expired
 Bitmask of expired timeouts. More...
 

static void tick_handler ( uint32_t  time)
static

Callback function for RTC compare interrupt handler.

The function executes when the RTC compare interrupt occurs and loop through all timeout channels. The timeout_array[channel_index] which contains the remaining ticks before timeout is decremented and the timeout active/expired masks are updated.

References timeout_struct::count, timeout_struct::period, rtc_set_alarm(), rtc_set_time(), timeout_active, timeout_array, TIMEOUT_COMP, and timeout_expired.

Referenced by timeout_init().

void timeout_init ( void  )

Initialize timeout.

Initializes timeout counter for desired tick rate and starts it. The device interrupt controller should be initialized prior to calling this function, and global interrupts must be enabled.

Note
If the service is configured to use the asynchronous RTC32 module, there are restrictions on the timeout period that can be used - see to Minimum allowed alarm time for details.

References rtc_init(), rtc_set_alarm(), rtc_set_callback(), rtc_set_time(), tick_handler(), and TIMEOUT_COMP.

Referenced by main().

void timeout_start_offset ( timeout_id_t  id,
uint16_t  period,
uint16_t  offset 
)

Start periodic timeout with a specific start timeout.

Parameters
idtimeout_id_t
periodTime period in number of ticks
offsetTime to first timeout in number of ticks

References timeout_struct::count, cpu_irq_restore(), cpu_irq_save(), timeout_struct::period, timeout_active, timeout_array, and timeout_expired.

Referenced by timeout_start_periodic(), and timeout_start_singleshot().

void timeout_start_periodic ( timeout_id_t  id,
uint16_t  period 
)

Start periodic timeout.

Parameters
idtimeout_id_t
periodTime period in number of ticks

References timeout_start_offset().

Referenced by main(), and test_periodic_timeout().

void timeout_start_singleshot ( timeout_id_t  id,
uint16_t  timeout 
)

Start singleshot timeout.

Parameters
idtimeout_id_t
timeoutTimeout in number of ticks

References timeout_start_offset().

Referenced by main(), and test_singleshot_timeout().

void timeout_stop ( timeout_id_t  id)

Stop running timeout.

Parameters
idtimeout_id_t

References cpu_irq_restore(), cpu_irq_save(), and timeout_active.

bool timeout_test_and_clear_expired ( timeout_id_t  id)

Test and clear expired flag for running timeout.

Parameters
idtimeout_id_t
Return values
trueTimer have expired; clearing expired flag
falseTimer still running

References cpu_irq_restore(), cpu_irq_save(), and timeout_expired.

Referenced by main(), test_initialization(), test_periodic_timeout(), and test_singleshot_timeout().

uint8_t timeout_active
static

Bitmask of active timeouts.

Referenced by tick_handler(), timeout_start_offset(), and timeout_stop().

struct timeout_struct timeout_array[TIMEOUT_COUNT]
static

Array of configurable timeout timekeeping data.

Referenced by tick_handler(), and timeout_start_offset().

uint8_t timeout_expired
static

Bitmask of expired timeouts.

Referenced by tick_handler(), timeout_start_offset(), and timeout_test_and_clear_expired().