Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


xQueueReceive with structures

Posted by echel0n on February 18, 2009
Ok what I'm trying to do is send data from my uart to another task that will send it out via ethernet.
Problem is when I transfer the data and length variables it seems to only send and store one of the values.

Any idea's on how I can accomplish or fix this code ?

Here's some of the code I have so far:

typedef struct
long length;
signed char *data;
} xIKSMessage;

// Task 1
/* The queue used to send data to the IKS task. */
xQueueHandle xIKSQueue;

void task1(void)
xIKSMessage xMessage;

xIKSQueue = xQueueCreate( 10, sizeof( struct xIKSMessage * ) );

// Wait for RX Data from receiver
while ((uart1in.length = uart1Read(uart1in.data)) == pdFALSE);

// Send data to IKS Server
xMessage.length = uart1in.length;
xMessage.data = uart1in.data;

/* Send the message to the LCD gatekeeper for display. */
xQueueSend( xIKSQueue, &xMessage, portMAX_DELAY );

// Task2
/* The queue used to send data to the IKS task. */
xQueueHandle xIKSQueue;

void iks_appcall(void)
xIKSMessage xData;

if( xIKSQueue != 0 )
// Receive a message on the created queue. Block for 10 ticks if a
// message is not immediately available.
if( xQueueReceive( xIKSQueue, &xData, ( portTickType ) 10 ) )
if(uip_connected() || uip_rexmit())
uip_send(xData.data, xData.length);
iks_datasent = 1;

RE: xQueueReceive with structures

Posted by Richard Damon on February 18, 2009
You are defining your queue to hold a "struct xIKSMessage *", but are sending it a "struct xIKSMessage".

Your queue should be sized to hold "struct xIKSMessage"

RE: xQueueReceive with structures

Posted by echel0n on February 18, 2009
Ok I was able to get it working fine but now I'm having issues with xQueueSend ....
I'm trying to send a char array and it seems as if only the first byte gets sent and the rest of the data never makes it.

RE: xQueueReceive with structures

Posted by Adam Turowski on February 18, 2009
The queque copies to internal queque structures the data you provide it as an input . So to send structures or tables, you should create queque that has elements size equal to of structure/table size NOT size of pointers to structure/table.

When you attempt to send something, queue Send function copies the amount of bytes (usually) declared as element size during queue creation. It copies this amount of bytes from buffer pointer provided as Send function input argument.
If you declared queue element of size of pointer, it will send only amount of bytes equal to pointer size in bytes each time you call Send function.

[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

Version 10.1.0 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers


STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner