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

MeshX Tx Control Module This file contains the implementation of the MeshX Tx Control Module, which is responsible for managing transmission control in the MeshX BLE Mesh stack. More...

#include "meshx.h"
#include "meshx_txcm.h"

Data Structures

struct  meshx_txcm_tx_q
 Structure for queued transmission items in the Tx Control module. More...
struct  meshx_tx_queue_t
 Structure for the transmission queue in the Tx Control module. More...

Macros

#define MESHX_TXCM_INIT_MAGIC   0x4455
 Magic value used to check if the Tx Control module has been initialized.
#define MESHX_TXCM_TASK_STACK_SIZE   4096
 Stack size for the Tx Control task in bytes.
#define MESHX_TXCM_TASK_PRIO   5
 Priority level for the Tx Control task.
#define MESHX_TXCM_SIG_Q_LEN   10
 Maximum number of signals in the Tx Control signal queue.
#define MESHX_TXCM_SIG_Q_DEPTH   sizeof(meshx_txcm_request_t)
 Depth (size) of each signal queue entry.

Typedefs

typedef meshx_err_t(* meshx_txcm_sig_proc_t) (meshx_txcm_request_t *request)
 Type definition for signal processing functions in the Tx Control module.
typedef struct meshx_txcm_tx_q meshx_txcm_tx_q_t
 Structure for queued transmission items in the Tx Control module.

Functions

static meshx_err_t meshx_tx_queue_is_full (const meshx_tx_queue_t *q)
 Checks if the transmission queue is full.
static meshx_err_t meshx_tx_queue_is_empty (const meshx_tx_queue_t *q)
 Checks if the transmission queue is empty.
static meshx_err_t meshx_tx_queue_enqueue (meshx_tx_queue_t *q, const meshx_txcm_tx_q_t *item)
 Adds an item to the transmission queue.
static meshx_err_t meshx_tx_queue_enqueue_front (meshx_tx_queue_t *q, const meshx_txcm_tx_q_t *item)
 Adds an item to the front of the transmission queue.
static void meshx_txcm_task_handler (const dev_struct_t *args)
 Handler function for the MeshX TXCM task.
static meshx_err_t meshx_txcm_sig_resend (meshx_txcm_request_t *request)
 Handles the resend signal for the Tx Control module.
static meshx_err_t meshx_txcm_sig_enq_send (meshx_txcm_request_t *request)
 Enqueues a send request to the Tx Control module.
static meshx_err_t meshx_txcm_sig_ack (const meshx_txcm_request_t *request)
 Handles the flush signal for the Tx Control module.
static meshx_err_t meshx_txcm_sig_direct_send (meshx_txcm_request_t *request)
 Enqueues a direct send request to the Tx Control module.
static meshx_err_t meshx_tx_queue_search (const meshx_tx_queue_t *q, const uint8_t *param, uint16_t param_len, uint16_t dest_addr)
 Searches for a parameter in the transmission queue.
static meshx_err_t meshx_tx_queue_dequeue_at (meshx_tx_queue_t *q, int16_t index, meshx_txcm_tx_q_t *item)
 Removes an item from the transmission queue.
static meshx_err_t meshx_txcm_msg_q_try_send (bool resend, uint16_t target_addr)
 Attempts to send messages from the transmission queue.
static meshx_err_t meshx_txcm_msg_q_front_try_send (bool resend)
static meshx_err_t meshx_txcm_proccess_request_msg (meshx_txcm_request_t *request, meshx_txcm_msg_type_t msg_type)
 Processes a request message for the Tx Control module.
meshx_err_t meshx_txcm_init (dev_struct_t *pdev)
 Initializes the MeshX Tx Control Module.
meshx_err_t meshx_txcm_request_send (meshx_txcm_sig_t request_type, uint16_t dest_addr, meshx_cptr_t msg_param, uint16_t msg_param_len, meshx_txcm_fn_model_send_t send_fn)
 Sends a request to the Tx Control module.
meshx_err_t meshx_txcm_event_cb_reg (meshx_txcm_cb_t event_cb)
 Registers a callback function for handling Tx Control module events.

Variables

