Quality RTOS & Embedded Software

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


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