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




Loading

Queue losing data

Posted by keith soldavin on November 5, 2009
I am having a problem with a Queue losing the first item stored in it. I am using version 5.4.2 with the dsPIC port. Here is a basic description of my setup. I have a sensor that is transmitting 4304 bytes of data every 5 seconds over a RS-232 port at 57.6k. I have a task that calls SerGetc() to pull a byte from the queue. The byte is then placed in an array. When the array is full I would normally do some analysis.
The first 4304 bytes that are sent are stored correctly and the data looks good. Every data transfer after that is always missing the first byte of data. I have verified that the data is coming over the serial port and is being picked up by the RX ISR. For some reason it is being lost in the queue. Any thoughts? I am out of ideas.
Here is the relevant code:


//This is how I am creating the task and the Queue. They are pulled from my MAIN
xTaskCreate(vSerial_StoreData,( signed portCHAR * )"store data", 1000, NULL, 1, NULL);// Create the task
xSerialDataIn_1_Queue = xQueueCreate(1000, sizeof(int8));// Create a receiver Queue for serial 1



//Serial pot 1 receive ISR
void __attribute__((__interrupt__, auto_psv)) _U1RXInterrupt(void)
{
static uint8 newCh = 0;
static uint8init = 0;
static uint8output = 0;
static uint16index = 0;
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
static portBASE_TYPE result_send;
static portBASE_TYPE result_peek;

IFS0bits.U1RXIF = 0;// Clear the interupt flag

while( U1STAbits.URXDA == 1 )
{
newCh = U1RXREG;
result_send = xQueueSendToBackFromISR( xSerialDataIn_1_Queue, &newCh, &xHigherPriorityTaskWoken );
}

if( xHigherPriorityTaskWoken != pdFALSE )
{
taskYIELD();
}
}

//Gets a single char from Serial port 1. The function will wait, and yield, until a char is available
void Ser1RxGetc(int8 *pc)
{
int8 data = 0;

while (xQueueReceive(xSerialDataIn_1_Queue, &data, 0) == errQUEUE_EMPTY)
taskYIELD();

*pc = data;
}


void vSerial_StoreData (void *pvParameters)
{
uint8data = 0;// Current data byte
uint16index = 0;// Byte number received
uint16count = 0;
uint16 result = 0;

while (1)
{

Ser1RxGetc((int8*)&data);// Grab the data
dataRead[index] = data;// Store the data

if (index < 4304)
{
index++;// Increment the counter
}

else
{
index = 0;// I place break points at thses locations to look at the data
if (count == 0)
result ++;
if (count == 1)
result ++;
if (count == 2)
result ++;

count++;
memset(&dataRead, 0x00, sizeof(dataRead));// Clear the read buffer
}
}
}

RE: Queue losing data

Posted by MEdwards on November 5, 2009
A couple of comments.

I don't understand what the memset is doing. Is it supposed to be clearing the whole array each time a char is received?

Your code is polling xSerialDataIn_1_Queue and yielding when it has no data. Why not just block on the queue?

If you know how many chars are coming then it would be more efficient to simply place the chars in the array in the interrupt, then use a semaphore to unblock a task to process the array.


RE: Queue losing data

Posted by keith soldavin on November 5, 2009
Thanks for your comments.
The code I provided is just some test code to try to find this problem. The memset clears the data array after the 4304 characters have been received to get it ready for the next batch of data.

Originally I was blocking on the queue. I tried it this way just to see if it would fix the problem...it didn't. Both methods had the same problem.

It would be more efficient to just store the data in an array but this is just a small portion of the entire system. Other portions of the system dictate I do it this way.

Keith


[ 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