Core timeout library.
This core library component can be used to set timeouts for both software events and core library events. Timeouts are specified by a core_timeout_t struct.
Typical initialization
- Initialize a core_timeout_t struct for each timeout
- Set the
timeout member to the desired timeout length in milliseconds
- Set the
callback member to the timeout's callback function. When the function is called, a pointer to the struct defining the timeout that called the callback function is passed to it.
- Set the
module and ref members. See below.
- Set the 'check' member. See below.
- Add the timeout structs to the internal list with core_timeout_insert()
- Start all of the timeouts with core_timeout_start_all()
- Call
core_timeout_check_all at regular intervals. If a timeout has elapsed, the handler is called. Timeouts are checked in the order they are added.
- Reset timeouts as needed with the core_timeout_reset() function.
module and ref
The module and ref members of the core_timeout_t struct can be used to define timeouts that are automatically reset by other core library components. To reset these timeouts, the core_timeout_reset_by_module_ref() function is used. The module member is set to a register struct defined by the HAL (e.g. FDCAN1, SPI1, USART3, etc.). The meaning of ref depends on the selected module. Currently, the modules that support this feature are:
FDCAN1, FDCAN2, and FDCAN3: The timeout is reset when a frame with an ID equal to the value of ref is received
Timeouts with a module not in the above list will never be reset by the core library. Thus, the user can define timeouts where module is NULL or equal to a custom value and reset them using the core_timeout_reset_by_module_ref() function.
check
The 'check' member can be implemented to have the timeout library automatically check whether or not a timeout should be reset. The 'check' member should point to a function returning a bool value, true if the timeout should be reset, false if not. This is checked inside the core_timeout_check_all function.
latching
Set this member to 1 to not allow it to be reset by a normal reset function. A timeout with this parameter set can only be reset through the core_timeout_hard_reset function.
single_shot
Set this member to 1 to only have callback trigger once, the first time the timeout has hit its limit.