You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

serial.c 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (C) 2004 Tobias Lorenz
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include "etherboot.h"
  9. #include "hardware.h"
  10. #ifdef CONSOLE_SERIAL
  11. /*
  12. * void serial_putc(int ch);
  13. * Write character `ch' to port UART_BASE.
  14. */
  15. void serial_putc(int ch)
  16. {
  17. /* wait for room in the 32 byte tx FIFO */
  18. while ((P2001_UART->r.STATUS & 0x3f) > /* 30 */ 0) ;
  19. P2001_UART->w.TX1 = ch & 0xff;
  20. }
  21. /*
  22. * int serial_getc(void);
  23. * Read a character from port UART_BASE.
  24. */
  25. int serial_getc(void)
  26. {
  27. while (((P2001_UART->r.STATUS >> 6) & 0x3f) == 0) ;
  28. return P2001_UART->r.RX1 & 0xff;
  29. }
  30. /*
  31. * int serial_ischar(void);
  32. * If there is a character in the input buffer of port UART_BASE,
  33. * return nonzero; otherwise return 0.
  34. */
  35. int serial_ischar(void)
  36. {
  37. return (P2001_UART->r.STATUS >> 6) & 0x3f;
  38. }
  39. /*
  40. * int serial_init(void);
  41. * Initialize port to speed 57.600, line settings 8N1.
  42. */
  43. int serial_init(void)
  44. {
  45. static unsigned int N;
  46. // const M=3
  47. P2001_UART->w.Clear = 0; // clear
  48. N = ((SYSCLK/8)*3)/CONSPEED;
  49. P2001_UART->w.Baudrate = (N<<16)+3; // set 57.600 BAUD
  50. P2001_UART->w.Config = 0xcc100; // set 8N1, *water = 12
  51. return 1;
  52. }
  53. /*
  54. * void serial_fini(void);
  55. * Cleanup our use of the serial port, in particular flush the
  56. * output buffer so we don't accidentially loose characters.
  57. */
  58. void serial_fini(void)
  59. {
  60. }
  61. #endif