/*1* Copyright 2008-2012 Freescale Semiconductor Inc.2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions are met:5* * Redistributions of source code must retain the above copyright6* notice, this list of conditions and the following disclaimer.7* * Redistributions in binary form must reproduce the above copyright8* notice, this list of conditions and the following disclaimer in the9* documentation and/or other materials provided with the distribution.10* * Neither the name of Freescale Semiconductor nor the11* names of its contributors may be used to endorse or promote products12* derived from this software without specific prior written permission.13*14*15* ALTERNATIVELY, this software may be distributed under the terms of the16* GNU General Public License ("GPL") as published by the Free Software17* Foundation, either version 2 of that License or (at your option) any18* later version.19*20* THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY21* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED22* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE23* DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY24* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES25* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;26* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND27* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT28* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS29* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.30*/313233/**************************************************************************//**34@File debug_ext.h3536@Description Debug mode definitions.37*//***************************************************************************/3839#ifndef __DEBUG_EXT_H40#define __DEBUG_EXT_H4142#include "std_ext.h"43#include "xx_ext.h"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 */495051#if (DEBUG_ERRORS > 0)5253/* Internally used macros */5455#define DUMP_Print XX_Print56#define DUMP_MAX_LEVELS 657#define DUMP_IDX_LEN 658#define DUMP_MAX_STR 64596061#define _CREATE_DUMP_SUBSTR(phrase) \62dumpTmpLevel = 0; dumpSubStr[0] = '\0'; \63snprintf(dumpTmpStr, DUMP_MAX_STR, "%s", #phrase); \64p_DumpToken = strtok(dumpTmpStr, (dumpIsArr[0] ? "[" : ".")); \65while ((p_DumpToken != NULL) && (dumpTmpLevel < DUMP_MAX_LEVELS)) \66{ \67strlcat(dumpSubStr, p_DumpToken, DUMP_MAX_STR); \68if (dumpIsArr[dumpTmpLevel]) \69{ \70strlcat(dumpSubStr, dumpIdxStr[dumpTmpLevel], DUMP_MAX_STR); \71p_DumpToken = strtok(NULL, "."); \72} \73if ((p_DumpToken != NULL) && \74((p_DumpToken = strtok(NULL, (dumpIsArr[++dumpTmpLevel] ? "[" : "."))) != NULL)) \75strlcat(dumpSubStr, ".", DUMP_MAX_STR); \76}777879/**************************************************************************//**80@Group gen_id General Drivers Utilities8182@Description External routines.8384@{85*//***************************************************************************/8687/**************************************************************************//**88@Group dump_id Memory and Registers Dump Mechanism8990@Description Macros for dumping memory mapped structures.9192@{93*//***************************************************************************/9495/**************************************************************************//**96@Description Declaration of dump mechanism variables.9798This macro must be declared at the beginning of each routine99which uses the dump mechanism macros, before the routine's code100starts.101*//***************************************************************************/102#define DECLARE_DUMP \103char dumpIdxStr[DUMP_MAX_LEVELS + 1][DUMP_IDX_LEN] = { "", }; \104char dumpSubStr[DUMP_MAX_STR] = ""; \105char dumpTmpStr[DUMP_MAX_STR] = ""; \106char *p_DumpToken = NULL; \107int dumpArrIdx = 0, dumpArrSize = 0, dumpLevel = 0, dumpTmpLevel = 0; \108uint8_t dumpIsArr[DUMP_MAX_LEVELS + 1] = { 0 }; \109/* Prevent warnings if not all used */ \110UNUSED(dumpIdxStr[0][0]); \111UNUSED(dumpSubStr[0]); \112UNUSED(dumpTmpStr[0]); \113UNUSED(p_DumpToken); \114UNUSED(dumpArrIdx); \115UNUSED(dumpArrSize); \116UNUSED(dumpLevel); \117UNUSED(dumpTmpLevel); \118UNUSED(dumpIsArr[0]);119120121/**************************************************************************//**122@Description Prints a title for a subsequent dumped structure or memory.123124The inputs for this macro are the structure/memory title and125its base addresses.126*//***************************************************************************/127#define DUMP_TITLE(addr, msg) \128DUMP_Print("\r\n"); DUMP_Print msg; \129if (addr) \130DUMP_Print(" (%p)", (addr)); \131DUMP_Print("\r\n---------------------------------------------------------\r\n");132133/**************************************************************************//**134@Description Prints a subtitle for a subsequent dumped sub-structure (optional).135136The inputs for this macro are the sub-structure subtitle.137A separating line with this subtitle will be printed.138*//***************************************************************************/139#define DUMP_SUBTITLE(subtitle) \140DUMP_Print("----------- "); DUMP_Print subtitle; DUMP_Print("\r\n")141142143/**************************************************************************//**144@Description Dumps a memory region in 4-bytes aligned format.145146The inputs for this macro are the base addresses and size147(in bytes) of the memory region.148*//***************************************************************************/149#define DUMP_MEMORY(addr, size) \150MemDisp((uint8_t *)(addr), (int)(size))151152153/**************************************************************************//**154@Description Declares a dump loop, for dumping a sub-structure array.155156The inputs for this macro are:157- idx: an index variable, for indexing the sub-structure items158inside the loop. This variable must be declared separately159in the beginning of the routine.160- cnt: the number of times to repeat the loop. This number should161equal the number of items in the sub-structures array.162163Note, that the body of the loop must be written inside brackets.164*//***************************************************************************/165#define DUMP_SUBSTRUCT_ARRAY(idx, cnt) \166for (idx=0, dumpIsArr[dumpLevel++] = 1; \167(idx < cnt) && (dumpLevel > 0) && snprintf(dumpIdxStr[dumpLevel-1], DUMP_IDX_LEN, "[%d]", idx); \168idx++, ((idx < cnt) || (dumpIsArr[--dumpLevel] = 0)))169170171/**************************************************************************//**172@Description Dumps a structure's member variable.173174The input for this macro is the full reference for the member175variable, where the structure is referenced using a pointer.176177Note, that a members array must be dumped using DUMP_ARR macro,178rather than using this macro.179180If the member variable is part of a sub-structure hierarchy,181the full hierarchy (including array indexing) must be specified.182183Examples: p_Struct->member184p_Struct->sub.member185p_Struct->sub[i].member186*//***************************************************************************/187#define DUMP_VAR(st, phrase) \188do { \189void *addr = (void *)&((st)->phrase); \190physAddress_t physAddr = XX_VirtToPhys(addr); \191_CREATE_DUMP_SUBSTR(phrase); \192DUMP_Print("0x%010llX: 0x%08x%8s\t%s\r\n", \193physAddr, GET_UINT32(*(uint32_t*)addr), "", dumpSubStr); \194} while (0)195196197/**************************************************************************//**198@Description Dumps a structure's members array.199200The input for this macro is the full reference for the members201array, where the structure is referenced using a pointer.202203If the members array is part of a sub-structure hierarchy,204the full hierarchy (including array indexing) must be specified.205206Examples: p_Struct->array207p_Struct->sub.array208p_Struct->sub[i].array209*//***************************************************************************/210#define DUMP_ARR(st, phrase) \211do { \212physAddress_t physAddr; \213_CREATE_DUMP_SUBSTR(phrase); \214dumpArrSize = ARRAY_SIZE((st)->phrase); \215for (dumpArrIdx=0; dumpArrIdx < dumpArrSize; dumpArrIdx++) { \216physAddr = XX_VirtToPhys((void *)&((st)->phrase[dumpArrIdx])); \217DUMP_Print("0x%010llX: 0x%08x%8s\t%s[%d]\r\n", \218physAddr, GET_UINT32((st)->phrase[dumpArrIdx]), "", dumpSubStr, dumpArrIdx); \219} \220} while (0)221222223224#endif /* DEBUG_ERRORS > 0 */225226227/** @} */ /* end of dump_id group */228/** @} */ /* end of gen_id group */229230231#endif /* __DEBUG_EXT_H */232233234235