Library for Modtronix NZ32 STM32 boards, like the NZ32-SC151, NZ32-SB072, NZ32-SE411 and others
mx_default_debug.h@19:42ae82a8f571, 2016-08-19 (annotated)
- Committer:
- modtronix-com
- Date:
- Fri Aug 19 15:52:51 2016 +1000
- Revision:
- 19:42ae82a8f571
- Parent:
- 17:86034c970ea0
Added tag v1.1 for changeset 37e7c8fac8c7
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
modtronix | 4:43abdd8eda40 | 1 | /** |
modtronix | 4:43abdd8eda40 | 2 | * File: mx_default_debug.h |
modtronix | 4:43abdd8eda40 | 3 | * |
modtronix | 4:43abdd8eda40 | 4 | * Author: Modtronix Engineering - www.modtronix.com |
modtronix | 4:43abdd8eda40 | 5 | * |
modtronix | 4:43abdd8eda40 | 6 | * Description: |
modtronix | 4:43abdd8eda40 | 7 | * |
modtronix | 4:43abdd8eda40 | 8 | * Software License Agreement: |
modtronix | 4:43abdd8eda40 | 9 | * This software has been written or modified by Modtronix Engineering. The code |
modtronix | 4:43abdd8eda40 | 10 | * may be modified and can be used free of charge for commercial and non commercial |
modtronix | 4:43abdd8eda40 | 11 | * applications. If this is modified software, any license conditions from original |
modtronix | 4:43abdd8eda40 | 12 | * software also apply. Any redistribution must include reference to 'Modtronix |
modtronix | 4:43abdd8eda40 | 13 | * Engineering' and web link(www.modtronix.com) in the file header. |
modtronix | 4:43abdd8eda40 | 14 | * |
modtronix | 4:43abdd8eda40 | 15 | * THIS SOFTWARE IS PROVIDED IN AN 'AS IS' CONDITION. NO WARRANTIES, WHETHER EXPRESS, |
modtronix | 4:43abdd8eda40 | 16 | * IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF |
modtronix | 4:43abdd8eda40 | 17 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE |
modtronix | 4:43abdd8eda40 | 18 | * COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
modtronix | 4:43abdd8eda40 | 19 | * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
modtronix | 4:43abdd8eda40 | 20 | */ |
modtronix | 4:43abdd8eda40 | 21 | #ifndef SRC_MX_DEFAULT_DEBUG_H_ |
modtronix | 4:43abdd8eda40 | 22 | #define SRC_MX_DEFAULT_DEBUG_H_ |
modtronix | 4:43abdd8eda40 | 23 | |
modtronix-com |
17:86034c970ea0 | 24 | #include "nz32s_default_config.h" |
modtronix-com |
17:86034c970ea0 | 25 | |
modtronix | 4:43abdd8eda40 | 26 | //This file is used for default debugging. Standard way to use it is: |
modtronix | 4:43abdd8eda40 | 27 | // |
modtronix | 4:43abdd8eda40 | 28 | // |
modtronix | 4:43abdd8eda40 | 29 | //=================================================================== |
modtronix | 4:43abdd8eda40 | 30 | //========= Use in c or cpp file (NOT main.c or main.cpp) =========== |
modtronix | 4:43abdd8eda40 | 31 | // |
modtronix | 4:43abdd8eda40 | 32 | //----- Add following code to top of file debugging is required ----- |
modtronix | 4:43abdd8eda40 | 33 | //#define DEBUG_ENABLE 1 |
modtronix | 4:43abdd8eda40 | 34 | //#include "mx_default_debug.h" |
modtronix | 4:43abdd8eda40 | 35 | // |
modtronix | 4:43abdd8eda40 | 36 | //-------------- Use MX_DEBUG function to write debug --------------- |
modtronix | 4:43abdd8eda40 | 37 | //MX_DEBUG("\r\nTest Debug message"); |
modtronix | 4:43abdd8eda40 | 38 | // |
modtronix | 4:43abdd8eda40 | 39 | // |
modtronix | 4:43abdd8eda40 | 40 | // |
modtronix | 4:43abdd8eda40 | 41 | //=================================================================== |
modtronix | 4:43abdd8eda40 | 42 | //=================== Use in main.c or main.cpp ===================== |
modtronix | 4:43abdd8eda40 | 43 | // |
modtronix | 4:43abdd8eda40 | 44 | //--------------- Add following code to top of main.c --------------- |
modtronix | 4:43abdd8eda40 | 45 | //#define DEBUG_ENABLE_MAIN 1 |
modtronix | 4:43abdd8eda40 | 46 | //Serial streamDebug(USBTX, USBRX); //Default is UART3 |
modtronix | 4:43abdd8eda40 | 47 | //Stream* pMxDebug = &streamDebug; //DON'T EDIT!! This pointer is used by external debug code to write to debug stream |
modtronix | 4:43abdd8eda40 | 48 | //#include "mx_default_debug.h" |
modtronix | 4:43abdd8eda40 | 49 | // |
modtronix | 4:43abdd8eda40 | 50 | //------------- Add following code to bottom of main.c -------------- |
modtronix | 4:43abdd8eda40 | 51 | //void mxDebug(const char *format, ...) { |
modtronix | 4:43abdd8eda40 | 52 | //#define STRING_STACK_LIMIT 100 |
modtronix | 4:43abdd8eda40 | 53 | // |
modtronix | 4:43abdd8eda40 | 54 | // //Process argument list, and write out somewhere |
modtronix | 4:43abdd8eda40 | 55 | // va_list arg; |
modtronix | 4:43abdd8eda40 | 56 | // va_start(arg, format); |
modtronix | 4:43abdd8eda40 | 57 | // int len = vsnprintf(NULL, 0, format, arg); |
modtronix | 4:43abdd8eda40 | 58 | // if (len < STRING_STACK_LIMIT) { |
modtronix | 4:43abdd8eda40 | 59 | // char temp[STRING_STACK_LIMIT]; |
modtronix | 4:43abdd8eda40 | 60 | // vsprintf(temp, format, arg); |
modtronix | 4:43abdd8eda40 | 61 | // streamDebug.puts(temp); |
modtronix | 4:43abdd8eda40 | 62 | // } else { |
modtronix | 4:43abdd8eda40 | 63 | // char *temp = new char[len + 1]; |
modtronix | 4:43abdd8eda40 | 64 | // vsprintf(temp, format, arg); |
modtronix | 4:43abdd8eda40 | 65 | // streamDebug.puts(temp); |
modtronix | 4:43abdd8eda40 | 66 | // delete[] temp; |
modtronix | 4:43abdd8eda40 | 67 | // } |
modtronix | 4:43abdd8eda40 | 68 | // va_end(arg); |
modtronix | 4:43abdd8eda40 | 69 | // |
modtronix | 4:43abdd8eda40 | 70 | // //Send to standard stream |
modtronix | 4:43abdd8eda40 | 71 | // //va_list args; |
modtronix | 4:43abdd8eda40 | 72 | // //va_start(args, format); |
modtronix | 4:43abdd8eda40 | 73 | // //vfprintf(stderr, format, args); |
modtronix | 4:43abdd8eda40 | 74 | // //va_end(args); |
modtronix | 4:43abdd8eda40 | 75 | //} |
modtronix | 4:43abdd8eda40 | 76 | |
modtronix | 4:43abdd8eda40 | 77 | |
modtronix | 4:43abdd8eda40 | 78 | #ifndef WEAK |
modtronix | 4:43abdd8eda40 | 79 | #if defined (__ICCARM__) |
modtronix | 4:43abdd8eda40 | 80 | #define WEAK __weak |
modtronix | 4:43abdd8eda40 | 81 | #else |
modtronix | 4:43abdd8eda40 | 82 | #define WEAK __attribute__((weak)) |
modtronix | 4:43abdd8eda40 | 83 | #endif |
modtronix | 4:43abdd8eda40 | 84 | #endif |
modtronix | 4:43abdd8eda40 | 85 | |
modtronix-com |
12:0303f1aef603 | 86 | #if !defined(MX_DEBUG_IS_POINTER) |
modtronix-com |
13:328bfac0e686 | 87 | #define MX_DEBUG_IS_POINTER 1 |
modtronix-com |
13:328bfac0e686 | 88 | #endif |
modtronix-com |
13:328bfac0e686 | 89 | |
modtronix-com |
13:328bfac0e686 | 90 | #if !defined(DEBUG_ENABLE) |
modtronix-com |
13:328bfac0e686 | 91 | #define DEBUG_ENABLE 0 |
modtronix-com |
12:0303f1aef603 | 92 | #endif |
modtronix | 4:43abdd8eda40 | 93 | |
modtronix-com |
13:328bfac0e686 | 94 | #if !defined(DEBUG_ENABLE_INFO) |
modtronix-com |
13:328bfac0e686 | 95 | #define DEBUG_ENABLE_INFO 0 |
modtronix-com |
13:328bfac0e686 | 96 | #endif |
modtronix-com |
13:328bfac0e686 | 97 | |
modtronix-com |
13:328bfac0e686 | 98 | #if (DEBUG_ENABLE==0) && (DEBUG_ENABLE_INFO==1) |
modtronix-com |
13:328bfac0e686 | 99 | #error "Can not have DEBUG_ENABLE=0 and DEBUG_ENABLE_INFO=1!" |
modtronix-com |
13:328bfac0e686 | 100 | #endif |
modtronix-com |
13:328bfac0e686 | 101 | |
modtronix-com |
13:328bfac0e686 | 102 | |
modtronix | 4:43abdd8eda40 | 103 | /////////////////////////////////////////////////////////////////////////////// |
modtronix | 4:43abdd8eda40 | 104 | // Following is for main file - file that has mxDebug() defined in it |
modtronix | 4:43abdd8eda40 | 105 | #if defined(DEBUG_ENABLE_MAIN) |
modtronix-com |
14:f8583913e1c1 | 106 | #if (DEBUG_ENABLE_MAIN==1) && !defined(MX_DEBUG_DISABLE) |
modtronix-com |
13:328bfac0e686 | 107 | #define MX_DEBUG pMxDebug->printf |
modtronix-com |
13:328bfac0e686 | 108 | //#define MX_DEBUG(format, args...) ((void)0) //DISABLE Debugging |
modtronix-com |
13:328bfac0e686 | 109 | #else |
modtronix-com |
13:328bfac0e686 | 110 | //GCC's CPP has extensions; it allows for macros with a variable number of arguments. We use this extension here to preprocess pmesg away. |
modtronix-com |
13:328bfac0e686 | 111 | #define MX_DEBUG(format, args...) ((void)0) |
modtronix-com |
13:328bfac0e686 | 112 | #endif |
modtronix | 4:43abdd8eda40 | 113 | |
modtronix-com |
14:f8583913e1c1 | 114 | #if (DEBUG_ENABLE_MAIN==1) && (DEBUG_ENABLE_INFO_MAIN==1) && !defined(MX_DEBUG_DISABLE) |
modtronix-com |
13:328bfac0e686 | 115 | #define MX_DEBUG_INFO pMxDebug->printf |
modtronix-com |
13:328bfac0e686 | 116 | //#define MX_DEBUG(format, args...) ((void)0) //DISABLE Debugging |
modtronix-com |
13:328bfac0e686 | 117 | #else |
modtronix-com |
13:328bfac0e686 | 118 | //GCC's CPP has extensions; it allows for macros with a variable number of arguments. We use this extension here to preprocess pmesg away. |
modtronix-com |
13:328bfac0e686 | 119 | #define MX_DEBUG_INFO(format, args...) ((void)0) |
modtronix-com |
13:328bfac0e686 | 120 | #endif |
modtronix | 4:43abdd8eda40 | 121 | |
modtronix | 4:43abdd8eda40 | 122 | /////////////////////////////////////////////////////////////////////////////// |
modtronix | 4:43abdd8eda40 | 123 | // Following is for any file that uses debugging (except main file that has mxDebug() defined in it) |
modtronix | 4:43abdd8eda40 | 124 | #else //#if defined(DEBUG_ENABLE_MAIN) |
modtronix | 4:43abdd8eda40 | 125 | |
modtronix | 4:43abdd8eda40 | 126 | //IMPORTANT, when enabling debugging, it is very important to note the following: |
modtronix | 4:43abdd8eda40 | 127 | //- If (MX_DEBUG_IS_POINTER==1), ensure there is global Stream pointer defined somewhere in code to override "pMxDebug = NULL" below! |
modtronix-com |
12:0303f1aef603 | 128 | //- If (MX_DEBUG_IS_POINTER==0), define a mxDebug() function somewhere in code to handle debug output |
modtronix | 4:43abdd8eda40 | 129 | |
modtronix-com |
14:f8583913e1c1 | 130 | #if (DEBUG_ENABLE==1) && !defined(MX_DEBUG_DISABLE) |
modtronix-com |
13:328bfac0e686 | 131 | //Alternative method in stead of using NULL below. This requires to create derived Stream class in each file we want to use debugging |
modtronix-com |
13:328bfac0e686 | 132 | // class modtronixDebugStream : public Stream {int _putc(int value) {return 0;}int _getc() {return 0;}}; |
modtronix-com |
13:328bfac0e686 | 133 | // static modtronixDebugStream modtronixDebug; |
modtronix-com |
13:328bfac0e686 | 134 | // WEAK Stream* pMxDebug = &modtronixDebug; |
modtronix-com |
13:328bfac0e686 | 135 | #if (MX_DEBUG_IS_POINTER==1) //More efficient, but only works if pMxDebug is defined in code. Disabled by default! |
modtronix-com |
13:328bfac0e686 | 136 | WEAK Stream* pMxDebug = NULL; |
modtronix-com |
13:328bfac0e686 | 137 | #define MX_DEBUG pMxDebug->printf |
modtronix-com |
13:328bfac0e686 | 138 | #else |
modtronix-com |
13:328bfac0e686 | 139 | WEAK void mxDebug(const char *format, ...) {} |
modtronix-com |
13:328bfac0e686 | 140 | #define MX_DEBUG mxDebug |
modtronix-com |
13:328bfac0e686 | 141 | #endif |
modtronix | 4:43abdd8eda40 | 142 | #else |
modtronix-com |
13:328bfac0e686 | 143 | //GCC's CPP has extensions; it allows for macros with a variable number of arguments. We use this extension here to preprocess pmesg away. |
modtronix-com |
13:328bfac0e686 | 144 | #define MX_DEBUG(format, args...) ((void)0) |
modtronix | 4:43abdd8eda40 | 145 | #endif |
modtronix-com |
13:328bfac0e686 | 146 | |
modtronix-com |
14:f8583913e1c1 | 147 | #if (DEBUG_ENABLE==1) && (DEBUG_ENABLE_INFO==1) && !defined(MX_DEBUG_DISABLE) |
modtronix-com |
13:328bfac0e686 | 148 | #if (MX_DEBUG_IS_POINTER==1) //More efficient, but only works if pMxDebug is defined in code. Disabled by default! |
modtronix-com |
13:328bfac0e686 | 149 | #define MX_DEBUG_INFO pMxDebug->printf |
modtronix-com |
13:328bfac0e686 | 150 | #else |
modtronix-com |
13:328bfac0e686 | 151 | #define MX_DEBUG_INFO mxDebug |
modtronix-com |
13:328bfac0e686 | 152 | #endif |
modtronix-com |
13:328bfac0e686 | 153 | #else |
modtronix-com |
13:328bfac0e686 | 154 | //GCC's CPP has extensions; it allows for macros with a variable number of arguments. We use this extension here to preprocess pmesg away. |
modtronix-com |
13:328bfac0e686 | 155 | #define MX_DEBUG_INFO(format, args...) ((void)0) |
modtronix-com |
13:328bfac0e686 | 156 | #endif |
modtronix | 4:43abdd8eda40 | 157 | |
modtronix | 4:43abdd8eda40 | 158 | #endif //#if defined(DEBUG_ENABLE_MAIN) |
modtronix | 4:43abdd8eda40 | 159 | #endif /* SRC_MX_DEFAULT_DEBUG_H_ */ |