title: Sending data via a queue in FreeRTOS
body: <p>I have got two files with code.</p>
  
  <ol>
  <li>Ethernet</li>
  <li>CAN</li>
  </ol>
  
  <p>And between this files I would like sending data. 
  So, in the <strong>CAN file</strong> I created structure:</p>
  
  <pre><code>struct screenData {
          uint16_t gyroskop_x;
          uint16_t gyroskop_y;
          uint16_t gyroskop_z;
          uint16_t euler_x;
          uint16_t euler_y;
          uint16_t euler_z;
      } data;
  </code></pre>
  
  <p>And I tried initialise of this structure with my test values.</p>
  
  <pre><code>struct screenData * toSend;
      data.gyroskop_x = 1;
      data.gyroskop_y = 2;
      data.gyroskop_z = 3;
      data.euler_x = 4;
      data.euler_y = 5;
      data.euler_z = 6;
      toSend = &amp;data;
  </code></pre>
  
  <p>And I created new task, whrere I sending data every 1s.</p>
  
  <pre><code>xQueueSend ( fronta_gyroskop, ( void * ) &amp;toSend , 10 );
  </code></pre>
  
  <p>In <strong>ethernet file</strong> I initialise queue.
  In ethernet file:</p>
  
  <ol>
  <li>initialise queue</li>
  <li>Created receive structure for data</li>
  <li>Receive data from queue</li>
  </ol>
  
  <p>Code</p>
  
  <pre><code>xQueueHandle fronta_gyroskop = 0;
  
  extern void init_queue(void)
   {
     fronta_gyroskop = xQueueCreate(6, sizeof(struct ethernetData *));
   }
  
  struct ethernetData {
          uint16_t gyroskop_x;
          uint16_t gyroskop_y;
          uint16_t gyroskop_z;
          uint16_t euler_x;
          uint16_t euler_y;
          uint16_t euler_z;
      } gyro;
  </code></pre>
  
  <p>And in task I receive data every 1second.</p>
  
  <pre><code>if (xQueueReceive(fronta_gyroskop, &amp;gyro, 20)){ 
  }
  </code></pre>
  
  <p>But the values in gyro aren't my values (1,2,3,4,5,6), but the values are random 32bit values. Any idea, what I doing wrong?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>CAN side code</p>
  
  <pre><code>#include "Tasky/Ethernet.h"
  void *fronta_gyroskop;
  
  can_mb_conf_t tx_mailbox;
  can_mb_conf_t rx_mailbox;
  /** Receive status */
  volatile uint32_t g_ul_recv_status = 0;
  
  void CAN0_Handler(void)
  {
      uint32_t ul_status;
  
      ul_status = can_mailbox_get_status(CAN0, 0);
      if (ul_status &amp; CAN_MSR_MRDY) {
          rx_mailbox.ul_status = ul_status;
          can_mailbox_read(CAN0, &amp;rx_mailbox);
          g_ul_recv_status = 1;
      }
  }
  
  struct screenData {
          uint16_t gyroskop_x;
          uint16_t gyroskop_y;
          uint16_t gyroskop_z;
          uint16_t euler_x;
          uint16_t euler_y;
          uint16_t euler_z;
      } data;
  
  extern void task_can_read(void *pvParameters)
  {
      UNUSED(pvParameters);
      const portTickType xDelayTime = 10;
      uint8_t nacti = 1;
  
      /* init test value to sending */
      struct screenData * toSend;
      data.gyroskop_x = 1;
      data.gyroskop_y = 2;
      data.gyroskop_z = 3;
      data.euler_x = 4;
      data.euler_y = 5;
      data.euler_z = 6;
      toSend = &amp;data;
  
      for (;;){
          if (!g_ul_recv_status) {
              //puts("zadna zprava na CAN sbernici\r");
          } else {
              if ((rx_mailbox.ul_id &gt;&gt; 18) == FIRST_GYRO_ID) //rotation to 11bit number
              {
                  //calculate
                  nacti = 1;
              }
  
              if ((rx_mailbox.ul_id &gt;&gt; 18) == SECOND_GYRO_ID)
              {
                  //calculate
                  xQueueSend ( fronta_gyroskop, ( void * ) &amp;data , 10 );  //send data over queue
                  nacti = 0;
              }
  
              if (nacti == 1)
              {
                  rx_mailbox.ul_id = CAN_MID_MIDvA(SECOND_GYRO_ID);
                  can_mailbox_init(CAN0, &amp;rx_mailbox);
              }
              if (nacti == 0)
              {
                  rx_mailbox.ul_id = CAN_MID_MIDvA(FIRST_GYRO_ID);
                  can_mailbox_init(CAN0, &amp;rx_mailbox);
              }
  
              g_ul_recv_status = 0;   //clear flag
          }
  
          vTaskDelay(xDelayTime);
      }
  }
  </code></pre>
  
  <p>ETH code</p>
  
  <pre><code>#include "Tasky/CAN_TASKs.h"
  
  struct tcp_pcb *output = NULL;
  void *dataeth;
  
  struct netif gs_net_if;
  uint32_t g_ip_mode;
  int8_t g_c_ipconfig[];
  
  struct ethernetData {
          uint16_t gyroskop_x;
          uint16_t gyroskop_y;
          uint16_t gyroskop_z;
          uint16_t euler_x;
          uint16_t euler_y;
          uint16_t euler_z;
      } gyro;
  
  
  /************************************************************************/
  /*                  INIT QUEU to analyze data from TCPIP                */
  /************************************************************************/
  xQueueHandle fronta_gyroskop = 0;
  
  extern void init_fronta_ethernet(void)
  {
      fronta_gyroskop = xQueueCreate(6, sizeof(struct ethernetData *));
  }
  
  /************************************************************************/
  /*                  TASK of FREERTOS to TCPIP                           */
  /************************************************************************/
  extern void TCP_connection(void *pvParameters)
  {
      UNUSED(pvParameters);
  
      const portTickType xDelayTime = 1000 / portTICK_RATE_MS;
  
      uint16_t trest[6];
  
      while (1){  
  
          if (xQueueReceive(fronta_gyroskop, &amp;gyro, 10)){ //receive data over queue
              tcp_write(output, (void *)&amp;gyro, sizeof(gyro), TCP_WRITE_FLAG_COPY);    //Write data for sending (but does not send it immediately)
              tcp_sent(output, NULL); //Used to specify the function that should be called when TCP data has been successfully delivered to the remote host
              tcp_output(output); //Find out what we can send and send it.
          }
          vTaskDelay(xDelayTime);
      }
  }
  </code></pre>