targets/plc_debug.c
author Edouard Tisserant
Fri, 09 Sep 2022 09:45:27 +0200
changeset 3599 0d7c41546854
parent 3576 58c09e84c369
child 3644 ecf43c7ac1fb
permissions -rw-r--r--
SVGHMI: fix ToggleButton not always reflecting current state
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
     1
/*
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
     2
 * DEBUGGER code
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
     3
 * 
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
     4
 * On "publish", when buffer is free, debugger stores arbitrary variables 
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
     5
 * content into, and mark this buffer as filled
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
     6
 * 
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
     7
 * 
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
     8
 * Buffer content is read asynchronously, (from non real time part), 
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
     9
 * and then buffer marked free again.
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    10
 *  
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    11
 * 
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    12
 * */
2501
eba2bbb2dd9a Make online debug optional
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2190
diff changeset
    13
#ifdef TARGET_DEBUG_AND_RETAIN_DISABLE
1800
1711339585ce make possible to turn off at compile time online debugging, logging
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1677
diff changeset
    14
1711339585ce make possible to turn off at compile time online debugging, logging
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1677
diff changeset
    15
void __init_debug    (void){}
1711339585ce make possible to turn off at compile time online debugging, logging
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1677
diff changeset
    16
void __cleanup_debug (void){}
1711339585ce make possible to turn off at compile time online debugging, logging
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1677
diff changeset
    17
void __retrieve_debug(void){}
1711339585ce make possible to turn off at compile time online debugging, logging
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1677
diff changeset
    18
void __publish_debug (void){}
1711339585ce make possible to turn off at compile time online debugging, logging
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1677
diff changeset
    19
1711339585ce make possible to turn off at compile time online debugging, logging
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1677
diff changeset
    20
#else
1711339585ce make possible to turn off at compile time online debugging, logging
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1677
diff changeset
    21
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    22
#include "iec_types_all.h"
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    23
#include "POUS.h"
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    24
/*for memcpy*/
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    25
#include <string.h>
335
c5f3f71e7260 fixed bug : buffer overflow when debugging PLC with python blocks
greg
parents: 280
diff changeset
    26
#include <stdio.h>
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    27
3395
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    28
typedef unsigned int dbgvardsc_index_t;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    29
typedef unsigned short trace_buf_offset_t;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    30
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    31
#define BUFFER_EMPTY 0
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    32
#define BUFFER_FULL 1
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    33
2501
eba2bbb2dd9a Make online debug optional
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2190
diff changeset
    34
#ifndef TARGET_ONLINE_DEBUG_DISABLE
3395
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    35
3394
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
    36
#define TRACE_BUFFER_SIZE 4096
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
    37
#define TRACE_LIST_SIZE 1024
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    38
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    39
/* Atomically accessed variable for buffer state */
3395
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    40
static long trace_buffer_state = BUFFER_EMPTY;
3394
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
    41
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
    42
typedef struct trace_item_s {
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
    43
    dbgvardsc_index_t dbgvardsc_index;
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
    44
} trace_item_t;
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
    45
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
    46
trace_item_t trace_list[TRACE_LIST_SIZE];
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
    47
char trace_buffer[TRACE_BUFFER_SIZE];
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    48
3395
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    49
/* Trace's cursor*/
3394
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
    50
static trace_item_t *trace_list_collect_cursor = trace_list;
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
    51
static trace_item_t *trace_list_addvar_cursor = trace_list;
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
    52
static const trace_item_t *trace_list_end = 
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
    53
    &trace_list[TRACE_LIST_SIZE-1];
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
    54
static char *trace_buffer_cursor = trace_buffer;
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
    55
