ns16550.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * COM1 NS16550 support
  3. * originally from linux source (arch/ppc/boot/ns16550.c)
  4. * modified to use CFG_ISA_MEM and new defines
  5. */
  6. #include <config.h>
  7. #ifdef CFG_NS16550
  8. #include <ns16550.h>
  9. #define LCRVAL LCR_8N1 /* 8 data, 1 stop, no parity */
  10. #define MCRVAL (MCR_DTR | MCR_RTS) /* RTS/DTR */
  11. #define FCRVAL (FCR_FIFO_EN | FCR_RXSR | FCR_TXSR) /* Clear & enable FIFOs */
  12. void NS16550_init (NS16550_t com_port, int baud_divisor)
  13. {
  14. com_port->ier = 0x00;
  15. com_port->lcr = LCR_BKSE | LCRVAL;
  16. com_port->dll = baud_divisor & 0xff;
  17. com_port->dlm = (baud_divisor >> 8) & 0xff;
  18. com_port->lcr = LCRVAL;
  19. com_port->mcr = MCRVAL;
  20. com_port->fcr = FCRVAL;
  21. }
  22. void NS16550_reinit (NS16550_t com_port, int baud_divisor)
  23. {
  24. com_port->ier = 0x00;
  25. com_port->lcr = LCR_BKSE;
  26. com_port->dll = baud_divisor & 0xff;
  27. com_port->dlm = (baud_divisor >> 8) & 0xff;
  28. com_port->lcr = LCRVAL;
  29. com_port->mcr = MCRVAL;
  30. com_port->fcr = FCRVAL;
  31. }
  32. void NS16550_putc (NS16550_t com_port, char c)
  33. {
  34. while ((com_port->lsr & LSR_THRE) == 0);
  35. com_port->thr = c;
  36. }
  37. char NS16550_getc (NS16550_t com_port)
  38. {
  39. while ((com_port->lsr & LSR_DR) == 0);
  40. return (com_port->rbr);
  41. }
  42. int NS16550_tstc (NS16550_t com_port)
  43. {
  44. return ((com_port->lsr & LSR_DR) != 0);
  45. }
  46. #endif