1 /* Copyright (c) 2008-2011 Freescale Semiconductor, Inc.
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.
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
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.
33 /**************************************************************************//**
36 @Description Debug mode definitions.
37 *//***************************************************************************/
44 #include "memcpy_ext.h"
45 #if (DEBUG_ERRORS > 0)
46 #include "sprint_ext.h"
47 #include "string_ext.h"
48 #endif /* DEBUG_ERRORS > 0 */
51 #if (DEBUG_ERRORS > 0)
53 /* Internally used macros */
55 #define DUMP_Print XX_Print
56 #define DUMP_MAX_LEVELS 6
57 #define DUMP_MAX_STR 64
60 #define _CREATE_DUMP_SUBSTR(phrase) \
61 dumpTmpLevel = 0; dumpSubStr[0] = '\0'; \
62 sprintf(dumpTmpStr, "%s", #phrase); \
63 p_DumpToken = strtok(dumpTmpStr, (dumpIsArr[0] ? "[" : ".")); \
64 while (p_DumpToken != NULL) \
66 strcat(dumpSubStr, p_DumpToken); \
67 if (dumpIsArr[dumpTmpLevel]) \
69 strcat(dumpSubStr, dumpIdxStr[dumpTmpLevel]); \
70 p_DumpToken = strtok(NULL, "."); \
72 if ((p_DumpToken = strtok(NULL, (dumpIsArr[++dumpTmpLevel] ? "[" : "."))) != 0) \
73 strcat(dumpSubStr, "."); \
77 /**************************************************************************//**
78 @Group gen_id General Drivers Utilities
80 @Description External routines.
83 *//***************************************************************************/
85 /**************************************************************************//**
86 @Group dump_id Memory and Registers Dump Mechanism
88 @Description Macros for dumping memory mapped structures.
91 *//***************************************************************************/
93 /**************************************************************************//**
94 @Description Declaration of dump mechanism variables.
96 This macro must be declared at the beginning of each routine
97 which uses the dump mechanism macros, before the routine's code
99 *//***************************************************************************/
100 #define DECLARE_DUMP \
101 char dumpIdxStr[DUMP_MAX_LEVELS + 1][6] = { "", }; \
102 char dumpSubStr[DUMP_MAX_STR] = ""; \
103 char dumpTmpStr[DUMP_MAX_STR] = ""; \
104 char *p_DumpToken = NULL; \
105 int dumpArrIdx = 0, dumpArrSize = 0, dumpVarSize = 0, dumpLevel = 0, dumpTmpLevel = 0; \
106 uint8_t dumpIsArr[DUMP_MAX_LEVELS + 1] = { 0 }; \
107 /* Prevent warnings if not all used */ \
108 UNUSED(dumpIdxStr[0][0]); \
109 UNUSED(dumpSubStr[0]); \
110 UNUSED(dumpTmpStr[0]); \
111 UNUSED(p_DumpToken); \
112 UNUSED(dumpArrIdx); \
113 UNUSED(dumpArrSize); \
114 UNUSED(dumpVarSize); \
116 UNUSED(dumpTmpLevel); \
117 UNUSED(dumpIsArr[0]);
120 /**************************************************************************//**
121 @Description Prints a title for a subsequent dumped structure or memory.
123 The inputs for this macro are the structure/memory title and
125 *//***************************************************************************/
126 #define DUMP_TITLE(addr, msg) \
127 DUMP_Print("\r\n"); DUMP_Print msg; \
128 DUMP_Print(" (0x%p)\r\n" \
129 "---------------------------------------------------------\r\n", \
132 /**************************************************************************//**
133 @Description Prints a subtitle for a subsequent dumped sub-structure (optional).
135 The inputs for this macro are the sub-structure subtitle.
136 A separating line with this subtitle will be printed.
137 *//***************************************************************************/
138 #define DUMP_SUBTITLE(subtitle) \
139 DUMP_Print("----------- "); DUMP_Print subtitle; DUMP_Print("\r\n")
142 /**************************************************************************//**
143 @Description Dumps a memory region in 4-bytes aligned format.
145 The inputs for this macro are the base addresses and size
146 (in bytes) of the memory region.
147 *//***************************************************************************/
148 #define DUMP_MEMORY(addr, size) \
149 MemDisp((uint8_t *)(addr), (int)(size))
152 /**************************************************************************//**
153 @Description Declares a dump loop, for dumping a sub-structure array.
155 The inputs for this macro are:
156 - idx: an index variable, for indexing the sub-structure items
157 inside the loop. This variable must be declared separately
158 in the beginning of the routine.
159 - cnt: the number of times to repeat the loop. This number should
160 equal the number of items in the sub-structures array.
162 Note, that the body of the loop must be written inside brackets.
163 *//***************************************************************************/
164 #define DUMP_SUBSTRUCT_ARRAY(idx, cnt) \
165 for (idx=0, dumpIsArr[dumpLevel++] = 1; \
166 (idx < cnt) && sprintf(dumpIdxStr[dumpLevel-1], "[%d]", idx); \
167 idx++, ((idx < cnt) || ((dumpIsArr[--dumpLevel] = 0) == 0)))
170 /**************************************************************************//**
171 @Description Dumps a structure's member variable.
173 The input for this macro is the full reference for the member
174 variable, where the structure is referenced using a pointer.
176 Note, that a members array must be dumped using DUMP_ARR macro,
177 rather than using this macro.
179 If the member variable is part of a sub-structure hierarchy,
180 the full hierarchy (including array indexing) must be specified.
182 Examples: p_Struct->member
184 p_Struct->sub[i].member
185 *//***************************************************************************/
186 #define DUMP_VAR(st, phrase) \
188 void *addr = (void *)&((st)->phrase); \
189 _CREATE_DUMP_SUBSTR(phrase); \
190 dumpVarSize = sizeof((st)->phrase); \
191 switch (dumpVarSize) \
193 case 1: DUMP_Print("0x%08X: 0x%02x%14s\t%s\r\n", \
194 addr, GET_UINT8(*(uint8_t*)addr), "", dumpSubStr); break; \
195 case 2: DUMP_Print("0x%08X: 0x%04x%12s\t%s\r\n", \
196 addr, GET_UINT16(*(uint16_t*)addr), "", dumpSubStr); break; \
197 case 4: DUMP_Print("0x%08X: 0x%08x%8s\t%s\r\n", \
198 addr, GET_UINT32(*(uint32_t*)addr), "", dumpSubStr); break; \
199 case 8: DUMP_Print("0x%08X: 0x%016llx\t%s\r\n", \
200 addr, GET_UINT64(*(uint64_t*)addr), dumpSubStr); break; \
201 default: DUMP_Print("Bad size %d (" #st "->" #phrase ")\r\n", dumpVarSize); \
206 /**************************************************************************//**
207 @Description Dumps a structure's members array.
209 The input for this macro is the full reference for the members
210 array, where the structure is referenced using a pointer.
212 If the members array is part of a sub-structure hierarchy,
213 the full hierarchy (including array indexing) must be specified.
215 Examples: p_Struct->array
217 p_Struct->sub[i].array
218 *//***************************************************************************/
219 #define DUMP_ARR(st, phrase) \
221 _CREATE_DUMP_SUBSTR(phrase); \
222 dumpArrSize = ARRAY_SIZE((st)->phrase); \
223 dumpVarSize = sizeof((st)->phrase[0]); \
224 switch (dumpVarSize) \
227 for (dumpArrIdx=0; dumpArrIdx < dumpArrSize; dumpArrIdx++) { \
228 DUMP_Print("0x%08X: 0x%02x%14s\t%s[%d]\r\n", \
229 &((st)->phrase[dumpArrIdx]), GET_UINT8((st)->phrase[dumpArrIdx]), "", dumpSubStr, dumpArrIdx); \
232 for (dumpArrIdx=0; dumpArrIdx < dumpArrSize; dumpArrIdx++) { \
233 DUMP_Print("0x%08X: 0x%04x%12s\t%s[%d]\r\n", \
234 &((st)->phrase[dumpArrIdx]), GET_UINT16((st)->phrase[dumpArrIdx]), "", dumpSubStr, dumpArrIdx); \
237 for (dumpArrIdx=0; dumpArrIdx < dumpArrSize; dumpArrIdx++) { \
238 DUMP_Print("0x%08X: 0x%08x%8s\t%s[%d]\r\n", \
239 &((st)->phrase[dumpArrIdx]), GET_UINT32((st)->phrase[dumpArrIdx]), "", dumpSubStr, dumpArrIdx); \
242 for (dumpArrIdx=0; dumpArrIdx < dumpArrSize; dumpArrIdx++) { \
243 DUMP_Print("0x%08X: 0x%016llx\t%s[%d]\r\n", \
244 &((st)->phrase[dumpArrIdx]), GET_UINT64((st)->phrase[dumpArrIdx]), dumpSubStr, dumpArrIdx); \
246 default: DUMP_Print("Bad size %d (" #st "->" #phrase "[0])\r\n", dumpVarSize); \
251 #endif /* DEBUG_ERRORS > 0 */
254 /** @} */ /* end of dump_id group */
255 /** @} */ /* end of gen_id group */
258 #endif /* __DEBUG_EXT_H */