static const char *trace_buffer_end = trace_buffer + TRACE_BUFFER_SIZE;
3395
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    56
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    57
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    58
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    59
#define FORCE_BUFFER_SIZE 1024
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    60
#define FORCE_LIST_SIZE 256
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    61
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    62
typedef struct force_item_s {
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    63
    dbgvardsc_index_t dbgvardsc_index;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    64
    void *value_pointer_backup;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    65
} force_item_t;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    66
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    67
force_item_t force_list[FORCE_LIST_SIZE];
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    68
char force_buffer[FORCE_BUFFER_SIZE];
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    69
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    70
/* Force's cursor*/
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    71
static force_item_t *force_list_apply_cursor = force_list;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    72
static force_item_t *force_list_addvar_cursor = force_list;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    73
static const force_item_t *force_list_end = 
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    74
    &force_list[FORCE_LIST_SIZE-1];
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    75
static char *force_buffer_cursor = force_buffer;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    76
static const char *force_buffer_end = force_buffer + FORCE_BUFFER_SIZE;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    77
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
    78
2501
eba2bbb2dd9a Make online debug optional
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2190
diff changeset
    79
#endif
eba2bbb2dd9a Make online debug optional
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2190
diff changeset
    80
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    81
/***
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    82
 * Declare programs 
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    83
 **/
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    84
%(programs_declarations)s
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    85
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    86
/***
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    87
 * Declare global variables from resources and conf 
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    88
 **/
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    89
%(extern_variables_declarations)s
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    90
1432
8872223a675b Optimized plc_debug.c generated code. Should produce smaller code size. Added statically initialized array for PLC tracable variable description.
Edouard Tisserant
parents: 1403
diff changeset
    91
typedef const struct {
8872223a675b Optimized plc_debug.c generated code. Should produce smaller code size. Added statically initialized array for PLC tracable variable description.
Edouard Tisserant
parents: 1403
diff changeset
    92
    void *ptr;
8872223a675b Optimized plc_debug.c generated code. Should produce smaller code size. Added statically initialized array for PLC tracable variable description.
Edouard Tisserant
parents: 1403
diff changeset
    93
    __IEC_types_enum type;
8872223a675b Optimized plc_debug.c generated code. Should produce smaller code size. Added statically initialized array for PLC tracable variable description.
Edouard Tisserant
parents: 1403
diff changeset
    94
} dbgvardsc_t;
8872223a675b Optimized plc_debug.c generated code. Should produce smaller code size. Added statically initialized array for PLC tracable variable description.
Edouard Tisserant
parents: 1403
diff changeset
    95
3396
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
    96
static const dbgvardsc_t dbgvardsc[] = {
1432
8872223a675b Optimized plc_debug.c generated code. Should produce smaller code size. Added statically initialized array for PLC tracable variable description.
Edouard Tisserant
parents: 1403
diff changeset
    97
%(variable_decl_array)s
8872223a675b Optimized plc_debug.c generated code. Should produce smaller code size. Added statically initialized array for PLC tracable variable description.
Edouard Tisserant
parents: 1403
diff changeset
    98
};
8872223a675b Optimized plc_debug.c generated code. Should produce smaller code size. Added statically initialized array for PLC tracable variable description.
Edouard Tisserant
parents: 1403
diff changeset
    99
3396
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   100
static const dbgvardsc_index_t retain_list[] = {
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   101
%(retain_vardsc_index_array)s
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   102
};
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   103
static unsigned int retain_list_collect_cursor = 0;
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   104
static const unsigned int retain_list_size = sizeof(retain_list)/sizeof(dbgvardsc_index_t);
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   105
1432
8872223a675b Optimized plc_debug.c generated code. Should produce smaller code size. Added statically initialized array for PLC tracable variable description.
Edouard Tisserant
parents: 1403
diff changeset
   106
typedef void(*__for_each_variable_do_fp)(dbgvardsc_t*);
452
2d0718a05cc7 Reflect changes in iec type definitions in matiec/lib
edouard
parents: 450
diff changeset
   107
