SW Timer component for the IoT(Internet of things) service.
Copyright (c) 2016-2018 Microchip Technology Inc. and its subsidiaries.
#include "sw_timer.h"
Functions | |
void | sw_timer_disable (struct sw_timer_module *const module_inst) |
Stop the timer. More... | |
void | sw_timer_disable_callback (struct sw_timer_module *const module_inst, int timer_id) |
Disable callback. More... | |
void | sw_timer_enable (struct sw_timer_module *const module_inst) |
Start the timer. More... | |
void | sw_timer_enable_callback (struct sw_timer_module *const module_inst, int timer_id, uint32_t delay) |
Enables callback. More... | |
void | sw_timer_get_config_defaults (struct sw_timer_config *const config) |
Get default configuration of SW timer. More... | |
void | sw_timer_init (struct sw_timer_module *const module_inst, struct sw_timer_config *const config) |
Initialize the SW timer module. More... | |
int | sw_timer_register_callback (struct sw_timer_module *const module_inst, sw_timer_callback_t callback, void *context, uint32_t period) |
Register callback. More... | |
void | sw_timer_task (struct sw_timer_module *const module_inst) |
Checks the time out of each timer handlers. More... | |
static void | sw_timer_tcc_callback (struct tcc_module *const module) |
TCC callback of SW timer. More... | |
void | sw_timer_unregister_callback (struct sw_timer_module *const module_inst, int timer_id) |
Unregister callback. More... | |
Variables | |
static uint32_t | sw_timer_tick = 0 |
Tick count of timer. More... | |
void sw_timer_disable | ( | struct sw_timer_module *const | module_inst | ) |
Stop the timer.
[in] | module_inst | Pointer of timer. |
References Assert, tcc_disable(), and sw_timer_module::tcc_inst.
void sw_timer_disable_callback | ( | struct sw_timer_module *const | module_inst, |
int | timer_id | ||
) |
Disable callback.
Disable the callback function registered by the sw_timer_register_callback.
[in] | module_inst | Pointer to USART software instance struct |
[in] | timer_id | Timer ID . |
References Assert, sw_timer_handle::callback_enable, CONF_SW_TIMER_COUNT, and sw_timer_module::handler.
void sw_timer_enable | ( | struct sw_timer_module *const | module_inst | ) |
Start the timer.
[in] | module_inst | Pointer of timer. |
References Assert, tcc_enable(), and sw_timer_module::tcc_inst.
Referenced by configure_timer().
void sw_timer_enable_callback | ( | struct sw_timer_module *const | module_inst, |
int | timer_id, | ||
uint32_t | delay | ||
) |
Enables callback.
Enables the callback function registered by the sw_timer_register_callback.
[in] | module_inst | Pointer to USART software instance struct |
[in] | timer_id | Timer ID . |
[in] | delay | Initialization value of timer. |
References sw_timer_module::accuracy, Assert, sw_timer_handle::callback_enable, CONF_SW_TIMER_COUNT, sw_timer_handle::expire_time, sw_timer_module::handler, and sw_timer_tick.
void sw_timer_get_config_defaults | ( | struct sw_timer_config *const | config | ) |
Get default configuration of SW timer.
[in] | config | Pointer of configuration structure which will be used in the timer. |
References sw_timer_config::accuracy, Assert, sw_timer_config::tcc_callback_channel, and sw_timer_config::tcc_dev.
Referenced by configure_timer().
void sw_timer_init | ( | struct sw_timer_module *const | module_inst, |
struct sw_timer_config *const | config | ||
) |
Initialize the SW timer module.
[in] | module_inst | Pointer of timer. |
[in] | config | Pointer of configuration structure which will be used in the timer. |
References sw_timer_config::accuracy, sw_timer_module::accuracy, Assert, tcc_counter_config::clock_prescaler, tcc_config::counter, tcc_module::hw, tcc_counter_config::period, sw_timer_tcc_callback(), system_cpu_clock_get_hz(), sw_timer_config::tcc_callback_channel, TCC_CLOCK_PRESCALER_DIV64, sw_timer_config::tcc_dev, tcc_enable_callback(), tcc_get_config_defaults(), tcc_init(), sw_timer_module::tcc_inst, TCC_NUM_CHANNELS, and tcc_register_callback().
Referenced by configure_timer().
int sw_timer_register_callback | ( | struct sw_timer_module *const | module_inst, |
sw_timer_callback_t | callback, | ||
void * | context, | ||
uint32_t | period | ||
) |
Register callback.
[in] | module_inst | Pointer of timer. |
[in] | callback | Callback entry of time out. |
[in] | context | Private data of timer. |
[in] | period | Period of timer. |
References sw_timer_module::accuracy, Assert, sw_timer_handle::callback, sw_timer_handle::callback_enable, CONF_SW_TIMER_COUNT, sw_timer_handle::context, sw_timer_module::handler, sw_timer_handle::period, and sw_timer_handle::used.
void sw_timer_task | ( | struct sw_timer_module *const | module_inst | ) |
Checks the time out of each timer handlers.
This function must be called continuously for the checking the expiration of the timer handle.
[in] | module_inst | Pointer to USART software instance struct |
References Assert, sw_timer_handle::busy, sw_timer_handle::callback, sw_timer_handle::callback_enable, CONF_SW_TIMER_COUNT, sw_timer_handle::context, sw_timer_handle::expire_time, sw_timer_module::handler, sw_timer_handle::period, sw_timer_tick, and sw_timer_handle::used.
Referenced by main().
|
static |
TCC callback of SW timer.
This function performs to the increasing the tick count.
[in] | module | Instance of the TCC. |
References sw_timer_tick.
Referenced by sw_timer_init().
void sw_timer_unregister_callback | ( | struct sw_timer_module *const | module_inst, |
int | timer_id | ||
) |
Unregister callback.
[in] | module_inst | Pointer of timer. |
[in] | timer_id | Timer ID . |
References Assert, CONF_SW_TIMER_COUNT, sw_timer_module::handler, and sw_timer_handle::used.
|
static |
Tick count of timer.
Referenced by sw_timer_enable_callback(), sw_timer_task(), and sw_timer_tcc_callback().