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 File Reference

Implementation of RTOS timer abstraction for MeshX using FreeRTOS. This file provides functions to create, start, stop, delete, reset, and modify RTOS timers in the MeshX framework. More...

#include "interface/rtos/meshx_rtos_timer.h"
#include "interface/logging/meshx_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/timers.h"
Include dependency graph for meshx_timer.c:

Go to the source code of this file.

Functions

static void timer_callback (TimerHandle_t xTimer)
 Callback function for FreeRTOS timer events.
 
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.
 
meshx_err_t meshx_rtos_timer_start (meshx_rtos_timer_t *timer)
 Starts the RTOS timer.
 
meshx_err_t meshx_rtos_timer_stop (meshx_rtos_timer_t *timer)
 Stops the RTOS timer.
 
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.
 

Detailed Description

Implementation of RTOS timer abstraction for MeshX using FreeRTOS. This file provides functions to create, start, stop, delete, reset, and modify RTOS timers in the MeshX framework.

Copyright (c) 2024 - 2025 MeshX

Author
Pranjal Chanda

Definition in file meshx_timer.c.

Function Documentation

◆ meshx_rtos_timer_change_period()

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.

This function changes the period of an active or dormant RTOS timer.

Parameters
[in]timerPointer to the meshx_rtos_timer_t structure.
[in]new_period_msNew timer period in milliseconds.
Returns
meshx_err_t Returns MESHX_SUCCESS if the timer period was changed successfully, or an error code if the change operation failed.

Definition at line 154 of file meshx_timer.c.

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}
@ MESHX_SUCCESS
Definition meshx_err.h:40
@ MESHX_INVALID_ARG
Definition meshx_err.h:42
@ MESHX_FAIL
Definition meshx_err.h:41
Here is the caller graph for this function:

◆ meshx_rtos_timer_create()

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.

This function initializes and creates a new RTOS timer with the specified parameters.

Parameters
[out]timerPointer to the meshx_rtos_timer_t structure to be initialized.
[in]nameTimer Name String
[in]cbCallback function to be invoked when the timer expires.
[in]argArgument to be passed to the callback function.
[in]period_msTimer period in milliseconds.
[in]reloadFlag set if timer is a auto reload type.
Returns
meshx_err_t Returns MESHX_SUCCESS if the timer was created successfully, or an error code if the creation failed.

Definition at line 46 of file meshx_timer.c.

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}
@ MESHX_NO_MEM
Definition meshx_err.h:44
static void timer_callback(TimerHandle_t xTimer)
Callback function for FreeRTOS timer events.
Definition meshx_timer.c:26
meshx_rtos_timer_callback_t timer_cb
const char * timer_name
Here is the call graph for this function:
Here is the caller graph for this function:

◆ meshx_rtos_timer_delete()

meshx_err_t meshx_rtos_timer_delete ( meshx_rtos_timer_t * timer)

Deletes the RTOS timer.

This function deletes the RTOS timer and frees associated resources.

Parameters
[in]timerPointer to the meshx_rtos_timer_t structure.
Returns
meshx_err_t Returns MESHX_SUCCESS if the timer was deleted successfully, or an error code if the delete operation failed.

Definition at line 129 of file meshx_timer.c.

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}
Here is the caller graph for this function:

◆ meshx_rtos_timer_reset()

meshx_err_t meshx_rtos_timer_reset ( meshx_rtos_timer_t * timer)

Resets the RTOS timer.

This function resets the RTOS timer, causing it to restart from its beginning.

Parameters
[in]timerPointer to the meshx_rtos_timer_t structure.
Returns
meshx_err_t Returns MESHX_SUCCESS if the timer was reset successfully, or an error code if the reset operation failed.

Definition at line 178 of file meshx_timer.c.

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}
Here is the caller graph for this function:

◆ meshx_rtos_timer_start()

meshx_err_t meshx_rtos_timer_start ( meshx_rtos_timer_t * timer)

Starts the RTOS timer.

This function starts the RTOS timer.

Parameters
[in]timerPointer to the meshx_rtos_timer_t structure.
Returns
meshx_err_t Returns MESHX_SUCCESS if the timer was started successfully, or an error code if the start operation failed.

Definition at line 83 of file meshx_timer.c.

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}
Here is the caller graph for this function:

◆ meshx_rtos_timer_stop()

meshx_err_t meshx_rtos_timer_stop ( meshx_rtos_timer_t * timer)

Stops the RTOS timer.

This function stops the RTOS timer.

Parameters
[in]timerPointer to the meshx_rtos_timer_t structure.
Returns
meshx_err_t Returns MESHX_SUCCESS if the timer was stopped successfully, or an error code if the stop operation failed.

Definition at line 106 of file meshx_timer.c.

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}
Here is the caller graph for this function:

◆ timer_callback()

static void timer_callback ( TimerHandle_t xTimer)
static

Callback function for FreeRTOS timer events.

This function is triggered when the associated FreeRTOS timer expires. It invokes the meshx_os_timer_fire_cb function to handle the timer event.

Parameters
xTimerHandle to the FreeRTOS timer that triggered the callback.

Definition at line 26 of file meshx_timer.c.

27{
29}
void meshx_os_timer_fire_cb(const void *timer_handle)
Here is the call graph for this function:
Here is the caller graph for this function: