2022-07-20 10:56:33 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "core/base.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef void (*FuriTimerCallback)(void* context);
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
FuriTimerTypeOnce = 0, ///< One-shot timer.
|
|
|
|
FuriTimerTypePeriodic = 1 ///< Repeating timer.
|
|
|
|
} FuriTimerType;
|
|
|
|
|
|
|
|
typedef void FuriTimer;
|
|
|
|
|
|
|
|
/** Allocate timer
|
|
|
|
*
|
|
|
|
* @param[in] func The callback function
|
|
|
|
* @param[in] type The timer type
|
|
|
|
* @param context The callback context
|
|
|
|
*
|
|
|
|
* @return The pointer to FuriTimer instance
|
|
|
|
*/
|
|
|
|
FuriTimer* furi_timer_alloc(FuriTimerCallback func, FuriTimerType type, void* context);
|
|
|
|
|
|
|
|
/** Free timer
|
|
|
|
*
|
|
|
|
* @param instance The pointer to FuriTimer instance
|
|
|
|
*/
|
|
|
|
void furi_timer_free(FuriTimer* instance);
|
|
|
|
|
|
|
|
/** Start timer
|
2023-11-15 16:11:05 +00:00
|
|
|
*
|
|
|
|
* @warning This is asynchronous call, real operation will happen as soon as
|
|
|
|
* timer service process this request.
|
2022-07-20 10:56:33 +00:00
|
|
|
*
|
|
|
|
* @param instance The pointer to FuriTimer instance
|
2023-11-01 15:23:02 +00:00
|
|
|
* @param[in] ticks The interval in ticks
|
2022-07-20 10:56:33 +00:00
|
|
|
*
|
|
|
|
* @return The furi status.
|
|
|
|
*/
|
|
|
|
FuriStatus furi_timer_start(FuriTimer* instance, uint32_t ticks);
|
|
|
|
|
2023-11-01 07:24:11 +00:00
|
|
|
/** Restart timer with previous timeout value
|
2023-11-15 16:11:05 +00:00
|
|
|
*
|
|
|
|
* @warning This is asynchronous call, real operation will happen as soon as
|
|
|
|
* timer service process this request.
|
2023-11-01 07:24:11 +00:00
|
|
|
*
|
|
|
|
* @param instance The pointer to FuriTimer instance
|
2023-11-01 15:23:02 +00:00
|
|
|
* @param[in] ticks The interval in ticks
|
2023-11-01 07:24:11 +00:00
|
|
|
*
|
|
|
|
* @return The furi status.
|
|
|
|
*/
|
2023-11-01 15:23:02 +00:00
|
|
|
FuriStatus furi_timer_restart(FuriTimer* instance, uint32_t ticks);
|
2023-11-01 07:24:11 +00:00
|
|
|
|
2022-07-20 10:56:33 +00:00
|
|
|
/** Stop timer
|
2023-11-15 16:11:05 +00:00
|
|
|
*
|
|
|
|
* @warning This is asynchronous call, real operation will happen as soon as
|
|
|
|
* timer service process this request.
|
2022-07-20 10:56:33 +00:00
|
|
|
*
|
|
|
|
* @param instance The pointer to FuriTimer instance
|
|
|
|
*
|
|
|
|
* @return The furi status.
|
|
|
|
*/
|
|
|
|
FuriStatus furi_timer_stop(FuriTimer* instance);
|
|
|
|
|
|
|
|
/** Is timer running
|
2023-11-15 16:11:05 +00:00
|
|
|
*
|
|
|
|
* @warning This cal may and will return obsolete timer state if timer
|
|
|
|
* commands are still in the queue. Please read FreeRTOS timer
|
|
|
|
* documentation first.
|
2022-07-20 10:56:33 +00:00
|
|
|
*
|
|
|
|
* @param instance The pointer to FuriTimer instance
|
|
|
|
*
|
|
|
|
* @return 0: not running, 1: running
|
|
|
|
*/
|
|
|
|
uint32_t furi_timer_is_running(FuriTimer* instance);
|
|
|
|
|
2023-11-01 07:24:11 +00:00
|
|
|
/** Get timer expire time
|
|
|
|
*
|
|
|
|
* @param instance The Timer instance
|
|
|
|
*
|
|
|
|
* @return expire tick
|
|
|
|
*/
|
|
|
|
uint32_t furi_timer_get_expire_time(FuriTimer* instance);
|
|
|
|
|
2023-05-05 12:40:55 +00:00
|
|
|
typedef void (*FuriTimerPendigCallback)(void* context, uint32_t arg);
|
|
|
|
|
|
|
|
void furi_timer_pending_callback(FuriTimerPendigCallback callback, void* context, uint32_t arg);
|
|
|
|
|
2023-11-01 07:24:11 +00:00
|
|
|
typedef enum {
|
|
|
|
FuriTimerThreadPriorityNormal, /**< Lower then other threads */
|
|
|
|
FuriTimerThreadPriorityElevated, /**< Same as other threads */
|
|
|
|
} FuriTimerThreadPriority;
|
|
|
|
|
|
|
|
/** Set Timer thread priority
|
|
|
|
*
|
|
|
|
* @param[in] priority The priority
|
|
|
|
*/
|
|
|
|
void furi_timer_set_thread_priority(FuriTimerThreadPriority priority);
|
|
|
|
|
2022-07-20 10:56:33 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|