struct { 
   uint16_t   init_magic 
   meshx_task_t   txcm_task 
   meshx_msg_q_t   txcm_sig_queue 
   meshx_tx_queue_t   txcm_tx_queue 
g_txcm
 Global structure for Tx Control module state and resources.
static meshx_txcm_sig_proc_t g_sig_proc_table [MESHX_TXCM_SIG_MAX]
 Signal processing function table for the Tx Control module.

Detailed Description

MeshX Tx Control Module This file contains the implementation of the MeshX Tx Control Module, which is responsible for managing transmission control in the MeshX BLE Mesh stack.

Author
Pranjal Chanda

Macro Definition Documentation

◆ MESHX_TXCM_INIT_MAGIC

#define MESHX_TXCM_INIT_MAGIC   0x4455

Magic value used to check if the Tx Control module has been initialized.

◆ MESHX_TXCM_SIG_Q_DEPTH

#define MESHX_TXCM_SIG_Q_DEPTH   sizeof(meshx_txcm_request_t)

Depth (size) of each signal queue entry.

◆ MESHX_TXCM_SIG_Q_LEN

#define MESHX_TXCM_SIG_Q_LEN   10

Maximum number of signals in the Tx Control signal queue.

◆ MESHX_TXCM_TASK_PRIO

#define MESHX_TXCM_TASK_PRIO   5

Priority level for the Tx Control task.

◆ MESHX_TXCM_TASK_STACK_SIZE

#define MESHX_TXCM_TASK_STACK_SIZE   4096

Stack size for the Tx Control task in bytes.

Typedef Documentation

◆ meshx_txcm_sig_proc_t

typedef meshx_err_t(* meshx_txcm_sig_proc_t) (meshx_txcm_request_t *request)

Type definition for signal processing functions in the Tx Control module.

A signal processing function takes a pointer to a transmission control request structure and processes the request accordingly.

◆ meshx_txcm_tx_q_t

Structure for queued transmission items in the Tx Control module.

This structure represents an item in the transmission queue, containing the send callback and message parameters ready for transmission.

Function Documentation

◆ meshx_tx_queue_dequeue_at()

meshx_err_t meshx_tx_queue_dequeue_at ( meshx_tx_queue_t * q,
int16_t index,
meshx_txcm_tx_q_t * item )
static

Removes an item from the transmission queue.

This function removes an item from the transmission queue. The item is a pointer to the meshx_txcm_tx_q_t structure to be removed.

Parameters
[in]qPointer to the transmission queue structure to remove the item from.
[in]indexIndex of the item to dequeue.
[out]itemPointer to the meshx_txcm_tx_q_t structure to store the removed item.
Returns
meshx_err_t
282{
283 if (q->count == 0) return MESHX_INVALID_STATE;
284
285 if (item) memcpy(item, &q->q_param[index], sizeof(meshx_txcm_tx_q_t));
286
287 // If it's the head, just use standard dequeue logic
288 if (index == q->head)
289 {
290 q->head = (q->head + 1) % MESHX_TXCM_TX_Q_LEN;
291 }
292 else
293 {
294 // Shift elements to fill the gap
295 int16_t current = index;
296 while (current != q->head)
297 {
298 int16_t prev = (current - 1 + MESHX_TXCM_TX_Q_LEN) % MESHX_TXCM_TX_Q_LEN;
299 memcpy(&q->q_param[current], &q->q_param[prev], sizeof(meshx_txcm_tx_q_t));
300 current = prev;
301 }
302 q->head = (q->head + 1) % MESHX_TXCM_TX_Q_LEN;
303 }
304 q->count--;
305 return MESHX_SUCCESS;
306}
@ MESHX_INVALID_STATE
Definition meshx_err.h:49
**This function is called by the parent element when a state change request *is received It validates the request and returns a result to the element not the model layer **return * MESHX_SUCCESS
Definition meshx_model_level.cpp:385
struct meshx_txcm_tx_q meshx_txcm_tx_q_t
Structure for queued transmission items in the Tx Control module.
#define MESHX_TXCM_TX_Q_LEN
Maximum number of transmission items in the Tx queue.
Definition meshx_txcm.h:41
meshx_txcm_tx_q_t q_param[10]
Definition meshx_txcm.c:71
int16_t head
Definition meshx_txcm.c:68
uint16_t count
Definition meshx_txcm.c:70

◆ meshx_tx_queue_enqueue()

meshx_err_t meshx_tx_queue_enqueue ( meshx_tx_queue_t * q,
const meshx_txcm_tx_q_t * item )
static

Adds an item to the transmission queue.

This function adds an item to the transmission queue. The item is a pointer to the meshx_txcm_tx_q_t structure to be added.

Parameters
[in]qPointer to the transmission queue structure to add the item to.
[in]itemPointer to the meshx_txcm_tx_q_t structure to be added.
Returns
true if the item was successfully added, false if the queue is full.
178{
180 err = meshx_tx_queue_is_full(q);
181 if (err == MESHX_SUCCESS)
182 {
183 return MESHX_NO_MEM;
184 }
185
186 // Copy the entire item structure into the q_param.
187 memcpy(q->q_param + q->tail, item, sizeof(meshx_txcm_tx_q_t));
188
189 q->tail = (q->tail + 1) % MESHX_TXCM_TX_Q_LEN;
190
191 // Increment count.
192 q->count++;
193
194 return MESHX_SUCCESS;
195}
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43
@ MESHX_NO_MEM
Definition meshx_err.h:48
static meshx_err_t meshx_tx_queue_is_full(const meshx_tx_queue_t *q)
Checks if the transmission queue is full.
Definition meshx_txcm.c:147
int16_t tail
Definition meshx_txcm.c:69

◆ meshx_tx_queue_enqueue_front()

meshx_err_t meshx_tx_queue_enqueue_front ( meshx_tx_queue_t * q,
const meshx_txcm_tx_q_t * item )
static

Adds an item to the front of the transmission queue.

This function adds an item to the front of the transmission queue. The item is a pointer to the meshx_txcm_tx_q_t structure to be added.

Parameters
[in]qPointer to the transmission queue structure to add the item to.
[in]itemPointer to the meshx_txcm_tx_q_t structure to be added.
Returns
true if the item was successfully added, false if the queue is full.
209{
211 err = meshx_tx_queue_is_full(q);
212 if (err == MESHX_SUCCESS)
213 {
214 return MESHX_NO_MEM;
215 }
216 // Increment tail and wrap around if necessary.
218
219 // Copy the entire item structure into the q_param.
220 memcpy(q->q_param + q->head, item, sizeof(meshx_txcm_tx_q_t));
221
222 // Increment count.
223 q->count++;
224
225 return MESHX_SUCCESS;
226}

◆ meshx_tx_queue_is_empty()

meshx_err_t meshx_tx_queue_is_empty ( const meshx_tx_queue_t * q)
static

Checks if the transmission queue is empty.

This function checks if the count of messages in the transmission queue has reached zero.

Parameters
[in]qPointer to the transmission queue structure to be checked.
Returns
true if the queue is empty, false otherwise.
162{
163 return q->count == 0 ? MESHX_SUCCESS : MESHX_INVALID_STATE;
164}

◆ meshx_tx_queue_is_full()

meshx_err_t meshx_tx_queue_is_full ( const meshx_tx_queue_t * q)
static

Checks if the transmission queue is full.

This function checks if the count of messages in the transmission queue has reached the maximum capacity.

Parameters
[in]qPointer to the transmission queue structure to be checked.
Returns
true if the queue is full, false otherwise.
148{
150}

◆ meshx_tx_queue_search()

meshx_err_t meshx_tx_queue_search ( const meshx_tx_queue_t * q,
const uint8_t * param,
uint16_t param_len,
uint16_t dest_addr )
static

Searches for a parameter in the transmission queue.

Parameters
[in]qPointer to the transmission queue structure to search in.
[in]paramPointer to the uint8_t array to search for.
[in]param_lenLength of the parameter array.
[in]dest_addrDestination address associated with the parameter.
Returns
MESHX_SUCCESS if found, MESHX_NOT_FOUND otherwise.
242{
245 if (err == MESHX_SUCCESS)
246 {
247 return MESHX_INVALID_STATE;
248 }
249
250 int16_t head = q->head;
251 int16_t tail = q->tail;
252
253 while(head != tail)
254 {
255 // Move tail back
256 tail = (tail - 1 + MESHX_TXCM_TX_Q_LEN) % MESHX_TXCM_TX_Q_LEN;
257 // compare param with q_param[tail]
258 if (q->q_param[tail].msg_param_len == param_len &&
259 memcmp(param, q->q_param[tail].msg_param, param_len) == 0 &&
260 q->q_param[tail].dest_addr == dest_addr)
261 {
262 MESHX_LOGD(MODULE_ID_TXCM, "Found param in queue");
263 return MESHX_SUCCESS;
264 }
265 }
266
267 return MESHX_NOT_FOUND;
268}
@ MESHX_NOT_FOUND
Definition meshx_err.h:50
#define MESHX_LOGD(module_id, format,...)
Definition meshx_log.h:132
static meshx_err_t meshx_tx_queue_is_empty(const meshx_tx_queue_t *q)
Checks if the transmission queue is empty.
Definition meshx_txcm.c:161
@ MODULE_ID_TXCM
Definition module_id.h:37
uint16_t msg_param_len
Definition meshx_txcm.c:55
uint16_t dest_addr
Definition meshx_txcm.c:53
uint8_t msg_param[64]
Definition meshx_txcm.c:59

◆ meshx_txcm_event_cb_reg()

meshx_err_t meshx_txcm_event_cb_reg ( meshx_txcm_cb_t event_cb)

Registers a callback function for handling Tx Control module events.

This function registers a callback function to handle specific events from the Tx Control module. The callback will be invoked when the specified event occurs.

Parameters
[in]event_cbPointer to the callback function to be registered for event handling.
Returns
meshx_err_t
  • MESHX_SUCCESS on successful registration.
  • Error code (meshx_err_t) if registration fails.
735{
739 event_cb);
740}
CONTROL_TASK_MSG_EVT_TXCM_MSG_TIMEOUT
Definition meshx_control_task.h:177
@ CONTROL_TASK_MSG_CODE_TXCM
Definition meshx_control_task.h:74
meshx_err_t control_task_msg_subscribe(control_task_msg_code_t msg_code, control_task_msg_evt_t evt_bmap, control_task_msg_handle_t callback)
Subscribe to a control task message.
Definition meshx_control_task.c:142

