1 /*
2 * Copyright 2008-2012 Freescale Semiconductor Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of Freescale Semiconductor nor the
12 * names of its contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 *
16 * ALTERNATIVELY, this software may be distributed under the terms of the
17 * GNU General Public License ("GPL") as published by the Free Software
18 * Foundation, either version 2 of that License or (at your option) any
19 * later version.
20 *
21 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33
34 /**************************************************************************//**
35 @File debug_ext.h
36
37 @Description Debug mode definitions.
38 *//***************************************************************************/
39
40 #ifndef __DEBUG_EXT_H
41 #define __DEBUG_EXT_H
42
43 #include "std_ext.h"
44 #include "xx_ext.h"
45 #include "memcpy_ext.h"
46 #if (DEBUG_ERRORS > 0)
47 #include "sprint_ext.h"
48 #include "string_ext.h"
49 #endif /* DEBUG_ERRORS > 0 */
50
51
52 #if (DEBUG_ERRORS > 0)
53
54 /* Internally used macros */
55
56 #define DUMP_Print XX_Print
57 #define DUMP_MAX_LEVELS 6
58 #define DUMP_IDX_LEN 6
59 #define DUMP_MAX_STR 64
60
61
62 #define _CREATE_DUMP_SUBSTR(phrase) \
63 dumpTmpLevel = 0; dumpSubStr[0] = '\0'; \
64 snprintf(dumpTmpStr, DUMP_MAX_STR, "%s", #phrase); \
65 p_DumpToken = strtok(dumpTmpStr, (dumpIsArr[0] ? "[" : ".")); \
66 while ((p_DumpToken != NULL) && (dumpTmpLevel < DUMP_MAX_LEVELS)) \
67 { \
68 strlcat(dumpSubStr, p_DumpToken, DUMP_MAX_STR); \
69 if (dumpIsArr[dumpTmpLevel]) \
70 { \
71 strlcat(dumpSubStr, dumpIdxStr[dumpTmpLevel], DUMP_MAX_STR); \
72 p_DumpToken = strtok(NULL, "."); \
73 } \
74 if ((p_DumpToken != NULL) && \
75 ((p_DumpToken = strtok(NULL, (dumpIsArr[++dumpTmpLevel] ? "[" : "."))) != NULL)) \
76 strlcat(dumpSubStr, ".", DUMP_MAX_STR); \
77 }
78
79
80 /**************************************************************************//**
81 @Group gen_id General Drivers Utilities
82
83 @Description External routines.
84
85 @{
86 *//***************************************************************************/
87
88 /**************************************************************************//**
89 @Group dump_id Memory and Registers Dump Mechanism
90
91 @Description Macros for dumping memory mapped structures.
92
93 @{
94 *//***************************************************************************/
95
96 /**************************************************************************//**
97 @Description Declaration of dump mechanism variables.
98
99 This macro must be declared at the beginning of each routine
100 which uses the dump mechanism macros, before the routine's code
101 starts.
102 *//***************************************************************************/
103 #define DECLARE_DUMP \
104 char dumpIdxStr[DUMP_MAX_LEVELS + 1][DUMP_IDX_LEN] = { "", }; \
105 char dumpSubStr[DUMP_MAX_STR] = ""; \
106 char dumpTmpStr[DUMP_MAX_STR] = ""; \
107 char *p_DumpToken = NULL; \
108 int dumpArrIdx = 0, dumpArrSize = 0, dumpLevel = 0, dumpTmpLevel = 0; \
109 uint8_t dumpIsArr[DUMP_MAX_LEVELS + 1] = { 0 }; \
110 /* Prevent warnings if not all used */ \
111 UNUSED(dumpIdxStr[0][0]); \
112 UNUSED(dumpSubStr[0]); \
113 UNUSED(dumpTmpStr[0]); \
114 UNUSED(p_DumpToken); \
115 UNUSED(dumpArrIdx); \
116 UNUSED(dumpArrSize); \
117 UNUSED(dumpLevel); \
118 UNUSED(dumpTmpLevel); \
119 UNUSED(dumpIsArr[0]);
120
121
122 /**************************************************************************//**
123 @Description Prints a title for a subsequent dumped structure or memory.
124
125 The inputs for this macro are the structure/memory title and
126 its base addresses.
127 *//***************************************************************************/
128 #define DUMP_TITLE(addr, msg) \
129 DUMP_Print("\r\n"); DUMP_Print msg; \
130 if (addr) \
131 DUMP_Print(" (%p)", (addr)); \
132 DUMP_Print("\r\n---------------------------------------------------------\r\n");
133
134 /**************************************************************************//**
135 @Description Prints a subtitle for a subsequent dumped sub-structure (optional).
136
137 The inputs for this macro are the sub-structure subtitle.
138 A separating line with this subtitle will be printed.
139 *//***************************************************************************/
140 #define DUMP_SUBTITLE(subtitle) \
141 DUMP_Print("----------- "); DUMP_Print subtitle; DUMP_Print("\r\n")
142
143
144 /**************************************************************************//**
145 @Description Dumps a memory region in 4-bytes aligned format.
146
147 The inputs for this macro are the base addresses and size
148 (in bytes) of the memory region.
149 *//***************************************************************************/
150 #define DUMP_MEMORY(addr, size) \
151 MemDisp((uint8_t *)(addr), (int)(size))
152
153
154 /**************************************************************************//**
155 @Description Declares a dump loop, for dumping a sub-structure array.
156
157 The inputs for this macro are:
158 - idx: an index variable, for indexing the sub-structure items
159 inside the loop. This variable must be declared separately
160 in the beginning of the routine.
161 - cnt: the number of times to repeat the loop. This number should
162 equal the number of items in the sub-structures array.
163
164 Note, that the body of the loop must be written inside brackets.
165 *//***************************************************************************/
166 #define DUMP_SUBSTRUCT_ARRAY(idx, cnt) \
167 for (idx=0, dumpIsArr[dumpLevel++] = 1; \
168 (idx < cnt) && (dumpLevel > 0) && snprintf(dumpIdxStr[dumpLevel-1], DUMP_IDX_LEN, "[%d]", idx); \
169 idx++, ((idx < cnt) || (dumpIsArr[--dumpLevel] = 0)))
170
171
172 /**************************************************************************//**
173 @Description Dumps a structure's member variable.
174
175 The input for this macro is the full reference for the member
176 variable, where the structure is referenced using a pointer.
177
178 Note, that a members array must be dumped using DUMP_ARR macro,
179 rather than using this macro.
180
181 If the member variable is part of a sub-structure hierarchy,
182 the full hierarchy (including array indexing) must be specified.
183
184 Examples: p_Struct->member
185 p_Struct->sub.member
186 p_Struct->sub[i].member
187 *//***************************************************************************/
188 #define DUMP_VAR(st, phrase) \
189 do { \
190 void *addr = (void *)&((st)->phrase); \
191 physAddress_t physAddr = XX_VirtToPhys(addr); \
192 _CREATE_DUMP_SUBSTR(phrase); \
193 DUMP_Print("0x%010llX: 0x%08x%8s\t%s\r\n", \
194 physAddr, GET_UINT32(*(uint32_t*)addr), "", dumpSubStr); \
195 } while (0)
196
197
198 /**************************************************************************//**
199 @Description Dumps a structure's members array.
200
201 The input for this macro is the full reference for the members
202 array, where the structure is referenced using a pointer.
203
204 If the members array is part of a sub-structure hierarchy,
205 the full hierarchy (including array indexing) must be specified.
206
207 Examples: p_Struct->array
208 p_Struct->sub.array
209 p_Struct->sub[i].array
210 *//***************************************************************************/
211 #define DUMP_ARR(st, phrase) \
212 do { \
213 physAddress_t physAddr; \
214 _CREATE_DUMP_SUBSTR(phrase); \
215 dumpArrSize = ARRAY_SIZE((st)->phrase); \
216 for (dumpArrIdx=0; dumpArrIdx < dumpArrSize; dumpArrIdx++) { \
217 physAddr = XX_VirtToPhys((void *)&((st)->phrase[dumpArrIdx])); \
218 DUMP_Print("0x%010llX: 0x%08x%8s\t%s[%d]\r\n", \
219 physAddr, GET_UINT32((st)->phrase[dumpArrIdx]), "", dumpSubStr, dumpArrIdx); \
220 } \
221 } while (0)
222
223
224
225 #endif /* DEBUG_ERRORS > 0 */
226
227
228 /** @} */ /* end of dump_id group */
229 /** @} */ /* end of gen_id group */
230
231
232 #endif /* __DEBUG_EXT_H */
233
Cache object: 85124dfeef54a468a8ded926becbf8fb
|