/* Receive a byte from USART/LEUART and put into global buffer.  */
int RETARGET_ReadChar(void)
/* Receive a byte from USART/LEUART and put into global buffer.  */
int RETARGET_ReadChar(void)
{
  int c = -1;
  CORE_DECLARE_IRQ_STATE;
  if (initialized == false)
  {
    RETARGET_SerialInit();
  }
  CORE_ENTER_ATOMIC();
  if (rxCount > 0)
  {
    c = rxBuffer[rxReadIndex];
    rxReadIndex++;
    if (rxReadIndex == RXBUFSIZE)
    {
      rxReadIndex = 0;
    }
    rxCount--;
  }
  CORE_EXIT_ATOMIC();
  return c;
}