hpm_mcl_debug.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) 2024 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_MCL_DEBUG_H
  8. #define HPM_MCL_DEBUG_H
  9. #include "hpm_mcl_common.h"
  10. #define MCL_DEBUG_FIFO MCL_USER_DEFINED_DEBUG_FIFO
  11. /**
  12. * @brief callback function
  13. *
  14. */
  15. typedef struct {
  16. void (*write_buf)(uint8_t *byte, uint16_t num);
  17. } mcl_debug_callback_t;
  18. #define MCL_DEBUG_DATA_TYPE_SET(num, size) (((num) << 8) | (size))
  19. #define MCL_DEBUG_DATA_TYPE_GET_SIZE(type) ((type) & 0xff)
  20. /**
  21. * @brief Types of debug data
  22. *
  23. */
  24. typedef enum {
  25. mcl_debug_data_i8 = MCL_DEBUG_DATA_TYPE_SET(0, 1),
  26. mcl_debug_data_i16 = MCL_DEBUG_DATA_TYPE_SET(1, 2),
  27. mcl_debug_data_i32 = MCL_DEBUG_DATA_TYPE_SET(2, 4),
  28. mcl_debug_data_f32 = MCL_DEBUG_DATA_TYPE_SET(3, 4)
  29. } mcl_debug_data_type_t;
  30. /**
  31. * @brief debug config
  32. *
  33. */
  34. typedef struct {
  35. mcl_debug_callback_t callback;
  36. union {
  37. float *f32;
  38. int16_t *i16;
  39. int32_t *i32;
  40. int8_t *i8;
  41. uint8_t *addr;
  42. } data;
  43. uint8_t cnt;
  44. mcl_debug_data_type_t data_type;
  45. } mcl_debug_cfg_t;
  46. /**
  47. * @brief debug data
  48. *
  49. */
  50. typedef struct {
  51. mcl_debug_cfg_t cfg;
  52. } mcl_debug_t;
  53. /**
  54. * @brief init debug data struct
  55. *
  56. * @param debug @ref mcl_debug_t
  57. */
  58. void hpm_mcl_debug_init(mcl_debug_t *debug);
  59. /**
  60. * @brief Sends data in the buffer to the outside, Depending on how the callback function works,
  61. * this function could potentially hang the application
  62. *
  63. * @param debug @ref mcl_debug_t
  64. */
  65. void hpm_mcl_debug_send_scope(mcl_debug_t *debug);
  66. /**
  67. * @brief Update debug data
  68. *
  69. * @param debug @ref mcl_debug_t
  70. * @param chn channel number
  71. * @param data input data
  72. * @param type @ref mcl_debug_data_type_t
  73. */
  74. void hpm_mcl_debug_update_data(mcl_debug_t *debug, uint8_t chn, void *data, mcl_debug_data_type_t type);
  75. #endif