1*852ba100SJustin Hibbits /* 2*852ba100SJustin Hibbits * Copyright 2008-2012 Freescale Semiconductor Inc. 30aeed3e9SJustin Hibbits * 40aeed3e9SJustin Hibbits * Redistribution and use in source and binary forms, with or without 50aeed3e9SJustin Hibbits * modification, are permitted provided that the following conditions are met: 60aeed3e9SJustin Hibbits * * Redistributions of source code must retain the above copyright 70aeed3e9SJustin Hibbits * notice, this list of conditions and the following disclaimer. 80aeed3e9SJustin Hibbits * * Redistributions in binary form must reproduce the above copyright 90aeed3e9SJustin Hibbits * notice, this list of conditions and the following disclaimer in the 100aeed3e9SJustin Hibbits * documentation and/or other materials provided with the distribution. 110aeed3e9SJustin Hibbits * * Neither the name of Freescale Semiconductor nor the 120aeed3e9SJustin Hibbits * names of its contributors may be used to endorse or promote products 130aeed3e9SJustin Hibbits * derived from this software without specific prior written permission. 140aeed3e9SJustin Hibbits * 150aeed3e9SJustin Hibbits * 160aeed3e9SJustin Hibbits * ALTERNATIVELY, this software may be distributed under the terms of the 170aeed3e9SJustin Hibbits * GNU General Public License ("GPL") as published by the Free Software 180aeed3e9SJustin Hibbits * Foundation, either version 2 of that License or (at your option) any 190aeed3e9SJustin Hibbits * later version. 200aeed3e9SJustin Hibbits * 210aeed3e9SJustin Hibbits * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY 220aeed3e9SJustin Hibbits * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 230aeed3e9SJustin Hibbits * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 240aeed3e9SJustin Hibbits * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY 250aeed3e9SJustin Hibbits * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 260aeed3e9SJustin Hibbits * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 270aeed3e9SJustin Hibbits * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 280aeed3e9SJustin Hibbits * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 290aeed3e9SJustin Hibbits * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 300aeed3e9SJustin Hibbits * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 310aeed3e9SJustin Hibbits */ 320aeed3e9SJustin Hibbits 33*852ba100SJustin Hibbits 340aeed3e9SJustin Hibbits /**************************************************************************//** 350aeed3e9SJustin Hibbits @File debug_ext.h 360aeed3e9SJustin Hibbits 370aeed3e9SJustin Hibbits @Description Debug mode definitions. 380aeed3e9SJustin Hibbits *//***************************************************************************/ 390aeed3e9SJustin Hibbits 400aeed3e9SJustin Hibbits #ifndef __DEBUG_EXT_H 410aeed3e9SJustin Hibbits #define __DEBUG_EXT_H 420aeed3e9SJustin Hibbits 430aeed3e9SJustin Hibbits #include "std_ext.h" 440aeed3e9SJustin Hibbits #include "xx_ext.h" 450aeed3e9SJustin Hibbits #include "memcpy_ext.h" 460aeed3e9SJustin Hibbits #if (DEBUG_ERRORS > 0) 470aeed3e9SJustin Hibbits #include "sprint_ext.h" 480aeed3e9SJustin Hibbits #include "string_ext.h" 490aeed3e9SJustin Hibbits #endif /* DEBUG_ERRORS > 0 */ 500aeed3e9SJustin Hibbits 510aeed3e9SJustin Hibbits 520aeed3e9SJustin Hibbits #if (DEBUG_ERRORS > 0) 530aeed3e9SJustin Hibbits 540aeed3e9SJustin Hibbits /* Internally used macros */ 550aeed3e9SJustin Hibbits 560aeed3e9SJustin Hibbits #define DUMP_Print XX_Print 570aeed3e9SJustin Hibbits #define DUMP_MAX_LEVELS 6 58*852ba100SJustin Hibbits #define DUMP_IDX_LEN 6 590aeed3e9SJustin Hibbits #define DUMP_MAX_STR 64 600aeed3e9SJustin Hibbits 610aeed3e9SJustin Hibbits 620aeed3e9SJustin Hibbits #define _CREATE_DUMP_SUBSTR(phrase) \ 630aeed3e9SJustin Hibbits dumpTmpLevel = 0; dumpSubStr[0] = '\0'; \ 64*852ba100SJustin Hibbits snprintf(dumpTmpStr, DUMP_MAX_STR, "%s", #phrase); \ 650aeed3e9SJustin Hibbits p_DumpToken = strtok(dumpTmpStr, (dumpIsArr[0] ? "[" : ".")); \ 66*852ba100SJustin Hibbits while ((p_DumpToken != NULL) && (dumpTmpLevel < DUMP_MAX_LEVELS)) \ 670aeed3e9SJustin Hibbits { \ 68*852ba100SJustin Hibbits strlcat(dumpSubStr, p_DumpToken, DUMP_MAX_STR); \ 690aeed3e9SJustin Hibbits if (dumpIsArr[dumpTmpLevel]) \ 700aeed3e9SJustin Hibbits { \ 71*852ba100SJustin Hibbits strlcat(dumpSubStr, dumpIdxStr[dumpTmpLevel], DUMP_MAX_STR); \ 720aeed3e9SJustin Hibbits p_DumpToken = strtok(NULL, "."); \ 730aeed3e9SJustin Hibbits } \ 74*852ba100SJustin Hibbits if ((p_DumpToken != NULL) && \ 75*852ba100SJustin Hibbits ((p_DumpToken = strtok(NULL, (dumpIsArr[++dumpTmpLevel] ? "[" : "."))) != NULL)) \ 76*852ba100SJustin Hibbits strlcat(dumpSubStr, ".", DUMP_MAX_STR); \ 77*852ba100SJustin Hibbits } 780aeed3e9SJustin Hibbits 790aeed3e9SJustin Hibbits 800aeed3e9SJustin Hibbits /**************************************************************************//** 810aeed3e9SJustin Hibbits @Group gen_id General Drivers Utilities 820aeed3e9SJustin Hibbits 830aeed3e9SJustin Hibbits @Description External routines. 840aeed3e9SJustin Hibbits 850aeed3e9SJustin Hibbits @{ 860aeed3e9SJustin Hibbits *//***************************************************************************/ 870aeed3e9SJustin Hibbits 880aeed3e9SJustin Hibbits /**************************************************************************//** 890aeed3e9SJustin Hibbits @Group dump_id Memory and Registers Dump Mechanism 900aeed3e9SJustin Hibbits 910aeed3e9SJustin Hibbits @Description Macros for dumping memory mapped structures. 920aeed3e9SJustin Hibbits 930aeed3e9SJustin Hibbits @{ 940aeed3e9SJustin Hibbits *//***************************************************************************/ 950aeed3e9SJustin Hibbits 960aeed3e9SJustin Hibbits /**************************************************************************//** 970aeed3e9SJustin Hibbits @Description Declaration of dump mechanism variables. 980aeed3e9SJustin Hibbits 990aeed3e9SJustin Hibbits This macro must be declared at the beginning of each routine 1000aeed3e9SJustin Hibbits which uses the dump mechanism macros, before the routine's code 1010aeed3e9SJustin Hibbits starts. 1020aeed3e9SJustin Hibbits *//***************************************************************************/ 1030aeed3e9SJustin Hibbits #define DECLARE_DUMP \ 104*852ba100SJustin Hibbits char dumpIdxStr[DUMP_MAX_LEVELS + 1][DUMP_IDX_LEN] = { "", }; \ 1050aeed3e9SJustin Hibbits char dumpSubStr[DUMP_MAX_STR] = ""; \ 1060aeed3e9SJustin Hibbits char dumpTmpStr[DUMP_MAX_STR] = ""; \ 1070aeed3e9SJustin Hibbits char *p_DumpToken = NULL; \ 108*852ba100SJustin Hibbits int dumpArrIdx = 0, dumpArrSize = 0, dumpLevel = 0, dumpTmpLevel = 0; \ 1090aeed3e9SJustin Hibbits uint8_t dumpIsArr[DUMP_MAX_LEVELS + 1] = { 0 }; \ 1100aeed3e9SJustin Hibbits /* Prevent warnings if not all used */ \ 1110aeed3e9SJustin Hibbits UNUSED(dumpIdxStr[0][0]); \ 1120aeed3e9SJustin Hibbits UNUSED(dumpSubStr[0]); \ 1130aeed3e9SJustin Hibbits UNUSED(dumpTmpStr[0]); \ 1140aeed3e9SJustin Hibbits UNUSED(p_DumpToken); \ 1150aeed3e9SJustin Hibbits UNUSED(dumpArrIdx); \ 1160aeed3e9SJustin Hibbits UNUSED(dumpArrSize); \ 1170aeed3e9SJustin Hibbits UNUSED(dumpLevel); \ 1180aeed3e9SJustin Hibbits UNUSED(dumpTmpLevel); \ 1190aeed3e9SJustin Hibbits UNUSED(dumpIsArr[0]); 1200aeed3e9SJustin Hibbits 1210aeed3e9SJustin Hibbits 1220aeed3e9SJustin Hibbits /**************************************************************************//** 1230aeed3e9SJustin Hibbits @Description Prints a title for a subsequent dumped structure or memory. 1240aeed3e9SJustin Hibbits 1250aeed3e9SJustin Hibbits The inputs for this macro are the structure/memory title and 1260aeed3e9SJustin Hibbits its base addresses. 1270aeed3e9SJustin Hibbits *//***************************************************************************/ 1280aeed3e9SJustin Hibbits #define DUMP_TITLE(addr, msg) \ 1290aeed3e9SJustin Hibbits DUMP_Print("\r\n"); DUMP_Print msg; \ 130*852ba100SJustin Hibbits if (addr) \ 131*852ba100SJustin Hibbits DUMP_Print(" (%p)", (addr)); \ 132*852ba100SJustin Hibbits DUMP_Print("\r\n---------------------------------------------------------\r\n"); 1330aeed3e9SJustin Hibbits 1340aeed3e9SJustin Hibbits /**************************************************************************//** 1350aeed3e9SJustin Hibbits @Description Prints a subtitle for a subsequent dumped sub-structure (optional). 1360aeed3e9SJustin Hibbits 1370aeed3e9SJustin Hibbits The inputs for this macro are the sub-structure subtitle. 1380aeed3e9SJustin Hibbits A separating line with this subtitle will be printed. 1390aeed3e9SJustin Hibbits *//***************************************************************************/ 1400aeed3e9SJustin Hibbits #define DUMP_SUBTITLE(subtitle) \ 1410aeed3e9SJustin Hibbits DUMP_Print("----------- "); DUMP_Print subtitle; DUMP_Print("\r\n") 1420aeed3e9SJustin Hibbits 1430aeed3e9SJustin Hibbits 1440aeed3e9SJustin Hibbits /**************************************************************************//** 1450aeed3e9SJustin Hibbits @Description Dumps a memory region in 4-bytes aligned format. 1460aeed3e9SJustin Hibbits 1470aeed3e9SJustin Hibbits The inputs for this macro are the base addresses and size 1480aeed3e9SJustin Hibbits (in bytes) of the memory region. 1490aeed3e9SJustin Hibbits *//***************************************************************************/ 1500aeed3e9SJustin Hibbits #define DUMP_MEMORY(addr, size) \ 1510aeed3e9SJustin Hibbits MemDisp((uint8_t *)(addr), (int)(size)) 1520aeed3e9SJustin Hibbits 1530aeed3e9SJustin Hibbits 1540aeed3e9SJustin Hibbits /**************************************************************************//** 1550aeed3e9SJustin Hibbits @Description Declares a dump loop, for dumping a sub-structure array. 1560aeed3e9SJustin Hibbits 1570aeed3e9SJustin Hibbits The inputs for this macro are: 1580aeed3e9SJustin Hibbits - idx: an index variable, for indexing the sub-structure items 1590aeed3e9SJustin Hibbits inside the loop. This variable must be declared separately 1600aeed3e9SJustin Hibbits in the beginning of the routine. 1610aeed3e9SJustin Hibbits - cnt: the number of times to repeat the loop. This number should 1620aeed3e9SJustin Hibbits equal the number of items in the sub-structures array. 1630aeed3e9SJustin Hibbits 1640aeed3e9SJustin Hibbits Note, that the body of the loop must be written inside brackets. 1650aeed3e9SJustin Hibbits *//***************************************************************************/ 1660aeed3e9SJustin Hibbits #define DUMP_SUBSTRUCT_ARRAY(idx, cnt) \ 1670aeed3e9SJustin Hibbits for (idx=0, dumpIsArr[dumpLevel++] = 1; \ 168*852ba100SJustin Hibbits (idx < cnt) && (dumpLevel > 0) && snprintf(dumpIdxStr[dumpLevel-1], DUMP_IDX_LEN, "[%d]", idx); \ 169*852ba100SJustin Hibbits idx++, ((idx < cnt) || (dumpIsArr[--dumpLevel] = 0))) 1700aeed3e9SJustin Hibbits 1710aeed3e9SJustin Hibbits 1720aeed3e9SJustin Hibbits /**************************************************************************//** 1730aeed3e9SJustin Hibbits @Description Dumps a structure's member variable. 1740aeed3e9SJustin Hibbits 1750aeed3e9SJustin Hibbits The input for this macro is the full reference for the member 1760aeed3e9SJustin Hibbits variable, where the structure is referenced using a pointer. 1770aeed3e9SJustin Hibbits 1780aeed3e9SJustin Hibbits Note, that a members array must be dumped using DUMP_ARR macro, 1790aeed3e9SJustin Hibbits rather than using this macro. 1800aeed3e9SJustin Hibbits 1810aeed3e9SJustin Hibbits If the member variable is part of a sub-structure hierarchy, 1820aeed3e9SJustin Hibbits the full hierarchy (including array indexing) must be specified. 1830aeed3e9SJustin Hibbits 1840aeed3e9SJustin Hibbits Examples: p_Struct->member 1850aeed3e9SJustin Hibbits p_Struct->sub.member 1860aeed3e9SJustin Hibbits p_Struct->sub[i].member 1870aeed3e9SJustin Hibbits *//***************************************************************************/ 1880aeed3e9SJustin Hibbits #define DUMP_VAR(st, phrase) \ 1890aeed3e9SJustin Hibbits do { \ 1900aeed3e9SJustin Hibbits void *addr = (void *)&((st)->phrase); \ 191*852ba100SJustin Hibbits physAddress_t physAddr = XX_VirtToPhys(addr); \ 1920aeed3e9SJustin Hibbits _CREATE_DUMP_SUBSTR(phrase); \ 193*852ba100SJustin Hibbits DUMP_Print("0x%010llX: 0x%08x%8s\t%s\r\n", \ 194*852ba100SJustin Hibbits physAddr, GET_UINT32(*(uint32_t*)addr), "", dumpSubStr); \ 1950aeed3e9SJustin Hibbits } while (0) 1960aeed3e9SJustin Hibbits 1970aeed3e9SJustin Hibbits 1980aeed3e9SJustin Hibbits /**************************************************************************//** 1990aeed3e9SJustin Hibbits @Description Dumps a structure's members array. 2000aeed3e9SJustin Hibbits 2010aeed3e9SJustin Hibbits The input for this macro is the full reference for the members 2020aeed3e9SJustin Hibbits array, where the structure is referenced using a pointer. 2030aeed3e9SJustin Hibbits 2040aeed3e9SJustin Hibbits If the members array is part of a sub-structure hierarchy, 2050aeed3e9SJustin Hibbits the full hierarchy (including array indexing) must be specified. 2060aeed3e9SJustin Hibbits 2070aeed3e9SJustin Hibbits Examples: p_Struct->array 2080aeed3e9SJustin Hibbits p_Struct->sub.array 2090aeed3e9SJustin Hibbits p_Struct->sub[i].array 2100aeed3e9SJustin Hibbits *//***************************************************************************/ 2110aeed3e9SJustin Hibbits #define DUMP_ARR(st, phrase) \ 2120aeed3e9SJustin Hibbits do { \ 213*852ba100SJustin Hibbits physAddress_t physAddr; \ 2140aeed3e9SJustin Hibbits _CREATE_DUMP_SUBSTR(phrase); \ 2150aeed3e9SJustin Hibbits dumpArrSize = ARRAY_SIZE((st)->phrase); \ 2160aeed3e9SJustin Hibbits for (dumpArrIdx=0; dumpArrIdx < dumpArrSize; dumpArrIdx++) { \ 217*852ba100SJustin Hibbits physAddr = XX_VirtToPhys((void *)&((st)->phrase[dumpArrIdx])); \ 218*852ba100SJustin Hibbits DUMP_Print("0x%010llX: 0x%08x%8s\t%s[%d]\r\n", \ 219*852ba100SJustin Hibbits physAddr, GET_UINT32((st)->phrase[dumpArrIdx]), "", dumpSubStr, dumpArrIdx); \ 2200aeed3e9SJustin Hibbits } \ 2210aeed3e9SJustin Hibbits } while (0) 2220aeed3e9SJustin Hibbits 2230aeed3e9SJustin Hibbits 224*852ba100SJustin Hibbits 2250aeed3e9SJustin Hibbits #endif /* DEBUG_ERRORS > 0 */ 2260aeed3e9SJustin Hibbits 2270aeed3e9SJustin Hibbits 2280aeed3e9SJustin Hibbits /** @} */ /* end of dump_id group */ 2290aeed3e9SJustin Hibbits /** @} */ /* end of gen_id group */ 2300aeed3e9SJustin Hibbits 2310aeed3e9SJustin Hibbits 2320aeed3e9SJustin Hibbits #endif /* __DEBUG_EXT_H */ 2330aeed3e9SJustin Hibbits 234