◆ meshx_txcm_init()

meshx_err_t meshx_txcm_init ( dev_struct_t * pdev)

Initializes the MeshX Tx Control Module.

This function sets up the transmission control module for MeshX. It checks if the module has already been initialized using an initialization magic value. If not initialized, it sets the magic value, assigns the provided device structure to the task argument, and creates the Tx Control task.

Parameters
[in]pdevPointer to the device structure to be used by the Tx Control Module.
Returns
  • MESHX_SUCCESS on successful initialization or if already initialized.
  • Error code (meshx_err_t) if task creation fails.
629{
630 MESHX_LOGD(MODULE_ID_TXCM, "Initializing MeshX Tx Control Module");
631 if(g_txcm.init_magic == MESHX_TXCM_INIT_MAGIC)
632 {
633 return MESHX_SUCCESS;
634 }
636 g_txcm.init_magic = MESHX_TXCM_INIT_MAGIC;
637 g_txcm.txcm_task.arg = pdev;
638
639 /* Create Control Signal Queue */
640 err = meshx_msg_q_create(&g_txcm.txcm_sig_queue);
641 if(err)
642 {
643 MESHX_LOGE(MODULE_ID_TXCM, "Failed to create Tx Control Signal Queue: %p", (void *)err);
644 return err;
645 }
646
647 err = meshx_task_create(&g_txcm.txcm_task);
648 if(err)
649 {
650 MESHX_LOGE(MODULE_ID_TXCM, "Failed to create Tx Control task: %p", (void *)err);
651 return err;
652 }
653
654 return MESHX_SUCCESS;
655}
#define MESHX_LOGE(module_id, format,...)
Definition meshx_log.h:114
meshx_err_t meshx_msg_q_create(meshx_msg_q_t *msg_q_handle)
Create a MeshX Message Queue.
meshx_err_t meshx_task_create(meshx_task_t *task_handle)
Create a MeshX Task.
#define MESHX_TXCM_INIT_MAGIC
Magic value used to check if the Tx Control module has been initialized.
Definition meshx_txcm.c:19
static struct @104313017062212276207200041132370204061105256055 g_txcm
Global structure for Tx Control module state and resources.

