2 * Copyright 2008-2012 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.
34 /**************************************************************************//**
37 @Description Debug mode definitions.
38 *//***************************************************************************/
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 */
52 #if (DEBUG_ERRORS > 0)
54 /* Internally used macros */
56 #define DUMP_Print XX_Print
57 #define DUMP_MAX_LEVELS 6
58 #define DUMP_IDX_LEN 6
59 #define DUMP_MAX_STR 64
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)) \
68 strlcat(dumpSubStr, p_DumpToken, DUMP_MAX_STR); \
69 if (dumpIsArr[dumpTmpLevel]) \
71 strlcat(dumpSubStr, dumpIdxStr[dumpTmpLevel], DUMP_MAX_STR); \
72 p_DumpToken = strtok(NULL, "."); \
74 if ((p_DumpToken != NULL) && \
75 ((p_DumpToken = strtok(NULL, (dumpIsArr[++dumpTmpLevel] ? "[" : "."))) != NULL)) \
76 strlcat(dumpSubStr, ".", DUMP_MAX_STR); \
80 /**************************************************************************//**
81 @Group gen_id General Drivers Utilities
83 @Description External routines.
86 *//***************************************************************************/
88 /**************************************************************************//**
89 @Group dump_id Memory and Registers Dump Mechanism
91 @Description Macros for dumping memory mapped structures.
94 *//***************************************************************************/
96 /**************************************************************************//**
97 @Description Declaration of dump mechanism variables.
99 This macro must be declared at the beginning of each routine
100 which uses the dump mechanism macros, before the routine's code
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); \
118 UNUSED(dumpTmpLevel); \
119 UNUSED(dumpIsArr[0]);
122 /**************************************************************************//**
123 @Description Prints a title for a subsequent dumped structure or memory.
125 The inputs for this macro are the structure/memory title and
127 *//***************************************************************************/
128 #define DUMP_TITLE(addr, msg) \
129 DUMP_Print("\r\n"); DUMP_Print msg; \
131 DUMP_Print(" (%p)", (addr)); \
132 DUMP_Print("\r\n---------------------------------------------------------\r\n");
134 /**************************************************************************//**
135 @Description Prints a subtitle for a subsequent dumped sub-structure (optional).
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")
144 /**************************************************************************//**
145 @Description Dumps a memory region in 4-bytes aligned format.
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))
154 /**************************************************************************//**
155 @Description Declares a dump loop, for dumping a sub-structure array.
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.
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)))
172 /**************************************************************************//**
173 @Description Dumps a structure's member variable.
175 The input for this macro is the full reference for the member
176 variable, where the structure is referenced using a pointer.
178 Note, that a members array must be dumped using DUMP_ARR macro,
179 rather than using this macro.
181 If the member variable is part of a sub-structure hierarchy,
182 the full hierarchy (including array indexing) must be specified.
184 Examples: p_Struct->member
186 p_Struct->sub[i].member
187 *//***************************************************************************/
188 #define DUMP_VAR(st, phrase) \
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); \
198 /**************************************************************************//**
199 @Description Dumps a structure's members array.
201 The input for this macro is the full reference for the members
202 array, where the structure is referenced using a pointer.
204 If the members array is part of a sub-structure hierarchy,
205 the full hierarchy (including array indexing) must be specified.
207 Examples: p_Struct->array
209 p_Struct->sub[i].array
210 *//***************************************************************************/
211 #define DUMP_ARR(st, phrase) \
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); \
225 #endif /* DEBUG_ERRORS > 0 */
228 /** @} */ /* end of dump_id group */
229 /** @} */ /* end of gen_id group */
232 #endif /* __DEBUG_EXT_H */