MeshX 0.3
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_timer.c
Go to the documentation of this file.
1
12
15#include "freertos/FreeRTOS.h"
16#include "freertos/timers.h"
17
26static void timer_callback(TimerHandle_t xTimer)
27{
29}
30
46meshx_err_t meshx_rtos_timer_create(meshx_rtos_timer_t *timer, const char * name, meshx_rtos_timer_callback_t cb, void *arg, uint32_t period_ms, bool reload)
47{
48 if (timer == NULL || cb == NULL) {
49 return MESHX_INVALID_ARG;
50 }
51
52 timer->timer_name = name;
53 timer->timer_cb = cb;
54 timer->timer_arg = arg;
55 timer->timer_period = pdMS_TO_TICKS(period_ms);
56 timer->auto_reload = reload;
57
58 timer->__timer_handle = xTimerCreate(
59 timer->timer_name,
60 timer->timer_period,
61 timer->auto_reload,
62 NULL,
64 );
65
66 if (timer->__timer_handle == NULL) {
67 return MESHX_NO_MEM;
68 }
69
70 return MESHX_SUCCESS;
71}
72
84{
85 if (timer == NULL || timer->__timer_handle == NULL) {
86 return MESHX_INVALID_ARG;
87 }
88
89 if (xTimerStart(timer->__timer_handle, 0) != pdPASS) {
90 return MESHX_FAIL;
91 }
92
93 return MESHX_SUCCESS;
94}
95
107{
108 if (timer == NULL || timer->__timer_handle == NULL) {
109 return MESHX_INVALID_ARG;
110 }
111
112 if (xTimerStop(timer->__timer_handle, 0) != pdPASS) {
113 return MESHX_FAIL;
114 }
115
116 return MESHX_SUCCESS;
117}
118
130{
131 if (timer == NULL || timer->__timer_handle == NULL) {
132 return MESHX_INVALID_ARG;
133 }
134
135 if (xTimerDelete(timer->__timer_handle, 0) != pdPASS) {
136 return MESHX_FAIL;
137 }
138
139 timer->__timer_handle = NULL;
140 return MESHX_SUCCESS;
141}
142
155{
156 if (timer == NULL || timer->__timer_handle == NULL) {
157 return MESHX_INVALID_ARG;
158 }
159
160 if (xTimerChangePeriod(timer->__timer_handle, pdMS_TO_TICKS(new_period_ms), 0) != pdPASS) {
161 return MESHX_FAIL;
162 }
163
164 timer->timer_period = new_period_ms;
165 return MESHX_SUCCESS;
166}
167
179{
180 if (timer == NULL || timer->__timer_handle == NULL) {
181 return MESHX_INVALID_ARG;
182 }
183
184 if (xTimerReset(timer->__timer_handle, 0) != pdPASS) {
185 return MESHX_FAIL;
186 }
187
188 return MESHX_SUCCESS;
189}
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:39
@ MESHX_SUCCESS
Definition meshx_err.h:40
@ MESHX_INVALID_ARG
Definition meshx_err.h:42
@ MESHX_FAIL
Definition meshx_err.h:41
@ MESHX_NO_MEM
Definition meshx_err.h:44
Logging interface for MeshX with color-coded output.
Header file for MeshX RTOS Timer interface. Provides APIs for creating, starting, stopping,...
struct meshx_rtos_timer meshx_rtos_timer_t
void(* meshx_rtos_timer_callback_t)(void *)
void meshx_os_timer_fire_cb(const void *timer_handle)
meshx_err_t meshx_rtos_timer_stop(meshx_rtos_timer_t *timer)
Stops the RTOS timer.
static void timer_callback(TimerHandle_t xTimer)
Callback function for FreeRTOS timer events.
Definition meshx_timer.c:26
meshx_err_t meshx_rtos_timer_start(meshx_rtos_timer_t *timer)
Starts the RTOS timer.
Definition meshx_timer.c:83
meshx_err_t meshx_rtos_timer_delete(meshx_rtos_timer_t *timer)
Deletes the RTOS timer.
meshx_err_t meshx_rtos_timer_change_period(meshx_rtos_timer_t *timer, uint32_t new_period_ms)
Changes the period of the RTOS timer.
meshx_err_t meshx_rtos_timer_reset(meshx_rtos_timer_t *timer)
Resets the RTOS timer.
meshx_err_t meshx_rtos_timer_create(meshx_rtos_timer_t *timer, const char *name, meshx_rtos_timer_callback_t cb, void *arg, uint32_t period_ms, bool reload)
Creates a new RTOS timer.
Definition meshx_timer.c:46
meshx_rtos_timer_callback_t timer_cb
const char * timer_name