AnsweredAssumed Answered

osMessagePut problems

Question asked by Stepan Podhorsky on Mar 23, 2017
Latest reply on Mar 23, 2017 by Stepan Podhorsky

Hello,

 

I have been trying to solve problem with the osMessagePut function from

CMSIS-RTOS wrapper. I am not able to insert instances of C structure into

the message queue.  

 

My code is following:

 

// transmission queue

static osMessageQId tx_CAN_Message_queue;

// mutex related to transmission queue  

static osMutexId tx_mutex;

 

 

// function initializes the task's internal objects

void Init_Task(void){

 

   // transmission queue

   osMessageQDef(tx_CAN_Message_queue, CAN_BUFFER_LENGTH, msg_t);

   tx_CAN_Message_queue = osMessageCreate(osMessageQ(tx_CAN_Message_queue), NULL);

 

 

   // mutex related to transmission queue  

   osMutexDef(tx_mut);

   tx_mutex = osMutexCreate(osMutex(tx_mut));

 

}

 

void send_single_gdt_read_resp(uint8_t blk_index, uint8_t rec_index){

 

   // created message

   thb_msg_t tx_msg;

   // created packets for the transmitted message

   thb_pkt_t tx_pkt_array[MAX_NO_PACKETS];

   uint8_t i;

   uint8_t no_packets;

    can_message_t can_msg;

 

   // prepare the message

   build_single_gdt_msg(SHORT_SINGLE_GDT_READ_RESP_MSG, blk_index, rec_index, &tx_msg);

   // divide the message into packets

   no_packets = calc_no_packets(&tx_msg);

   tx_msg_to_packets(&tx_msg, no_packets, tx_pkt_array);

   // convert each packet into appropriate format and send it

   for(i = 0; i < no_packets; i++){

        can_msg = packet_to_can_msg(tx_pkt_array+i);

         // insert the prepared packet into the transmission queue

         // osOK = 0x0

        if(!osMutexWait(tx_mutex, osWaitForever)){

            // put the packet into the queue

            // wait 5 ms?

            osMessagePut(tx_CAN_Message_queue, (uint32_t)(&can_msg), 5);

            osMutexRelease(tx_mutex);

      }

   }

}

 

I have tried to insert integers into the message queue and it was successfull.

Please can anybody tell me what I do wrong? Thanks.

 

Outcomes