◆ meshx_txcm_msg_q_front_try_send()

meshx_err_t meshx_txcm_msg_q_front_try_send ( bool resend)
static
392{
393 return meshx_txcm_msg_q_try_send(resend, 0xFFFF);
394}
static meshx_err_t meshx_txcm_msg_q_try_send(bool resend, uint16_t target_addr)
Attempts to send messages from the transmission queue.
Definition meshx_txcm.c:316

◆ meshx_txcm_msg_q_try_send()

meshx_err_t meshx_txcm_msg_q_try_send ( bool resend,
uint16_t target_addr )
static

Attempts to send messages from the transmission queue.

Parameters
[in]resendTrue if this is a resend attempt.
[in]target_addrTarget address for the message.
Returns
MESHX_SUCCESS on success.
317{
319 int16_t current = g_txcm.txcm_tx_queue.head;
320 int16_t count = g_txcm.txcm_tx_queue.count;
321
322 // Destinations currently waiting for ACKs
323 uint16_t blocked_addrs[MESHX_TXCM_TX_Q_LEN];
324 uint8_t blocked_count = 0;
325
326 for (int i = 0; i < count; i++)
327 {
328 meshx_txcm_tx_q_t *item = &g_txcm.txcm_tx_queue.q_param[current];
330 {
331 blocked_addrs[blocked_count++] = item->dest_addr;
332 }
333 current = (current + 1) % MESHX_TXCM_TX_Q_LEN;
334 }
335
336 current = g_txcm.txcm_tx_queue.head;
337 for (int i = 0; i < count; i++)
338 {
339 meshx_txcm_tx_q_t *item = &g_txcm.txcm_tx_queue.q_param[current];
340 bool is_resend_match = resend && (item->dest_addr == target_addr && item->msg_state == MESHX_TXCM_MSG_STATE_WAITING_ACK);
341 bool is_new_runnable = !resend && (item->msg_state == MESHX_TXCM_MSG_STATE_NEW);
342
343 if (is_resend_match || is_new_runnable)
344 {
345 // Check if destination is blocked (only for NEW messages)
346 bool blocked = false;
347 if (is_new_runnable)
348 {
349 for (uint8_t b = 0; b < blocked_count; b++)
350 {
351 if (blocked_addrs[b] == item->dest_addr) { blocked = true; break; }
352 }
353 }
354
355 if (!blocked)
356 {
357 meshx_txcm_tx_q_t active_tx;
358 err = meshx_tx_queue_dequeue_at(&g_txcm.txcm_tx_queue, current, &active_tx);
359
360 if (active_tx.retry_cnt-- <= 0)
361 {
362 MESHX_LOGW(MODULE_ID_TXCM, "Message exhausted retries for 0x%X", active_tx.dest_addr);
363 return MESHX_TIMEOUT;
364 }
365
367 if (active_tx.send_fn != NULL)
368 {
369 err = active_tx.send_fn(active_tx.msg_param, active_tx.msg_param_len);
370 if (err != MESHX_SUCCESS)
371 {
373 return err;
374 }
375 }
376
377 if (active_tx.msg_type == MESHX_TXCM_MSG_TYPE_ACKED)
378 {
380 meshx_tx_queue_enqueue_front(&g_txcm.txcm_tx_queue, &active_tx);
381 }
382 return MESHX_SUCCESS;
383 }
384 }
385 current = (current + 1) % MESHX_TXCM_TX_Q_LEN;
386 }
387
388 return MESHX_SUCCESS;
389}
@ MESHX_TIMEOUT
Definition meshx_err.h:52
#define MESHX_LOGW(module_id, format,...)
Definition meshx_log.h:120
static meshx_err_t meshx_tx_queue_enqueue_front(meshx_tx_queue_t *q, const meshx_txcm_tx_q_t *item)
Adds an item to the front of the transmission queue.
Definition meshx_txcm.c:208
static meshx_err_t meshx_tx_queue_dequeue_at(meshx_tx_queue_t *q, int16_t index, meshx_txcm_tx_q_t *item)
Removes an item from the transmission queue.
Definition meshx_txcm.c:281
@ MESHX_TXCM_MSG_STATE_SENDING
Definition meshx_txcm.h:75
@ MESHX_TXCM_MSG_STATE_NACK
Definition meshx_txcm.h:78
@ MESHX_TXCM_MSG_STATE_NEW
Definition meshx_txcm.h:74
@ MESHX_TXCM_MSG_STATE_WAITING_ACK
Definition meshx_txcm.h:76
@ MESHX_TXCM_MSG_TYPE_ACKED
Definition meshx_txcm.h:84
meshx_txcm_fn_model_send_t send_fn
Definition meshx_txcm.c:58
meshx_txcm_msg_state_t msg_state
Definition meshx_txcm.c:57
meshx_txcm_msg_type_t msg_type
Definition meshx_txcm.c:56
uint16_t retry_cnt
Definition meshx_txcm.c:54

