equal
deleted
inserted
replaced
1 /** |
1 /** |
2 * Yagarto specific code |
2 * Yagarto specific code |
3 **/ |
3 **/ |
4 |
4 |
|
5 #include <string.h> |
5 #include <app_glue.h> |
6 #include <app_glue.h> |
6 |
7 |
7 /* provided by POUS.C */ |
8 /* provided by POUS.C */ |
8 extern unsigned long long common_ticktime__; |
9 extern unsigned long long common_ticktime__; |
9 extern unsigned long __tick; |
10 extern unsigned long __tick; |
|
11 |
|
12 extern unsigned long idLen; |
|
13 extern unsigned char *idBuf; |
|
14 |
|
15 static unsigned char RetainedIdBuf[128] __attribute__((section (".nvolatile"))); |
|
16 static unsigned char retain_buffer[RETAIN_BUFFER_SIZE] __attribute__((section (".nvolatile"))); |
10 |
17 |
11 static int debug_locked = 0; |
18 static int debug_locked = 0; |
12 static int _DebugDataAvailable = 0; |
19 static int _DebugDataAvailable = 0; |
13 static unsigned long __debug_tick; |
20 static unsigned long __debug_tick; |
14 |
21 |
38 } |
45 } |
39 |
46 |
40 int startPLC(int argc,char **argv) |
47 int startPLC(int argc,char **argv) |
41 { |
48 { |
42 if(__init(argc,argv) == 0){ |
49 if(__init(argc,argv) == 0){ |
|
50 /* sign retain buffer */ |
|
51 memcpy(RetainedIdBuf, idBuf, idLen); |
43 PLC_SetTimer(0, common_ticktime__); |
52 PLC_SetTimer(0, common_ticktime__); |
44 return 0; |
53 return 0; |
45 }else{ |
54 }else{ |
46 return 1; |
55 return 1; |
47 } |
56 } |
103 debug_locked = 0; |
112 debug_locked = 0; |
104 } |
113 } |
105 |
114 |
106 int CheckRetainBuffer(void) |
115 int CheckRetainBuffer(void) |
107 { |
116 { |
108 /* TODO : compare RETAIN buffer start with MD5 */ |
117 /* compare RETAIN ID buffer with MD5 */ |
109 return 0; |
118 /* return true if identical */ |
|
119 int res = memcmp(RetainedIdBuf, idBuf, idLen) == 0; |
|
120 /* invalidate that buffer, might help when value cause PLC crash before next publish */ |
|
121 RetainedIdBuf[0] = 0; |
|
122 return res; |
|
123 |
110 } |
124 } |
111 |
125 |
112 void Retain(unsigned int offset, unsigned int count, void *p) |
126 void Retain(unsigned int offset, unsigned int count, void *p) |
113 { |
127 { |
114 /* TODO : write in RETAIN buffer at offset*/ |
128 if(offset + count < RETAIN_BUFFER_SIZE) |
|
129 /* write in RETAIN buffer at offset*/ |
|
130 memcpy(&retain_buffer[offset], p, count); |
115 } |
131 } |
116 |
132 |
117 void Remind(unsigned int offset, unsigned int count, void *p) |
133 void Remind(unsigned int offset, unsigned int count, void *p) |
118 { |
134 { |
119 /* TODO : read at offset in RETAIN buffer */ |
135 if(offset + count < RETAIN_BUFFER_SIZE) |
|
136 /* read at offset in RETAIN buffer */ |
|
137 memcpy(p, &retain_buffer[offset], count); |
120 } |
138 } |