11-37
ASYNCHRONOUS SERIAL I/O UNIT
until a character has been received from the serial port.
Parameters:
Unit Unit number of the serial port. 0 for SIO port 0,
1 for SIO port 1.
Returns:
BYTE Read from serial port, if zero an error occurred.
Assumptions:
REMAPCFG register has Expanded I/O space access enabled (ESE bit set).
The processor Port pin are initialized separately.
Syntax:
#define SIO_0 0
BYTE character;
character = SerialReadChar (SIO_0);
Real/Protected Mode
No changes required.
*****************************************************************************/
BYTE SerialReadChar(int Unit)
{
WORD ReceivePortAddr;
WORD StatusPortAddr;
WORD Status;
/* Set Port base, based on serial port used */
ReceivePortAddr = (Unit ? RBR1 : RBR0);
StatusPortAddr = (Unit ? LSR1 : LSR0);
// Status register is cleared after read, so we must save
// it’s value when read
while(!((Status=_GetEXRegByte(StatusPortAddr)) & SIO_RX_BUF_FULL))
if( Status & SIO_ERROR_BITS ) // Error Bit set then return NULL
{
return 0;
}
return _GetEXRegByte(ReceivePortAddr);
}/* SerialReadChar */
/*****************************************************************************