The C command to set the UART for an
outportb(BASEADDR +3, 0x03)
The final initialization step is to flush the receiver buffers. You do this with two reads from the receiver buffer at Base Address +0. When done, the UART is ready to use.
Reception
Reception can be handled in two ways: polling and
do
{
while (!(inportb(BASEADDR +5) & 1)); /*Wait until data ready*/ data[i++]= inportb(BASEADDR);
}
while (data[i]!=13); /*Reads the line until null character rec'd*/
The handler would first read the Interrupt Identification Register at Base Address +2. If the interrupt is for Received Data Available, the handler then reads the data. If no interrupt is pending, control exits the routine. A sample handler, written in C, is as follows:
readback = inportb(BASEADDR +2);
if (readback & 4) /*Readback will be set to 4 if data are available*/ data[i++]=inportb(BASEADDR);
outportb(0x20,0x20); /*Write EOI to 8259 Interrupt Controller*/ return;
Manual | Page |