Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


Queue Communication not working

Posted by rclub123 on October 4, 2016

Hi i am trying to send an array from one task to another task.. but it is not working. here is my pseudo code: ~~~ int main(void) { xQueue = xQueueCreate( 2, sizeof(unsigned int) ); if ((xTaskCreate(vTask0, (const char )"Task0", configMINIMALSTACKSIZE, NULL, tskIDLEPRIORITY+2, &xHandle) != pdPASS) || (xTaskCreate(vTask1, (const char *)"Task1", configMINIMALSTACKSIZE, NULL, tskIDLEPRIORITY+2, &xHandle1) != pdPASS)) { printf("xTaskCreate() failed to create a task.n"); } else { / Start scheduler */ printf("Starting scheduler.n"); vTaskStartScheduler(); } } ~~~

~~~ void vTask0(void *pvParameters) { TickTypet xNextWakeTime; unsigned int data[2]; uint16t samplecount = 0; const TickTypet xFrequency =10; xNextWakeTime = xTaskGetTickCount(); while(1) { if (xQueueReceive(xQueue, &data,(portTickType)2)) { printf("received = %d n", data[0]); printf("received1 = %d n", data[1]); } vTaskDelayUntil(&xNextWakeTime, xFrequency); } } ~~~ ~~~ void vTask1(void *pvParameters) { TickTypet xNextWakeTime; unsigned int data[2]; const TickType_t xFrequency = 10; xNextWakeTime = xTaskGetTickCount(); while(1) { data[0]=3; data[1]=4; xQueueSendToBack(xQueue, &data, 0); vTaskDelayUntil(&xNextWakeTime, xFrequency); } } ~~~ Sorry i am new to RTOS, i want to send both data[0] and [1] to another task.. if i change the priority it will receive some random number. can anyone tell me what mistake i have done?

Queue Communication not working

Posted by davedoors on October 4, 2016

xQueueCreate( 2, sizeof(unsigned int) );

This creates a queue where each space can hold 1 unsigned int, so

xQueueSendToBack(xQueue, &data, 0);

sends one unsigned int, not two. Plus you are sending the address of the array not the array contents. Change '&data' to just 'data' in both the xQueueReceive and xQueueSendToBack calls.

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

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists