fdebug.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright : (C) 2022 Phytium Information Technology, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is OPEN SOURCE software: you can redistribute it and/or modify it
  6. * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
  7. * either version 1.0 of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
  10. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. * See the Phytium Public License for more details.
  12. *
  13. *
  14. * FilePath: ft_debug.c
  15. * Date: 2021-04-25 16:44:23
  16. * LastEditTime: 2022-02-17 18:04:50
  17. * Description:  This files is for
  18. *
  19. * Modify History:
  20. * Ver   Who        Date         Changes
  21. * ----- ------     --------    --------------------------------------
  22. */
  23. #include "fdebug.h"
  24. #include "fprintf.h"
  25. #include "stdio.h"
  26. #define __is_print(ch) ((unsigned int)((ch) - ' ') < 127u - ' ')
  27. void FtDumpHexByte(const u8 *ptr, u32 buflen)
  28. {
  29. u8 *buf = (u8 *)ptr;
  30. fsize_t i, j;
  31. for (i = 0; i < buflen; i += 16)
  32. {
  33. printf("%p: ", ptr + i);
  34. for (j = 0; j < 16; j++)
  35. if (i + j < buflen)
  36. printf("%02X ", buf[i + j]);
  37. else
  38. printf(" ");
  39. printf(" ");
  40. for (j = 0; j < 16; j++)
  41. if (i + j < buflen)
  42. printf("%c", (char)(__is_print(buf[i + j]) ? buf[i + j] : '.'));
  43. printf("\r\n");
  44. }
  45. }
  46. void FtDumpHexByteDebug(const u8 *ptr, u32 buflen)
  47. {
  48. u8 *buf = (u8 *)ptr;
  49. fsize_t i, j;
  50. for (i = 0; i < buflen; i += 16)
  51. {
  52. f_printf("%x: ", ptr + i);
  53. for (j = 0; j < 16; j++)
  54. if (i + j < buflen)
  55. f_printf("%x ", buf[i + j]);
  56. else
  57. f_printf(" ");
  58. f_printf(" ");
  59. for (j = 0; j < 16; j++)
  60. if (i + j < buflen)
  61. f_printf("%c", (char)(__is_print(buf[i + j]) ? buf[i + j] : '.'));
  62. f_printf("\r\n");
  63. }
  64. }
  65. void FtDumpHexWord(const u32 *ptr, u32 buflen)
  66. {
  67. u32 *buf = (u32 *)ptr;
  68. u8 *char_data = (u8 *)ptr;
  69. fsize_t i, j;
  70. buflen = buflen / 4;
  71. for (i = 0; i < buflen; i += 4)
  72. {
  73. printf("%p: ", ptr + i);
  74. for (j = 0; j < 4; j++)
  75. {
  76. if (i + j < buflen)
  77. {
  78. printf("%lx ", buf[i + j]);
  79. }
  80. else
  81. {
  82. printf(" ");
  83. }
  84. }
  85. printf(" ");
  86. for (j = 0; j < 16; j++)
  87. if (i + j < buflen)
  88. printf("%c", (char)(__is_print(char_data[i + j]) ? char_data[i + j] : '.'));
  89. printf("\r\n");
  90. }
  91. }