targets/plc_debug.c
author Edouard Tisserant
Thu, 09 Dec 2021 10:21:45 +0100
branchRuntimeLists
changeset 3395 93ad018fb602
parent 3394 9ea29ac18837
child 3396 8c8cb5c9ff38
permissions -rw-r--r--
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.
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
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
    81
static unsigned int retain_offset = 0;
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    82
/***
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    83
 * Declare programs 
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    84
 **/
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    85
%(programs_declarations)s
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
/***
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    88
 * Declare global variables from resources and conf 
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    89
 **/
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    90
%(extern_variables_declarations)s
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
    91
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
    92
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
    93
    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
    94
    __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
    95
} 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
    96
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
static dbgvardsc_t dbgvardsc[] = {
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
%(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
    99
};
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
   100
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
   101
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
   102
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
   103
{
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
   104
    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
   105
    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
   106
        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
   107
        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
   108
            (*fp)(dsc);
452
2d0718a05cc7 Reflect changes in iec type definitions in matiec/lib
edouard
parents: 450
diff changeset
   109
    }
450
18583d13f0fa Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents: 423
diff changeset
   110
}
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   111
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
   112
#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
   113
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
   114
%(var_access_code)s
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   115
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   116
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
   117
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
   118
void RemindIterator(dbgvardsc_t *dsc)
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   119
{
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
   120
    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
   121
    char flags;
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
   122
    size_t 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
   123
    UnpackVar(dsc, &value_p, &flags, &size);
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   124
507
bf6f623d7450 Bug on testing Retain and Force flags fixed
laurent
parents: 504
diff changeset
   125
    if(flags & __IEC_RETAIN_FLAG){
450
18583d13f0fa Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents: 423
diff changeset
   126
        /* compute next cursor positon*/
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   127
        unsigned int next_retain_offset = retain_offset + size;
450
18583d13f0fa Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents: 423
diff changeset
   128
        /* if buffer not full */
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
   129
        Remind(retain_offset, size, value_p);
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   130
        /* increment cursor according size*/
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   131
        retain_offset = next_retain_offset;
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   132
    }
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   133
}
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   134
580
9dd978e6537c More robust retain buffer validity management
edouard
parents: 579
diff changeset
   135
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
   136
extern void InitRetain(void);
521
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 511
diff changeset
   137
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   138
void __init_debug(void)
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   139
{
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   140
    /* 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
   141
#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
   142
    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
   143
    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
   144
    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
   145
    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
   146
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
   147
    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
   148
    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
   149
    force_list_apply_cursor = force_list;
2501
eba2bbb2dd9a Make online debug optional
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2190
diff changeset
   150
#endif
eba2bbb2dd9a Make online debug optional
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2190
diff changeset
   151
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   152
    retain_offset = 0;
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
   153
    InitRetain();
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   154
    /* Iterate over all variables to fill debug buffer */
1459
c9065fb5de0a Added log message when RETAIN memory not valid
Edouard Tisserant
parents: 1457
diff changeset
   155
    if(CheckRetainBuffer()){
2710
aaa1dc426213 plc_debug.c/var_acces.c : whitespace cleanup and other cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2632
diff changeset
   156
        __for_each_variable_do(RemindIterator);
1459
c9065fb5de0a Added log message when RETAIN memory not valid
Edouard Tisserant
parents: 1457
diff changeset
   157
    }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
   158
        char mstr[] = "RETAIN memory invalid - defaults used";
1459
c9065fb5de0a Added log message when RETAIN memory not valid
Edouard Tisserant
parents: 1457
diff changeset
   159
        LogMessage(LOG_WARNING, mstr, sizeof(mstr));
c9065fb5de0a Added log message when RETAIN memory not valid
Edouard Tisserant
parents: 1457
diff changeset
   160
    }
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   161
    retain_offset = 0;
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   162
}
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   163
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   164
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
   165
extern void CleanupRetain(void);
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   166
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   167
extern unsigned long __tick;
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   168
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   169
void __cleanup_debug(void)
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   170
{
2710
aaa1dc426213 plc_debug.c/var_acces.c : whitespace cleanup and other cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2632
diff changeset
   171
#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
   172
    trace_buffer_cursor = trace_buffer;
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   173
    InitiateDebugTransfer();
2501
eba2bbb2dd9a Make online debug optional
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2190
diff changeset
   174
#endif    
eba2bbb2dd9a Make online debug optional
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2190
diff changeset
   175
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
   176
    CleanupRetain();
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   177
}
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   178
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   179
void __retrieve_debug(void)
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   180
{
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   181
}
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   182
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   183
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   184
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
   185
1479
8f41aa88aa46 fix many compilation warnings about static variables used by non-static functions
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1459
diff changeset
   186
