targets/Linux/plc_Linux_main.c
changeset 462 274e83a5534e
parent 446 1edde533db19
child 483 bc26c42d2eec
equal deleted inserted replaced
461:bcbc472c0ba8 462:274e83a5534e
    83     sigev.sigev_notify = SIGEV_THREAD;
    83     sigev.sigev_notify = SIGEV_THREAD;
    84     sigev.sigev_notify_attributes = NULL;
    84     sigev.sigev_notify_attributes = NULL;
    85     sigev.sigev_notify_function = PLC_timer_notify;
    85     sigev.sigev_notify_function = PLC_timer_notify;
    86 
    86 
    87     pthread_mutex_init(&debug_wait_mutex, NULL);
    87     pthread_mutex_init(&debug_wait_mutex, NULL);
       
    88     pthread_mutex_init(&debug_mutex, NULL);
    88     pthread_mutex_init(&python_wait_mutex, NULL);
    89     pthread_mutex_init(&python_wait_mutex, NULL);
       
    90     pthread_mutex_init(&python_mutex, NULL);
    89 
    91 
    90     pthread_mutex_lock(&debug_wait_mutex);
    92     pthread_mutex_lock(&debug_wait_mutex);
    91     pthread_mutex_lock(&python_wait_mutex);
    93     pthread_mutex_lock(&python_wait_mutex);
    92 
    94 
    93     timer_create (CLOCK_REALTIME, &sigev, &PLC_timer);
    95     timer_create (CLOCK_REALTIME, &sigev, &PLC_timer);
    94     if(  __init(argc,argv) == 0 ){
    96     if(  __init(argc,argv) == 0 ){
    95         PLC_SetTimer(Ttick,Ttick);
    97         PLC_SetTimer(Ttick,Ttick);
    96 
    98 
    97         /* install signal handler for manual break */
    99         /* install signal handler for manual break */
    98 //        signal(SIGTERM, catch_signal);
       
    99         signal(SIGINT, catch_signal);
   100         signal(SIGINT, catch_signal);
   100 
       
   101         pthread_mutex_trylock(&debug_mutex);
       
   102     }else{
   101     }else{
   103         return 1;
   102         return 1;
   104     }
   103     }
   105     return 0;
   104     return 0;
   106 }
   105 }
   107 
   106 
   108 int TryEnterDebugSection(void)
   107 int TryEnterDebugSection(void)
   109 {
   108 {
   110     return pthread_mutex_trylock(&debug_mutex) == 0;
   109     if (pthread_mutex_trylock(&debug_mutex) == 0){
       
   110         /* Only enter if debug active */
       
   111         if(__DEBUG){
       
   112             return 1;
       
   113         }
       
   114     }
       
   115     pthread_mutex_unlock(&debug_mutex);
       
   116     return 0;
   111 }
   117 }
   112 
   118 
   113 void LeaveDebugSection(void)
   119 void LeaveDebugSection(void)
   114 {
   120 {
   115     pthread_mutex_unlock(&debug_mutex);
   121     pthread_mutex_unlock(&debug_mutex);
   147     __debug_tick = __tick;
   153     __debug_tick = __tick;
   148     /* signal debugger thread it can read data */
   154     /* signal debugger thread it can read data */
   149     pthread_mutex_unlock(&debug_wait_mutex);
   155     pthread_mutex_unlock(&debug_wait_mutex);
   150 }
   156 }
   151 
   157 
   152 void suspendDebug(void)
   158 void suspendDebug(int disable)
   153 {
   159 {
   154     __DEBUG = 0;
       
   155     /* Prevent PLC to enter debug code */
   160     /* Prevent PLC to enter debug code */
   156     pthread_mutex_lock(&debug_mutex);
   161     pthread_mutex_lock(&debug_mutex);
       
   162     /*__DEBUG is protected by this mutex */
       
   163     __DEBUG = !disable;
   157 }
   164 }
   158 
   165 
   159 void resumeDebug(void)
   166 void resumeDebug(void)
   160 {
   167 {
   161     __DEBUG = 1;
   168     __DEBUG = 1;