void __for_each_variable_do(__for_each_variable_do_fp fp)
450
18583d13f0fa Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents: 423
diff changeset
   108
{
2190
b7d803fc44db Fix compilation warning/error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2172
diff changeset
   109
    unsigned int i;
1432
8872223a675b Optimized plc_debug.c generated code. Should produce smaller code size. Added statically initialized array for PLC tracable variable description.
Edouard Tisserant
parents: 1403
diff changeset
   110
    for(i = 0; i < sizeof(dbgvardsc)/sizeof(dbgvardsc_t); i++){
8872223a675b Optimized plc_debug.c generated code. Should produce smaller code size. Added statically initialized array for PLC tracable variable description.
Edouard Tisserant
parents: 1403
diff changeset
   111
        dbgvardsc_t *dsc = &dbgvardsc[i];
8872223a675b Optimized plc_debug.c generated code. Should produce smaller code size. Added statically initialized array for PLC tracable variable description.
Edouard Tisserant
parents: 1403
diff changeset
   112
        if(dsc->type != UNKNOWN_ENUM) 
8872223a675b Optimized plc_debug.c generated code. Should produce smaller code size. Added statically initialized array for PLC tracable variable description.
Edouard Tisserant
parents: 1403
diff changeset
   113
            (*fp)(dsc);
452
2d0718a05cc7 Reflect changes in iec type definitions in matiec/lib
edouard
parents: 450
diff changeset
   114
    }
450
18583d13f0fa Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents: 423
diff changeset
   115
}
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   116
2632
534387caf43d variable access code moved from plc_debug.c to targets/var_access.c for easiewr re-use in ext.
Edouard Tisserant
parents: 2501
diff changeset
   117
#define __Unpack_desc_type dbgvardsc_t
534387caf43d variable access code moved from plc_debug.c to targets/var_access.c for easiewr re-use in ext.
Edouard Tisserant
parents: 2501
diff changeset
   118
534387caf43d variable access code moved from plc_debug.c to targets/var_access.c for easiewr re-use in ext.
Edouard Tisserant
parents: 2501
diff changeset
   119
%(var_access_code)s
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   120
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   121
void Remind(unsigned int offset, unsigned int count, void * p);
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   122
580
9dd978e6537c More robust retain buffer validity management
edouard
parents: 579
diff changeset
   123
extern int CheckRetainBuffer(void);
1457
ff7cfce737ca Added PLCID variable accessible from C side, set with binarie's MD5. Added retain init and cleanup calls. Extended tests/python to test PLCID
Edouard Tisserant
parents: 1432
diff changeset
   124
extern void InitRetain(void);
521
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 511
diff changeset
   125
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   126
void __init_debug(void)
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   127
{
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   128
    /* init local static vars */
2710
aaa1dc426213 plc_debug.c/var_acces.c : whitespace cleanup and other cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2632
diff changeset
   129
#ifndef TARGET_ONLINE_DEBUG_DISABLE
3394
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   130
    trace_buffer_cursor = trace_buffer;
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   131
    trace_list_addvar_cursor = trace_list;
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   132
    trace_list_collect_cursor = trace_list;
3395
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   133
    trace_buffer_state = BUFFER_EMPTY;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   134
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   135
    force_buffer_cursor = force_buffer;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   136
    force_list_addvar_cursor = force_list;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   137
    force_list_apply_cursor = force_list;
2501
eba2bbb2dd9a Make online debug optional
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2190
diff changeset
   138
#endif
eba2bbb2dd9a Make online debug optional
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2190
diff changeset
   139
1457
ff7cfce737ca Added PLCID variable accessible from C side, set with binarie's MD5. Added retain init and cleanup calls. Extended tests/python to test PLCID
Edouard Tisserant
parents: 1432
diff changeset
   140
    InitRetain();
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   141
    /* Iterate over all variables to fill debug buffer */
1459
c9065fb5de0a Added log message when RETAIN memory not valid
Edouard Tisserant
parents: 1457
diff changeset
   142
    if(CheckRetainBuffer()){
3576
58c09e84c369 Runtime: Retain: fix missuse of static classifier leading to ever increasing offset.
Edouard Tisserant
parents: 3441
diff changeset
   143
        unsigned int retain_offset = 0;
3396
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   144
        retain_list_collect_cursor = 0;
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   145
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   146
        /* iterate over retain list */
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   147
        while(retain_list_collect_cursor < retain_list_size){
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   148
            void *value_p = NULL;
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   149
            size_t size;
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   150
            char* next_cursor;
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   151
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   152
            dbgvardsc_t *dsc = &dbgvardsc[
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   153
                retain_list[retain_list_collect_cursor]];
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   154
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   155
            UnpackVar(dsc, &value_p, NULL, &size);
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   156
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   157
            printf("Reminding %%d %%ld \n", retain_list_collect_cursor, size);
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   158
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   159
            /* if buffer not full */
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   160
            Remind(retain_offset, size, value_p);
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   161
            /* increment cursor according size*/
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   162
            retain_offset += size;
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   163
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   164
            retain_list_collect_cursor++;
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   165
        }
1459
c9065fb5de0a Added log message when RETAIN memory not valid
Edouard Tisserant
parents: 1457
diff changeset
   166
    }else{
2710
aaa1dc426213 plc_debug.c/var_acces.c : whitespace cleanup and other cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2632
diff changeset
   167
        char mstr[] = "RETAIN memory invalid - defaults used";
1459
c9065fb5de0a Added log message when RETAIN memory not valid
Edouard Tisserant
parents: 1457
diff changeset
   168
        LogMessage(LOG_WARNING, mstr, sizeof(mstr));
c9065fb5de0a Added log message when RETAIN memory not valid
Edouard Tisserant
parents: 1457
diff changeset
   169
    }
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   170
}
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   171
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   172
extern void InitiateDebugTransfer(void);
1457
ff7cfce737ca Added PLCID variable accessible from C side, set with binarie's MD5. Added retain init and cleanup calls. Extended tests/python to test PLCID
Edouard Tisserant
parents: 1432
diff changeset
   173