◆ meshx_txcm_proccess_request_msg()

meshx_err_t meshx_txcm_proccess_request_msg ( meshx_txcm_request_t * request,
meshx_txcm_msg_type_t msg_type )
static

Processes a request message for the Tx Control module.

This function handles the processing of a request message for the Tx Control module. It checks if the request is valid, creates a new transmission entry with a sequence number, and then queues the message to the transmission queue. If the queued message is at the front of the queue, it immediately processes the send function.

Parameters
[in]requestPointer to the transmission control request structure containing the send msg
[in]msg_typeType of the message (ACKED or UNACKED)
Returns
meshx_err_t
412{
414 meshx_txcm_tx_q_t new_tx;
415
416 if ( request == NULL
417 || request->send_fn == NULL
418 || msg_type >= MESHX_TXCM_MSG_TYPE_MAX
420 )
421 {
422 return MESHX_INVALID_ARG;
423 }
424
425 MESHX_LOGD(MODULE_ID_TXCM, "Processing a new request");
426
427 err = meshx_tx_queue_search(&g_txcm.txcm_tx_queue, request->msg_param, request->msg_param_len, request->dest_addr);
428 if (err == MESHX_SUCCESS)
429 {
430 MESHX_LOGD(MODULE_ID_TXCM, "Message already in queue");
431 return MESHX_SUCCESS;
432 }
433
434 memset(&new_tx, 0, sizeof(meshx_txcm_tx_q_t));
435
436 new_tx.msg_type = msg_type;
437 new_tx.send_fn = request->send_fn;
438 new_tx.dest_addr = request->dest_addr;
439 new_tx.msg_param_len = request->msg_param_len;
442
443 memcpy(new_tx.msg_param, request->msg_param, request->msg_param_len);
444
445 err = meshx_tx_queue_enqueue(&g_txcm.txcm_tx_queue, &new_tx);
446 if (err)
447 {
448 MESHX_LOGE(MODULE_ID_TXCM, "Failed to send message to Tx Control Tx Queue: %p", (void *)err);
449 return err;
450 }
451
453 if(err)
454 {
455 MESHX_LOGE(MODULE_ID_TXCM, "Failed to process front of Tx Control Tx Queue: %p", (void *)err);
456 }
457 return err;
458}
@ MESHX_INVALID_ARG
Definition meshx_err.h:46
static meshx_err_t meshx_tx_queue_enqueue(meshx_tx_queue_t *q, const meshx_txcm_tx_q_t *item)
Adds an item to the transmission queue.
Definition meshx_txcm.c:177
static meshx_err_t meshx_tx_queue_search(const meshx_tx_queue_t *q, const uint8_t *param, uint16_t param_len, uint16_t dest_addr)
Searches for a parameter in the transmission queue.
Definition meshx_txcm.c:237
static meshx_err_t meshx_txcm_msg_q_front_try_send(bool resend)
Definition meshx_txcm.c:391
#define MESHX_TXCM_MSG_PARAM_MAX_LEN
Maximum length of the message parameters in bytes.
Definition meshx_txcm.h:34
#define MESHX_TXCM_MSG_RETRY_MAX
Maximum number of retries for a message.
Definition meshx_txcm.h:27
@ MESHX_TXCM_MSG_TYPE_MAX
Definition meshx_txcm.h:86
uint16_t dest_addr
Definition meshx_txcm.h:104
meshx_ptr_t msg_param
Definition meshx_txcm.h:106
meshx_txcm_fn_model_send_t send_fn
Definition meshx_txcm.h:108
uint16_t msg_param_len
Definition meshx_txcm.h:105

