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_sem.c File Reference

Implementation of MeshX Semaphore APIs using FreeRTOS. This file provides functions to create, delete, take, and give semaphores for synchronization in the MeshX framework. More...

#include "interface/rtos/meshx_sem.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "esp_system.h"
Include dependency graph for meshx_sem.c:

Go to the source code of this file.

Functions

meshx_err_t meshx_sem_create (meshx_sem_t *sem_handle)
 Create a MeshX Semaphore.
 
meshx_err_t meshx_sem_delete (meshx_sem_t *sem_handle)
 Delete a MeshX Semaphore.
 
meshx_err_t meshx_sem_take (meshx_sem_t *sem_handle, uint32_t delay_ms)
 Take a MeshX Semaphore.
 
meshx_err_t meshx_sem_give (meshx_sem_t *sem_handle)
 Give a MeshX Semaphore.
 

Detailed Description

Implementation of MeshX Semaphore APIs using FreeRTOS. This file provides functions to create, delete, take, and give semaphores for synchronization in the MeshX framework.

Copyright (c) 2024 - 2025 MeshX

Author
Pranjal Chanda

Definition in file meshx_sem.c.

Function Documentation

◆ meshx_sem_create()

meshx_err_t meshx_sem_create ( meshx_sem_t * sem_handle)

Create a MeshX Semaphore.

This function creates a MeshX Semaphore.

Parameters
[in,out]sem_handleSemaphore Handle
Returns
meshx_err_t

Definition at line 27 of file meshx_sem.c.

28{
29 if (sem_handle == NULL)
30 {
31 return MESHX_INVALID_ARG;
32 }
33
34 sem_handle->__sem_handle = xSemaphoreCreateCounting(sem_handle->max_count, sem_handle->init_count);
35
36 if (sem_handle->__sem_handle == NULL)
37 {
38 return MESHX_FAIL;
39 }
40
41 return MESHX_SUCCESS;
42}
@ MESHX_SUCCESS
Definition meshx_err.h:40
@ MESHX_INVALID_ARG
Definition meshx_err.h:42
@ MESHX_FAIL
Definition meshx_err.h:41
int init_count
Definition meshx_sem.h:25
void * __sem_handle
Definition meshx_sem.h:27
int max_count
Definition meshx_sem.h:24

◆ meshx_sem_delete()

meshx_err_t meshx_sem_delete ( meshx_sem_t * sem_handle)

Delete a MeshX Semaphore.

This function deletes a MeshX Semaphore.

Parameters
[in]sem_handleSemaphore Handle
Returns
meshx_err_t

Definition at line 52 of file meshx_sem.c.

53{
54 if (sem_handle == NULL)
55 {
56 return MESHX_INVALID_ARG;
57 }
58
59 vSemaphoreDelete(sem_handle->__sem_handle);
60
61 return MESHX_SUCCESS;
62}

◆ meshx_sem_give()

meshx_err_t meshx_sem_give ( meshx_sem_t * sem_handle)

Give a MeshX Semaphore.

This function gives a MeshX Semaphore.

Parameters
[in]sem_handleSemaphore Handle
Returns
meshx_err_t

Definition at line 99 of file meshx_sem.c.

100{
101 if (sem_handle == NULL)
102 {
103 return MESHX_INVALID_ARG;
104 }
105
106 if (xSemaphoreGive(sem_handle->__sem_handle) != pdTRUE)
107 {
108 return MESHX_FAIL;
109 }
110
111 return MESHX_SUCCESS;
112}

◆ meshx_sem_take()

meshx_err_t meshx_sem_take ( meshx_sem_t * sem_handle,
uint32_t delay_ms )

Take a MeshX Semaphore.

This function takes a MeshX Semaphore.

Parameters
[in]sem_handleSemaphore Handle
[in]delay_msDelay in milliseconds
Returns
meshx_err_t

Definition at line 74 of file meshx_sem.c.

75{
76 if (sem_handle == NULL)
77 {
78 return MESHX_INVALID_ARG;
79 }
80
81 BaseType_t err = xPortInIsrContext() ? xSemaphoreTakeFromISR(sem_handle->__sem_handle, NULL) : xSemaphoreTake(sem_handle->__sem_handle, delay_ms);
82 if(err != pdPASS)
83 {
84 return MESHX_FAIL;
85 }
86
87 return MESHX_SUCCESS;
88}