static inline void BufferIterator(dbgvardsc_t *dsc, int do_debug)
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
   187
{
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
   188
    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
   189
    char flags;
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
   190
    size_t 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
   191
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
   192
    UnpackVar(dsc, &value_p, &flags, &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
   193
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
   194
    if(flags & __IEC_RETAIN_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
   195
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
   196
            /* compute next cursor positon*/
2250ed42e306 debugger : forcing %M and %Q variables on each cycle, and rework of code for optimization and concision
Edouard Tisserant
parents: 582
diff changeset
   197
            unsigned int next_retain_offset = retain_offset + size;
2250ed42e306 debugger : forcing %M and %Q variables on each cycle, and rework of code for optimization and concision
Edouard Tisserant
parents: 582
diff changeset
   198
            /* if buffer not full */
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
   199
            Retain(retain_offset, size, value_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
   200
            /* increment cursor according size*/
2250ed42e306 debugger : forcing %M and %Q variables on each cycle, and rework of code for optimization and concision
Edouard Tisserant
parents: 582
diff changeset
   201
            retain_offset = next_retain_offset;
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
   202
    }
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
   203
}
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
   204
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
   205
void RetainIterator(dbgvardsc_t *dsc){
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
   206
    BufferIterator(dsc, 0);
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   207
}
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   208
2172
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   209
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   210
unsigned int retain_size = 0;
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   211
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   212
/* GetRetainSizeIterator */
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   213
void GetRetainSizeIterator(dbgvardsc_t *dsc)
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   214
{
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
   215
    char flags;
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
   216
    size_t 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
   217
    UnpackVar(dsc, NULL, &flags, &size);
2172
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
    if(flags & __IEC_RETAIN_FLAG){
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   220
        /* Calc retain buffer size */
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   221
        retain_size += size;
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   222
    }
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   223
}
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   224
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   225
/* Return size of all retain variables */
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   226
unsigned int GetRetainSize(void)
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   227
{
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   228
    __for_each_variable_do(GetRetainSizeIterator);
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   229
    return retain_size;
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   230
}
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   231
9fa5be79bb77 Add helper function GetRetainSize()
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1800
diff changeset
   232
969
1950fe687dde Fix warning with LogMessage function
Laurent Bessard
parents: 954
diff changeset
   233
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
   234
extern int TryEnterDebugSection(void);
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   235
extern long AtomicCompareExchange(long*, long, long);
954
ab487d32ce9a Made logging compatible with windows API
Edouard Tisserant
parents: 944
diff changeset
   236
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
   237
extern void LeaveDebugSection(void);
580
9dd978e6537c More robust retain buffer validity management
edouard
parents: 579
diff changeset
   238
extern void ValidateRetainBuffer(void);
9dd978e6537c More robust retain buffer validity management
edouard
parents: 579
diff changeset
   239
extern void InValidateRetainBuffer(void);
450
18583d13f0fa Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents: 423
diff changeset
   240
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
   241
#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
   242
        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
   243
        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
   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
                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
   246
                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
   247
                    /* 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
   248
                    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
   249
                        /* 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
   250
                        *((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
   251
                            *((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
   252
                    /* 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
   253
                    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
   254
                }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
   255
                    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
   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
   257
            }                                                                                       \
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
   258
            break;
423
4d7ac355701d Fix some warnings during compilation
greg
parents: 397
diff changeset
   259
void __publish_debug(void)
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   260
{
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 477
diff changeset
   261
    retain_offset = 0;
580
9dd978e6537c More robust retain buffer validity management
edouard
parents: 579
diff changeset
   262
    InValidateRetainBuffer();
2501
eba2bbb2dd9a Make online debug optional
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2190
diff changeset
   263
    
eba2bbb2dd9a Make online debug optional
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2190
diff changeset
   264
#ifndef TARGET_ONLINE_DEBUG_DISABLE 
239
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   265
    /* Check there is no running debugger re-configuration */
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   266
    if(TryEnterDebugSection()){
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   267
        /* Lock buffer */
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   268
        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
   269
            &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
   270
            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
   271
            BUFFER_FULL);
239
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   272
            
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   273
        /* 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
   274
        if(latest_state == BUFFER_EMPTY)
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   275
        {
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
   276
            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
   277
            /* 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
   278
            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
   279
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
   280
            /* 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
   281
            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
   282
                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
   283
                    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
   284
                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
   285
                __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
   286
                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
   287
                    __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
   288
                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
   289
                    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
   290
                }
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
   291
                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
   292
            }
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
   293
239
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   294
            /* 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
   295
            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
   296
            /* 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
   297
            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
   298
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
   299
            /* 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
   300
            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
   301
                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
   302
                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
   303
                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
   304
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
                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
   306
                    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
   307
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
                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
   309
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
                /* 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
   311
                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
   312
                    /* 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
   313
                    /* 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
   314
                    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
   315
                }
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
   316
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
   317
                /* 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
   318
                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
   319
                /* 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
   320
                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
   321
                    /* 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
   322
                    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
   323
                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
   324
                    /* 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
   325
                    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
   326
                /* 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
   327
                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
   328
                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
   329
            }
239
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   330
            
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   331
            /* Leave debug section,
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   332
             * Trigger asynchronous transmission 
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   333
             * (returns immediately) */
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   334
            InitiateDebugTransfer(); /* size */
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   335
        }
239
112b4bc523b3 Fixed bad IPC choice for debugger/PLC/control thread collaboration
etisserant
parents: 236
diff changeset
   336
        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
   337
    }
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
   338
