serial.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. extern char rt_keyboard_getc(void);
  19. /**
  20. * @addtogroup QEMU
  21. */
  22. /*@{*/
  23. /**
  24. * This function initializes serial
  25. */
  26. void rt_serial_init(void)
  27. {
  28. outb(COM1+3,0x80); /* set DLAB of line control reg */
  29. outb(COM1,0x0c); /* LS of divisor (48 -> 2400 bps */
  30. outb(COM1+1,0x00); /* MS of divisor */
  31. outb(COM1+3,0x03); /* reset DLAB */
  32. outb(COM1+4,0x0b); /* set DTR,RTS, OUT_2 */
  33. outb(COM1+1,0x0d); /* enable all intrs but writes */
  34. inb(COM1); /* read data port to reset things (?) */
  35. }
  36. /**
  37. * This function read a character from serial without interrupt enable mode
  38. *
  39. * @return the read char
  40. */
  41. char rt_serial_getc(void)
  42. {
  43. return rt_keyboard_getc();
  44. #if 0
  45. while(!(inb(COM1+COMSTATUS) & COMDATA));
  46. return inb(COM1+COMREAD);
  47. #endif
  48. }
  49. /**
  50. * This function will write a character to serial without interrupt enable mode
  51. *
  52. * @param c the char to write
  53. */
  54. void rt_serial_putc(const char c)
  55. {
  56. int val;
  57. while(1)
  58. {
  59. if ((val = inb(COM1+COMSTATUS)) & THRE)
  60. break;
  61. }
  62. outb(COM1+COMWRITE, c&0xff);
  63. }
  64. /*@}*/