targets/plc_debug.c
changeset 452 2d0718a05cc7
parent 450 18583d13f0fa
child 458 dfc6164e4022
equal deleted inserted replaced
451:73b3913b6d9c 452:2d0718a05cc7
    39  * Declare global variables from resources and conf 
    39  * Declare global variables from resources and conf 
    40  **/
    40  **/
    41 %(extern_variables_declarations)s
    41 %(extern_variables_declarations)s
    42 
    42 
    43 typedef void(*__for_each_variable_do_fp)(void*, __IEC_types_enum);
    43 typedef void(*__for_each_variable_do_fp)(void*, __IEC_types_enum);
    44 __for_each_variable_do(__for_each_variable_do_fp fp)
    44 void __for_each_variable_do(__for_each_variable_do_fp fp)
    45 {
    45 {
    46 %(for_each_variable_do_code)s
    46 %(for_each_variable_do_code)s
    47 }
    47 }
    48 
    48 
    49 __IEC_types_enum __find_variable(unsigned int varindex, void ** varp)
    49 __IEC_types_enum __find_variable(unsigned int varindex, void ** varp)
    50 {
    50 {
    51     switch(varindex){
    51     switch(varindex){
    52 %(find_variable_case_code)s
    52 %(find_variable_case_code)s
    53     }
    53      default:
    54     *varp = NULL;
    54       *varp = NULL;
    55     return UNKNOWN_ENUM;
    55       return UNKNOWN_ENUM;
       
    56     }
    56 }
    57 }
    57 
    58 
    58 void __init_debug(void)
    59 void __init_debug(void)
    59 {
    60 {
    60     buffer_state = BUFFER_FREE;
    61     buffer_state = BUFFER_FREE;
    91     char flags = 0;
    92     char flags = 0;
    92     /* find data to copy*/
    93     /* find data to copy*/
    93     switch(vartype){
    94     switch(vartype){
    94         ANY(__BufferDebugDataIterator_case_t)
    95         ANY(__BufferDebugDataIterator_case_t)
    95         ANY(__BufferDebugDataIterator_case_p)
    96         ANY(__BufferDebugDataIterator_case_p)
       
    97     default:
       
    98         break;
    96     }
    99     }
    97     if(flags && __IEC_DEBUG_FLAG){
   100     if(flags && __IEC_DEBUG_FLAG){
    98         USINT size = __get_type_enum_size(vartype);
   101         USINT size = __get_type_enum_size(vartype);
    99         /* compute next cursor positon*/
   102         /* compute next cursor positon*/
   100         char* next_cursor = buffer_cursor + size;
   103         char* next_cursor = buffer_cursor + size;
   145 #define __RegisterDebugVariable_case_p(TYPENAME)\
   148 #define __RegisterDebugVariable_case_p(TYPENAME)\
   146         case TYPENAME##_P_ENUM :\
   149         case TYPENAME##_P_ENUM :\
   147             ((__IEC_##TYPENAME##_p *)varp)->flags |= __IEC_DEBUG_FLAG;
   150             ((__IEC_##TYPENAME##_p *)varp)->flags |= __IEC_DEBUG_FLAG;
   148 void RegisterDebugVariable(int idx)
   151 void RegisterDebugVariable(int idx)
   149 {
   152 {
   150     void *varp;
   153     void *varp = NULL;
   151     switch(__find_variable(idx, varp)){
   154     switch(__find_variable(idx, varp)){
   152         ANY(__RegisterDebugVariable_case_t)
   155         ANY(__RegisterDebugVariable_case_t)
   153         ANY(__RegisterDebugVariable_case_p)
   156         ANY(__RegisterDebugVariable_case_p)
       
   157     default:
       
   158         break;
   154     }
   159     }
   155 }
   160 }
   156 
   161 
   157 #define __ResetDebugVariablesIterator_case_t(TYPENAME) \
   162 #define __ResetDebugVariablesIterator_case_t(TYPENAME) \
   158         case TYPENAME##_ENUM :\
   163         case TYPENAME##_ENUM :\
   166 {
   171 {
   167     /* force debug flag to 0*/
   172     /* force debug flag to 0*/
   168     switch(vartype){
   173     switch(vartype){
   169         ANY(__ResetDebugVariablesIterator_case_t)
   174         ANY(__ResetDebugVariablesIterator_case_t)
   170         ANY(__ResetDebugVariablesIterator_case_p)
   175         ANY(__ResetDebugVariablesIterator_case_p)
       
   176     default:
       
   177         break;
   171     }
   178     }
   172 }
   179 }
   173 
   180 
   174 void ResetDebugVariables(void)
   181 void ResetDebugVariables(void)
   175 {
   182 {
   183     latest_state = AtomicCompareExchange(
   190     latest_state = AtomicCompareExchange(
   184         &buffer_state,
   191         &buffer_state,
   185         BUFFER_BUSY,
   192         BUFFER_BUSY,
   186         BUFFER_FREE);
   193         BUFFER_FREE);
   187 }
   194 }
   188 
   195 int WaitDebugData(unsigned long *tick);
   189 /* Wait until debug data ready and return pointer to it */
   196 /* Wait until debug data ready and return pointer to it */
   190 int GetDebugData(unsigned long *tick, unsigned long *size, void **buffer){
   197 int GetDebugData(unsigned long *tick, unsigned long *size, void **buffer){
   191     int res = WaitDebugData(tick);
   198     int res = WaitDebugData(tick);
   192     *size = buffer_cursor - debug_buffer;
   199     *size = buffer_cursor - debug_buffer;
   193     *buffer = NULL;
   200     *buffer = NULL;