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_utils.h
Go to the documentation of this file.
1/**
2 * @file meshx_rtos_utils.h
3 * @brief Utility functions for RTOS operations in the MeshX framework.
4 *
5 * This header file provides a set of utility functions for interacting with
6 * the RTOS in the MeshX framework. These utilities include functions for
7 * retrieving system time, memory allocation and deallocation, and querying
8 * the amount of free heap memory.
9 *
10 * The functions in this file are designed to simplify common RTOS operations
11 * and ensure consistent error handling across the MeshX framework.
12 *
13 * @author Pranjal Chanda
14 */
15
16#ifndef __MESHX_RTOS_UTILS_H__
17#define __MESHX_RTOS_UTILS_H__
18
19#include "meshx_err.h"
20#include "stddef.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26/**
27 * @brief Retrieves the current system time in milliseconds.
28 *
29 * This function calculates the system time in milliseconds based on the
30 * FreeRTOS tick count and the configured tick rate. The result is stored
31 * in the variable pointed to by the `millis` parameter.
32 *
33 * @param[out] millis Pointer to an unsigned integer where the system time
34 * in milliseconds will be stored.
35 *
36 * @return
37 * - MESHX_SUCCESS: If the system time was successfully retrieved.
38 *
39 * @note Ensure that the `millis` pointer is valid and not NULL before
40 * calling this function.
41 */
43
44/**
45 * @brief Allocates memory dynamically in a thread-safe manner using FreeRTOS.
46 *
47 * This function wraps the memory allocation process to ensure compatibility
48 * with the FreeRTOS environment. It allocates a block of memory of the specified
49 * size and assigns the pointer to the provided pointer variable.
50 *
51 * @param[out] ptr Pointer to the memory location where the allocated memory address
52 * will be stored. Must not be NULL.
53 * @param[in] size The size of the memory block to allocate, in bytes.
54 *
55 * @return
56 * - MESHX_SUCCESS on successful memory allocation.
57 * - MESHX_ERR_NO_MEM if memory allocation fails.
58 * - Other error codes as defined in the meshx_err_t enumeration.
59 */
60meshx_err_t meshx_rtos_malloc(void** ptr, size_t size);
61
62/**
63 * @brief Allocates memory for an array of elements and initializes it to zero.
64 *
65 * This function allocates memory for an array of `num` elements, each of size `size`,
66 * and initializes all bytes in the allocated memory to zero. The allocated memory
67 * pointer is returned via the `ptr` parameter.
68 *
69 * @param[out] ptr Pointer to the allocated memory. This will be set to NULL if the allocation fails.
70 * @param[in] num Number of elements to allocate.
71 * @param[in] size Size of each element in bytes.
72 *
73 * @return
74 * - MESHX_SUCCESS: Memory allocation was successful.
75 * - MESHX_ERR_NO_MEM: Memory allocation failed due to insufficient memory.
76 */
77meshx_err_t meshx_rtos_calloc(void **ptr, size_t num, size_t size);
78
79/**
80 * @brief Frees memory allocated to a pointer and sets it to NULL.
81 *
82 * This function is used to safely deallocate memory that was previously
83 * allocated and ensures that the pointer is set to NULL to avoid dangling
84 * pointer issues.
85 *
86 * @param[in,out] ptr A double pointer to the memory to be freed. After the
87 * memory is freed, the pointer is set to NULL.
88 *
89 * @return
90 * - MESHX_SUCCESS on successful deallocation.
91 * - MESHX_ERR_INVALID_ARG if the provided pointer is NULL or invalid.
92 * - Other error codes depending on the implementation.
93 */
95
96/**
97 * @brief Retrieves the amount of free heap memory available in the system.
98 *
99 * This function is used to query the current amount of free heap memory
100 * available in the system. It is useful for monitoring memory usage and
101 * ensuring that the system has sufficient resources for dynamic memory
102 * allocation.
103 *
104 * @return size_t The amount of free heap memory in bytes.
105 */
107
108/**
109 * @brief Retrieves the current task ID.
110 *
111 * This function retrieves the current task ID using FreeRTOS APIs.
112 * The task ID is stored in the variable pointed to by the `task_id` parameter.
113 *
114 * @param[out] task_id Pointer to an unsigned integer where the task ID will be stored.
115 *
116 * @return
117 * - MESHX_SUCCESS: If the task ID was successfully retrieved.
118 * - MESHX_ERR_INVALID_ARG: If the provided pointer is NULL or invalid.
119 *
120 * @note Ensure that the `task_id` pointer is valid and not NULL before
121 * calling this function.
122 */
124
125#ifdef __cplusplus
126}
127#endif
128
129#endif /* __MESHX_RTOS_UTILS_H__ */
130
MeshX Error Codes.
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43
meshx_err_t meshx_rtos_get_sys_time(unsigned int *millis)
Retrieves the current system time in milliseconds.
meshx_err_t meshx_rtos_get_curr_task_id_prio(unsigned int *task_id)
Retrieves the current task ID.
meshx_err_t meshx_rtos_calloc(void **ptr, size_t num, size_t size)
Allocates memory for an array of elements and initializes it to zero.
meshx_err_t meshx_rtos_free(void **ptr)
Frees memory allocated to a pointer and sets it to NULL.
meshx_err_t meshx_rtos_malloc(void **ptr, size_t size)
Allocates memory dynamically in a thread-safe manner using FreeRTOS.
size_t meshx_rtos_get_free_heap(void)
Retrieves the amount of free heap memory available in the system.