This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How can i pass a structure to another thread through mailbox in zephyr

Hi,

Im using nrf9160 based custom board, nrf sdk 1.5.1

I have below structure to frame the data packet and i need to send this packet to another thread through MailBox. i have tested mail box with char array buffers and its working fine but not in the case of these packets(structure).

typedef enum
{
    MSG_UNKOWN_COMM,
    MSG_COMM1,
    MSG_COMM2,
    MSG_COMM3,
    MSG_COMM4,
    MSG_COMM5,
}MSG_SOURCE;


typedef struct Mesg
{
   MSG_SOURCE         MsgSource;
   uint16_t           NumOfBytes;
   uint8_t           *BufferHandler;
}msg_t;

   msg_t msgSendPacket;
   //Fill the Packet from UART
   
    /* prepare to send message through Mailbox*/
    mailBoxMsg.info = sizeof(&msgSendPacket);
    mailBoxMsg.size = sizeof(&msgSendPacket);
    mailBoxMsg.tx_data = &msgSendPacket;
    mailBoxMsg.tx_block.data = NULL;
    mailBoxMsg.tx_target_thread = tid_myThread;
    k_mbox_async_put(&mailBoxMsgMailBox, &mailBoxMsg, NULL);//NULL means no semphore used
    
    k_poll_signal_raise(&myThreadSignal, dataSig);

so please help me to send this data packet to another thread.

Best Regards

Rajender

Parents
  • Hello Rajender,

    so please help me to send this data packet to another thread.

    You have to make usage of a pointer pointing towards your struct.

     msg_t msgSendPacket, *msgSendPacketPtr = &msgSendPacket;
       //Fill the Packet from UART
       
        /* prepare to send message through Mailbox*/
        mailBoxMsg.info = sizeof(&msgSendPacket);
        mailBoxMsg.size = sizeof(&msgSendPacket);
        mailBoxMsg.tx_data = msgSendPacketPtr;
        mailBoxMsg.tx_block.data = NULL;
        mailBoxMsg.tx_target_thread = tid_myThread;
        k_mbox_async_put(&mailBoxMsgMailBox, &mailBoxMsg, NULL);//NULL means no semphore used
        
        k_poll_signal_raise(&myThreadSignal, dataSig);

    During reception, a pointer pointing towards a struct of the same type will fill it with the respective data.

    struct k_mbox_msg recv_msg;
    msg_t msgRecvPacket, *msgRecvPacketPtr = &msgRecvPacket;
    
    ...
    
    /* retrieve message data and delete the message */
    k_mbox_data_get(&recv_msg, msgRecvPacketPtr);

    I hope this solves your issue!

    Regards,

    Markus

Reply
  • Hello Rajender,

    so please help me to send this data packet to another thread.

    You have to make usage of a pointer pointing towards your struct.

     msg_t msgSendPacket, *msgSendPacketPtr = &msgSendPacket;
       //Fill the Packet from UART
       
        /* prepare to send message through Mailbox*/
        mailBoxMsg.info = sizeof(&msgSendPacket);
        mailBoxMsg.size = sizeof(&msgSendPacket);
        mailBoxMsg.tx_data = msgSendPacketPtr;
        mailBoxMsg.tx_block.data = NULL;
        mailBoxMsg.tx_target_thread = tid_myThread;
        k_mbox_async_put(&mailBoxMsgMailBox, &mailBoxMsg, NULL);//NULL means no semphore used
        
        k_poll_signal_raise(&myThreadSignal, dataSig);

    During reception, a pointer pointing towards a struct of the same type will fill it with the respective data.

    struct k_mbox_msg recv_msg;
    msg_t msgRecvPacket, *msgRecvPacketPtr = &msgRecvPacket;
    
    ...
    
    /* retrieve message data and delete the message */
    k_mbox_data_get(&recv_msg, msgRecvPacketPtr);

    I hope this solves your issue!

    Regards,

    Markus

Children
No Data
Related