serial.c 1.4 KB

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