#endif
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
   339
    /* when not debugging, do only retain */
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
   340
    __for_each_variable_do(RetainIterator);
580
9dd978e6537c More robust retain buffer validity management
edouard
parents: 579
diff changeset
   341
    ValidateRetainBuffer();
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   342
}
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   343
2501
eba2bbb2dd9a Make online debug optional
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2190
diff changeset
   344
#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
   345
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
   346
#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
   347
#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
   348
#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
   349
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
   350
#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
   351
        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
   352
            /* 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
   353
            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
   354
            ((__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
   355
            ((__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
   356
            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
   357
#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
   358
        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
   359
        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
   360
            {                                                                           \
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
                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
   362
                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
   363
                    /* 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
   364
                    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
   365
                    /* 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
   366
                    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
   367
                        ((__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
   368
                    /* 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
   369
                    *((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
   370
                    /* 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
   371
                    ((__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
   372
                        (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
   373
                    /* 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
   374
                    ((__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
   375
                    /* 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
   376
                    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
   377
                    /* 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
   378
                    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
   379
                        *(((__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
   380
                } 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
   381
                    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
   382
                    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
   383
                }                                                                       \
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
            }                                                                           \
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
            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
   386
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
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
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
   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
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
   391
{
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
    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
   393
    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
   394
        /* 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
   395
        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
   396
            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
   397
            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
   398
        } 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
   399
            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
   400
            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
   401
        }
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
        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
   403
            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
   404
                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
   405
                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
   406
                __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
   407
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
   408
                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
   409
                    __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
   410
                    __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
   411
                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
   412
                    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
   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
                /* 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
   415
                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
   416
            } 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
   417
                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
   418
                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
   419
            }
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
   420
        }
450
18583d13f0fa Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents: 423
diff changeset
   421
    }
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
   422
    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
   423
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
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
   425
    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
   426
    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
   427
    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
   428
    
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
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
#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
   432
        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
   433
            ((__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
   434
            /* 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
   435
            /* 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
   436
            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
   437
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
#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
   439
        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
   440
        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
   441
            ((__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
   442
            /* 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
   443
            ((__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
   444
                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
   445
            break;
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   446
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   447
void ResetDebugVariables(void)
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   448
{
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
   449
    /* 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
   450
    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
   451
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
   452
    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
   453
    /* 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
   454
    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
   455
        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
   456
            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
   457
        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
   458
        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
   459
            __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
   460
            __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
   461
        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
   462
            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
   463
        }
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
        /* 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
   465
        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
   466
    } /* 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
   467
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
    /* 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
   469
    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
   470
    /* 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
   471
    force_buffer_cursor = force_buffer;
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   472
}
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   473
423
4d7ac355701d Fix some warnings during compilation
greg
parents: 397
diff changeset
   474
void FreeDebugData(void)
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   475
{
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   476
    /* atomically mark buffer as free */
1403
dd6d40094782 Fixed unused variable in plc_debug.c
Edouard Tisserant
parents: 1074
diff changeset
   477
    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
   478
        &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
   479
        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
   480
        BUFFER_EMPTY);
209
08dc3d064cb5 Moved template C code to targets dir. Cleaned up some forgotten print.
etisserant
parents:
diff changeset
   481
}
452
2d0718a05cc7 Reflect changes in iec type definitions in matiec/lib
edouard
parents: 450
diff changeset
   482
int WaitDebugData(unsigned long *tick);
450
18583d13f0fa Preliminary accessor support for debug
Edouard TISSERANT <edouard.tisserant@gmail.com>
parents: 423
diff changeset
   483
/* 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
   484
int GetDebugData(unsigned long *tick, unsigned long *size, void **buffer){
504
688e84df3408 Fixed debug again, did some code tidying
edouard
parents: 502
diff changeset
   485
    int wait_error = WaitDebugData(tick);
688e84df3408 Fixed debug again, did some code tidying
edouard
parents: 502
diff changeset
   486
    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
   487
        *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
   488
        *buffer = trace_buffer;
502
5343ae43f6d0 LPC connector - one step further
edouard
parents: 491
diff changeset
   489
    }
504
688e84df3408 Fixed debug again, did some code tidying
edouard
parents: 502
diff changeset
   490
    return wait_error;
688e84df3408 Fixed debug again, did some code tidying
edouard
parents: 502
diff changeset
   491
}
2501
eba2bbb2dd9a Make online debug optional
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2190
diff changeset
   492
#endif
eba2bbb2dd9a Make online debug optional
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2190
diff changeset
   493
#endif
eba2bbb2dd9a Make online debug optional
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2190
diff changeset
   494