void serial_cfg_baudrate(unsigned short com, unsigned short divisor) { /* * Tell the serial controller that we are about to * set the divisor of the baudrate. This is done * by writing to the data register and interrupt * enabling register. These two bytes will hold the * divisor data WHILE the DLAB bit is set. */ outb(SERIAL_LINE_CMD_PORT(com), SERIAL_LINE_ENABLE_DLAB); outb(SERIAL_DATA_PORT(com), (divisor >> 8) & 0x00FF); outb(SERIAL_DATA_PORT(com), divisor & 0x00FF); outb(SERIAL_LINE_CMD_PORT(com), 0x0); }
int serial_write(char *buf, unsigned short com) { serial_configure_baud_rate(com, 2); serial_configure_line(com); while(*buf != 0) { if((serial_is_transmit_fifo_empty(com) & 0x20) == 0x00) continue; outb(SERIAL_DATA_PORT(com), *buf); buf++; } return currPos; }
void sprint(uint8_t* buf, uint16_t len){ if(is_configured == 1){ serial_configure_bit_rate(SERIAL_COM1_BASE, 1); serial_configure_line(SERIAL_COM1_BASE); serial_configure_fifo(SERIAL_COM1_BASE); serial_configure_modem(SERIAL_COM1_BASE); is_configured = 1; } for(unsigned int i = 0; i < len; i++){ while(serial_is_transmit_fifo_empty(SERIAL_COM1_BASE) == 0); outb(SERIAL_DATA_PORT(SERIAL_COM1_BASE), buf[i]); } }
void serial_write(char * buf, int len) { int burst_length = (len < 14) ? len : 14; int i = 0; while (burst_length) { while (!serial_is_transmit_fifo_empty(SERIAL_COM1_BASE)) {}; for (i = 0; i < burst_length; ++i) { outb(SERIAL_DATA_PORT(SERIAL_COM1_BASE), *(buf + i)); } buf += burst_length; len -= burst_length; burst_length = (len < 14) ? len : 14; } }
/** serial_configure_baud_rate: * Sets the speed of the data being sent. The default speed of a serial * port is 115200 bits/s. The argument is a divisor of that number, hence * the resulting speed becomes (115200 / divisor) bits/s * * @param com The COM port to configure * @param divisor The divisor */ void serial_configure_baud_rate(unsigned short com, unsigned short divisor) { outb(SERIAL_LINE_COMMAND_PORT(com), SERIAL_LINE_ENABLE_DLAB); outb(SERIAL_DATA_PORT(com), (divisor >> 8) & 0x00FF); outb(SERIAL_DATA_PORT(com), (divisor & 0x00FF)); }
void serial_configure_bit_rate(uint16_t com, uint16_t divisor){ outb(SERIAL_LINE_COMMAND_PORT(com), SERIAL_LINE_ENABLE_DLAB); outb(SERIAL_DATA_PORT(com), (divisor >> 8) & 0x00FF); outb(SERIAL_DATA_PORT(com), divisor & 0x00FF); }