void dc_dbg_init() { #ifdef DBG_COM u32 divisor; u8 lcr; /* set baud rate and data format (8N1) */ /* turn on DTR and RTS */ WRITE_PORT_UCHAR(pv(SER_MCR(COM_BASE)), SR_MCR_DTR | SR_MCR_RTS); /* set DLAB */ lcr = READ_PORT_UCHAR(pv(SER_LCR(COM_BASE))) | SR_LCR_DLAB; WRITE_PORT_UCHAR(pv(SER_LCR(COM_BASE)), lcr); /* set baud rate */ divisor = 115200 / DEFAULT_BAUD_RATE; WRITE_PORT_UCHAR(pv(SER_DLL(COM_BASE)), divisor & 0xff); WRITE_PORT_UCHAR(pv(SER_DLM(COM_BASE)), (divisor >> 8) & 0xff); /* reset DLAB and set 8N1 format */ WRITE_PORT_UCHAR(pv(SER_LCR(COM_BASE)), SR_LCR_CS8 | SR_LCR_ST1 | SR_LCR_PNO); /* read junk out of the RBR */ READ_PORT_UCHAR(pv(SER_RBR(COM_BASE))); #endif /* DBG_COM */ #ifdef DBG_HAL_DISPLAY InbvAcquireDisplayOwnership(); InbvEnableDisplayString(TRUE); #endif /* DBG_HAL_DISPLAY */ }
NTSTATUS NTAPI SerialSetBaudRate( IN PSERIAL_DEVICE_EXTENSION DeviceExtension, IN ULONG NewBaudRate) { ULONG BaudRate; USHORT divisor; PUCHAR ComPortBase = ULongToPtr(DeviceExtension->BaseAddress); NTSTATUS Status = STATUS_SUCCESS; if (NewBaudRate == 0) return STATUS_INVALID_PARAMETER; divisor = (USHORT)(BAUD_CLOCK / (CLOCKS_PER_BIT * NewBaudRate)); BaudRate = BAUD_CLOCK / (CLOCKS_PER_BIT * divisor); Status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, ULongToPtr(DeviceExtension->ComPort)); if (NT_SUCCESS(Status)) { UCHAR Lcr; TRACE_(SERIAL, "SerialSetBaudRate(COM%lu, %lu Bauds)\n", DeviceExtension->ComPort, BaudRate); /* Set Bit 7 of LCR to expose baud registers */ Lcr = READ_PORT_UCHAR(SER_LCR(ComPortBase)); WRITE_PORT_UCHAR(SER_LCR(ComPortBase), Lcr | SR_LCR_DLAB); /* Write the baud rate */ WRITE_PORT_UCHAR(SER_DLL(ComPortBase), divisor & 0xff); WRITE_PORT_UCHAR(SER_DLM(ComPortBase), divisor >> 8); /* Switch back to normal registers */ WRITE_PORT_UCHAR(SER_LCR(ComPortBase), Lcr); IoReleaseRemoveLock(&DeviceExtension->RemoveLock, ULongToPtr(DeviceExtension->ComPort)); } if (NT_SUCCESS(Status)) DeviceExtension->BaudRate = BaudRate; return Status; }