◆ meshx_txcm_request_send()

meshx_err_t meshx_txcm_request_send ( meshx_txcm_sig_t request_type,
uint16_t dest_addr,
meshx_cptr_t msg_param,
uint16_t msg_param_len,
meshx_txcm_fn_model_send_t send_fn )

Sends a request to the Tx Control module.

This function sends a request to the Tx Control module with the specified parameters. It creates a new request structure, copies the message parameters, and sends the request to the signal queue of the Tx Control module.

Parameters
[in]request_typeType of the request (ACK, RESEND, ENQ_SEND, DIRECT_SEND)
[in]dest_addrDestination address of the message
[in]msg_paramPointer to the message parameters
[in]msg_param_lenLength of the message parameters
[in]send_fnFunction pointer to the send function to be used for the request
Returns
meshx_err_t
679{
681 meshx_txcm_request_t new_req;
682 memset(&new_req, 0, sizeof(meshx_txcm_request_t));
683
684 /* Prepare request message */
685 new_req.dest_addr = dest_addr;
686 new_req.send_fn = send_fn;
687 new_req.request_type = request_type;
688 new_req.msg_param_len = msg_param_len;
689
690 /* Auto-downgrade Group/Broadcast addresses to DIRECT_SEND */
691 if (dest_addr >= MESHX_ADDR_GROUP_START && new_req.request_type == MESHX_TXCM_SIG_ENQ_SEND)
692 {
693 MESHX_LOGW(MODULE_ID_TXCM, "Auto-downgrading multicast/broadcast (0x%X) to DIRECT_SEND", dest_addr);
695 }
696
697 if(msg_param_len != 0 && msg_param != NULL)
698 {
699 /* Retain message context */
700 err = meshx_rtos_malloc(&new_req.msg_param, msg_param_len);
701 if (err)
702 {
703 MESHX_LOGE(MODULE_ID_TXCM, "Malloc Failure: %p", (void *)err);
704 return err;
705 }
706 memcpy(new_req.msg_param, msg_param, msg_param_len);
707 }
708 else
709 {
710 new_req.msg_param = NULL;
711 }
712 err = meshx_msg_q_send(&g_txcm.txcm_sig_queue, &new_req, sizeof(meshx_txcm_request_t), 0);
713 if (err)
714 {
715 MESHX_LOGE(MODULE_ID_TXCM, "TXCM Signal failed: %p", (void *)err);
716 meshx_rtos_free(&new_req.msg_param);
717 return err;
718 }
719 return err;
720}
#define MESHX_ADDR_GROUP_START
Definition meshx_ble_mesh_cmn_def.h:29
meshx_err_t meshx_msg_q_send(meshx_msg_q_t *msg_q_handle, void const *msg, size_t msg_len, uint32_t delay_ms)
Send a Message to a MeshX Message Queue Back.
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.
struct meshx_txcm_request meshx_txcm_request_t
Structure for Tx Control module requests.
@ MESHX_TXCM_SIG_ENQ_SEND
Definition meshx_txcm.h:58
@ MESHX_TXCM_SIG_DIRECT_SEND
Definition meshx_txcm.h:59
meshx_txcm_sig_t request_type
Definition meshx_txcm.h:107

