targets/Xenomai/plc_Xenomai_main.c
changeset 1981 d0718654d9b0
parent 1980 28a369bb2676
child 1990 2e0fbdd152de
equal deleted inserted replaced
1980:28a369bb2676 1981:d0718654d9b0
   157     signal(SIGINT, catch_signal);
   157     signal(SIGINT, catch_signal);
   158     printf("Got Signal %d\n",sig);
   158     printf("Got Signal %d\n",sig);
   159     exit(0);
   159     exit(0);
   160 }
   160 }
   161 
   161 
       
   162 #define _startPLCLog(text) \
       
   163     {\
       
   164     	char mstr[] = text;\
       
   165         LogMessage(LOG_CRITICAL, mstr, sizeof(mstr));\
       
   166         goto error;\
       
   167     }
       
   168 
       
   169 #define FO "Failed opening "
       
   170 
   162 #define max_val(a,b) ((a>b)?a:b)
   171 #define max_val(a,b) ((a>b)?a:b)
   163 int startPLC(int argc,char **argv)
   172 int startPLC(int argc,char **argv)
   164 {
   173 {
   165     signal(SIGINT, catch_signal);
   174     signal(SIGINT, catch_signal);
   166 
   175 
   169 
   178 
   170     PLC_shutdown = 0;
   179     PLC_shutdown = 0;
   171 
   180 
   172     /*** RT Pipes creation and opening ***/
   181     /*** RT Pipes creation and opening ***/
   173     /* create Debug_pipe */
   182     /* create Debug_pipe */
   174         goto error;
       
   175     if(rt_pipe_create(&Debug_pipe, "Debug_pipe", DEBUG_PIPE_MINOR, PIPE_SIZE) < 0) 
   183     if(rt_pipe_create(&Debug_pipe, "Debug_pipe", DEBUG_PIPE_MINOR, PIPE_SIZE) < 0) 
       
   184         _startPLCLog(FO "Debug_pipe real-time end");
   176     PLC_state |= PLC_STATE_DEBUG_PIPE_CREATED;
   185     PLC_state |= PLC_STATE_DEBUG_PIPE_CREATED;
   177 
   186 
   178     /* open Debug_pipe*/
   187     /* open Debug_pipe*/
   179     if((Debug_pipe_fd = open(DEBUG_PIPE_DEVICE, O_RDWR)) == -1) goto error;
   188     if((Debug_pipe_fd = open(DEBUG_PIPE_DEVICE, O_RDWR)) == -1)
       
   189         _startPLCLog(FO DEBUG_PIPE_DEVICE);
   180     PLC_state |= PLC_STATE_DEBUG_FILE_OPENED;
   190     PLC_state |= PLC_STATE_DEBUG_FILE_OPENED;
   181 
   191 
   182     /* create Python_pipe */
   192     /* create Python_pipe */
   183         goto error;
       
   184     if(rt_pipe_create(&Python_pipe, "Python_pipe", PYTHON_PIPE_MINOR, PIPE_SIZE) < 0) 
   193     if(rt_pipe_create(&Python_pipe, "Python_pipe", PYTHON_PIPE_MINOR, PIPE_SIZE) < 0) 
       
   194         _startPLCLog(FO "Python_pipe real-time end");
   185     PLC_state |= PLC_STATE_PYTHON_PIPE_CREATED;
   195     PLC_state |= PLC_STATE_PYTHON_PIPE_CREATED;
   186 
   196 
   187     /* open Python_pipe*/
   197     /* open Python_pipe*/
   188     if((Python_pipe_fd = open(PYTHON_PIPE_DEVICE, O_RDWR)) == -1) goto error;
   198     if((Python_pipe_fd = open(PYTHON_PIPE_DEVICE, O_RDWR)) == -1)
       
   199         _startPLCLog(FO PYTHON_PIPE_DEVICE);
   189     PLC_state |= PLC_STATE_PYTHON_FILE_OPENED;
   200     PLC_state |= PLC_STATE_PYTHON_FILE_OPENED;
   190 
   201 
   191     /* create WaitDebug_pipe */
   202     /* create WaitDebug_pipe */
   192         goto error;
       
   193     if(rt_pipe_create(&WaitDebug_pipe, "WaitDebug_pipe", WAITDEBUG_PIPE_MINOR, PIPE_SIZE) < 0)
   203     if(rt_pipe_create(&WaitDebug_pipe, "WaitDebug_pipe", WAITDEBUG_PIPE_MINOR, PIPE_SIZE) < 0)
       
   204         _startPLCLog(FO "WaitDebug_pipe real-time end");
   194     PLC_state |= PLC_STATE_WAITDEBUG_PIPE_CREATED;
   205     PLC_state |= PLC_STATE_WAITDEBUG_PIPE_CREATED;
   195 
   206 
   196     /* open WaitDebug_pipe*/
   207     /* open WaitDebug_pipe*/
   197     if((WaitDebug_pipe_fd = open(WAITDEBUG_PIPE_DEVICE, O_RDWR)) == -1) goto error;
   208     if((WaitDebug_pipe_fd = open(WAITDEBUG_PIPE_DEVICE, O_RDWR)) == -1)
       
   209         _startPLCLog(FO WAITDEBUG_PIPE_DEVICE);
   198     PLC_state |= PLC_STATE_WAITDEBUG_FILE_OPENED;
   210     PLC_state |= PLC_STATE_WAITDEBUG_FILE_OPENED;
   199 
   211 
   200     /* create WaitPython_pipe */
   212     /* create WaitPython_pipe */
   201         goto error;
       
   202     if(rt_pipe_create(&WaitPython_pipe, "WaitPython_pipe", WAITPYTHON_PIPE_MINOR, PIPE_SIZE) < 0)
   213     if(rt_pipe_create(&WaitPython_pipe, "WaitPython_pipe", WAITPYTHON_PIPE_MINOR, PIPE_SIZE) < 0)
       
   214         _startPLCLog(FO "WaitPython_pipe real-time end");
   203     PLC_state |= PLC_STATE_WAITPYTHON_PIPE_CREATED;
   215     PLC_state |= PLC_STATE_WAITPYTHON_PIPE_CREATED;
   204 
   216 
   205     /* open WaitPython_pipe*/
   217     /* open WaitPython_pipe*/
   206     if((WaitPython_pipe_fd = open(WAITPYTHON_PIPE_DEVICE, O_RDWR)) == -1) goto error;
   218     if((WaitPython_pipe_fd = open(WAITPYTHON_PIPE_DEVICE, O_RDWR)) == -1)
       
   219         _startPLCLog(FO WAITPYTHON_PIPE_DEVICE);
   207     PLC_state |= PLC_STATE_WAITPYTHON_FILE_OPENED;
   220     PLC_state |= PLC_STATE_WAITPYTHON_FILE_OPENED;
   208 
   221 
   209     /*** create PLC task ***/
   222     /*** create PLC task ***/
   210     if(rt_task_create(&PLC_task, "PLC_task", 0, 50, T_JOINABLE)) goto error;
   223     if(rt_task_create(&PLC_task, "PLC_task", 0, 50, T_JOINABLE))
       
   224         _startPLCLog("Failed creating PLC task");
   211     PLC_state |= PLC_STATE_TASK_CREATED;
   225     PLC_state |= PLC_STATE_TASK_CREATED;
   212 
   226 
   213     if(__init(argc,argv)) goto error;
   227     if(__init(argc,argv)) goto error;
   214 
   228 
   215     /* start PLC task */
   229     /* start PLC task */
   216     if(rt_task_start(&PLC_task, &PLC_task_proc, NULL)) goto error;
   230     if(rt_task_start(&PLC_task, &PLC_task_proc, NULL))
       
   231         _startPLCLog("Failed starting PLC task");
   217 
   232 
   218     return 0;
   233     return 0;
   219 
   234 
   220 error:
   235 error:
   221 
   236