serial.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2006-09-15 QiuYi the first version
  9. * 2006-10-10 Bernard use keyboard instead of serial
  10. */
  11. #include <rtthread.h>
  12. #include <rthw.h>
  13. #include <bsp.h>
  14. /**
  15. * @addtogroup QEMU
  16. */
  17. /*@{*/
  18. /**
  19. * This function initializes serial
  20. */
  21. void rt_serial_init(void)
  22. {
  23. outb(COM1+3,0x80); /* set DLAB of line control reg */
  24. outb(COM1,0x0c); /* LS of divisor (48 -> 2400 bps */
  25. outb(COM1+1,0x00); /* MS of divisor */
  26. outb(COM1+3,0x03); /* reset DLAB */
  27. outb(COM1+4,0x0b); /* set DTR,RTS, OUT_2 */
  28. outb(COM1+1,0x0d); /* enable all intrs but writes */
  29. inb(COM1); /* read data port to reset things (?) */
  30. }
  31. /**
  32. * This function read a character from serial without interrupt enable mode
  33. *
  34. * @return the read char
  35. */
  36. char rt_serial_getc(void)
  37. {
  38. while(!(inb(COM1+COMSTATUS) & COMDATA));
  39. return inb(COM1+COMREAD);
  40. }
  41. /**
  42. * This function will write a character to serial without interrupt enable mode
  43. *
  44. * @param c the char to write
  45. */
  46. void rt_serial_putc(const char c)
  47. {
  48. int val;
  49. while(1)
  50. {
  51. if ((val = inb(COM1+COMSTATUS)) & THRE)
  52. break;
  53. }
  54. outb(COM1+COMWRITE, c&0xff);
  55. }
  56. /*@}*/