targets/plc_debug.c
changeset 423 4d7ac355701d
parent 397 6a7ff66a811d
child 450 18583d13f0fa
equal deleted inserted replaced
422:76aebe92fd5f 423:4d7ac355701d
    49 static int* latest_subscription = subscription_table;
    49 static int* latest_subscription = subscription_table;
    50 static int* subscription_cursor = subscription_table;
    50 static int* subscription_cursor = subscription_table;
    51 
    51 
    52 struct_plcvar variable_table[%(variables_pointer_type_table_count)d];
    52 struct_plcvar variable_table[%(variables_pointer_type_table_count)d];
    53 
    53 
    54 void __init_debug()
    54 void __init_debug(void)
    55 {
    55 {
    56 %(variables_pointer_type_table_initializer)s
    56 %(variables_pointer_type_table_initializer)s
    57     buffer_state = BUFFER_FREE;
    57     buffer_state = BUFFER_FREE;
    58 }
    58 }
    59 
    59 
    60 void __cleanup_debug()
    60 void __cleanup_debug(void)
    61 {
    61 {
    62 }
    62 }
    63 
    63 
    64 void __retrieve_debug()
    64 void __retrieve_debug(void)
    65 {
    65 {
    66 }
    66 }
    67 
    67 
    68 extern int TryEnterDebugSection(void);
    68 extern int TryEnterDebugSection(void);
    69 extern void LeaveDebugSection(void);
    69 extern void LeaveDebugSection(void);
    70 extern long AtomicCompareExchange(long*, long, long);
    70 extern long AtomicCompareExchange(long*, long, long);
    71 extern void InitiateDebugTransfer(void);
    71 extern void InitiateDebugTransfer(void);
    72 
    72 
    73 extern unsigned long __tick;
    73 extern unsigned long __tick;
    74 void __publish_debug()
    74 void __publish_debug(void)
    75 {
    75 {
    76     /* Check there is no running debugger re-configuration */
    76     /* Check there is no running debugger re-configuration */
    77     if(TryEnterDebugSection()){
    77     if(TryEnterDebugSection()){
    78         /* Lock buffer */
    78         /* Lock buffer */
    79         long latest_state = AtomicCompareExchange(
    79         long latest_state = AtomicCompareExchange(
   141 void ResetDebugVariables(void)
   141 void ResetDebugVariables(void)
   142 {
   142 {
   143     latest_subscription = subscription_table;
   143     latest_subscription = subscription_table;
   144 }
   144 }
   145 
   145 
   146 void FreeDebugData()
   146 void FreeDebugData(void)
   147 {
   147 {
   148     /* atomically mark buffer as free */
   148     /* atomically mark buffer as free */
   149     long latest_state = AtomicCompareExchange(
   149     long latest_state;
       
   150     latest_state = AtomicCompareExchange(
   150         &buffer_state,
   151         &buffer_state,
   151         BUFFER_BUSY,
   152         BUFFER_BUSY,
   152         BUFFER_FREE);
   153         BUFFER_FREE);
   153 }
   154 }
   154 
   155 
   167         buffer_cursor = buffer_cursor + size;
   168         buffer_cursor = buffer_cursor + size;
   168         if(old_cursor < debug_buffer + BUFFER_SIZE)
   169         if(old_cursor < debug_buffer + BUFFER_SIZE)
   169         {
   170         {
   170             return old_cursor;
   171             return old_cursor;
   171         }else{
   172         }else{
   172             printf("%%d > %%d\n", old_cursor - debug_buffer, BUFFER_SIZE);
   173             //printf("%%d > %%d\n", old_cursor - debug_buffer, BUFFER_SIZE);
   173 	    return NULL;
   174             return NULL;
   174         } 
   175         } 
   175     }
   176     }
   176     *idx = -1;
   177     *idx = -1;
   177     *type_name = NULL;
   178     *type_name = NULL;
   178     return NULL;
   179     return NULL;