Exemplo n.º 1
0
int
serialPutAttributes (SerialDevice *serial, const SerialAttributes *attributes) {
  {
    if (attributes->speed.biosBPS <= 7) {
      if (bioscom(0, attributes->bios.byte, serial->package.deviceIndex) & 0X0700) {
        logMessage(LOG_ERR, "bioscom failed");
        return 0;
      }
    } else {
      int interruptsWereEnabled = disable();
      SerialBiosConfiguration lcr = attributes->bios;
      lcr.fields.bps = 0;

      serialWritePort(serial, UART_PORT_LCR,
                      lcr.byte | UART_FLAG_LCR_DLAB);
      serialWritePort(serial, UART_PORT_DLL,
                      attributes->speed.divisor & 0XFF);
      serialWritePort(serial, UART_PORT_DLH,
                      attributes->speed.divisor >> 8);
      serialWritePort(serial, UART_PORT_LCR, lcr.byte);

      if (interruptsWereEnabled) enable();
    }
  }

  return 1;
}
Exemplo n.º 2
0
int
serialPutAttributes (SerialDevice *serial, const SerialAttributes *attributes) {
  if (attributes->speed.bps < (0X1 << 3)) {
    unsigned char byte = attributes->bios.byte;

    logMessage(LOG_CATEGORY(SERIAL_IO), "put attributes: port=%d byte=0X%02X",
               serialGetPort(serial), byte);
    serialBiosCommand(serial, _COM_INIT, byte);
  } else {
    SerialBiosConfiguration lcr = attributes->bios;

    lcr.fields.bps = 0;
    logMessage(LOG_CATEGORY(SERIAL_IO), "put attributes: port=%d lcr=0X%02X divisor=%u",
               serialGetPort(serial), lcr.byte, attributes->speed.divisor);

    {
      int wasEnabled = disable();

      serialWritePort(serial, UART_PORT_LCR, (lcr.byte | UART_FLAG_LCR_DLAB));
      serialWritePort(serial, UART_PORT_DLL, (attributes->speed.divisor & 0XFF));
      serialWritePort(serial, UART_PORT_DLH, (attributes->speed.divisor >> 8));
      serialWritePort(serial, UART_PORT_LCR, lcr.byte);

      if (wasEnabled) enable();
    }
  }

  return 1;
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
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;
}