◆ meshx_txcm_sig_ack()

meshx_err_t meshx_txcm_sig_ack ( const meshx_txcm_request_t * request)
static

Handles the flush signal for the Tx Control module.

This function clears all messages from the transmission queue of the Tx Control module. It removes only front message from the queue and returns the status of the operation.

Parameters
[in]requestPointer to the transmission control request structure containing the flush request
Returns
meshx_err_t
540{
542
543 MESHX_LOGD(MODULE_ID_TXCM, "Processing an ack for 0x%X", request->dest_addr);
544
545 // Search the queue for the message matching this destination that is WAITING_ACK
546 int16_t current = g_txcm.txcm_tx_queue.head;
547 int16_t count = g_txcm.txcm_tx_queue.count;
548 bool found = false;
549
550 for (int i = 0; i < count; i++)
551 {
552 meshx_txcm_tx_q_t *item = &g_txcm.txcm_tx_queue.q_param[current];
553 if (item->dest_addr == request->dest_addr && item->msg_state == MESHX_TXCM_MSG_STATE_WAITING_ACK)
554 {
555 meshx_tx_queue_dequeue_at(&g_txcm.txcm_tx_queue, current, NULL);
556 found = true;
557 break;
558 }
559 current = (current + 1) % MESHX_TXCM_TX_Q_LEN;
560 }
561
562 if (!found)
563 {
564 MESHX_LOGW(MODULE_ID_TXCM, "ACK received for unknown/non-pending address 0x%X", request->dest_addr);
565 }
566
567 err = meshx_rtos_free(request->msg_param);
568 if (err)
569 {
570 MESHX_LOGE(MODULE_ID_TXCM, "RTOS Free failed: %p", (void *)err);
571 }
573 return err;
574}

◆ meshx_txcm_sig_direct_send()

meshx_err_t meshx_txcm_sig_direct_send ( meshx_txcm_request_t * request)
static

Enqueues a direct send request to the Tx Control module.

This function adds a direct send request to the transmission queue of the Tx Control module. It checks if the request is valid, creates a new transmission entry with a sequence number, and then queues the message to the transmission queue. If the queued message is at the front of the queue, it immediately processes the send function.

Parameters
[in]requestPointer to the transmission control request structure containing the send msg
Returns
meshx_err_t
491{
492 MESHX_LOGD(MODULE_ID_TXCM, "Processing a new direct request");
493 /* The same path can take care as the msg type */
495}
static meshx_err_t meshx_txcm_proccess_request_msg(meshx_txcm_request_t *request, meshx_txcm_msg_type_t msg_type)
Processes a request message for the Tx Control module.
Definition meshx_txcm.c:409
@ MESHX_TXCM_MSG_TYPE_UNACKED
Definition meshx_txcm.h:85

◆ meshx_txcm_sig_enq_send()

meshx_err_t meshx_txcm_sig_enq_send ( meshx_txcm_request_t * request)
static

Enqueues a send request to the Tx Control module.

This function adds a send request to the transmission queue of the Tx Control module. It checks if the request is valid, creates a new transmission entry with a sequence number, and then queues the message to the transmission queue. If the queued message is at the front of the queue, it immediately processes the send function.

Parameters
[in]requestPointer to the transmission control request structure containing the send msg
Returns
meshx_err_t
473{
474 MESHX_LOGD(MODULE_ID_TXCM, "Enqueuing a new request");
476}

◆ meshx_txcm_sig_resend()

meshx_err_t meshx_txcm_sig_resend ( meshx_txcm_request_t * request)
static

Handles the resend signal for the Tx Control module.

Parameters
[in]requestPointer to the transmission control request structure containing the send msg
Returns
meshx_err_t
505{
507
508 MESHX_LOGD(MODULE_ID_TXCM, "Processing a retry for 0x%X", request->dest_addr);
509 err = meshx_txcm_msg_q_try_send(true, request->dest_addr);
510 if(err == MESHX_TIMEOUT)
511 {
512 MESHX_LOGD(MODULE_ID_TXCM, "Timeout for 0x%X", request->dest_addr);
516 request->msg_param,
517 request->msg_param_len
518 );
519 if(err)
520 {
521 MESHX_LOGE(MODULE_ID_TXCM, "Failed to publish timeout: %p", (void *)err);
522 }
524 }
525 meshx_rtos_free(&request->msg_param);
526 return err;
527}
meshx_err_t control_task_msg_publish(control_task_msg_code_t msg_code, control_task_msg_evt_t msg_evt, const void *msg_evt_params, size_t sizeof_msg_evt_params)
Publish a control task message.
Definition meshx_control_task.c:84

