Trying to send data from xQueue to uart1

echel0n wrote on Thursday, 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.

[code]
  xIKSServerMessage xSMessage;

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

      for(i=0; xSMessage.data[i] !=0; i++) {
        uart1PutChar(xSMessage.data[i], 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;
}
[/code]

prithwee wrote on Thursday, 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.

echel0n wrote on Thursday, February 19, 2009:

It’s in my uart1ISR code

[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 ();
}
[/code]

echel0n wrote on Thursday, 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.

echel0n wrote on Thursday, 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 ???

edwards3 wrote on Thursday, February 19, 2009:

What tick frequency are you using? If its over 1000Hz then that code wont work.

echel0n wrote on Thursday, 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

echel0n wrote on Thursday, 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 …