serial.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * (C) Copyright 2000
  3. * Rob Taylor, Flying Pig Systems. robt@flyingpig.com.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #ifdef CFG_NS16550_SERIAL
  25. #include <ns16550.h>
  26. #ifdef CFG_NS87308
  27. #include <ns87308.h>
  28. #endif
  29. #if CONFIG_CONS_INDEX == 1
  30. static NS16550_t console = (NS16550_t) CFG_NS16550_COM1;
  31. #elif CONFIG_CONS_INDEX == 2
  32. static NS16550_t console = (NS16550_t) CFG_NS16550_COM2;
  33. #elif CONFIG_CONS_INDEX == 3
  34. static NS16550_t console = (NS16550_t) CFG_NS16550_COM3;
  35. #elif CONFIG_CONS_INDEX == 4
  36. static NS16550_t console = (NS16550_t) CFG_NS16550_COM4;
  37. #else
  38. #error no valid console defined
  39. #endif
  40. int serial_init (void)
  41. {
  42. DECLARE_GLOBAL_DATA_PTR;
  43. int clock_divisor = (CFG_NS16550_CLK + gd->baudrate * 8 )
  44. / (gd->baudrate * 16);
  45. #ifdef CFG_NS87308
  46. initialise_ns87308();
  47. #endif
  48. NS16550_init(console, clock_divisor);
  49. return (0);
  50. }
  51. void
  52. serial_putc(const char c)
  53. {
  54. if (c == '\n')
  55. NS16550_putc(console, '\r');
  56. NS16550_putc(console, c);
  57. }
  58. void
  59. serial_puts (const char *s)
  60. {
  61. while (*s) {
  62. serial_putc (*s++);
  63. }
  64. }
  65. int
  66. serial_getc(void)
  67. {
  68. return NS16550_getc(console);
  69. }
  70. int
  71. serial_tstc(void)
  72. {
  73. return NS16550_tstc(console);
  74. }
  75. void
  76. serial_setbrg (void)
  77. {
  78. DECLARE_GLOBAL_DATA_PTR;
  79. int clock_divisor = CFG_NS16550_CLK / 16 / gd->baudrate;
  80. NS16550_reinit(console, clock_divisor);
  81. }
  82. #endif