Retain variable for LPC
authoredouard
Thu, 24 Feb 2011 15:54:45 +0100
changeset 579 554ba6df4ee0
parent 578 6f5795bdee49
child 580 9dd978e6537c
Retain variable for LPC
plugger.py
targets/LPC/plc_LPC_main.c
targets/plc_debug.c
--- a/plugger.py	Wed Feb 23 16:54:29 2011 +0100
+++ b/plugger.py	Thu Feb 24 15:54:45 2011 +0100
@@ -1341,10 +1341,6 @@
                "OUT":"extern __IEC_%(type)s_p %(C_path)s;",
                "VAR":"extern __IEC_%(type)s_t %(C_path)s;"}[v["vartype"]]%v 
                for v in self._VariablesList if v["vartype"] != "FB" and v["C_path"].find('.')<0]),
-           "subscription_table_count":
-               len(self._VariablesList),
-           "variables_pointer_type_table_count":
-               len(self._VariablesList),
            "for_each_variable_do_code":"\n".join([
                {"EXT":"    (*fp)((void*)&%(C_path)s,%(type)s_P_ENUM);\n",
                 "IN":"    (*fp)((void*)&%(C_path)s,%(type)s_P_ENUM);\n",
--- a/targets/LPC/plc_LPC_main.c	Wed Feb 23 16:54:29 2011 +0100
+++ b/targets/LPC/plc_LPC_main.c	Thu Feb 24 15:54:45 2011 +0100
@@ -2,12 +2,19 @@
  * Yagarto specific code
  **/
 
+#include <string.h>
 #include <app_glue.h>
 
 /* provided by POUS.C */
 extern unsigned long long common_ticktime__;
 extern unsigned long __tick;
 
+extern unsigned long idLen;
+extern unsigned char *idBuf;
+
+static unsigned char RetainedIdBuf[128] __attribute__((section (".nvolatile")));
+static unsigned char retain_buffer[RETAIN_BUFFER_SIZE] __attribute__((section (".nvolatile")));
+
 static int debug_locked = 0;
 static int _DebugDataAvailable = 0;
 static unsigned long __debug_tick;
@@ -40,6 +47,8 @@
 int startPLC(int argc,char **argv)
 {
 	if(__init(argc,argv) == 0){
+        /* sign retain buffer */
+        memcpy(RetainedIdBuf, idBuf, idLen);
 		PLC_SetTimer(0, common_ticktime__);
 		return 0;
 	}else{
@@ -105,16 +114,25 @@
 
 int CheckRetainBuffer(void)
 {
-	/* TODO : compare RETAIN buffer start with MD5 */
-	return 0;
+	/* compare RETAIN ID buffer with MD5 */
+    /* return true if identical */
+    int res = memcmp(RetainedIdBuf, idBuf, idLen) == 0;
+    /* invalidate that buffer, might help when value cause PLC crash before next publish */
+    RetainedIdBuf[0] = 0;
+    return res;
+
 }
 
 void Retain(unsigned int offset, unsigned int count, void *p)
 {
-	/* TODO : write in RETAIN buffer at offset*/
+    if(offset + count < RETAIN_BUFFER_SIZE)
+        /* write in RETAIN buffer at offset*/
+        memcpy(&retain_buffer[offset], p, count);
 }
 
 void Remind(unsigned int offset, unsigned int count, void *p)
 {
-	/* TODO : read at offset in RETAIN buffer */
+    if(offset + count < RETAIN_BUFFER_SIZE)
+        /* read at offset in RETAIN buffer */
+        memcpy(p, &retain_buffer[offset], count);
 }
--- a/targets/plc_debug.c	Wed Feb 23 16:54:29 2011 +0100
+++ b/targets/plc_debug.c	Thu Feb 24 15:54:45 2011 +0100
@@ -17,7 +17,6 @@
 #include <stdio.h>
 
 #define BUFFER_SIZE %(buffer_size)d
-#define MAX_SUBSCRIBTION %(subscription_table_count)d
 
 /* Atomically accessed variable for buffer state */
 #define BUFFER_FREE 0