1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*
3 * Copyright (c) 2020-2021 Rockchip Electronics Co., Ltd.
4 */
5
6 /** @addtogroup RK_HAL_Driver
7 * @{
8 */
9
10 /** @addtogroup DEBUG
11 * @{
12 */
13
14 /** @defgroup DEBUG_How_To_Use How To Use
15 * @{
16
17 The DEBUG driver can be used as follows:
18
19 Implement DBG hook:
20
21 - printf func: define new HAL_SYSLOG in hal_conf.h or use HAL_DBG_Printf() in default;
22 - assert func: redefine AssertFailed().
23
24 Define debug level in hal_conf.h:
25
26 - HAL_DBG_ON: print master switch;
27 - HAL_DBG_INFO_ON: information printing switch;
28 - HAL_DBG_WRN_ON: information printing switch;
29 - HAL_DBG_ERR_ON: information printing switch;
30 - HAL_ASSERT_ON: Support assert.
31
32 APIS:
33
34 - printf information by calling HAL_DBG();
35 - printf warning by calling HAL_DBG_WRN();
36 - printf error by calling HAL_DBG_ERR();
37 - do assert by calling HAL_ASSERT().
38
39 @} */
40
41 #include "hal_base.h"
42
43 /** @defgroup DEBUG_Private_Definition Private Definition
44 * @{
45 */
46 /********************* Private MACRO Definition ******************************/
47
48 /********************* Private Structure Definition **************************/
49
50 /********************* Private Variable Definition ***************************/
51
52 /********************* Private Function Definition ***************************/
53
54 /** @} */
55 /********************* Public Function Definition ****************************/
56
57 /** @defgroup DEBUG_Exported_Functions_Group5 Other Functions
58
59 This section provides functions allowing to init and deinit module as follows:
60
61 * @{
62 */
63
64 /**
65 * @brief Reports the name of the source file and the source line number
66 * where the HAL_ASSERT error has occurred.
67 * @param file: pointer to the source file name
68 * @param line: HAL_ASSERT error line source number
69 */
HAL_AssertFailed(const char * file,uint32_t line)70 __WEAK void HAL_AssertFailed(const char *file, uint32_t line)
71 {
72 HAL_DBG_ERR("assert failed at %s %lu\n", file, line);
73 while (1) {
74 ;
75 }
76 }
77
78 /**
79 * @brief format hex print.
80 * @param s: head tag for every new line.
81 * @param buf: buffer for printing.
82 * @param width: every single printed object width.
83 * @param len: the number of printed objects.
84 * @return HAL_Status: HAL_OK.
85 * sum = width * len (BYTE).
86 */
HAL_DBG_HEX(char * s,void * buf,uint32_t width,uint32_t len)87 HAL_Status HAL_DBG_HEX(char *s, void *buf, uint32_t width, uint32_t len)
88 {
89 #ifdef HAL_DBG_ON
90 uint32_t i, j;
91 unsigned char *p8 = (unsigned char *)buf;
92 unsigned short *p16 = (unsigned short *)buf;
93 uint32_t *p32 = (uint32_t *)buf;
94
95 j = 0;
96 for (i = 0; i < len; i++) {
97 if (j == 0) {
98 HAL_SYSLOG("[HAL_DBG_HEX] %s %p + 0x%lx:", s, buf, i * width);
99 }
100
101 if (width == 4) {
102 HAL_SYSLOG("0x%08lx,", p32[i]);
103 } else if (width == 2) {
104 HAL_SYSLOG("0x%04x,", p16[i]);
105 } else {
106 HAL_SYSLOG("0x%02x,", p8[i]);
107 }
108
109 if (++j >= 16) {
110 j = 0;
111 HAL_SYSLOG("\n");
112 }
113 }
114 HAL_SYSLOG("\n");
115 #endif
116
117 return HAL_OK;
118 }
119
120 /**
121 * @brief format and print data
122 * @param format: format printf param.
123 * @return int32_t.
124 */
HAL_DBG_Printf(const char * format,...)125 __WEAK int32_t HAL_DBG_Printf(const char *format, ...)
126 {
127 return 0;
128 }
129
130 /** @} */
131
132 /** @} */
133
134 /** @} */
135