MeshX 0.4
This repository provides an implementation for Bluetooth Low Energy (BLE) Mesh network nodes. The project allows you to create BLE mesh nodes that can communicate with each other, enabling the development of smart home solutions or other IoT-based applications.
Loading...
Searching...
No Matches
meshx_os_timer.h
Go to the documentation of this file.
1/**
2 * Copyright © 2024 - 2025 MeshX
3 *
4 * @file meshx_os_timer.h
5 * @brief Header file for OS timer utilities.
6 *
7 * This file contains the definitions and includes necessary for
8 * working with OS timers in the ESP32 BLE mesh node application.
9 *
10 * @author Pranjal Chanda
11 */
12
13#ifndef __OS_TIMER_H__
14#define __OS_TIMER_H__
15
16#include <stdint.h>
17#include "sys/queue.h"
18#include "meshx_control_task.h"
20
21/**
22 * @brief return meshx_os_timer_t size
23 */
24#define OS_TIMER_SIZE sizeof(meshx_os_timer_t)
25
26/**
27 * @brief return timer registered name pointer
28 */
29#define OS_TMER_GET_TIMER_NAME(timer) (timer->timer_handle.timer_name)
30
31/**
32 * @typedef meshx_os_timer_handle_t
33 * @brief Alias for the meshx_rtos_timer_t type.
34 *
35 * This typedef provides a more convenient name for the FreeRTOS
36 * timer handle type, used for creating and managing timers.
37 */
39
40/**
41 * @typedef meshx_os_timer_t
42 * @brief Alias for the meshx_os_timer structure.
43 *
44 * This typedef provides a more convenient name for the meshx_os_timer
45 * structure, which holds the parameters for the OS timer control task message.
46 */
48/**
49 * @brief Timer callback function prototype.
50 *
51 * This function is called when the timer expires.
52 *
53 * @param[in] p_timer The timer handle.
54 */
55typedef void (*meshx_os_timer_cb_t)(const meshx_os_timer_t* p_timer);
56
57/**
58 * @brief Structure to hold parameters for the OS timer control task message.
59 *
60 * This structure contains the parameters required to configure and control
61 * an OS timer. It includes options for setting the timer to reload, specifying
62 * the timer period, providing a name for the timer, and assigning a callback
63 * function to be executed when the timer expires.
64 */
73
74/**
75 * @brief Initialize the OS timer module.
76 *
77 * This function initializes the OS timer module.
78 *
79 * @return MESHX_SUCCESS on success, or an error code on failure.
80 */
82
83/**
84 * @brief Create a timer.
85 *
86 * This function creates a timer with the given period and callback function.
87 *
88 * @param[in] name The name of the timer.
89 * @param[in] period The period of the timer in milliseconds.
90 * @param[in] reload If true, the timer will automatically reload after expiring.
91 * @param[in] cb The callback function to be called when the timer expires.
92 * @param[inout] timer_handle The timer handle.
93 *
94 * Example:
95 * ```c
96 * meshx_os_timer_t * meshx_os_timer_inst;
97 * meshx_err_t err = meshx_os_timer_create("Example_Timer", 1000, 1, &example_os_timer_cb, &os_timer_inst);
98 * ```
99 * @return MESHX_SUCCESS on success, or an error code on failure.
100 */
101meshx_err_t meshx_os_timer_create(const char *name, uint32_t period, bool reload, meshx_os_timer_cb_t cb, meshx_os_timer_t **timer_handle);
102
103/**
104 * @brief Start a timer.
105 *
106 * This function starts the given timer.
107 *
108 * @param timer_handle The timer handle.
109 *
110 * @return MESHX_SUCCESS on success, or an error code on failure.
111 */
113
114/**
115 * @brief Restart a timer.
116 *
117 * This function re-starts the given timer.
118 *
119 * @param timer_handle The timer handle.
120 *
121 * @return MESHX_SUCCESS on success, or an error code on failure.
122 */
124
125/**
126 * @brief Set period on an initialised timer.
127 *
128 * This function reset period of initialised timer.
129 *
130 * @param timer_handle The timer handle.
131 * @param period_ms New period in ms
132 *
133 * @return MESHX_SUCCESS on success, or an error code on failure.
134 */
135meshx_err_t meshx_os_timer_set_period(meshx_os_timer_t *timer_handle, const uint32_t period_ms);
136
137/**
138 * @brief Stop a timer.
139 *
140 * This function stops the given timer.
141 *
142 * @param timer_handle The timer handle.
143 *
144 * @return MESHX_SUCCESS on success, or an error code on failure.
145 */
147
148/**
149 * @brief Delete a timer.
150 *
151 * This function deletes the given timer.
152 *
153 * @param timer_handle The timer handle.
154 *
155 * @return MESHX_SUCCESS on success, or an error code on failure.
156 */
158
159#endif /* __OS_TIMER_H__ */
Header file for the control task in the BLE mesh node application.
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43
meshx_err_t meshx_os_timer_start(const meshx_os_timer_t *timer_handle)
Start a timer.
Definition meshx_os_timer.c:315
struct meshx_os_timer meshx_os_timer_t
Alias for the meshx_os_timer structure.
Definition meshx_os_timer.h:47
meshx_err_t meshx_os_timer_init(void)
Initialize the OS timer module.
Definition meshx_os_timer.c:227
void(* meshx_os_timer_cb_t)(const meshx_os_timer_t *p_timer)
Timer callback function prototype.
Definition meshx_os_timer.h:55
meshx_err_t meshx_os_timer_create(const char *name, uint32_t period, bool reload, meshx_os_timer_cb_t cb, meshx_os_timer_t **timer_handle)
Create a timer.
Definition meshx_os_timer.c:264
meshx_err_t meshx_os_timer_restart(const meshx_os_timer_t *timer_handle)
Restart a timer.
Definition meshx_os_timer.c:340
meshx_err_t meshx_os_timer_set_period(meshx_os_timer_t *timer_handle, const uint32_t period_ms)
Set period on an initialised timer.
Definition meshx_os_timer.c:366
meshx_err_t meshx_os_timer_stop(const meshx_os_timer_t *timer_handle)
Stop a timer.
Definition meshx_os_timer.c:393
meshx_rtos_timer_t meshx_os_timer_handle_t
Alias for the meshx_rtos_timer_t type.
Definition meshx_os_timer.h:38
meshx_err_t meshx_os_timer_delete(meshx_os_timer_t **timer_handle)
Delete a timer.
Definition meshx_os_timer.c:419
Header file for MeshX RTOS Timer interface. Provides APIs for creating, starting, stopping,...
struct meshx_rtos_timer meshx_rtos_timer_t
Structure to hold parameters for the OS timer control task message.
Definition meshx_os_timer.h:66
meshx_os_timer_cb_t cb
Definition meshx_os_timer.h:69
meshx_os_timer_handle_t timer_handle
Definition meshx_os_timer.h:70
SLIST_ENTRY(meshx_os_timer) next
uint16_t init
Definition meshx_os_timer.h:67
uint32_t period
Definition meshx_os_timer.h:68