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.h File Reference

MeshX Tx Control Module This header file contains the definitions and function prototypes for the MeshX Tx Control Module, which is responsible for managing transmission control in the MeshX BLE Mesh stack. More...

#include <stdint.h>
#include <stddef.h>
#include "meshx_err.h"
#include "meshx_common.h"
#include "meshx_control_task.h"
#include "interface/ble_mesh/meshx_ble_mesh_cmn_def.h"

Go to the source code of this file.

Data Structures

struct  meshx_txcm_request
 Structure for Tx Control module requests. More...

Macros

#define MESHX_TXCM_MSG_RETRY_MAX   3
 Maximum number of retries for a message.
#define MESHX_TXCM_MSG_PARAM_MAX_LEN   64
 Maximum length of the message parameters in bytes.
#define MESHX_TXCM_TX_Q_LEN   10
 Maximum number of transmission items in the Tx queue.
#define MESHX_TXCM_TX_Q_DEPTH   sizeof(meshx_txcm_tx_q_t)
 Depth (size) of each transmission queue entry.

Typedefs

typedef control_task_msg_handle_t meshx_txcm_cb_t
typedef meshx_err_t(* meshx_txcm_fn_model_send_t) (meshx_cptr_t msg_param, size_t msg_param_len)
 Function pointer the Model client layer needs to provide for the msg to be sent for both MESHX_TXCM_SIG_ENQ_SEND and MESHX_TXCM_SIG_DIRECT_SEND.
typedef struct meshx_txcm_request meshx_txcm_request_t
 Structure for Tx Control module requests.

Enumerations

enum  meshx_txcm_sig_t {
  MESHX_TXCM_SIG_ENQ_SEND = 0 ,
  MESHX_TXCM_SIG_DIRECT_SEND = 1 ,
  MESHX_TXCM_SIG_RESEND = 2 ,
  MESHX_TXCM_SIG_ACK = 3 ,
  MESHX_TXCM_SIG_MAX
}
 Enumeration of signal types for the Tx Control Module. More...
enum  meshx_txcm_msg_state_t {
  MESHX_TXCM_MSG_STATE_NONE = 0 ,
  MESHX_TXCM_MSG_STATE_NEW = 1 ,
  MESHX_TXCM_MSG_STATE_SENDING = 2 ,
  MESHX_TXCM_MSG_STATE_WAITING_ACK = 3 ,
  MESHX_TXCM_MSG_STATE_ACK = 4 ,
  MESHX_TXCM_MSG_STATE_NACK = 5 ,
  MESHX_TXCM_MSG_STATE_MAX
}
 Enumeration of message states for the Tx Control Module. More...
enum  meshx_txcm_msg_type_t {
  MESHX_TXCM_MSG_TYPE_ACKED ,
  MESHX_TXCM_MSG_TYPE_UNACKED ,
  MESHX_TXCM_MSG_TYPE_MAX
}

Functions

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.

Detailed Description

MeshX Tx Control Module This header file contains the definitions and function prototypes for 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_MSG_PARAM_MAX_LEN

#define MESHX_TXCM_MSG_PARAM_MAX_LEN   64

Maximum length of the message parameters in bytes.

◆ MESHX_TXCM_MSG_RETRY_MAX

#define MESHX_TXCM_MSG_RETRY_MAX   3

Maximum number of retries for a message.

◆ MESHX_TXCM_TX_Q_DEPTH

#define MESHX_TXCM_TX_Q_DEPTH   sizeof(meshx_txcm_tx_q_t)

Depth (size) of each transmission queue entry.

◆ MESHX_TXCM_TX_Q_LEN

#define MESHX_TXCM_TX_Q_LEN   10

Maximum number of transmission items in the Tx queue.

Typedef Documentation

◆ meshx_txcm_cb_t

◆ meshx_txcm_fn_model_send_t

typedef meshx_err_t(* meshx_txcm_fn_model_send_t) (meshx_cptr_t msg_param, size_t msg_param_len)

Function pointer the Model client layer needs to provide for the msg to be sent for both MESHX_TXCM_SIG_ENQ_SEND and MESHX_TXCM_SIG_DIRECT_SEND.

Parameters
[in]msg_paramPointer to the model specific parameter structure
[in]msg_param_lenLength of the msg_param

◆ meshx_txcm_request_t

Structure for Tx Control module requests.

This structure holds the details of a transmission request, including the type of signal, the send function callback, and parameters for the message to be transmitted.

Enumeration Type Documentation

◆ meshx_txcm_msg_state_t

Enumeration of message states for the Tx Control Module.

This enumeration defines the different states a message can be in during transmission, including new messages, waiting for acknowledgment, acknowledged messages, and the maximum state value.

Enumerator
MESHX_TXCM_MSG_STATE_NONE 

New message state

MESHX_TXCM_MSG_STATE_NEW 

New message state

MESHX_TXCM_MSG_STATE_SENDING 

Message sending state

