Add helper function GetRetainSize()
authorAndrey Skvortsov <andrej.skvortzov@gmail.com>
Fri, 01 Jun 2018 15:46:17 +0300
changeset 2172 9fa5be79bb77
parent 2171 d1536c271866
child 2173 976841968d74
Add helper function GetRetainSize()

it will be useful for retain implementations.
targets/plc_debug.c
--- a/targets/plc_debug.c	Fri Jun 01 12:21:37 2018 +0300
+++ b/targets/plc_debug.c	Fri Jun 01 15:46:17 2018 +0300
@@ -211,6 +211,31 @@
     BufferIterator(dsc, 0);
 }
 
+
+unsigned int retain_size = 0;
+
+/* GetRetainSizeIterator */
+void GetRetainSizeIterator(dbgvardsc_t *dsc)
+{
+    void *real_value_p = NULL;
+    char flags = 0;
+    UnpackVar(dsc, &real_value_p, &flags);
+
+    if(flags & __IEC_RETAIN_FLAG){
+        USINT size = __get_type_enum_size(dsc->type);
+        /* Calc retain buffer size */
+        retain_size += size;
+    }
+}
+
+/* Return size of all retain variables */
+unsigned int GetRetainSize(void)
+{
+    __for_each_variable_do(GetRetainSizeIterator);
+    return retain_size;
+}
+
+
 extern void PLC_GetTime(IEC_TIME*);
 extern int TryEnterDebugSection(void);
 extern long AtomicCompareExchange(long*, long, long);