etisserant@52: etisserant@52: #include "canfestival.h" etisserant@52: etisserant@52: %(nodes_includes)s etisserant@52: etisserant@52: #define BOARD_DECL(nodename, busname, baudrate)\ etisserant@52: s_BOARD nodename##Board = {busname, baudrate}; etisserant@52: etisserant@52: %(board_decls)s etisserant@52: etisserant@52: static int init_level=0; etisserant@57: extern int common_ticktime__; etisserant@52: etisserant@59: etisserant@59: static void ConfigureSlaveNode(CO_Data* d, UNS8 nodeId) etisserant@59: { etisserant@59: /* Put the master in operational mode */ etisserant@59: setState(d, Operational); etisserant@59: etisserant@59: /* Ask slave node to go in operational mode */ etisserant@59: masterSendNMTstateChange (d, 0, NMT_Start_Node); etisserant@59: } etisserant@59: etisserant@59: #define NODE_DECLARE(nodename, nodeid)\ etisserant@59: void nodename##_preOperational()\ etisserant@59: {\ etisserant@59: ConfigureSlaveNode(&nodename##_Data, nodeid);\ etisserant@59: }\ etisserant@59: etisserant@59: %(nodes_declare)s etisserant@59: etisserant@59: etisserant@52: #define NODE_INIT(nodename, nodeid) \ etisserant@57: /* Artificially force sync state to 1 so that it is not started */\ etisserant@57: nodename##_Data.CurrentCommunicationState.csSYNC = -1;\ etisserant@57: /* Force sync period to common_ticktime__ so that other node can read it*/\ etisserant@57: *nodename##_Data.COB_ID_Sync = 0x40000080;\ etisserant@57: *nodename##_Data.Sync_Cycle_Period = common_ticktime__ * 1000;\ etisserant@52: /* Defining the node Id */\ etisserant@52: setNodeId(&nodename##_Data, nodeid);\ etisserant@52: /* init */\ etisserant@52: setState(&nodename##_Data, Initialisation); etisserant@52: etisserant@52: void InitNodes(CO_Data* d, UNS32 id) etisserant@52: { etisserant@52: %(nodes_init)s etisserant@52: } etisserant@52: etisserant@52: #define NODE_CLOSE(nodename) \ etisserant@57: if(init_level-- > 0)\ etisserant@52: {\ etisserant@52: EnterMutex();\ etisserant@52: setState(&nodename##_Data, Stopped);\ etisserant@52: LeaveMutex();\ etisserant@52: canClose(&nodename##_Data);\ etisserant@52: } etisserant@52: etisserant@52: void __cleanup_%(locstr)s() etisserant@52: { etisserant@52: %(nodes_close)s etisserant@52: etisserant@52: // Stop timer thread etisserant@57: if(init_level-- > 0) etisserant@57: StopTimerLoop(); etisserant@52: etisserant@52: } etisserant@52: etisserant@52: #define NODE_OPEN(nodename)\ etisserant@59: nodename##_Data.preOperational = nodename##_preOperational;\ etisserant@52: if(!canOpen(&nodename##Board,&nodename##_Data)){\ etisserant@52: printf("Cannot open " #nodename " Board (%%s,%%s)\n",nodename##Board.busname, nodename##Board.baudrate);\ etisserant@52: return -1;\ etisserant@52: }\ etisserant@52: init_level++; etisserant@52: etisserant@52: /*************************** INIT *****************************************/ etisserant@52: int __init_%(locstr)s(int argc,char **argv) etisserant@52: { etisserant@57: #ifndef NOT_USE_DYNAMIC_LOADING etisserant@57: if( !LoadCanDriver("libcanfestival_can_%(candriver)s.so") ){ etisserant@57: fprintf(stderr, "Cannot load CAN interface library for CanFestival (%(candriver)s)\n");\ etisserant@57: return -1; etisserant@57: } etisserant@57: #endif etisserant@52: etisserant@52: %(nodes_open)s etisserant@52: etisserant@52: // Start timer thread etisserant@52: StartTimerLoop(&InitNodes); etisserant@57: init_level++; etisserant@52: return 0; etisserant@52: } etisserant@52: etisserant@57: #define NODE_SEND_SYNC(nodename)\ etisserant@57: sendSYNCMessage(&nodename##_Data); etisserant@57: etisserant@52: void __retrive_%(locstr)s() etisserant@52: { etisserant@57: /* Locks the stack, so that no changes occurs while PLC access variables etisserant@57: * TODO : implement buffers to avoid such a big lock etisserant@57: * */ etisserant@52: EnterMutex(); etisserant@57: /*Send Sync */ etisserant@57: %(nodes_send_sync)s etisserant@52: } etisserant@52: etisserant@57: #define NODE_PROCEED_SYNC(nodename)\ etisserant@57: proceedSYNC(&nodename##_Data); etisserant@57: etisserant@52: void __publish_%(locstr)s() etisserant@52: { etisserant@57: /*Call SendPDOEvent */ etisserant@57: %(nodes_proceed_sync)s etisserant@52: LeaveMutex(); etisserant@52: } etisserant@52: