Edouard@0: /** Drauoude@29: * LPC specific code Edouard@0: **/ Edouard@0: Edouard@0: #include Edouard@0: #include Edouard@0: Edouard@0: extern unsigned long idLen; Edouard@0: extern unsigned char *idBuf; Edouard@0: Drauoude@29: static unsigned char RetainedIdBuf[128] NONVOLATILE; Drauoude@29: static unsigned char retain_buffer[RETAIN_BUFFER_SIZE] NONVOLATILE; Drauoude@29: Drauoude@29: #define LOG_BUFFER_SIZE (1<<10) /*1Ko*/ Drauoude@29: #define LOG_BUFFER_ATTRS NONVOLATILE Edouard@0: Edouard@0: static int debug_locked = 0; Edouard@0: static int _DebugDataAvailable = 0; Edouard@0: static unsigned long __debug_tick; Edouard@0: Edouard@0: void LPC_GetTime(IEC_TIME*); Edouard@0: void LPC_SetTimer(unsigned long long next, unsigned long long period); Edouard@0: Edouard@0: long AtomicCompareExchange(long* atomicvar,long compared, long exchange) Edouard@0: { Edouard@0: /* No need for real atomic op on LPC, Edouard@0: * no possible preemption between debug and PLC */ Edouard@0: long res = *atomicvar; Edouard@0: if(res == compared){ Edouard@0: *atomicvar = exchange; Edouard@0: } Edouard@0: return res; Edouard@0: } Edouard@0: Edouard@0: void PLC_GetTime(IEC_TIME *CURRENT_TIME) Edouard@0: { Edouard@0: /* Call target GetTime function */ Edouard@0: LPC_GetTime(CURRENT_TIME); Edouard@0: } Edouard@0: Edouard@0: void PLC_SetTimer(unsigned long long next, unsigned long long period) Edouard@0: { Edouard@0: LPC_SetTimer(next, period); Edouard@0: } Edouard@0: Edouard@0: int startPLC(int argc,char **argv) Edouard@0: { Edouard@0: if(__init(argc,argv) == 0){ Drauoude@29: PLC_SetTimer(0, Ttick); Edouard@0: return 0; Edouard@0: }else{ Edouard@0: return 1; Edouard@0: } Edouard@0: } Edouard@0: Edouard@0: int TryEnterDebugSection(void) Edouard@0: { Edouard@0: if(!debug_locked && __DEBUG){ Edouard@0: debug_locked = 1; Edouard@0: return 1; Edouard@0: } Edouard@0: return 0; Edouard@0: } Edouard@0: Edouard@0: void LeaveDebugSection(void) Edouard@0: { Edouard@0: debug_locked = 0; Edouard@0: } Edouard@0: Edouard@0: int stopPLC(void) Edouard@0: { Edouard@0: __cleanup(); Edouard@0: return 0; Edouard@0: } Edouard@0: Edouard@0: /* from plc_debugger.c */ Edouard@0: int WaitDebugData(unsigned long *tick) Edouard@0: { Edouard@0: /* no blocking call on LPC */ Edouard@0: if(_DebugDataAvailable && !debug_locked){ Edouard@0: /* returns 0 on success */ Edouard@0: *tick = __debug_tick; Edouard@0: _DebugDataAvailable = 0; Edouard@0: return 0; Edouard@0: } Edouard@0: return 1; Edouard@0: } Edouard@0: Edouard@0: /* Called by PLC thread when debug_publish finished Edouard@0: * This is supposed to unlock debugger thread in WaitDebugData*/ Edouard@0: void InitiateDebugTransfer(void) Edouard@0: { Edouard@0: /* remember tick */ Edouard@0: __debug_tick = __tick; Edouard@0: _DebugDataAvailable = 1; Edouard@0: } Edouard@0: Edouard@0: void suspendDebug(int disable) Edouard@0: { Edouard@0: /* Prevent PLC to enter debug code */ Edouard@0: __DEBUG = !disable; Edouard@0: debug_locked = !disable; Edouard@0: } Edouard@0: Edouard@0: void resumeDebug(void) Edouard@0: { Edouard@0: /* Let PLC enter debug code */ Edouard@0: __DEBUG = 1; Edouard@0: debug_locked = 0; Edouard@0: } Edouard@0: Edouard@0: void ValidateRetainBuffer(void) Edouard@0: { Edouard@0: memcpy(RetainedIdBuf, idBuf, idLen); Edouard@0: } Edouard@0: Edouard@0: void InValidateRetainBuffer(void) Edouard@0: { Edouard@0: /* invalidate that buffer */ Edouard@0: RetainedIdBuf[0] = 0; Edouard@0: } Edouard@0: Edouard@0: int CheckRetainBuffer(void) Edouard@0: { Edouard@0: /* compare RETAIN ID buffer with MD5 */ Edouard@0: /* return true if identical */ Edouard@0: int res = memcmp(RetainedIdBuf, idBuf, idLen) == 0; Edouard@0: return res; Edouard@0: } Edouard@0: Edouard@0: void Retain(unsigned int offset, unsigned int count, void *p) Edouard@0: { Edouard@0: if(offset + count < RETAIN_BUFFER_SIZE) Edouard@0: /* write in RETAIN buffer at offset*/ Edouard@0: memcpy(&retain_buffer[offset], p, count); Edouard@0: } Edouard@0: Edouard@0: void Remind(unsigned int offset, unsigned int count, void *p) Edouard@0: { Edouard@0: if(offset + count < RETAIN_BUFFER_SIZE) Edouard@0: /* read at offset in RETAIN buffer */ Edouard@0: memcpy(p, &retain_buffer[offset], count); Edouard@0: }