GEX core repository.

debug.c 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // Created by MightyPork on 2017/11/04.
  3. //
  4. #include "platform.h"
  5. #include <reent.h>
  6. #if USE_DEBUG_UART
  7. // debug printf
  8. void _DO_PRINTF(const char *format, ...)
  9. {
  10. va_list args;
  11. int len;
  12. char dbg_buf[DBG_BUF_LEN];
  13. va_start(args, format);
  14. /*convert into string at buff[0] of length iw*/
  15. len = (int)fixup_vsnprintf(&dbg_buf[0], DBG_BUF_LEN, format, args);
  16. if (len >= DBG_BUF_LEN) {
  17. dbg_buf[DBG_BUF_LEN-1] = 0;
  18. len = DBG_BUF_LEN-1;
  19. }
  20. debug_write(dbg_buf, (uint16_t) len);
  21. va_end(args);
  22. }
  23. /**
  24. * Puts with fixed size (print to debug uart)
  25. * @param string - buffer to print
  26. * @param len - number of bytes to print
  27. */
  28. void PUTSN(const char *string, uint16_t len)
  29. {
  30. if (len == 0) len = (uint16_t) strlen(string);
  31. debug_write(string, len);
  32. }
  33. /**
  34. * Print a string to debug uart
  35. * @param string - string to print, zero-terminated
  36. * @return number of characters printed
  37. */
  38. void PUTS(const char *string)
  39. {
  40. size_t len = strlen(string);
  41. debug_write(string, (uint16_t) len);
  42. }
  43. #endif