extern void CleanupRetain(void);
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   174
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   175
extern unsigned long __tick;
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   176
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   177
void __cleanup_debug(void)
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   178
{
2710
aaa1dc426213 plc_debug.c/var_acces.c : whitespace cleanup and other cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2632
diff changeset
   179
#ifndef TARGET_ONLINE_DEBUG_DISABLE
3394
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   180
    trace_buffer_cursor = trace_buffer;
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   181
    InitiateDebugTransfer();
2501
eba2bbb2dd9a Make online debug optional
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2190
diff changeset
   182
#endif    
eba2bbb2dd9a Make online debug optional
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2190
diff changeset
   183
1457
ff7cfce737ca Added PLCID variable accessible from C side, set with binarie's MD5. Added retain init and cleanup calls. Extended tests/python to test PLCID
Edouard Tisserant
parents: 1432
diff changeset
   184
    CleanupRetain();
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   185
}
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   186
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   187
void __retrieve_debug(void)
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   188
{
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   189
}
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   190
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   191
void Retain(unsigned int offset, unsigned int count, void * p);
605
2250ed42e306 debugger : forcing %M and %Q variables on each cycle, and rework of code for optimization and concision
Edouard Tisserant
parents: 582
diff changeset
   192
2172
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   193
/* Return size of all retain variables */
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   194
unsigned int GetRetainSize(void)
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   195
{
3396
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   196
    unsigned int retain_size = 0;
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   197
    retain_list_collect_cursor = 0;
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   198
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   199
    /* iterate over retain list */
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   200
    while(retain_list_collect_cursor < retain_list_size){
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   201
        void *value_p = NULL;
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   202
        size_t size;
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   203
        char* next_cursor;
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   204
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   205
        dbgvardsc_t *dsc = &dbgvardsc[
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   206
            retain_list[retain_list_collect_cursor]];
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   207
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   208
        UnpackVar(dsc, &value_p, NULL, &size);
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   209
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   210
        retain_size += size;
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   211
        retain_list_collect_cursor++;
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   212
    }
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   213
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   214
    printf("Retain size %%d \n", retain_size);
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   215
            
2172
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   216
    return retain_size;
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   217
}
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   218
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   219
969
1950fe687dde Fix warning with LogMessage function
Laurent Bessard
parents: 954
diff changeset
   220
extern void PLC_GetTime(IEC_TIME*);
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   221
extern int TryEnterDebugSection(void);
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   222
extern long AtomicCompareExchange(long*, long, long);
954
ab487d32ce9a Made logging compatible with windows API
Edouard Tisserant
parents: 944
diff changeset
   223
