# HG changeset patch # User Andrey Skvortsov # Date 1546733499 -10800 # Node ID eba2bbb2dd9a5645221c9da9d4a2dee6f207a182 # Parent 8ce461a40855423154a333ee6840390f1d064740 Make online debug optional It could be useful for very small targets like Atmega (Arduino) and for target bring-up there developer want to have running PLC program, but has not implemented runtime communication yet. TARGET_DEBUG_AND_RETAIN_DISABLE - completely disable debug and retain functionality. Previously named TARGET_DEBUG_DISABLE. TARGET_ONLINE_DEBUG_DISABLE - can be used to enable retain functionality (no define TARGET_DEBUG_AND_RETAIN_DISABLE is used), but disable online debug with corresponding RAM/FLASH overhead. TARGET_LOGGING_DISABLE - disables logging functionality from runtime and PLC program TARGET_EXT_SYNC_DISABLE - disables PLC program synchronization with external events. For example, it could be used to synchronize several PLCs that control motors for different axes. By default all these options are off. To test generate program for Generic target, put following files in project files directory and run build.sh after generating PLC program. This is very easy to integrate into makefile (Generic target). [------------- build.sh --------------------------] files=$(find $PWD/../build -iname '*.c' | grep -v POUS.c) arm-none-eabi-gcc \ -DTARGET_DEBUG_AND_RETAIN_DISABLE \ -DTARGET_ONLINE_DEBUG_DISABLE \ -DTARGET_LOGGING_DISABLE \ -DTARGET_EXT_SYNC_DISABLE \ -flto -ffunction-sections -fdata-sections -I../../../../matiec/lib/C \ $files \ main.c \ -Wl,--Map=./program.map,--cref \ -nodefaultlibs --specs=nano.specs -Wl,--static -Wl,--gc-section -Wl,--start-group -lc -lm -lnosys -lgcc -Wl,--end-group [------------------------------------------------] [------------- main.c --------------------------] #ifndef TARGET_DEBUG_AND_RETAIN_DISABLE void Retain(void){} void InValidateRetainBuffer(void){} void ValidateRetainBuffer(void){} #endif extern void __run(void); int main(void) { for(;;) { __run(); // sleep common_ticktime__ ns // add common_ticktime__ ns to __CURRENT_TIME } return 0; } [------------------------------------------------] diff -r 8ce461a40855 -r eba2bbb2dd9a targets/plc_debug.c --- a/targets/plc_debug.c Sun Jan 06 02:00:07 2019 +0300 +++ b/targets/plc_debug.c Sun Jan 06 03:11:39 2019 +0300 @@ -10,8 +10,7 @@ * * * */ - -#ifdef TARGET_DEBUG_DISABLE +#ifdef TARGET_DEBUG_AND_RETAIN_DISABLE void __init_debug (void){} void __cleanup_debug (void){} @@ -26,6 +25,7 @@ #include #include +#ifndef TARGET_ONLINE_DEBUG_DISABLE #define BUFFER_SIZE %(buffer_size)d /* Atomically accessed variable for buffer state */ @@ -38,6 +38,8 @@ /* Buffer's cursor*/ static char* buffer_cursor = debug_buffer; +#endif + static unsigned int retain_offset = 0; /*** * Declare programs @@ -126,9 +128,12 @@ void __init_debug(void) { /* init local static vars */ +#ifndef TARGET_ONLINE_DEBUG_DISABLE buffer_cursor = debug_buffer; + buffer_state = BUFFER_FREE; +#endif + retain_offset = 0; - buffer_state = BUFFER_FREE; InitRetain(); /* Iterate over all variables to fill debug buffer */ if(CheckRetainBuffer()){ @@ -147,8 +152,11 @@ void __cleanup_debug(void) { +#ifndef TARGET_ONLINE_DEBUG_DISABLE buffer_cursor = debug_buffer; InitiateDebugTransfer(); +#endif + CleanupRetain(); } @@ -169,6 +177,8 @@ if(flags & ( __IEC_DEBUG_FLAG | __IEC_RETAIN_FLAG)){ USINT size = __get_type_enum_size(dsc->type); + +#ifndef TARGET_ONLINE_DEBUG_DISABLE if(flags & __IEC_DEBUG_FLAG){ /* copy visible variable to buffer */; if(do_debug){ @@ -192,6 +202,8 @@ memcpy(real_value_p, visible_value_p, size); } } +#endif + if(flags & __IEC_RETAIN_FLAG){ /* compute next cursor positon*/ unsigned int next_retain_offset = retain_offset + size; @@ -248,6 +260,8 @@ { retain_offset = 0; InValidateRetainBuffer(); + +#ifndef TARGET_ONLINE_DEBUG_DISABLE /* Check there is no running debugger re-configuration */ if(TryEnterDebugSection()){ /* Lock buffer */ @@ -273,13 +287,16 @@ __for_each_variable_do(RetainIterator); } LeaveDebugSection(); - }else{ + }else +#endif + { /* when not debugging, do only retain */ __for_each_variable_do(RetainIterator); } ValidateRetainBuffer(); } +#ifndef TARGET_ONLINE_DEBUG_DISABLE #define __RegisterDebugVariable_case_t(TYPENAME) \ case TYPENAME##_ENUM :\ ((__IEC_##TYPENAME##_t *)varp)->flags |= flags;\ @@ -362,6 +379,6 @@ } return wait_error; } - -#endif - +#endif +#endif +