MESHX_TXCM_MSG_STATE_WAITING_ACK 

Message waiting for acknowledgment state

MESHX_TXCM_MSG_STATE_ACK 

Message acknowledged state

MESHX_TXCM_MSG_STATE_NACK 

Message not acknowledged state

MESHX_TXCM_MSG_STATE_MAX  
72{
73 MESHX_TXCM_MSG_STATE_NONE = 0, /**< New message state */
74 MESHX_TXCM_MSG_STATE_NEW = 1, /**< New message state */
75 MESHX_TXCM_MSG_STATE_SENDING = 2, /**< Message sending state */
76 MESHX_TXCM_MSG_STATE_WAITING_ACK = 3, /**< Message waiting for acknowledgment state */
77 MESHX_TXCM_MSG_STATE_ACK = 4, /**< Message acknowledged state */
78 MESHX_TXCM_MSG_STATE_NACK = 5, /**< Message not acknowledged state */
meshx_txcm_msg_state_t
Enumeration of message states for the Tx Control Module.
Definition meshx_txcm.h:72
@ MESHX_TXCM_MSG_STATE_SENDING
Definition meshx_txcm.h:75
@ MESHX_TXCM_MSG_STATE_NACK
Definition meshx_txcm.h:78
@ MESHX_TXCM_MSG_STATE_NONE
Definition meshx_txcm.h:73
@ MESHX_TXCM_MSG_STATE_NEW
Definition meshx_txcm.h:74
@ MESHX_TXCM_MSG_STATE_ACK
Definition meshx_txcm.h:77
@ MESHX_TXCM_MSG_STATE_WAITING_ACK
Definition meshx_txcm.h:76
@ MESHX_TXCM_MSG_STATE_MAX
Definition meshx_txcm.h:79

◆ meshx_txcm_msg_type_t

Enumerator
MESHX_TXCM_MSG_TYPE_ACKED 
MESHX_TXCM_MSG_TYPE_UNACKED 
MESHX_TXCM_MSG_TYPE_MAX 
83{
meshx_txcm_msg_type_t
Definition meshx_txcm.h:83
@ MESHX_TXCM_MSG_TYPE_UNACKED
Definition meshx_txcm.h:85
@ MESHX_TXCM_MSG_TYPE_MAX
Definition meshx_txcm.h:86
@ MESHX_TXCM_MSG_TYPE_ACKED
Definition meshx_txcm.h:84

◆ meshx_txcm_sig_t

Enumeration of signal types for the Tx Control Module.

This enumeration defines the different types of signals that can be sent to the Tx Control Module, each representing a different type of transmission command.

Enumerator
MESHX_TXCM_SIG_ENQ_SEND 

Signal to enqueue a transmission command

MESHX_TXCM_SIG_DIRECT_SEND 

Signal to directly send a transmission command without queuing

MESHX_TXCM_SIG_RESEND 

Signal to resend the last transmission queued message

MESHX_TXCM_SIG_ACK 

Signal to acknowledge the last transmission message

MESHX_TXCM_SIG_MAX  

Maximum signal type value

57{
58 MESHX_TXCM_SIG_ENQ_SEND = 0, /**< Signal to enqueue a transmission command */
59 MESHX_TXCM_SIG_DIRECT_SEND = 1, /**< Signal to directly send a transmission command without queuing */
60 MESHX_TXCM_SIG_RESEND = 2, /**< Signal to resend the last transmission queued message */
61 MESHX_TXCM_SIG_ACK = 3, /**< Signal to acknowledge the last transmission message */
62 MESHX_TXCM_SIG_MAX, /**< Maximum signal type value */
meshx_txcm_sig_t
Enumeration of signal types for the Tx Control Module.
Definition meshx_txcm.h:57
@ MESHX_TXCM_SIG_ENQ_SEND
Definition meshx_txcm.h:58
@ MESHX_TXCM_SIG_DIRECT_SEND
Definition meshx_txcm.h:59
@ MESHX_TXCM_SIG_ACK
Definition meshx_txcm.h:61
@ MESHX_TXCM_SIG_RESEND
Definition meshx_txcm.h:60
@ MESHX_TXCM_SIG_MAX
Definition meshx_txcm.h:62

Function Documentation

◆ 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}
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43
#define MESHX_LOGE(module_id, format,...)
Definition meshx_log.h:114
#define MESHX_LOGD(module_id, format,...)
Definition meshx_log.h:132
**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
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.
@ MODULE_ID_TXCM
Definition module_id.h:37

◆ 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
#define MESHX_LOGW(module_id, format,...)
Definition meshx_log.h:120
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.
uint16_t dest_addr
Definition meshx_txcm.h:104
meshx_ptr_t msg_param
Definition meshx_txcm.h:106
meshx_txcm_sig_t request_type
Definition meshx_txcm.h:107
meshx_txcm_fn_model_send_t send_fn
Definition meshx_txcm.h:108
uint16_t msg_param_len
Definition meshx_txcm.h:105