plugins/canfestival/cf_runtime.c
changeset 515 022e034bd4b8
parent 512 36aeab46f27d
equal deleted inserted replaced
514:d36a89dcd21c 515:022e034bd4b8
    77     if(init_level_c-- > 0)\
    77     if(init_level_c-- > 0)\
    78     {\
    78     {\
    79       canClose(&nodename##_Data);\
    79       canClose(&nodename##_Data);\
    80     }
    80     }
    81 
    81 
    82 void __cleanup_%(locstr)s()
    82 void __cleanup_%(locstr)s(void)
    83 {
    83 {
    84     // Stop timer thread
    84     // Stop timer thread
    85     if(init_level-- > 0){
    85     if(init_level-- > 0){
    86     int init_level_c = init_level;
    86     int init_level_c = init_level;
    87         StopTimerLoop(&Exit);
    87         StopTimerLoop(&Exit);
    88         %(nodes_close)s
    88         %(nodes_close)s
    89     }
    89     }
    90 
    90 
    91     TimerCleanup();
    91     TimerCleanup();
    92 }
    92 }
       
    93 
       
    94 #ifndef stderr
       
    95 #define fprintf(...)
       
    96 #define fflush(...)
       
    97 #endif
    93 
    98 
    94 #define NODE_OPEN(nodename)\
    99 #define NODE_OPEN(nodename)\
    95     if(!canOpen(&nodename##Board,&nodename##_Data)){\
   100     if(!canOpen(&nodename##Board,&nodename##_Data)){\
    96         fprintf(stderr,"Cannot open CAN intefrace %%s at speed %%s\n for CANopen node \"" #nodename "\"",nodename##Board.busname, nodename##Board.baudrate);\
   101         fprintf(stderr,"Cannot open CAN intefrace %%s at speed %%s\n for CANopen node \"" #nodename "\"",nodename##Board.busname, nodename##Board.baudrate);\
    97         fflush(stderr);\
   102         fflush(stderr);\
   103 int __init_%(locstr)s(int argc,char **argv)
   108 int __init_%(locstr)s(int argc,char **argv)
   104 {
   109 {
   105 #ifndef NOT_USE_DYNAMIC_LOADING
   110 #ifndef NOT_USE_DYNAMIC_LOADING
   106     if( !LoadCanDriver("%(candriver)s") ){
   111     if( !LoadCanDriver("%(candriver)s") ){
   107         fprintf(stderr, "Cannot load CAN interface library for CanFestival (%(candriver)s)\n");\
   112         fprintf(stderr, "Cannot load CAN interface library for CanFestival (%(candriver)s)\n");\
   108         fflush(stderr);
   113         fflush(stderr);\
   109         return -1;
   114         return -1;\
   110     }
   115     }
   111 #endif
   116 #endif
   112 
   117 
   113     TimerInit();
   118     TimerInit();
   114 
   119 
   121 }
   126 }
   122 
   127 
   123 #define NODE_SEND_SYNC(nodename)\
   128 #define NODE_SEND_SYNC(nodename)\
   124     sendSYNCMessage(&nodename##_Data);
   129     sendSYNCMessage(&nodename##_Data);
   125 
   130 
   126 void __retrieve_%(locstr)s()
   131 void __retrieve_%(locstr)s(void)
   127 {
   132 {
   128     /* Locks the stack, so that no changes occurs while PLC access variables
   133     /* Locks the stack, so that no changes occurs while PLC access variables
   129      * TODO : implement buffers to avoid such a big lock
   134      * TODO : implement buffers to avoid such a big lock
   130      *  */
   135      *  */
   131     EnterMutex();
   136     EnterMutex();
   134 }
   139 }
   135 
   140 
   136 #define NODE_PROCEED_SYNC(nodename)\
   141 #define NODE_PROCEED_SYNC(nodename)\
   137     proceedSYNC(&nodename##_Data);
   142     proceedSYNC(&nodename##_Data);
   138 
   143 
   139 void __publish_%(locstr)s()
   144 void __publish_%(locstr)s(void)
   140 {
   145 {
   141     /* Process sync event */
   146     /* Process sync event */
   142     %(nodes_proceed_sync)s
   147     %(nodes_proceed_sync)s
   143     LeaveMutex();
   148     LeaveMutex();
   144 }
   149 }