author | edouard |
Thu, 24 Feb 2011 15:54:45 +0100 | |
changeset 579 | 554ba6df4ee0 |
parent 577 | 04baf6607a44 |
child 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 */ |
51 |
memcpy(RetainedIdBuf, idBuf, idLen); |
|
518
8e61b0066859
Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents:
502
diff
changeset
|
52 |
PLC_SetTimer(0, common_ticktime__); |
425 | 53 |
return 0; |
518
8e61b0066859
Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents:
502
diff
changeset
|
54 |
}else{ |
425 | 55 |
return 1; |
518
8e61b0066859
Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents:
502
diff
changeset
|
56 |
} |
425 | 57 |
} |
58 |
||
59 |
int TryEnterDebugSection(void) |
|
60 |
{ |
|
577 | 61 |
if(!debug_locked && __DEBUG){ |
62 |
debug_locked = 1; |
|
63 |
return 1; |
|
64 |
} |
|
65 |
return 0; |
|
425 | 66 |
} |
67 |
||
68 |
void LeaveDebugSection(void) |
|
69 |
{ |
|
577 | 70 |
debug_locked = 0; |
425 | 71 |
} |
72 |
||
73 |
int stopPLC(void) |
|
74 |
{ |
|
75 |
__cleanup(); |
|
76 |
return 0; |
|
77 |
} |
|
78 |
||
79 |
/* from plc_debugger.c */ |
|
452
2d0718a05cc7
Reflect changes in iec type definitions in matiec/lib
edouard
parents:
425
diff
changeset
|
80 |
int WaitDebugData(unsigned long *tick) |
425 | 81 |
{ |
577 | 82 |
/* no blocking call on LPC */ |
83 |
if(_DebugDataAvailable && !debug_locked){ |
|
84 |
/* returns 0 on success */ |
|
85 |
*tick = __debug_tick; |
|
86 |
_DebugDataAvailable = 0; |
|
87 |
return 0; |
|
88 |
} |
|
89 |
return 1; |
|
425 | 90 |
} |
91 |
||
92 |
/* Called by PLC thread when debug_publish finished |
|
93 |
* This is supposed to unlock debugger thread in WaitDebugData*/ |
|
94 |
void InitiateDebugTransfer(void) |
|
95 |
{ |
|
577 | 96 |
/* remember tick */ |
97 |
__debug_tick = __tick; |
|
502 | 98 |
_DebugDataAvailable = 1; |
425 | 99 |
} |
100 |
||
502 | 101 |
void suspendDebug(int disable) |
425 | 102 |
{ |
577 | 103 |
/* Prevent PLC to enter debug code */ |
502 | 104 |
__DEBUG = !disable; |
577 | 105 |
debug_locked = !disable; |
425 | 106 |
} |
107 |
||
108 |
void resumeDebug(void) |
|
109 |
{ |
|
577 | 110 |
/* Let PLC enter debug code */ |
502 | 111 |
__DEBUG = 1; |
577 | 112 |
debug_locked = 0; |
425 | 113 |
} |
483
bc26c42d2eec
fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents:
478
diff
changeset
|
114 |
|
521
02cb9e5fb6f6
LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents:
518
diff
changeset
|
115 |
int CheckRetainBuffer(void) |
02cb9e5fb6f6
LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents:
518
diff
changeset
|
116 |
{ |
579 | 117 |
/* compare RETAIN ID buffer with MD5 */ |
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 |
||
521
02cb9e5fb6f6
LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents:
518
diff
changeset
|
124 |
} |
02cb9e5fb6f6
LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents:
518
diff
changeset
|
125 |
|
483
bc26c42d2eec
fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents:
478
diff
changeset
|
126 |
void Retain(unsigned int offset, unsigned int count, void *p) |
497 | 127 |
{ |
579 | 128 |
if(offset + count < RETAIN_BUFFER_SIZE) |
129 |
/* write in RETAIN buffer at offset*/ |
|
130 |
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
|
131 |
} |
bc26c42d2eec
fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents:
478
diff
changeset
|
132 |
|
bc26c42d2eec
fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents:
478
diff
changeset
|
133 |
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
|
134 |
{ |
579 | 135 |
if(offset + count < RETAIN_BUFFER_SIZE) |
136 |
/* read at offset in RETAIN buffer */ |
|
137 |
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
|
138 |
} |