Input and output operations are made by a program running on the processor.
Disadvantage: Inefficient - too much polling for general use. Interrupt driven I/O is more efficient.
//Macro definitions for C preprocessor //Enable a C program to access a hardware //UART using PIO or interrupts. #define IO_BASE 0xFFFC1000 // or whatever | The receiver spins
until the empty flag in the status register goes away. Reading the
data register makes the status register go empty again. The actual
hardware device might have a receive FIFO, so instead of going empty,
the next character from the FIFO would become available straightaway:
char uart_polled_read() { while (UART_STATUS() & UART_STATUS_RX_EMPTY) continue; return UART_RECEIVE(); }The output function is exactly the same in principle, except it spins while the device is still busy with any data written previously: uart_polled_write(char d) { while (!(UART_STATUS() & UART_STATUS_TX_EMPTY)) continue; UART_SEND() = d; } |
12: (C) 2008-13, DJ Greaves, University of Cambridge, Computer Laboratory. |