serial.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. return rt_keyboard_getc();
  43. #if 0
  44. while(!(inb(COM1+COMSTATUS) & COMDATA));
  45. return inb(COM1+COMREAD);
  46. #endif
  47. }
  48. /**
  49. * This function will write a character to serial without interrupt enable mode
  50. *
  51. * @param c the char to write
  52. */
  53. void rt_serial_putc(const char c)
  54. {
  55. int val;
  56. while(1)
  57. {
  58. if ((val = inb(COM1+COMSTATUS)) & THRE)
  59. break;
  60. }
  61. outb(COM1+COMWRITE, c&0xff);
  62. }
  63. /*@}*/