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