console.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <stddef.h>
  2. #include <stdint.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <stdarg.h>
  6. #include "console.h"
  7. #include "io.h"
  8. void con_set_baudrate(uint32_t b)
  9. {
  10. uint32_t bauddiv;
  11. /*
  12. * Produce a CON_BAUD_BITS binary fraction. The +1 produces better
  13. * rounding behavior: see Hacker's Delight.
  14. */
  15. bauddiv = (b * ((1ULL << (32+CON_BAUD_BITS))/CON_BAUD_BASE+1)) >> 32;
  16. /*
  17. * Not really a divisor, but a fractional multiplier. The -1
  18. * is simply a technicality of the implementation.
  19. */
  20. CON_BAUDDIV = bauddiv - 1;
  21. }
  22. void con_putc(char c)
  23. {
  24. CONSOLE = c;
  25. udelay(10);
  26. }
  27. void 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. }