extern long long AtomicCompareExchange64(long long* , long long , long long);
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   224
extern void LeaveDebugSection(void);
580
9dd978e6537c More robust retain buffer validity management
edouard
parents: 579
diff changeset
   225
extern void ValidateRetainBuffer(void);
9dd978e6537c More robust retain buffer validity management
edouard
parents: 579
diff changeset
   226
extern void InValidateRetainBuffer(void);
450
18583d13f0fa Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents: 423
diff changeset
   227
3395
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   228
#define __ReForceOutput_case_p(TYPENAME)                                                            \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   229
        case TYPENAME##_P_ENUM :                                                                    \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   230
        case TYPENAME##_O_ENUM :                                                                    \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   231
            {                                                                                       \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   232
                char *next_cursor = force_buffer_cursor + sizeof(TYPENAME);                         \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   233
                if(next_cursor <= force_buffer_end ){                                               \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   234
                    /* outputs real value must be systematically forced */                          \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   235
                    if(vartype == TYPENAME##_O_ENUM)                                                \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   236
                        /* overwrite value pointed by backup */                                     \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   237
                        *((TYPENAME *)force_list_apply_cursor->value_pointer_backup) =  \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   238
                            *((TYPENAME *)force_buffer_cursor);                                     \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   239
                    /* inc force_buffer cursor */                                                   \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   240
                    force_buffer_cursor = next_cursor;                                              \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   241
                }else{                                                                              \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   242
                    stop = 1;                                                                       \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   243
                }                                                                                   \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   244
            }                                                                                       \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   245
            break;
423
4d7ac355701d Fix some warnings during compilation
greg
parents: 397
diff changeset
   246
void __publish_debug(void)
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   247
{
580
9dd978e6537c More robust retain buffer validity management
edouard
parents: 579
diff changeset
   248
    InValidateRetainBuffer();
2501
eba2bbb2dd9a Make online debug optional
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2190
diff changeset
   249
    
eba2bbb2dd9a Make online debug optional
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2190
diff changeset
   250
#ifndef TARGET_ONLINE_DEBUG_DISABLE 
239
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   251
    /* Check there is no running debugger re-configuration */
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   252
    if(TryEnterDebugSection()){
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   253
        /* Lock buffer */
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   254
        long latest_state = AtomicCompareExchange(
3394
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   255
            &trace_buffer_state,
3395
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   256
            BUFFER_EMPTY,
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   257
            BUFFER_FULL);
239
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   258
            
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   259
        /* If buffer was free */
3395
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   260
        if(latest_state == BUFFER_EMPTY)
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   261
        {
3395
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   262
            int stop = 0;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   263
            /* Reset force list cursor */
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   264
            force_list_apply_cursor = force_list;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   265
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   266
            /* iterate over force list */
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   267
            while(!stop && force_list_apply_cursor < force_list_addvar_cursor){
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   268
                dbgvardsc_t *dsc = &dbgvardsc[
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   269
                    force_list_apply_cursor->dbgvardsc_index];
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   270
                void *varp = dsc->ptr;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   271
                __IEC_types_enum vartype = dsc->type;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   272
                switch(vartype){
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   273
                    __ANY(__ReForceOutput_case_p)
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   274
                default:
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   275
                    break;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   276
                }
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   277
                force_list_apply_cursor++;                                                      \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   278
            }
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   279
239
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   280
            /* Reset buffer cursor */
3394
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   281
            trace_buffer_cursor = trace_buffer;
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   282
            /* Reset trace list cursor */
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   283
            trace_list_collect_cursor = trace_list;
3395
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   284
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   285
            /* iterate over trace list */
3394
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   286
            while(trace_list_collect_cursor < trace_list_addvar_cursor){
3395
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   287
                void *value_p = NULL;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   288
                size_t size;
3394
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   289
                char* next_cursor;
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   290
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   291
                dbgvardsc_t *dsc = &dbgvardsc[
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   292
                    trace_list_collect_cursor->dbgvardsc_index];
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   293
3395
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   294
                UnpackVar(dsc, &value_p, NULL, &size);
3394
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   295
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   296
                /* copy visible variable to buffer */;
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   297
                if(__Is_a_string(dsc)){
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   298
                    /* optimization for strings */
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   299
                    /* assume NULL terminated strings */
3395
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   300
                    size = ((STRING*)value_p)->len + 1;
3394
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   301
                }
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   302
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   303
                /* compute next cursor positon.*/
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   304
                next_cursor = trace_buffer_cursor + size;
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   305
                /* check for buffer overflow */
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   306
                if(next_cursor < trace_buffer_end)
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   307
                    /* copy data to the buffer */
3395
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   308
                    memcpy(trace_buffer_cursor, value_p, size);
3394
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   309
                else
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   310
                    /* stop looping in case of overflow */
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   311
                    break;
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   312
                /* increment cursor according size*/
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   313
                trace_buffer_cursor = next_cursor;
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   314
                trace_list_collect_cursor++;
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   315
            }
239
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   316
            
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   317
            /* Leave debug section,
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   318
             * Trigger asynchronous transmission 
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   319
             * (returns immediately) */
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   320
            InitiateDebugTransfer(); /* size */
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   321
        }
239
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   322
        LeaveDebugSection();
3394
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   323
    }
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   324
#endif
3576
58c09e84c369 Runtime: Retain: fix missuse of static classifier leading to ever increasing offset.
Edouard Tisserant
parents: 3441
diff changeset
   325
    unsigned int retain_offset = 0;
3394
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   326
    /* when not debugging, do only retain */
3396
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   327
    retain_list_collect_cursor = 0;
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   328
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   329
    /* iterate over retain list */
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   330
    while(retain_list_collect_cursor < retain_list_size){
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   331
        void *value_p = NULL;
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   332
        size_t size;
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   333
        char* next_cursor;
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   334
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   335
        dbgvardsc_t *dsc = &dbgvardsc[
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   336
            retain_list[retain_list_collect_cursor]];
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   337
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   338
        UnpackVar(dsc, &value_p, NULL, &size);
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   339
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   340
        /* if buffer not full */
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   341
        Retain(retain_offset, size, value_p);
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   342
        /* increment cursor according size*/
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   343
        retain_offset += size;
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   344
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   345
        retain_list_collect_cursor++;
8c8cb5c9ff38 Runtime: Now retain uses a list based on data available in VARIABLES.csv instead of traversing the whole instance tree looking for RETAIN flag.
Edouard Tisserant
parents: 3395
diff changeset
   346
    }
580
9dd978e6537c More robust retain buffer validity management
edouard
parents: 579
diff changeset
   347
    ValidateRetainBuffer();
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   348
}
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   349
2501
eba2bbb2dd9a Make online debug optional
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2190
diff changeset
   350
#ifndef TARGET_ONLINE_DEBUG_DISABLE
3395
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   351
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   352
#define TRACE_LIST_OVERFLOW    1
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   353
#define FORCE_LIST_OVERFLOW    2
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   354
#define FORCE_BUFFER_OVERFLOW  3
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   355
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   356
#define __ForceVariable_case_t(TYPENAME)                                                \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   357
        case TYPENAME##_ENUM :                                                          \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   358
            /* add to force_list*/                                                      \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   359
            force_list_addvar_cursor->dbgvardsc_index = idx;                            \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   360
            ((__IEC_##TYPENAME##_t *)varp)->flags |= __IEC_FORCE_FLAG;                  \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   361
            ((__IEC_##TYPENAME##_t *)varp)->value = *((TYPENAME *)force);               \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   362
            break;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   363
#define __ForceVariable_case_p(TYPENAME)                                                \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   364
        case TYPENAME##_P_ENUM :                                                        \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   365
        case TYPENAME##_O_ENUM :                                                        \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   366
            {                                                                           \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   367
                char *next_cursor = force_buffer_cursor + sizeof(TYPENAME);             \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   368
                if(next_cursor <= force_buffer_end ){                                   \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   369
                    /* add to force_list*/                                              \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   370
                    force_list_addvar_cursor->dbgvardsc_index = idx;                    \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   371
                    /* save pointer to backup */                                        \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   372
                    force_list_addvar_cursor->value_pointer_backup =                    \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   373
                        ((__IEC_##TYPENAME##_p *)varp)->value;                          \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   374
                    /* store forced value in force_buffer */                            \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   375
                    *((TYPENAME *)force_buffer_cursor) = *((TYPENAME *)force);          \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   376
                    /* replace pointer with pointer to force_buffer */                  \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   377
                    ((__IEC_##TYPENAME##_p *)varp)->value =                             \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   378
                        (TYPENAME *)force_buffer_cursor;                                \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   379
                    /* mark variable as forced */                                       \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   380
                    ((__IEC_##TYPENAME##_p *)varp)->flags |= __IEC_FORCE_FLAG;          \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   381
                    /* inc force_buffer cursor */                                       \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   382
                    force_buffer_cursor = next_cursor;                                  \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   383
                    /* outputs real value must be systematically forced */              \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   384
                    if(vartype == TYPENAME##_O_ENUM)                                    \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   385
                        *(((__IEC_##TYPENAME##_p *)varp)->value) = *((TYPENAME *)force);\
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   386
                } else {                                                                \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   387
                    error_code = FORCE_BUFFER_OVERFLOW;                                 \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   388
                    goto error_cleanup;                                                 \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   389
                }                                                                       \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   390
            }                                                                           \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   391
            break;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   392
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   393
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   394
void ResetDebugVariables(void);
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   395
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   396
int RegisterDebugVariable(dbgvardsc_index_t idx, void* force)
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   397
{
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   398
    int error_code = 0;
3394
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   399
    if(idx < sizeof(dbgvardsc)/sizeof(dbgvardsc_t)){
3395
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   400
        /* add to trace_list, inc trace_list_addvar_cursor*/
3394
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   401
        if(trace_list_addvar_cursor <= trace_list_end){
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   402
            trace_list_addvar_cursor->dbgvardsc_index = idx;
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   403
            trace_list_addvar_cursor++;
3395
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   404
        } else {
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   405
            error_code = TRACE_LIST_OVERFLOW;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   406
            goto error_cleanup;
3394
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   407
        }
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   408
        if(force){
3395
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   409
            if(force_list_addvar_cursor <= force_list_end){
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   410
                dbgvardsc_t *dsc = &dbgvardsc[idx];
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   411
                void *varp = dsc->ptr;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   412
                __IEC_types_enum vartype = dsc->type;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   413
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   414
                switch(vartype){
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   415
                    __ANY(__ForceVariable_case_t)
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   416
                    __ANY(__ForceVariable_case_p)
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   417
                default:
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   418
                    break;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   419
                }
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   420
                /* inc force_list cursor */
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   421
                force_list_addvar_cursor++;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   422
            } else {
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   423
                error_code = FORCE_LIST_OVERFLOW;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   424
                goto error_cleanup;
3394
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   425
            }
1432
8872223a675b Optimized plc_debug.c generated code. Should produce smaller code size. Added statically initialized array for PLC tracable variable description.
Edouard Tisserant
parents: 1403
diff changeset
   426
        }
450
18583d13f0fa Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents: 423
diff changeset
   427
    }
3395
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   428
    return 0;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   429
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   430
error_cleanup:
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   431
    ResetDebugVariables();
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   432
    trace_buffer_state = BUFFER_EMPTY;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   433
    return error_code;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   434
    
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   435
}
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   436
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   437
#define ResetForcedVariable_case_t(TYPENAME)                                            \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   438
        case TYPENAME##_ENUM :                                                          \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   439
            ((__IEC_##TYPENAME##_t *)varp)->flags &= ~__IEC_FORCE_FLAG;                 \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   440
            /* for local variable we don't restore original value */                    \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   441
            /* that can be added if needed, but it was like that since ever */          \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   442
            break;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   443
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   444
#define ResetForcedVariable_case_p(TYPENAME)                                            \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   445
        case TYPENAME##_P_ENUM :                                                        \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   446
        case TYPENAME##_O_ENUM :                                                        \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   447
            ((__IEC_##TYPENAME##_p *)varp)->flags &= ~__IEC_FORCE_FLAG;                 \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   448
            /* restore backup to pointer */                                             \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   449
            ((__IEC_##TYPENAME##_p *)varp)->value =                                     \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   450
                force_list_apply_cursor->value_pointer_backup;                          \
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   451
            break;
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   452
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   453
void ResetDebugVariables(void)
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   454
{
3395
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   455
    /* Reset trace list */
3394
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   456
    trace_list_addvar_cursor = trace_list;
3395
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   457
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   458
    force_list_apply_cursor = force_list;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   459
    /* Restore forced variables */
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   460
    while(force_list_apply_cursor < force_list_addvar_cursor){
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   461
        dbgvardsc_t *dsc = &dbgvardsc[
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   462
            force_list_apply_cursor->dbgvardsc_index];
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   463
        void *varp = dsc->ptr;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   464
        switch(dsc->type){
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   465
            __ANY(ResetForcedVariable_case_t)
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   466
            __ANY(ResetForcedVariable_case_p)
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   467
        default:
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   468
            break;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   469
        }
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   470
        /* inc force_list cursor */
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   471
        force_list_apply_cursor++;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   472
    } /* else TODO: warn user about failure to force */ 
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   473
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   474
    /* Reset force list */
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   475
    force_list_addvar_cursor = force_list;
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   476
    /* Reset force buffer */
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   477
    force_buffer_cursor = force_buffer;
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   478
}
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   479
423
4d7ac355701d Fix some warnings during compilation
greg
parents: 397
diff changeset
   480
void FreeDebugData(void)
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   481
{
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   482
    /* atomically mark buffer as free */
1403
dd6d40094782 Fixed unused variable in plc_debug.c
Edouard Tisserant
parents: 1074
diff changeset
   483
    AtomicCompareExchange(
3394
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   484
        &trace_buffer_state,
3395
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   485
        BUFFER_FULL,
93ad018fb602 RUNTIME: Variable forcing now uses limited list and buffer instead of systematical instance tree traversal and in-tree "fvalue" to keep track of forced value for pointed variables (external, located). Pointer swapping is performed when forcing externals and located, with backup being restored when forcing is reset. Retain still uses tree traversal.
Edouard Tisserant
parents: 3394
diff changeset
   486
        BUFFER_EMPTY);
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   487
}
452
2d0718a05cc7 Reflect changes in iec type definitions in matiec/lib
edouard
parents: 450
diff changeset
   488
int WaitDebugData(unsigned long *tick);
450
18583d13f0fa Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents: 423
diff changeset
   489
/* Wait until debug data ready and return pointer to it */
18583d13f0fa Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents: 423
diff changeset
   490
int GetDebugData(unsigned long *tick, unsigned long *size, void **buffer){
504
688e84df3408 Fixed debug again, did some code tidying
edouard
parents: 502
diff changeset
   491
    int wait_error = WaitDebugData(tick);
688e84df3408 Fixed debug again, did some code tidying
edouard
parents: 502
diff changeset
   492
    if(!wait_error){
3394
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   493
        *size = trace_buffer_cursor - trace_buffer;
9ea29ac18837 RUNTIME: Variable trace now uses limited list and buffer instead of flags in instance tree that was requiring systematical instance tree traversal, and worst size buffer. Forcing and retain still use tree traversal.
Edouard Tisserant
parents: 2710
diff changeset
   494
        *buffer = trace_buffer;
502
5343ae43f6d0 LPC connector - one step further
edouard
parents: 491
diff changeset
   495
    }
504
688e84df3408 Fixed debug again, did some code tidying
edouard
parents: 502
diff changeset
   496
    return wait_error;
688e84df3408 Fixed debug again, did some code tidying
edouard
parents: 502
diff changeset
   497
}
2501
eba2bbb2dd9a Make online debug optional
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2190
diff changeset
   498
#endif
eba2bbb2dd9a Make online debug optional
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2190
diff changeset
   499
#endif
eba2bbb2dd9a Make online debug optional
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2190
diff changeset
   500