User manual

LPCXpresso Experiment Kit - User’s Guide
Page 110
Copyright 2013 © Embedded Artists AB
uint32_t tmpHead;
//calculate head index
tmpHead = (txHead + 1) & TX_BUFFER_MASK;
//wait for free space in buffer
while(tmpHead == txTail)
;
//disable TX IRQ
LPC_UART->IER &= ~IER_THRE;
if(txRunning == TRUE)
{
txBuf[tmpHead] = toSend;
txHead = tmpHead;
}
else
{
txRunning = TRUE;
/* Extra check - should not be needed: THRE status, contain valid data */
while ( !(LPC_UART->LSR & LSR_THRE) )
;
LPC_UART->THR = toSend;
}
//enable TX IRQ
LPC_UART->IER |= IER_THRE;
}
/*****************************************************************************
** Function name: UARTGetCharBlock
**
** Descriptions: Receive a char from UART 0
**
** parameters: None
** Returned value: Received char
**
*****************************************************************************/
uint8_t UARTGetCharBlock(void)
{
//exercise to implement this function...
}
/*****************************************************************************
** Function name: UARTGetChar
**
** Descriptions: Receive a char from UART 0
**
** parameters: pointer to where to store received char
** Returned value: TRUE if char received, else FALSE
**
*****************************************************************************/
uint8_t UARTGetChar(uint8_t *pRxChar)
{
uint32_t tmpTail;
/* check if buffer is empty */
if(rxHead == rxTail)
return FALSE;
tmpTail = (rxTail + 1) & RX_BUFFER_MASK;
rxTail = tmpTail;
*pRxChar = rxBuf[tmpTail];
return TRUE;
}