author | laurent |
Wed, 21 Dec 2011 19:42:49 +0100 | |
changeset 657 | 340c0b9caeca |
parent 580 | 9dd978e6537c |
permissions | -rwxr-xr-x |
425 | 1 |
/** |
2 |
* Yagarto specific code |
|
3 |
**/ |
|
4 |
||
579 | 5 |
#include <string.h> |
518
8e61b0066859
Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents:
502
diff
changeset
|
6 |
#include <app_glue.h> |
425 | 7 |
|
8 |
/* provided by POUS.C */ |
|
518
8e61b0066859
Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents:
502
diff
changeset
|
9 |
extern unsigned long long common_ticktime__; |
577 | 10 |
extern unsigned long __tick; |
11 |
||
579 | 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"))); |
|
17 |
||
577 | 18 |
static int debug_locked = 0; |
19 |
static int _DebugDataAvailable = 0; |
|
20 |
static unsigned long __debug_tick; |
|
21 |
||
518
8e61b0066859
Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents:
502
diff
changeset
|
22 |
void LPC_GetTime(IEC_TIME*); |
8e61b0066859
Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents:
502
diff
changeset
|
23 |
void LPC_SetTimer(unsigned long long next, unsigned long long period); |
425 | 24 |
|
25 |
long AtomicCompareExchange(long* atomicvar,long compared, long exchange) |
|
26 |
{ |
|
518
8e61b0066859
Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents:
502
diff
changeset
|
27 |
/* No need for real atomic op on LPC, |
8e61b0066859
Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents:
502
diff
changeset
|
28 |
* no possible preemption between debug and PLC */ |
8e61b0066859
Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents:
502
diff
changeset
|
29 |
long res = *atomicvar; |
8e61b0066859
Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents:
502
diff
changeset
|
30 |
if(res == compared){ |
8e61b0066859
Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents:
502
diff
changeset
|
31 |
*atomicvar = exchange; |
8e61b0066859
Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents:
502
diff
changeset
|
32 |
} |
8e61b0066859
Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents:
502
diff
changeset
|
33 |
return res; |
425 | 34 |
} |
35 |
||
36 |
void PLC_GetTime(IEC_TIME *CURRENT_TIME) |
|
37 |
{ |
|
38 |
/* Call target GetTime function */ |
|
518
8e61b0066859
Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents:
502
diff
changeset
|
39 |
LPC_GetTime(CURRENT_TIME); |
425 | 40 |
} |
41 |
||
518
8e61b0066859
Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents:
502
diff
changeset
|
42 |
void PLC_SetTimer(unsigned long long next, unsigned long long period) |
425 | 43 |
{ |
518
8e61b0066859
Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents:
502
diff
changeset
|
44 |
LPC_SetTimer(next, period); |
425 | 45 |
} |
46 |
||
47 |
int startPLC(int argc,char **argv) |
|
48 |
{ |
|
518
8e61b0066859
Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents:
502
diff
changeset
|
49 |
if(__init(argc,argv) == 0){ |
579 | 50 |
/* sign retain buffer */ |
518
8e61b0066859
Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents:
502
diff
changeset
|
51 |
PLC_SetTimer(0, common_ticktime__); |
425 | 52 |
return 0; |
518
8e61b0066859
Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents:
502
diff
changeset
|
53 |
}else{ |
425 | 54 |
return 1; |
518
8e61b0066859
Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents:
502
diff
changeset
|
55 |
} |
425 | 56 |
} |
57 |
||
58 |
int TryEnterDebugSection(void) |
|
59 |
{ |
|
577 | 60 |
if(!debug_locked && __DEBUG){ |
61 |
debug_locked = 1; |
|
62 |
return 1; |
|
63 |
} |
|
64 |
return 0; |
|
425 | 65 |
} |
66 |
||
67 |
void LeaveDebugSection(void) |
|
68 |
{ |
|
577 | 69 |
debug_locked = 0; |
425 | 70 |
} |
71 |
||
72 |
int stopPLC(void) |
|
73 |
{ |
|
74 |
__cleanup(); |
|
75 |
return 0; |
|
76 |
} |
|
77 |
||
78 |
/* from plc_debugger.c */ |
|
452
2d0718a05cc7
Reflect changes in iec type definitions in matiec/lib
edouard
parents:
425
diff
changeset
|
79 |
int WaitDebugData(unsigned long *tick) |
425 | 80 |
{ |
577 | 81 |
/* no blocking call on LPC */ |
82 |
if(_DebugDataAvailable && !debug_locked){ |
|
83 |
/* returns 0 on success */ |
|
84 |
*tick = __debug_tick; |
|
85 |
_DebugDataAvailable = 0; |
|
86 |
return 0; |
|
87 |
} |
|
88 |
return 1; |
|
425 | 89 |
} |
90 |
||
91 |
/* Called by PLC thread when debug_publish finished |
|
92 |
* This is supposed to unlock debugger thread in WaitDebugData*/ |
|
93 |
void InitiateDebugTransfer(void) |
|
94 |
{ |
|
577 | 95 |
/* remember tick */ |
96 |
__debug_tick = __tick; |
|
502 | 97 |
_DebugDataAvailable = 1; |
425 | 98 |
} |
99 |
||
502 | 100 |
void suspendDebug(int disable) |
425 | 101 |
{ |
577 | 102 |
/* Prevent PLC to enter debug code */ |
502 | 103 |
__DEBUG = !disable; |
577 | 104 |
debug_locked = !disable; |
425 | 105 |
} |
106 |
||
107 |
void resumeDebug(void) |
|
108 |
{ |
|
577 | 109 |
/* Let PLC enter debug code */ |
502 | 110 |
__DEBUG = 1; |
577 | 111 |
debug_locked = 0; |
425 | 112 |
} |
483
bc26c42d2eec
fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents:
478
diff
changeset
|
113 |
|
580 | 114 |
void ValidateRetainBuffer(void) |
115 |
{ |
|
116 |
memcpy(RetainedIdBuf, idBuf, idLen); |
|
117 |
} |
|
118 |
||
119 |
void InValidateRetainBuffer(void) |
|
120 |
{ |
|
121 |
/* invalidate that buffer */ |
|
122 |
RetainedIdBuf[0] = 0; |
|
123 |
} |
|
124 |
||
521
02cb9e5fb6f6
LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents:
518
diff
changeset
|
125 |
int CheckRetainBuffer(void) |
02cb9e5fb6f6
LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents:
518
diff
changeset
|
126 |
{ |
579 | 127 |
/* compare RETAIN ID buffer with MD5 */ |
128 |
/* return true if identical */ |
|
129 |
int res = memcmp(RetainedIdBuf, idBuf, idLen) == 0; |
|
130 |
return res; |
|
521
02cb9e5fb6f6
LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents:
518
diff
changeset
|
131 |
} |
02cb9e5fb6f6
LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents:
518
diff
changeset
|
132 |
|
483
bc26c42d2eec
fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents:
478
diff
changeset
|
133 |
void Retain(unsigned int offset, unsigned int count, void *p) |
497 | 134 |
{ |
579 | 135 |
if(offset + count < RETAIN_BUFFER_SIZE) |
136 |
/* write in RETAIN buffer at offset*/ |
|
137 |
memcpy(&retain_buffer[offset], p, count); |
|
483
bc26c42d2eec
fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents:
478
diff
changeset
|
138 |
} |
bc26c42d2eec
fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents:
478
diff
changeset
|
139 |
|
bc26c42d2eec
fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents:
478
diff
changeset
|
140 |
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:
478
diff
changeset
|
141 |
{ |
579 | 142 |
if(offset + count < RETAIN_BUFFER_SIZE) |
143 |
/* read at offset in RETAIN buffer */ |
|
144 |
memcpy(p, &retain_buffer[offset], count); |
|
483
bc26c42d2eec
fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents:
478
diff
changeset
|
145 |
} |