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_rtos_timer.h
Go to the documentation of this file.
1/**
2 * Copyright (c) 2024 - 2025 MeshX
3 *
4 * @file meshx_rtos_timer.h
5 * @brief Header file for MeshX RTOS Timer interface.
6 * Provides APIs for creating, starting, stopping, deleting,
7 * and managing RTOS timers in the MeshX framework.
8 *
9 * This module abstracts the RTOS timer functionalities and provides
10 * a unified interface for timer management, including support for
11 * auto-reload timers, callback functions, and dynamic period changes.
12 *
13 * @author Pranjal Chanda
14 *
15 */
16
17#ifndef __MESHX_RTOS_TIMER_H
18#define __MESHX_RTOS_TIMER_H
19
20#include <stdint.h>
21#include <stdbool.h>
22#include "meshx_err.h"
23
24typedef void (*meshx_rtos_timer_callback_t)(void *);
25
26typedef struct meshx_rtos_timer
27{
28 /* Public */
29 void *timer_arg;
31 uint32_t timer_period;
32 const char *timer_name;
34 /* Private */
37
38/**
39 * @brief Creates a new RTOS timer.
40 *
41 * This function initializes and creates a new RTOS timer with the specified parameters.
42 *
43 * @param[out] timer Pointer to the meshx_rtos_timer_t structure to be initialized.
44 * @param[in] name Timer Name String
45 * @param[in] cb Callback function to be invoked when the timer expires.
46 * @param[in] arg Argument to be passed to the callback function.
47 * @param[in] period_ms Timer period in milliseconds.
48 * @param[in] reload Flag set if timer is a auto reload type.
49 *
50 * @return meshx_err_t Returns MESHX_SUCCESS if the timer was created successfully,
51 * or an error code if the creation failed.
52 */
53meshx_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);
54/**
55 * @brief Starts the RTOS timer.
56 *
57 * This function starts the RTOS timer.
58 *
59 * @param[in] timer Pointer to the meshx_rtos_timer_t structure.
60 *
61 * @return meshx_err_t Returns MESHX_SUCCESS if the timer was started successfully,
62 * or an error code if the start operation failed.
63 */
65
66/**
67 * @brief Stops the RTOS timer.
68 *
69 * This function stops the RTOS timer.
70 *
71 * @param[in] timer Pointer to the meshx_rtos_timer_t structure.
72 *
73 * @return meshx_err_t Returns MESHX_SUCCESS if the timer was stopped successfully,
74 * or an error code if the stop operation failed.
75 */
77
78/**
79 * @brief Deletes the RTOS timer.
80 *
81 * This function deletes the RTOS timer and frees associated resources.
82 *
83 * @param[in] timer Pointer to the meshx_rtos_timer_t structure.
84 *
85 * @return meshx_err_t Returns MESHX_SUCCESS if the timer was deleted successfully,
86 * or an error code if the delete operation failed.
87 */
89
90/**
91 * @brief Changes the period of the RTOS timer.
92 *
93 * This function changes the period of an active or dormant RTOS timer.
94 *
95 * @param[in] timer Pointer to the meshx_rtos_timer_t structure.
96 * @param[in] new_period_ms New timer period in milliseconds.
97 *
98 * @return meshx_err_t Returns MESHX_SUCCESS if the timer period was changed successfully,
99 * or an error code if the change operation failed.
100 */
102
103/**
104 * @brief Resets the RTOS timer.
105 *
106 * This function resets the RTOS timer, causing it to restart from its beginning.
107 *
108 * @param[in] timer Pointer to the meshx_rtos_timer_t structure.
109 *
110 * @return meshx_err_t Returns MESHX_SUCCESS if the timer was reset successfully,
111 * or an error code if the reset operation failed.
112 */
114
115/*
116 * @brief Callback function for the OS timer to control task.
117 * @note This function is called internally not to be called by user.
118 *
119 * This function is called whenever a OS timer timeout occurs.
120 *
121 * @param timer_handle Timer haandle callback param
122 */
123void meshx_os_timer_fire_cb(const void* timer_handle);
124
125#endif /* __MESHX_RTOS_TIMER_H */
MeshX Error Codes.
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43
meshx_err_t meshx_rtos_timer_stop(meshx_rtos_timer_t *timer)
Stops the RTOS timer.
struct meshx_rtos_timer meshx_rtos_timer_t
meshx_err_t meshx_rtos_timer_start(meshx_rtos_timer_t *timer)
Starts the RTOS timer.
meshx_err_t meshx_rtos_timer_delete(meshx_rtos_timer_t *timer)
Deletes the RTOS timer.
void(* meshx_rtos_timer_callback_t)(void *)
Definition meshx_rtos_timer.h:24
void meshx_os_timer_fire_cb(const void *timer_handle)
Definition meshx_os_timer.c:149
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_rtos_timer.h:27
uint32_t timer_period
Definition meshx_rtos_timer.h:31
meshx_rtos_timer_callback_t timer_cb
Definition meshx_rtos_timer.h:33
const char * timer_name
Definition meshx_rtos_timer.h:32
bool auto_reload
Definition meshx_rtos_timer.h:30
void * __timer_handle
Definition meshx_rtos_timer.h:35
void * timer_arg
Definition meshx_rtos_timer.h:29