targets/Xenomai/plc_Xenomai_main.c
changeset 616 b9271faec96e
parent 615 72bc3e53a1fa
child 617 7c23fac40a2a
equal deleted inserted replaced
615:72bc3e53a1fa 616:b9271faec96e
   184     /* open Python_pipe*/
   184     /* open Python_pipe*/
   185     if((Python_pipe_fd = open(PYTHON_PIPE_DEVICE, O_RDWR)) == -1) goto error;
   185     if((Python_pipe_fd = open(PYTHON_PIPE_DEVICE, O_RDWR)) == -1) goto error;
   186     PLC_state |= PLC_STATE_PYTHON_FILE_OPENED;
   186     PLC_state |= PLC_STATE_PYTHON_FILE_OPENED;
   187 
   187 
   188     /* create WaitDebug_pipe */
   188     /* create WaitDebug_pipe */
   189     if(rt_pipe_create(&WaitDebug_pipe, "Debug_pipe", WAITDEBUG_PIPE_MINOR, PIPE_SIZE))
   189     if(rt_pipe_create(&WaitDebug_pipe, "WaitDebug_pipe", WAITDEBUG_PIPE_MINOR, PIPE_SIZE))
   190         goto error;
   190         goto error;
   191     PLC_state |= PLC_STATE_WAITDEBUG_PIPE_CREATED;
   191     PLC_state |= PLC_STATE_WAITDEBUG_PIPE_CREATED;
   192 
   192 
   193     /* open WaitDebug_pipe*/
   193     /* open WaitDebug_pipe*/
   194     if((WaitDebug_pipe_fd = open(WAITDEBUG_PIPE_DEVICE, O_RDWR)) == -1) goto error;
   194     if((WaitDebug_pipe_fd = open(WAITDEBUG_PIPE_DEVICE, O_RDWR)) == -1) goto error;
   195     PLC_state |= PLC_STATE_WAITDEBUG_FILE_OPENED;
   195     PLC_state |= PLC_STATE_WAITDEBUG_FILE_OPENED;
   196 
   196 
   197     /* create WaitPython_pipe */
   197     /* create WaitPython_pipe */
   198     if(rt_pipe_create(&WaitPython_pipe, "Python_pipe", WAITPYTHON_PIPE_MINOR, PIPE_SIZE))
   198     if(rt_pipe_create(&WaitPython_pipe, "WaitPython_pipe", WAITPYTHON_PIPE_MINOR, PIPE_SIZE))
   199         goto error;
   199         goto error;
   200     PLC_state |= PLC_STATE_WAITPYTHON_PIPE_CREATED;
   200     PLC_state |= PLC_STATE_WAITPYTHON_PIPE_CREATED;
   201 
   201 
   202     /* open WaitPython_pipe*/
   202     /* open WaitPython_pipe*/
   203     if((WaitPython_pipe_fd = open(WAITPYTHON_PIPE_DEVICE, O_RDWR)) == -1) goto error;
   203     if((WaitPython_pipe_fd = open(WAITPYTHON_PIPE_DEVICE, O_RDWR)) == -1) goto error;
   213     if(rt_task_start(&PLC_task, &PLC_task_proc, NULL)) goto error;
   213     if(rt_task_start(&PLC_task, &PLC_task_proc, NULL)) goto error;
   214 
   214 
   215     return 0;
   215     return 0;
   216 
   216 
   217 error:
   217 error:
       
   218 
   218     PLC_cleanup_all();
   219     PLC_cleanup_all();
   219     return 1;
   220     return 1;
   220 }
   221 }
   221 
   222 
   222 #define DEBUG_FREE 0
   223 #define DEBUG_FREE 0
   223 #define DEBUG_BUSY 1
   224 #define DEBUG_BUSY 1
   224 static long debug_state = DEBUG_FREE;
   225 static long debug_state = DEBUG_FREE;
   225 
   226 
   226 int TryEnterDebugSection(void)
   227 int TryEnterDebugSection(void)
   227 {
   228 {
   228     long old_debug_state = AtomicCompareExchange(
   229     if(AtomicCompareExchange(
   229         &debug_state,
   230         &debug_state,
   230         DEBUG_FREE,
   231         DEBUG_FREE,
   231         DEBUG_BUSY);
   232         DEBUG_BUSY) == DEBUG_FREE){
   232     return old_debug_state == DEBUG_FREE;
   233         if(__DEBUG){
       
   234             return 1;
       
   235         }
       
   236         AtomicCompareExchange( &debug_state, DEBUG_BUSY, DEBUG_FREE);
       
   237     }
       
   238     return 0;
   233 }
   239 }
   234 
   240 
   235 #define DEBUG_UNLOCK 1
   241 #define DEBUG_UNLOCK 1
   236 void LeaveDebugSection(void)
   242 void LeaveDebugSection(void)
   237 {
   243 {
   275     while(AtomicCompareExchange(
   281     while(AtomicCompareExchange(
   276             &debug_state,
   282             &debug_state,
   277             DEBUG_FREE,
   283             DEBUG_FREE,
   278             DEBUG_BUSY) != DEBUG_FREE &&
   284             DEBUG_BUSY) != DEBUG_FREE &&
   279             cmd == DEBUG_UNLOCK){
   285             cmd == DEBUG_UNLOCK){
   280        if(read(Debug_pipe_fd, &cmd, sizeof(cmd)) == sizeof(cmd)){
   286        if(read(Debug_pipe_fd, &cmd, sizeof(cmd)) != sizeof(cmd)){
   281            return -1;
   287            return -1;
   282        }
   288        }
   283     }
   289     }
   284     __DEBUG = !disable;
   290     __DEBUG = !disable;
   285     return 0;
   291     return 0;
   345            rt_pipe_write(&Python_pipe, &cmd, sizeof(cmd), P_NORMAL);
   351            rt_pipe_write(&Python_pipe, &cmd, sizeof(cmd), P_NORMAL);
   346         }/* otherwise, no signaling from non real time */
   352         }/* otherwise, no signaling from non real time */
   347     }    /* as plc does not wait for lock. */
   353     }    /* as plc does not wait for lock. */
   348 }
   354 }
   349 
   355 
       
   356 int CheckRetainBuffer(void)
       
   357 {
       
   358 	return 1;
       
   359 }
       
   360 
       
   361 void ValidateRetainBuffer(void)
       
   362 {
       
   363 }
       
   364 
       
   365 void InValidateRetainBuffer(void)
       
   366 {
       
   367 }
       
   368 
       
   369 void Retain(unsigned int offset, unsigned int count, void *p)
       
   370 {
       
   371 }
       
   372 
       
   373 void Remind(unsigned int offset, unsigned int count, void *p)
       
   374 {
       
   375 }
       
   376