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.
|
Utility functions for integrating MeshX with FreeRTOS. This file provides implementations for memory management, system time retrieval, and heap monitoring using FreeRTOS APIs. More...
#include "interface/rtos/meshx_rtos_utils.h"
#include "interface/logging/meshx_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/portmacro.h"
#include <string.h>
Go to the source code of this file.
Functions | |
meshx_err_t | meshx_rtos_get_sys_time (unsigned int *millis) |
Retrieves the current system time in milliseconds. | |
meshx_err_t | meshx_rtos_malloc (void **ptr, size_t size) |
Allocates memory dynamically in a thread-safe manner using FreeRTOS. | |
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. | |
size_t | meshx_rtos_get_free_heap (void) |
Retrieves the amount of free heap memory available in the system. | |
meshx_err_t | meshx_rtos_get_curr_task_id_prio (unsigned int *task_id) |
Retrieves the current task ID. | |
Utility functions for integrating MeshX with FreeRTOS. This file provides implementations for memory management, system time retrieval, and heap monitoring using FreeRTOS APIs.
Copyright (c) 2024 - 2025 MeshX
Definition in file meshx_utils.c.
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.
This function allocates memory for an array of num
elements, each of size size
, and initializes all bytes in the allocated memory to zero. The allocated memory pointer is returned via the ptr
parameter.
[out] | ptr | Pointer to the allocated memory. This will be set to NULL if the allocation fails. |
[in] | num | Number of elements to allocate. |
[in] | size | Size of each element in bytes. |
Definition at line 96 of file meshx_utils.c.
meshx_err_t meshx_rtos_free | ( | void ** | ptr | ) |
Frees memory allocated to a pointer and sets it to NULL.
This function is used to safely deallocate memory that was previously allocated and ensures that the pointer is set to NULL to avoid dangling pointer issues.
[in,out] | ptr | A double pointer to the memory to be freed. After the memory is freed, the pointer is set to NULL. |
Definition at line 129 of file meshx_utils.c.
meshx_err_t meshx_rtos_get_curr_task_id_prio | ( | unsigned int * | task_id | ) |
Retrieves the current task ID.
This function retrieves the current task ID using FreeRTOS APIs. The task ID is stored in the variable pointed to by the task_id
parameter.
[out] | task_id | Pointer to an unsigned integer where the task ID will be stored. |
task_id
pointer is valid and not NULL before calling this function. Definition at line 170 of file meshx_utils.c.
size_t meshx_rtos_get_free_heap | ( | void | ) |
Retrieves the amount of free heap memory available in the system.
This function is used to query the current amount of free heap memory available in the system. It is useful for monitoring memory usage and ensuring that the system has sufficient resources for dynamic memory allocation.
Definition at line 150 of file meshx_utils.c.
meshx_err_t meshx_rtos_get_sys_time | ( | unsigned int * | millis | ) |
Retrieves the current system time in milliseconds.
This function calculates the system time in milliseconds based on the FreeRTOS tick count and the configured tick rate. The result is stored in the variable pointed to by the millis
parameter.
[out] | millis | Pointer to an unsigned integer where the system time in milliseconds will be stored. |
millis
pointer is valid and not NULL before calling this function. Definition at line 36 of file meshx_utils.c.
meshx_err_t meshx_rtos_malloc | ( | void ** | ptr, |
size_t | size ) |
Allocates memory dynamically in a thread-safe manner using FreeRTOS.
This function wraps the memory allocation process to ensure compatibility with the FreeRTOS environment. It allocates a block of memory of the specified size and assigns the pointer to the provided pointer variable.
[out] | ptr | Pointer to the memory location where the allocated memory address will be stored. Must not be NULL. |
[in] | size | The size of the memory block to allocate, in bytes. |
Definition at line 65 of file meshx_utils.c.