2
0

console.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #ifndef CONSOLE_H
  2. #define CONSOLE_H
  3. #include "compiler.h"
  4. #include "io.h"
  5. #define CON_FLOW_CTL 0 /* Block on connected and output full? */
  6. #define CON_OUT_OF_LINE 0
  7. #define CON_DELAY 0 /* us delay after output */
  8. void __fmt_printf(1,0) con_vprintf(const char *, va_list);
  9. void __fmt_printf(1,2) con_printf(const char *, ...);
  10. static __always_inline void __con_wait_tx_ready(void)
  11. {
  12. /*
  13. * If CON_FLOW_CTL is set, wait here if the TX buffer is above
  14. * the high index mark *if* we are connected to a host
  15. */
  16. while (CON_FLOW_CTL &&
  17. (CON_STATUS & (TTY_STATUS_TX_HIGH|TTY_STATUS_DTR_IN))
  18. == (TTY_STATUS_TX_HIGH|TTY_STATUS_DTR_IN))
  19. relax();
  20. }
  21. static __always_inline void __con_putc(char c)
  22. {
  23. if (c == '\n') {
  24. CON_DATA = '\r';
  25. udelay(CON_DELAY);
  26. }
  27. CON_DATA = c;
  28. udelay(CON_DELAY);
  29. }
  30. static __always_inline void _con_putc(char c)
  31. {
  32. __con_wait_tx_ready();
  33. __con_putc(c);
  34. }
  35. static __always_inline void _con_puts(const char *str)
  36. {
  37. char c;
  38. __con_wait_tx_ready();
  39. while ((c = *str++))
  40. __con_putc(c);
  41. }
  42. #if CON_OUT_OF_LINE
  43. void con_putc(char c);
  44. void con_puts(const char *);
  45. #else
  46. /* Simple enough to inline if we don't care about flow control */
  47. static __always_inline void con_putc(char c)
  48. {
  49. _con_putc(c);
  50. }
  51. static __always_inline void con_puts(const char *str)
  52. {
  53. _con_puts(str);
  54. }
  55. #endif
  56. static __always_inline void con_flush_unconditional(void)
  57. {
  58. while (!(CON_STATUS & TTY_STATUS_TX_EMPTY))
  59. relax();
  60. }
  61. static __always_inline void con_flush(void)
  62. {
  63. if (CON_FLOW_CTL)
  64. con_flush_unconditional();
  65. }
  66. void con_print_hex(unsigned int); /* For pre-SDRAM capable code */
  67. void con_hexdump(const void *data, size_t len); /* For debugging */
  68. #endif /* CONSOLE_H */