targets/LPC/plc_LPC_main.c
changeset 577 04baf6607a44
parent 521 02cb9e5fb6f6
child 579 554ba6df4ee0
equal deleted inserted replaced
576:7fcdc0d3d8d9 577:04baf6607a44
     4 
     4 
     5 #include <app_glue.h>
     5 #include <app_glue.h>
     6 
     6 
     7 /* provided by POUS.C */
     7 /* provided by POUS.C */
     8 extern unsigned long long common_ticktime__;
     8 extern unsigned long long common_ticktime__;
       
     9 extern unsigned long __tick;
       
    10 
       
    11 static int debug_locked = 0;
       
    12 static int _DebugDataAvailable = 0;
       
    13 static unsigned long __debug_tick;
       
    14 
     9 void LPC_GetTime(IEC_TIME*);
    15 void LPC_GetTime(IEC_TIME*);
    10 void LPC_SetTimer(unsigned long long next, unsigned long long period);
    16 void LPC_SetTimer(unsigned long long next, unsigned long long period);
    11 
    17 
    12 long AtomicCompareExchange(long* atomicvar,long compared, long exchange)
    18 long AtomicCompareExchange(long* atomicvar,long compared, long exchange)
    13 {
    19 {
    41 	}
    47 	}
    42 }
    48 }
    43 
    49 
    44 int TryEnterDebugSection(void)
    50 int TryEnterDebugSection(void)
    45 {
    51 {
    46     return __DEBUG;
    52     if(!debug_locked && __DEBUG){
       
    53         debug_locked = 1;
       
    54 		return 1;
       
    55     }
       
    56     return 0;
    47 }
    57 }
    48 
    58 
    49 void LeaveDebugSection(void)
    59 void LeaveDebugSection(void)
    50 {
    60 {
       
    61         debug_locked = 0;
    51 }
    62 }
    52 
    63 
    53 int stopPLC(void)
    64 int stopPLC(void)
    54 {
    65 {
    55     __cleanup();
    66     __cleanup();
    56     return 0;
    67     return 0;
    57 }
    68 }
    58 
    69 
    59 extern unsigned long __tick;
       
    60 int _DebugDataAvailable = 0;
       
    61 /* from plc_debugger.c */
    70 /* from plc_debugger.c */
    62 int WaitDebugData(unsigned long *tick)
    71 int WaitDebugData(unsigned long *tick)
    63 {
    72 {
    64     *tick = __tick;
    73     /* no blocking call on LPC */
    65     return _DebugDataAvailable;
    74     if(_DebugDataAvailable && !debug_locked){
       
    75         /* returns 0 on success */
       
    76         *tick = __debug_tick;
       
    77         _DebugDataAvailable = 0;
       
    78         return 0;
       
    79     }
       
    80     return 1;
    66 }
    81 }
    67 
    82 
    68 /* Called by PLC thread when debug_publish finished
    83 /* Called by PLC thread when debug_publish finished
    69  * This is supposed to unlock debugger thread in WaitDebugData*/
    84  * This is supposed to unlock debugger thread in WaitDebugData*/
    70 void InitiateDebugTransfer(void)
    85 void InitiateDebugTransfer(void)
    71 {
    86 {
       
    87     /* remember tick */
       
    88     __debug_tick = __tick;
    72     _DebugDataAvailable = 1;
    89     _DebugDataAvailable = 1;
    73 }
    90 }
    74 
    91 
    75 void suspendDebug(int disable)
    92 void suspendDebug(int disable)
    76 {
    93 {
       
    94     /* Prevent PLC to enter debug code */
    77     __DEBUG = !disable;
    95     __DEBUG = !disable;
       
    96     debug_locked = !disable;
    78 }
    97 }
    79 
    98 
    80 void resumeDebug(void)
    99 void resumeDebug(void)
    81 {
   100 {
       
   101     /* Let PLC enter debug code */
    82     __DEBUG = 1;
   102     __DEBUG = 1;
       
   103     debug_locked = 0;
    83 }
   104 }
    84 
   105 
    85 int CheckRetainBuffer(void)
   106 int CheckRetainBuffer(void)
    86 {
   107 {
    87 	/* TODO : compare RETAIN buffer start with MD5 */
   108 	/* TODO : compare RETAIN buffer start with MD5 */