int serialGetAttributes (SerialDevice *serial, SerialAttributes *attributes) { int interruptsWereEnabled = disable(); unsigned char lcr = serialReadPort(serial, UART_PORT_LCR); int divisor; serialWritePort(serial, UART_PORT_LCR, lcr | UART_FLAG_LCR_DLAB); divisor = (serialReadPort(serial, UART_PORT_DLH) << 8) | serialReadPort(serial, UART_PORT_DLL); serialWritePort(serial, UART_PORT_LCR, lcr); if (interruptsWereEnabled) enable(); attributes->bios.byte = lcr; { const SerialBaudEntry *baud = serialGetBaudEntry(SERIAL_DIVISOR_BASE/divisor); if (baud) { attributes->speed = baud->speed; } else { memset(&attributes->speed, 0, sizeof(attributes->speed)); } } attributes->bios.fields.bps = attributes->speed.biosBPS; return 1; }
int serialGetAttributes (SerialDevice *serial, SerialAttributes *attributes) { unsigned char lcr; int divisor; { int wasEnabled = disable(); lcr = serialReadPort(serial, UART_PORT_LCR); serialWritePort(serial, UART_PORT_LCR, (lcr | UART_FLAG_LCR_DLAB)); divisor = (serialReadPort(serial, UART_PORT_DLH) << 8) | serialReadPort(serial, UART_PORT_DLL); serialWritePort(serial, UART_PORT_LCR, lcr); if (wasEnabled) enable(); } attributes->bios.byte = lcr; { const SerialBaudEntry *baud = serialGetBaudEntry(SERIAL_DIVISOR_BASE/divisor); if (baud) { attributes->speed = baud->speed; } else { logMessage(LOG_WARNING, "unsupported serial divisor: %d", divisor); memset(&attributes->speed, 0, sizeof(attributes->speed)); } } attributes->bios.fields.bps = attributes->speed.bps; return 1; }
int serialPutLines (SerialDevice *serial, SerialLines high, SerialLines low) { int interruptsWereEnabled = disable(); unsigned char oldMCR = serialReadPort(serial, UART_PORT_MCR); serialWritePort(serial, UART_PORT_MCR, (oldMCR | high) & ~low); if (interruptsWereEnabled) enable(); return 1; }
int serialGetLines (SerialDevice *serial) { serial->linesState = serialReadPort(serial, UART_PORT_MSR) & 0XF0; return 1; }