targets/LPC/plc_LPC_main.c
author laurent
Fri, 04 Jun 2010 17:04:25 +0200
changeset 562 2c8f08f4f874
parent 521 02cb9e5fb6f6
child 577 04baf6607a44
permissions -rwxr-xr-x
Fix MatchMD5 result if no serial connection available
425
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
     1
/**
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
     2
 * Yagarto specific code
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
     3
 **/
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
     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
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
     6
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
     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__;
8e61b0066859 Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents: 502
diff changeset
     9
void LPC_GetTime(IEC_TIME*);
8e61b0066859 Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents: 502
diff changeset
    10
void LPC_SetTimer(unsigned long long next, unsigned long long period);
425
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    11
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    12
long AtomicCompareExchange(long* atomicvar,long compared, long exchange)
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    13
{
518
8e61b0066859 Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents: 502
diff changeset
    14
	/* 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
    15
	 * no possible preemption between debug and PLC */
8e61b0066859 Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents: 502
diff changeset
    16
	long res = *atomicvar;
8e61b0066859 Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents: 502
diff changeset
    17
	if(res == compared){
8e61b0066859 Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents: 502
diff changeset
    18
		*atomicvar = exchange;
8e61b0066859 Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents: 502
diff changeset
    19
	}
8e61b0066859 Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents: 502
diff changeset
    20
	return res;
425
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    21
}
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    22
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    23
void PLC_GetTime(IEC_TIME *CURRENT_TIME)
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    24
{
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    25
	/* Call target GetTime function */
518
8e61b0066859 Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents: 502
diff changeset
    26
	LPC_GetTime(CURRENT_TIME);
425
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    27
}
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    28
518
8e61b0066859 Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents: 502
diff changeset
    29
void PLC_SetTimer(unsigned long long next, unsigned long long period)
425
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    30
{
518
8e61b0066859 Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents: 502
diff changeset
    31
	LPC_SetTimer(next, period);
425
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    32
}
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    33
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    34
int startPLC(int argc,char **argv)
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    35
{
518
8e61b0066859 Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents: 502
diff changeset
    36
	if(__init(argc,argv) == 0){
8e61b0066859 Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents: 502
diff changeset
    37
		PLC_SetTimer(0, common_ticktime__);
425
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    38
		return 0;
518
8e61b0066859 Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents: 502
diff changeset
    39
	}else{
425
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    40
		return 1;
518
8e61b0066859 Fixed confusion about __common_ticktime type, redesigned LPC PLC timer support
edouard
parents: 502
diff changeset
    41
	}
425
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    42
}
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    43
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    44
int TryEnterDebugSection(void)
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    45
{
502
5343ae43f6d0 LPC connector - one step further
edouard
parents: 497
diff changeset
    46
    return __DEBUG;
425
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    47
}
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    48
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    49
void LeaveDebugSection(void)
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    50
{
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    51
}
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    52
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    53
int stopPLC(void)
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    54
{
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    55
    __cleanup();
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    56
    return 0;
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    57
}
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    58
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    59
extern unsigned long __tick;
502
5343ae43f6d0 LPC connector - one step further
edouard
parents: 497
diff changeset
    60
int _DebugDataAvailable = 0;
425
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    61
/* from plc_debugger.c */
452
2d0718a05cc7 Reflect changes in iec type definitions in matiec/lib
edouard
parents: 425
diff changeset
    62
int WaitDebugData(unsigned long *tick)
425
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    63
{
452
2d0718a05cc7 Reflect changes in iec type definitions in matiec/lib
edouard
parents: 425
diff changeset
    64
    *tick = __tick;
502
5343ae43f6d0 LPC connector - one step further
edouard
parents: 497
diff changeset
    65
    return _DebugDataAvailable;
425
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    66
}
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    67
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    68
/* Called by PLC thread when debug_publish finished
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    69
 * This is supposed to unlock debugger thread in WaitDebugData*/
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    70
void InitiateDebugTransfer(void)
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    71
{
502
5343ae43f6d0 LPC connector - one step further
edouard
parents: 497
diff changeset
    72
    _DebugDataAvailable = 1;
425
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    73
}
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    74
502
5343ae43f6d0 LPC connector - one step further
edouard
parents: 497
diff changeset
    75
void suspendDebug(int disable)
425
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    76
{
502
5343ae43f6d0 LPC connector - one step further
edouard
parents: 497
diff changeset
    77
    __DEBUG = !disable;
425
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    78
}
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    79
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    80
void resumeDebug(void)
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    81
{
502
5343ae43f6d0 LPC connector - one step further
edouard
parents: 497
diff changeset
    82
    __DEBUG = 1;
425
f390e9fdd2cf Add new target (Makefile)
greg
parents:
diff changeset
    83
}
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 478
diff changeset
    84
521
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 518
diff changeset
    85
int CheckRetainBuffer(void)
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 518
diff changeset
    86
{
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 518
diff changeset
    87
	/* TODO : compare RETAIN buffer start with MD5 */
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 518
diff changeset
    88
	return 0;
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 518
diff changeset
    89
}
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 518
diff changeset
    90
483
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 478
diff changeset
    91
void Retain(unsigned int offset, unsigned int count, void *p)
497
ed7f72fc785f Typo in LPC
edouard
parents: 483
diff changeset
    92
{
521
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 518
diff changeset
    93
	/* 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
    94
}
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 478
diff changeset
    95
bc26c42d2eec fixed greg's crap in win32, enhanced debug stability, implemented preliminary retain
edouard
parents: 478
diff changeset
    96
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
    97
{
521
02cb9e5fb6f6 LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
edouard
parents: 518
diff changeset
    98
	/* 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
    99
}