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

Trying to send data from xQueue to uart1

Posted by echel0n on February 19, 2009
I've been successfull on getting data from uart1 then transfering it to my uIP task via xQueue and out through my ethernet port to my server and then receiving the response from the server back into my uIP task and then xQueue'd to my uart task but thats as far as I've gotten.

I've tried sending the data in the xQueue out to uart1 but it seems to be having issues. Could someone please look at my code and tell me whats wrong. The array of data that my xQueue variable holds is the exact hex I wanted so thats fine but it seems once I execute my uart1write function that it goes all to hell.


xIKSServerMessage xSMessage;

if(xIKSServerQueue != 0)
{
if( xQueueReceive( xIKSServerQueue, &xSMessage, ( portTickType ) 10 ) != pdFAIL )
{
int i;

for(i=0; xSMessage.data !=0; i++) {
uart1PutChar(xSMessage.data, xBlockTime);
}
}
}

signed portBASE_TYPE uart1PutChar (signed portCHAR cOutChar, portTickType xBlockTime)
{
signed portBASE_TYPE xReturn = 0;
char ch;
ch = cOutChar;

portENTER_CRITICAL ();
{
//
// Is there space to write directly to the UART?
//
if (*plTHREEmpty1 == (portLONG) pdTRUE)
{
*plTHREEmpty1 = pdFALSE;

U1THR = ch;
xReturn = pdPASS;
}
else
{
//
// We cannot write directly to the UART, so queue the character. Block for a maximum of
// xBlockTime if there is no space in the queue.
//

xReturn = xQueueSend (xTX1Queue, &cOutChar, xBlockTime);

//
// Depending on queue sizing and task prioritisation: While we were blocked waiting to post
// interrupts were not disabled. It is possible that the serial ISR has emptied the Tx queue,
// in which case we need to start the Tx off again.
//
if ((*plTHREEmpty1 == (portLONG) pdTRUE) && (xReturn == pdPASS))
{
xQueueReceive (xTX1Queue, &cOutChar, serNO_BLOCK);
*plTHREEmpty1 = pdFALSE;

U1THR = cOutChar;
}
}
}

portEXIT_CRITICAL ();

return xReturn;
}

RE: Trying to send data from xQueue to uart1

Posted by Prithwee on February 19, 2009

In the "else" part of "<if(*plTHREEmpty1 == (portLONG) pdTRUE>" you are checking for
"<if ((*plTHREEmpty1 == (portLONG) pdTRUE) && (xReturn == pdPASS)) >"

where is *plTHREEmpty1 = pdTRUE; ????

<xQueueReceive (xTX1Queue, &cOutChar, serNO_BLOCK)> statement is never going to reach.

Regards,
Prithwee.

RE: Trying to send data from xQueue to uart1

Posted by echel0n on February 19, 2009
It's in my uart1ISR code


lTHREEmpty1 = (portLONG) pdTRUE;
*pplTHREEmptyFlag = &lTHREEmpty1;
}

//
//
//
static void uart1ISR_Handler (void)
{
signed portCHAR cChar;
portBASE_TYPE higherPriorityTaskWoken = pdFALSE;

switch (U1IIR & serINTERRUPT_SOURCE_MASK)
{
//
// Not handling this, but clear the interrupt
//
case serSOURCE_ERROR :
{
cChar = U1LSR;
}
break;

//
// The THRE is empty. If there is another character in the Tx queue, send it now,
// otherwise, no more characters, so indicate THRE is available
//
case serSOURCE_THRE:
{
if (xQueueReceiveFromISR (xTX1Queue, &cChar, &higherPriorityTaskWoken) == pdPASS)
U1THR = cChar;
else
lTHREEmpty1 = pdTRUE;
}
break;

//
// A character was received. Place it in the queue of received characters
//
case serSOURCE_RX_TIMEOUT :
case serSOURCE_RX:
{
cChar = U1RBR;

xQueueSendFromISR (xRX1Queue, &cChar, &higherPriorityTaskWoken);
}
break;

default:
break;
}

VICVectAddr = (unsigned portLONG) 0;

if (higherPriorityTaskWoken)
portYIELD_FROM_ISR ();
}

void uart1ISR (void) __attribute__ ((naked));
void uart1ISR (void)
{
portSAVE_CONTEXT ();
uart1ISR_Handler ();
portRESTORE_CONTEXT ();
}

RE: Trying to send data from xQueue to uart1

Posted by echel0n on February 19, 2009
I should also mention that before it hits portENTER_CRITICAL() in my uartWrite routine that the value of cOutChar = 0x12 but once it reaches "if (*plTHREEmpty1 == (portLONG) pdTRUE)" the value of cOutChar = 0x06 so I'm lost at whats going on here.

RE: Trying to send data from xQueue to uart1

Posted by echel0n on February 19, 2009
Ok I think I may have figured the issue out but haven't got a solution yet.
Seems to me it's something to do with xBlockTime

const portTickType xBlockTime = ( portTickType ) 200 / portTICK_RATE_MS;

Any idea's or solutions ???

RE: Trying to send data from xQueue to uart1

Posted by MEdwards on February 19, 2009
What tick frequency are you using? If its over 1000Hz then that code wont work.

RE: Trying to send data from xQueue to uart1

Posted by echel0n on February 19, 2009
#define configCPU_CLOCK_HZ( ( unsigned portLONG ) 72000000 )/* =12Mhz xtal multiplied by 5 using the PLL. */
//#define configCPU_CLOCK_HZ( ( unsigned portLONG ) 60000000 )/* =12Mhz xtal multiplied by 5 using the PLL. */
//#define configCPU_CLOCK_HZ( ( unsigned portLONG ) 24000000 )/* =12Mhz xtal multiplied by 2 using the PLL. */
#define configTICK_RATE_HZ( ( portTickType ) 1000 )

those are in my freertosconfig.h file

RE: Trying to send data from xQueue to uart1

Posted by echel0n on February 19, 2009
It's just odd. Some times the data I send out uart1 gets to my other device and sometimes it doesn't.
Most times things just seem to stall ...


[ 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