All of the underlying stdin reads come down to the following function provided by the CW Processor Expert (see below). In this function it is blocking on the while /* Wait until a char is received */. I replaced the while loop with a break; and I am able to use stdin reads of 1 char at a time. I'm not sure how to instruct the processor expert to generate the function as nonblocking.
/*
** ===================================================================
** Method : CsIO1___read_console (component ConsoleIO)
**
** Description :
** __read_console
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
int __read_console(__file_handle handle, unsigned char* buffer, size_t * count)
{
size_t CharCnt = 0x00;
(void)handle; /* Parameter is not used, suppress unused argument warning */
for (;*count > 0x00; --*count) {
/* Clear error flags */
UART0_PDD_ClearInterruptFlags(UART0_BASE_PTR,0x1FU);
if ((UART0_PDD_ReadInterruptStatusReg(UART0_BASE_PTR) & UART0_S1_RDRF_MASK) == 0x00) { /* Any data in receiver buffer */
// MWS 10-11-2013 -- if no data is here, simply return instead of blocking on data
break;
if (CharCnt != 0x00) { /* No, at least one char received? */
break; /* Yes, return received char(s) */
} else { /* Wait until a char is received */
while ((UART0_PDD_ReadInterruptStatusReg(UART0_BASE_PTR) & UART0_S1_RDRF_MASK) == 0x00) {};
}
}
CharCnt++; /* Increase char counter */
/* Save character received by UARTx device into the receive buffer */
*buffer = (unsigned char)UART0_PDD_GetChar8(UART0_BASE_PTR);
/* Stop reading if CR (Ox0D) character is received */
if (*buffer == 0x0DU) { /* New line character (CR) received ? */
*buffer = '\n'; /* Yes, convert LF to '\n' char. */
break; /* Stop loop and return received char(s) */
}
buffer++; /* Increase buffer pointer */
}
*count = CharCnt;
return (__no_io_error);
}