title: FreeRTOS Queue Struct C
body: <p>I do not understand how to declare a structure that I can use to send data between two threads in FreeRTOS. </p>
  
  <p>I have two threads, the one should populate the struct with data, and the other one should read the data from the struct, which was sent with a message queue. </p>
  
  <p>The data can be copied or via pointer, it is not large amounts of data. </p>
  
  <p>In my main.c file I declare the structure and declare the queue and the queue handle:
  Before int main(void):</p>
  
  <pre><code>xQueueHandle LED_Queue_Handle, ChannelFreqQueue;
  
      struct AMessage
  {
          uint8_t channelID;
          float channelFreq;
  };
  </code></pre>
  
  <p>In main I create the queue</p>
  
  <pre><code>ChannelFreqQueue = xQueueCreate(2, sizeof(struct AMessage *));
  </code></pre>
  
  <p>In the task that needs to send data to the queue:</p>
  
  <pre><code>static void StopCompThread(void const *argument)
  {
      uint32_t count=0;
      uint8_t ActiveChannel =0;
      uint16_t uartcount =0;
      const float period = 0.0085;
      static float frequency = 0;
  
      for (;;)
    {
          struct AMessage txIdrisData;
  
          if(xSemaphoreTake(OscStopSem, portMAX_DELAY))       // Timer 17 Callback 8.5ms
          {
                      HAL_TIM_Base_Stop_IT(&amp;htim17);
                      __HAL_TIM_SET_COUNTER(&amp;htim17,0);       
                      count = __HAL_TIM_GetCounter(&amp;htim3);
                      uartcount++;
  
  
                              uint16_t pinstatus = (uint16_t)GPIOB-&gt;ODR &amp; 0x2000;
                              if (pinstatus == 0)
                              {
                                  ActiveChannel = 0x01;
                              }
                              else ActiveChannel = 0x02;
  
                              if (uartcount == 525)
                              {
                                  txIdrisData.channelID = ActiveChannel;
                                  txIdrisData.channelFreq = frequency;
  
                                  xQueueSend(ChannelFreqQueue, (void *) &amp;txIdrisData,portMAX_DELAY); 
  
                              }
  
          }
  
      } //FORever
  
  } // StopCompThread
  </code></pre>
  
  <p>And then the task that needs to receive the data from the queue:</p>
  
  <pre><code>static void IDRISThread(void const *argument)
      {
          struct AMessage rxIdrisData;    
  
          float temp = 0.0;
          uint8_t channel = 0;
          char IdrisDataBuf[11] = {0}; // 3 Bytes x 4 channels = 12 Bytes
          uint8_t IdrisStatusByte = 0;
  
          for (;;)
        {
            xQueueReceive( ChannelFreqQueue, &amp;( rxIdrisData ), portMAX_DELAY );
  
              temp = rxIdrisData.channelFreq;
              channel = rxIdrisData.channelID;
  
              temp = temp * 1000;
  
              snprintf(IdrisDataBuf, 2, "%.0f",temp); // Channel Data - Counts/Frequency
  
              if (channel == 0x00)
              {
                  IdrisDataBuf[2] = 0x00;
              }
              if (channel == 0x01)
              {
                  IdrisDataBuf[2] = 0x01;
              }
  
              uart_send(IdrisDataBuf, 12);
  
  
          } //FORever
  
      } // IDRISThread
  </code></pre>
  
  <p>I am sure that I have a misunderstanding of how to declare and use the structure and also that I have pointers and non-pointers mixed up. I have tried to use this API doc as reference: <a href="http://www.freertos.org/a00118.html" rel="nofollow noreferrer">http://www.freertos.org/a00118.html</a></p>
  
  <p>If someone can point out my mistakes or help with pseudo-code that might help me understand it would be appreciated.</p>