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

Function uart_write

core/uart.c:371–452  ·  view source on GitHub ↗

Write to the 0xE000 range of ports */

Source from the content-addressed store, hash-verified

369
370/* Write to the 0xE000 range of ports */
371static void uart_write(const uint16_t pio, const uint8_t byte, bool poke) {
372 (void)poke;
373 switch (pio) {
374 case 0x00:
375 if (unlikely(uart.lcr >> 7 & 1)) {
376 uart.divisor &= ~0xFF;
377 uart.divisor |= byte;
378 uart_set_timer(true);
379 } else {
380 /* FIFO write */
381 if (uart.tfve != (uart_fifo_enabled() ? UART_FIFO_DEPTH : 1)) {
382 uart.txfifo[(uart.tfvi + uart.tfve++) & (UART_FIFO_DEPTH - 1)] = byte;
383 uart.lsr &= ~(1 << 6 | 1 << 5);
384 uart.isr &= ~(1 << 1);
385 if (!likely(uart.txActive)) {
386 uart_next_transmit();
387 uart.txActive = true;
388 uart_set_timer(true);
389 }
390 intrpt_set(INT_UART, uart.ier & uart.isr);
391 }
392 }
393 break;
394 case 0x04:
395 if (unlikely(uart.lcr >> 7 & 1)) {
396 uart.divisor &= ~(0xFF << 8);
397 uart.divisor |= byte << 8;
398 uart_set_timer(true);
399 }
400 else {
401 uart.ier = byte;
402 intrpt_set(INT_UART, uart.ier & uart.isr);
403 }
404 break;
405 case 0x08: {
406 const uint8_t diff = uart.fcr ^ byte;
407 uart.fcr = byte & ~(1 << 2 | 1 << 1);
408 if (diff & (1 << 2 | 1 << 0)) {
409 /* Clear TX FIFO */
410 uart.tfvi = uart.tfve = 0;
411 uart.isr |= 1 << 1;
412 uart.lsr |= (1 << 6 | 1 << 5);
413 uart.lsr &= ~(uart.txActive << 6);
414 }
415 if (diff & (1 << 1 | 1 << 0)) {
416 /* Clear RX FIFO */
417 memset(&uart.rxstat, 0, sizeof(uart.rxstat));
418 uart.rfvi = uart.rfve = uart.rxstatCount = 0;
419 uart.lsr &= ~(1 << 7 | 1 << 0);
420 uart_reset_rx_timeout();
421 }
422 uart_update_rxfifo_trigger();
423 intrpt_set(INT_UART, uart.ier & uart.isr);
424 break;
425 }
426 case 0x0C: {
427 uint8_t lcrDiff = uart.lcr ^ byte;
428 uart.lcr = byte;

Callers

nothing calls this directly

Calls 8

uart_set_timerFunction · 0.85
uart_fifo_enabledFunction · 0.85
uart_next_transmitFunction · 0.85
intrpt_setFunction · 0.85
uart_reset_rx_timeoutFunction · 0.85
uart_get_modem_inputsFunction · 0.85
uart_set_device_funcsFunction · 0.85

Tested by

no test coverage detected