◆ meshx_txcm_task_handler()

void meshx_txcm_task_handler ( const dev_struct_t * args)
static

Handler function for the MeshX TXCM task.

This static function processes transmission commands for the MeshX component. It is intended to be run as a task handler, typically within a FreeRTOS or similar multitasking environment.

Parameters
[in]argsPointer to a device structure (dev_struct_t) containing context or parameters required for the task operation.
Note
This function is not intended to be called directly from outside this source file.
589{
590 MESHX_UNUSED(args);
591 MESHX_LOGD(MODULE_ID_TXCM, "MeshX Tx Control Task started");
593
594 while(true)
595 {
596 meshx_txcm_request_t request;
597 /* Wait for a signal from the signal queue */
598 if(meshx_msg_q_recv(&g_txcm.txcm_sig_queue, &request, UINT32_MAX) != MESHX_SUCCESS)
599 {
600 MESHX_LOGD(MODULE_ID_TXCM, "Failed to receive signal from Tx Control Signal Queue");
601 continue;
602 }
603 MESHX_LOGD(MODULE_ID_TXCM, "Processing sig: %d", request.request_type);
604
605 /* Process the signal based on the request type */
606 err = g_sig_proc_table[request.request_type](&request);
607 if(err)
608 {
609 MESHX_LOGE(MODULE_ID_TXCM, "Failed to process the request (%p): %p",(void*)request.request_type, (void *)err);
610 }
611 }
612}
#define MESHX_UNUSED(x)
Definition meshx_err.h:19
meshx_err_t meshx_msg_q_recv(meshx_msg_q_t *msg_q_handle, void *msg, uint32_t delay_ms)
Receive a Message from a MeshX Message Queue.
static meshx_txcm_sig_proc_t g_sig_proc_table[MESHX_TXCM_SIG_MAX]
Signal processing function table for the Tx Control module.
Definition meshx_txcm.c:129

Variable Documentation

◆ g_sig_proc_table

meshx_txcm_sig_proc_t g_sig_proc_table[MESHX_TXCM_SIG_MAX]
static
Initial value:
=
{
}
meshx_err_t(* meshx_txcm_sig_proc_t)(meshx_txcm_request_t *request)
Type definition for signal processing functions in the Tx Control module.
Definition meshx_txcm.c:43
static meshx_err_t meshx_txcm_sig_direct_send(meshx_txcm_request_t *request)
Enqueues a direct send request to the Tx Control module.
Definition meshx_txcm.c:490
static meshx_err_t meshx_txcm_sig_ack(const meshx_txcm_request_t *request)
Handles the flush signal for the Tx Control module.
Definition meshx_txcm.c:539
static meshx_err_t meshx_txcm_sig_enq_send(meshx_txcm_request_t *request)
Enqueues a send request to the Tx Control module.
Definition meshx_txcm.c:472
static meshx_err_t meshx_txcm_sig_resend(meshx_txcm_request_t *request)
Handles the resend signal for the Tx Control module.
Definition meshx_txcm.c:504
@ MESHX_TXCM_SIG_ACK
Definition meshx_txcm.h:61
@ MESHX_TXCM_SIG_RESEND
Definition meshx_txcm.h:60

Signal processing function table for the Tx Control module.

This table maps signal types to their corresponding processing functions. Each entry in the table is a function pointer that handles a specific type of signal. The table is indexed by the signal type (meshx_txcm_sig_t) and contains function pointers to the respective signal processing functions.

◆ [struct]

struct { ... } g_txcm
Initial value:
= {
.init_magic = 0,
.txcm_tx_queue = {
.head = 0,
.tail = 0,
.count = 0,
},
.txcm_sig_queue = {
.max_msg_length = 10 ,
.max_msg_depth = sizeof(meshx_txcm_request_t) ,
},
.txcm_task = {
.task_name = "meshx_txcm_task",
.priority = 5 ,
.stack_size = 4096 ,
}
}
void(* meshx_task_cb_t)(void *arg)
MeshX Task Function.
Definition meshx_task.h:26
static void meshx_txcm_task_handler(const dev_struct_t *args)
Handler function for the MeshX TXCM task.
Definition meshx_txcm.c:588

Global structure for Tx Control module state and resources.

This static structure manages the initialization state, task configuration, and queues for signals and transmissions in the Tx Control module.

◆ init_magic

uint16_t init_magic

◆ txcm_sig_queue

meshx_msg_q_t txcm_sig_queue

◆ txcm_task

meshx_task_t txcm_task

◆ txcm_tx_queue

meshx_tx_queue_t txcm_tx_queue