Library for Modtronix NZ32 STM32 boards, like the NZ32-SC151, NZ32-SB072, NZ32-SE411 and others

Committer:
modtronix
Date:
Sun Aug 30 09:29:08 2015 +1000
Revision:
4:43abdd8eda40
Child:
12:0303f1aef603
Added buffer and debug files

Who changed what in which revision?

UserRevisionLine numberNew 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 4:43abdd8eda40 24 //This file is used for default debugging. Standard way to use it is:
modtronix 4:43abdd8eda40 25 //
modtronix 4:43abdd8eda40 26 //
modtronix 4:43abdd8eda40 27 //===================================================================
modtronix 4:43abdd8eda40 28 //========= Use in c or cpp file (NOT main.c or main.cpp) ===========
modtronix 4:43abdd8eda40 29 //
modtronix 4:43abdd8eda40 30 //----- Add following code to top of file debugging is required -----
modtronix 4:43abdd8eda40 31 //#define DEBUG_ENABLE 1
modtronix 4:43abdd8eda40 32 //#include "mx_default_debug.h"
modtronix 4:43abdd8eda40 33 //
modtronix 4:43abdd8eda40 34 //-------------- Use MX_DEBUG function to write debug ---------------
modtronix 4:43abdd8eda40 35 //MX_DEBUG("\r\nTest Debug message");
modtronix 4:43abdd8eda40 36 //
modtronix 4:43abdd8eda40 37 //
modtronix 4:43abdd8eda40 38 //
modtronix 4:43abdd8eda40 39 //===================================================================
modtronix 4:43abdd8eda40 40 //=================== Use in main.c or main.cpp =====================
modtronix 4:43abdd8eda40 41 //
modtronix 4:43abdd8eda40 42 //--------------- Add following code to top of main.c ---------------
modtronix 4:43abdd8eda40 43 //#define DEBUG_ENABLE_MAIN 1
modtronix 4:43abdd8eda40 44 //Serial streamDebug(USBTX, USBRX); //Default is UART3
modtronix 4:43abdd8eda40 45 //Stream* pMxDebug = &streamDebug; //DON'T EDIT!! This pointer is used by external debug code to write to debug stream
modtronix 4:43abdd8eda40 46 //#include "mx_default_debug.h"
modtronix 4:43abdd8eda40 47 //
modtronix 4:43abdd8eda40 48 //------------- Add following code to bottom of main.c --------------
modtronix 4:43abdd8eda40 49 //void mxDebug(const char *format, ...) {
modtronix 4:43abdd8eda40 50 //#define STRING_STACK_LIMIT 100
modtronix 4:43abdd8eda40 51 //
modtronix 4:43abdd8eda40 52 // //Process argument list, and write out somewhere
modtronix 4:43abdd8eda40 53 // va_list arg;
modtronix 4:43abdd8eda40 54 // va_start(arg, format);
modtronix 4:43abdd8eda40 55 // int len = vsnprintf(NULL, 0, format, arg);
modtronix 4:43abdd8eda40 56 // if (len < STRING_STACK_LIMIT) {
modtronix 4:43abdd8eda40 57 // char temp[STRING_STACK_LIMIT];
modtronix 4:43abdd8eda40 58 // vsprintf(temp, format, arg);
modtronix 4:43abdd8eda40 59 // streamDebug.puts(temp);
modtronix 4:43abdd8eda40 60 // } else {
modtronix 4:43abdd8eda40 61 // char *temp = new char[len + 1];
modtronix 4:43abdd8eda40 62 // vsprintf(temp, format, arg);
modtronix 4:43abdd8eda40 63 // streamDebug.puts(temp);
modtronix 4:43abdd8eda40 64 // delete[] temp;
modtronix 4:43abdd8eda40 65 // }
modtronix 4:43abdd8eda40 66 // va_end(arg);
modtronix 4:43abdd8eda40 67 //
modtronix 4:43abdd8eda40 68 // //Send to standard stream
modtronix 4:43abdd8eda40 69 // //va_list args;
modtronix 4:43abdd8eda40 70 // //va_start(args, format);
modtronix 4:43abdd8eda40 71 // //vfprintf(stderr, format, args);
modtronix 4:43abdd8eda40 72 // //va_end(args);
modtronix 4:43abdd8eda40 73 //}
modtronix 4:43abdd8eda40 74
modtronix 4:43abdd8eda40 75
modtronix 4:43abdd8eda40 76 #ifndef WEAK
modtronix 4:43abdd8eda40 77 #if defined (__ICCARM__)
modtronix 4:43abdd8eda40 78 #define WEAK __weak
modtronix 4:43abdd8eda40 79 #else
modtronix 4:43abdd8eda40 80 #define WEAK __attribute__((weak))
modtronix 4:43abdd8eda40 81 #endif
modtronix 4:43abdd8eda40 82 #endif
modtronix 4:43abdd8eda40 83
modtronix 4:43abdd8eda40 84
modtronix 4:43abdd8eda40 85 ///////////////////////////////////////////////////////////////////////////////
modtronix 4:43abdd8eda40 86 // Following is for main file - file that has mxDebug() defined in it
modtronix 4:43abdd8eda40 87 #if defined(DEBUG_ENABLE_MAIN)
modtronix 4:43abdd8eda40 88
modtronix 4:43abdd8eda40 89 #if (DEBUG_ENABLE_MAIN==1) && !defined(NDEBUG)
modtronix 4:43abdd8eda40 90 #define MX_DEBUG pMxDebug->printf
modtronix 4:43abdd8eda40 91 //#define MX_DEBUG(format, args...) ((void)0) //DISABLE Debugging
modtronix 4:43abdd8eda40 92 #else
modtronix 4:43abdd8eda40 93 //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 4:43abdd8eda40 94 #define MX_DEBUG(format, args...) ((void)0)
modtronix 4:43abdd8eda40 95 #endif
modtronix 4:43abdd8eda40 96
modtronix 4:43abdd8eda40 97
modtronix 4:43abdd8eda40 98 ///////////////////////////////////////////////////////////////////////////////
modtronix 4:43abdd8eda40 99 // Following is for any file that uses debugging (except main file that has mxDebug() defined in it)
modtronix 4:43abdd8eda40 100 #else //#if defined(DEBUG_ENABLE_MAIN)
modtronix 4:43abdd8eda40 101
modtronix 4:43abdd8eda40 102 //IMPORTANT, when enabling debugging, it is very important to note the following:
modtronix 4:43abdd8eda40 103 //- If (MX_DEBUG_IS_POINTER==1), ensure there is global Stream pointer defined somewhere in code to override "pMxDebug = NULL" below!
modtronix 4:43abdd8eda40 104 //- If (MX_DEBUG_IS_POINTER==0), define a mxDebug() function somewhere in code to handel debug output
modtronix 4:43abdd8eda40 105
modtronix 4:43abdd8eda40 106 #if (DEBUG_ENABLE==1) && !defined(NDEBUG)
modtronix 4:43abdd8eda40 107 //Alternative method in stead of using NULL below. This requires to create derived Stream class in each file we want to use debugging
modtronix 4:43abdd8eda40 108 // class modtronixDebugStream : public Stream {int _putc(int value) {return 0;}int _getc() {return 0;}};
modtronix 4:43abdd8eda40 109 // static modtronixDebugStream modtronixDebug;
modtronix 4:43abdd8eda40 110 // WEAK Stream* pMxDebug = &modtronixDebug;
modtronix 4:43abdd8eda40 111 #if (MX_DEBUG_IS_POINTER==1) //More efficient, but only works if pMxDebug is defined in code. Disabled by default!
modtronix 4:43abdd8eda40 112 WEAK Stream* pMxDebug = NULL;
modtronix 4:43abdd8eda40 113 #define MX_DEBUG pMxDebug->printf
modtronix 4:43abdd8eda40 114 #else
modtronix 4:43abdd8eda40 115 WEAK void mxDebug(const char *format, ...) {}
modtronix 4:43abdd8eda40 116 #define MX_DEBUG mxDebug
modtronix 4:43abdd8eda40 117 #endif
modtronix 4:43abdd8eda40 118 #else
modtronix 4:43abdd8eda40 119 //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 4:43abdd8eda40 120 #define MX_DEBUG(format, args...) ((void)0)
modtronix 4:43abdd8eda40 121 #endif
modtronix 4:43abdd8eda40 122
modtronix 4:43abdd8eda40 123 #endif //#if defined(DEBUG_ENABLE_MAIN)
modtronix 4:43abdd8eda40 124
modtronix 4:43abdd8eda40 125
modtronix 4:43abdd8eda40 126
modtronix 4:43abdd8eda40 127 #endif /* SRC_MX_DEFAULT_DEBUG_H_ */