MCPcopy Create free account
hub / github.com/CE-Programming/CEmu / uart_read

Function uart_read

core/uart.c:256–368  ·  view source on GitHub ↗

Read from the 0xE000 range of ports */

Source from the content-addressed store, hash-verified

254
255/* Read from the 0xE000 range of ports */
256static uint8_t uart_read(const uint16_t pio, bool peek) {
257 uint8_t value;
258
259 switch (pio) {
260 case 0x00:
261 if (uart.lcr >> 7 & 1) {
262 value = uart.divisor & 0xFF;
263 } else if (uart.rfve) {
264 /* FIFO read */
265 size_t index = uart.rfvi & (UART_FIFO_DEPTH - 1);
266 value = uart.rxfifo[index];
267 if (!peek) {
268 /* Remove the error status tracking from the FIFO */
269 if (uart.rxstat[index]) {
270 if (--uart.rxstatCount == 0) {
271 uart.lsr &= ~(1 << 7);
272 }
273 }
274 uart.rfvi++;
275 if (--uart.rfve) {
276 /* Indicate error status from the next FIFO entry */
277 index = uart.rxstat[uart.rfvi & (UART_FIFO_DEPTH - 1)];
278 uart.lsr |= uart.rxstat[index];
279 uart.isr |= (uart.rxstat[index] != 0) << 2;
280 } else {
281 /* Indicate empty FIFO */
282 uart.lsr &= ~(1 << 0);
283 }
284 /* Reset the timeout status and interrupt based on the new FIFO state */
285 uart_reset_rx_timeout();
286 uart_update_rxfifo_trigger();
287 intrpt_set(INT_UART, uart.ier & uart.isr);
288 }
289 } else {
290 /* Empty FIFO */
291 value = 0;
292 }
293 break;
294 case 0x04:
295 if (uart.lcr >> 7 & 1) {
296 value = uart.divisor >> 8;
297 } else {
298 value = uart.ier;
299 }
300 break;
301 case 0x08:
302 /* Determine interrupt by priority */
303 value = uart.ier & uart.isr;
304 if (value >> 2 & 1) {
305 /* Receiver Line Status */
306 value = 6;
307 } else if (value >> 0 & 1) {
308 /* Received Data Available / Timeout */
309 value = 4 | uart.rxTimeout << 3;
310 } else if (value >> 1 & 1) {
311 /* Transmitter Holding Register Empty */
312 uart.isr &= ~(1 << 1);
313 intrpt_set(INT_UART, value & ~(1 << 1));

Callers

nothing calls this directly

Calls 5

uart_reset_rx_timeoutFunction · 0.85
intrpt_setFunction · 0.85
uart_fifo_enabledFunction · 0.85
uart_get_modem_inputsFunction · 0.85

Tested by

no test coverage detected