misc.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Unlicense OR CC0-1.0
  5. */
  6. #include "esp_peripheral.h"
  7. /**
  8. * Utility function to log an array of bytes.
  9. */
  10. void
  11. print_bytes(const uint8_t *bytes, int len)
  12. {
  13. int i;
  14. for (i = 0; i < len; i++) {
  15. MODLOG_DFLT(INFO, "%s0x%02x", i != 0 ? ":" : "", bytes[i]);
  16. }
  17. }
  18. void
  19. print_addr(const void *addr)
  20. {
  21. const uint8_t *u8p;
  22. u8p = addr;
  23. MODLOG_DFLT(INFO, "%02x:%02x:%02x:%02x:%02x:%02x",
  24. u8p[5], u8p[4], u8p[3], u8p[2], u8p[1], u8p[0]);
  25. }
  26. char *
  27. addr_str(const void *addr)
  28. {
  29. static char buf[6 * 2 + 5 + 1];
  30. const uint8_t *u8p;
  31. u8p = addr;
  32. sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
  33. u8p[5], u8p[4], u8p[3], u8p[2], u8p[1], u8p[0]);
  34. return buf;
  35. }
  36. void
  37. print_mbuf(const struct os_mbuf *om)
  38. {
  39. int colon, i;
  40. colon = 0;
  41. while (om != NULL) {
  42. if (colon) {
  43. MODLOG_DFLT(DEBUG, ":");
  44. } else {
  45. colon = 1;
  46. }
  47. for (i = 0; i < om->om_len; i++) {
  48. MODLOG_DFLT(DEBUG, "%s0x%02x", i != 0 ? ":" : "", om->om_data[i]);
  49. }
  50. om = SLIST_NEXT(om, om_next);
  51. }
  52. }