console.c 974 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include <stddef.h>
  2. #include <stdint.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <stdarg.h>
  6. #include "fw.h"
  7. #include "console.h"
  8. #include "io.h"
  9. static __always_inline void __con_putc(char c)
  10. {
  11. /*
  12. * Wait for FIFO space IF DTR is asserted (otherwise there might
  13. * not be anyone listening...
  14. */
  15. while (CON_FLOW_CTL &&
  16. (CON_STATUS & (TTY_STATUS_TX_HIGH|TTY_STATUS_DTR_IN))
  17. == (TTY_STATUS_TX_HIGH|TTY_STATUS_DTR_IN))
  18. pause();
  19. if (c == '\n')
  20. CON_DATA = '\r';
  21. CON_DATA = c;
  22. }
  23. void __hot con_putc(char c)
  24. {
  25. __con_putc(c);
  26. }
  27. void __hot con_puts(const char *str)
  28. {
  29. while (*str)
  30. __con_putc(*str++);
  31. }
  32. void con_vprintf(const char *fmt, va_list ap)
  33. {
  34. char buf[128]; /* Maximum text size */
  35. unsigned int len;
  36. const char *p;
  37. vsnprintf(buf, sizeof buf, fmt, ap);
  38. con_puts(buf);
  39. }
  40. void con_printf(const char *fmt, ...)
  41. {
  42. va_list ap;
  43. va_start(ap, fmt);
  44. con_vprintf(fmt, ap);
  45. va_end(ap);
  46. }