Hi to all!
I’m a newbe to FreeRTOS and I have a problem with my first example. I’m using FreeRTOS on ATmega2560.
I tryng to run a simple program that receive a char from the serial and send the same char back.
I have done a program for do this, but when i connect the serial terminal, i receive some values of 0xf0 even if I write nothing. The values of 0xf0 depend of the size of the queues that i using in my program. I use two queues of the same size, one for the rx side and one for the tx side of the serial.
This is my main task, in this task I reading the rx queue and if there is an item, i put this item into the tx queue and after i start the tx interrupt:
`static void vTestSerial( void *pvParameters ){
/* The parameters are not used. */
( void ) pvParameters;
uint8_t tmp;
/* Cycle for ever, delaying then checking all the other tasks are still
operating without error. */
for( ;; )
{
/* Wait for the maximum period for data to become available on the queue.
The period will be indefinite if INCLUDE_vTaskSuspend is set to 1 in
FreeRTOSConfig.h. */
if( xQueueReceive( xRxedChars, &tmp, 0 ) != pdPASS )
{
/* Nothing was received from the queue – even after blocking to wait
for data to arrive. */
}
else
{
/* tmp now contains the received data. */
/* Send the message to the queue, waiting for 10 ticks for space to become
available if the queue is already full. */
if( xQueueSend( xCharsForTx, &tmp, 0 ) != pdPASS )
{
/* Data could not be sent to the queue even after waiting 10 ticks. */
}
else{
START_SERIAL_TX;
}
}
}
}
`
and this are the interrupt routines:
SIGNAL( USART0_RX_vect ){
uint8_t cChar;
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
/* Get the character and post it on the queue of Rxed characters.
If the post causes a task to wake force a context switch as the woken task
may have a higher priority than the task we have interrupted. */
cChar = GET_CHAR;
xQueueSendFromISR( xRxedChars, &cChar, &xHigherPriorityTaskWoken );
if( xHigherPriorityTaskWoken != pdFALSE )
{
taskYIELD();
}
}
/*-----------------------------------------------------------*/
SIGNAL( USART0_UDRE_vect ){
uint8_t cChar;
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
if( xQueueReceiveFromISR( xCharsForTx, &cChar, &xHigherPriorityTaskWoken ) == pdTRUE ){
/* Send the next character queued for Tx. */
PUT_CHAR( cChar );
}
else
{
/* Queue empty, nothing to send. */
STOP_SERIAL_TX;
}
}
I have adapted this code from the demo in the AVR328 folder.
Can anyone tell me where am I wrong?