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