# KETIMER
[KERNEL]

Timer management module. More...

Collaboration diagram for KETIMER:

## Data Structures
struct | ke_timer
| Timer Object. More...
## Defines
#define | KE_TIMER_DELAY_MAX 300000000
| Timers can be set up to 300s in the future.
#define | MILLI2MICRO 1000
| Standard Multiplier.
## Functions
static void | ke_timer_hw_set (struct ke_timer *timer)
| Set the HW timer with the first timer of the queue.
static bool | cmp_abs_time (struct co_list_hdr const *timerA, struct co_list_hdr const *timerB)
| Compare timer absolute expiration time.
static bool | cmp_timer_id (struct co_list_hdr const *timer, uint32_t timer_task)
| Compare timer and task IDs callback.
void | ke_timer_set (ke_msg_id_t const timer_id, ke_task_id_t const task_id, uint32_t const delay)
| Set a timer.
void | ke_timer_clear (ke_msg_id_t const timer_id, ke_task_id_t const task_id)
| Remove an registered timer.
void | ke_timer_schedule (int dummy)
| Schedule the next timer(s).
bool | ke_timer_active (ke_msg_id_t const timer_id, ke_task_id_t const task_id)
| Checks if a requested timer is active.
void | ke_timer_reset (void)
| Remove all the programmed timers.
__INLINE uint32_t | ke_time ()
| Get the current kernel time.
__INLINE bool | ke_time_abs_cmp (uint32_t time1, uint32_t time2)
| Compare absolute expiration time.
__INLINE bool | ke_time_past (uint32_t time)
| Check if the kernel time passed as parameter is in the past.

## Detailed Description

Timer management module.

The KETIMER module implements the functions used for managing kernel timers.

## Function Documentation

static bool cmp_abs_time | ( | struct co_list_hdr const * | timerA,
|  | struct co_list_hdr const * | timerB |
| ) |  |  | `[static]`

Compare timer absolute expiration time.

Parameters:

  `[in]` | timerA | Timer to compare.
  `[in]` | timerB | Timer to compare.

Returns:
  true if timerA will expire before timerB.

Definition at line 86 of file ke_timer.c.

References KE_TIMER_DELAY_MAX.

static bool cmp_timer_id | ( | struct co_list_hdr const * | timer,
|  | uint32_t | timer_task |
| ) |  |  | `[static]`

Compare timer and task IDs callback.

Parameters:

  `[in]` | timer | Pointer to the timer element
  `[in]` | timer_task | Integer formed with the task_id and timer_id

Returns:
  true if the timer matches with the timer_id and task_id passed in timer_task

Definition at line 104 of file ke_timer.c.

__INLINE uint32_t ke_time | ( |  | ) |

Get the current kernel time.

Returns:
  The current kernel time

Definition at line 92 of file ke_timer.h.

References ASSERT_ERR, and hal_machw_time().

Referenced by bam_create_ba_agg(), bfr_calib_tmr_exp_cb(), bfr_calibrate(), chan_conn_less_delay_prog(), ke_time_past(), mm_ap_tbtt(), mm_set_p2p_noa_req_handler(), mm_set_vif_state_req_handler(), p2p_noa_timer_end(), ps_enable_cfm(), ps_uapsd_timer_handle(), rxu_cntrl_reord_timeout_cb(), tdls_check_frame_action(), tdls_check_tdls_channel_switch_request(), tdls_check_tdls_channel_switch_response(), tdls_chsw_rsp_tx_cfm(), tdls_chsw_time_evt(), and tdls_keep_alive_evt().

__INLINE bool ke_time_abs_cmp | ( | uint32_t | time1,
|  | uint32_t | time2 |
| ) |  |  |

Compare absolute expiration time.

Parameters:

  `[in]` | time1 | First time to compare.
  `[in]` | time2 | Second time to compare.

Returns:
  true if time1 is earlier than time2.

Definition at line 113 of file ke_timer.h.

Referenced by bfr_calibrate(), and ke_time_past().

__INLINE bool ke_time_past | ( | uint32_t | time | ) |

Check if the kernel time passed as parameter is in the past.

Parameters:

  `[in]` | time | Time to check

Returns:
  true if time is in the past, false otherwise

Definition at line 135 of file ke_timer.h.

References ke_time(), and ke_time_abs_cmp().

Referenced by ps_uapsd_timer_handle().

bool ke_timer_active | ( | ke_msg_id_t const | timer_id,
|  | ke_task_id_t const | task_id |
| ) |  |  |

Checks if a requested timer is active.

This function goes through the list of timers until it finds a timer matching the timer_id and task_id.

Parameters:

  `[in]` | timer_id | Identifier of the timer
  `[in]` | task_id | Task indentifier

Returns:
  true if a timer in the list matches the passed timer_id and task_id, false otherwise.

void ke_timer_clear | ( | ke_msg_id_t const | timer_id,
|  | ke_task_id_t const | task_id |
| ) |  |  |

Remove an registered timer.

This function search for the timer identified by its id and its task id. If found it is stopped and freed, otherwise an error message is returned.

Parameters:

  `[in]` | timer_id | Timer identifier.
  `[in]` | task_id | Task identifier.

Referenced by rxu_mgt_ind_handler().

static void ke_timer_hw_set | ( | struct ke_timer * | timer | ) | `[static]`

Set the HW timer with the first timer of the queue.

Parameters:

  `[in]` | timer |

Definition at line 48 of file ke_timer.c.

References GLOBAL_INT_DISABLE, GLOBAL_INT_RESTORE, HAL_KE_TIMER, HAL_KE_TIMER_BIT, and ke_timer::time.

void ke_timer_schedule | ( | int | dummy | ) |

Schedule the next timer(s).

This function pops the first timer from the timer queue and notifies the appropriate task by sending a kernel message. If the timer is periodic, it is set again; if it is one-shot, the timer is freed. The function checks also the next timers and process them if they have expired or are about to expire.

Parameters:

  `[in]` | dummy | Parameter not used but required to follow the kernel event callback format

void ke_timer_set | ( | ke_msg_id_t const | timer_id,
|  | ke_task_id_t const | task_id,
|  | uint32_t const | delay |
| ) |  |  |

Set a timer.

The function first cancel the timer if it is already existing, then it creates a new one. The timer can be one-shot or periodic, i.e. it will be automatically set again after each trigger.

When the timer expires, a message is sent to the task provided as argument, with the timer id as message id.

The timer is programmed in microseconds but is not accurate to the microsecond, due to the kernel message propagation delay and the configuration time.

Parameters:

  `[in]` | timer_id | Timer identifier (message identifier type).
  `[in]` | task_id | Task identifier which will be notified
  `[in]` | delay | Delay in time units.

Referenced by bam_create_ba_agg().