Quality RTOS & Embedded Software

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


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 ]    [ Privacy ]    [ Sitemap ]    [ ]


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

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 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.


Careers

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

Renesas

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