console.c 816 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. /* Wait for FIFO space */
  12. while (CON_FLOW_CTL && (CON_STATUS & CON_STATUS_TX_HIGH))
  13. pause();
  14. if (c == '\n')
  15. CON_DATA = '\r';
  16. CON_DATA = c;
  17. }
  18. void __hot con_putc(char c)
  19. {
  20. __con_putc(c);
  21. }
  22. void __hot con_puts(const char *str)
  23. {
  24. while (*str)
  25. __con_putc(*str++);
  26. }
  27. void con_vprintf(const char *fmt, va_list ap)
  28. {
  29. char buf[128]; /* Maximum text size */
  30. unsigned int len;
  31. const char *p;
  32. vsnprintf(buf, sizeof buf, fmt, ap);
  33. con_puts(buf);
  34. }
  35. void con_printf(const char *fmt, ...)
  36. {
  37. va_list ap;
  38. va_start(ap, fmt);
  39. con_vprintf(fmt, ap);
  40. va_end(ap);
  41. }