--- a/plugins/canfestival/cf_runtime.c Tue Sep 25 10:30:51 2007 +0200
+++ b/plugins/canfestival/cf_runtime.c Mon Oct 01 21:44:40 2007 +0200
@@ -9,8 +9,14 @@
%(board_decls)s
static int init_level=0;
+extern int common_ticktime__;
#define NODE_INIT(nodename, nodeid) \
+ /* Artificially force sync state to 1 so that it is not started */\
+ nodename##_Data.CurrentCommunicationState.csSYNC = -1;\
+ /* Force sync period to common_ticktime__ so that other node can read it*/\
+ *nodename##_Data.COB_ID_Sync = 0x40000080;\
+ *nodename##_Data.Sync_Cycle_Period = common_ticktime__ * 1000;\
/* Defining the node Id */\
setNodeId(&nodename##_Data, nodeid);\
/* init */\
@@ -22,7 +28,7 @@
}
#define NODE_CLOSE(nodename) \
- if(init_level--)\
+ if(init_level-- > 0)\
{\
EnterMutex();\
setState(&nodename##_Data, Stopped);\
@@ -35,14 +41,14 @@
%(nodes_close)s
// Stop timer thread
- StopTimerLoop();
+ if(init_level-- > 0)
+ StopTimerLoop();
}
#define NODE_OPEN(nodename)\
if(!canOpen(&nodename##Board,&nodename##_Data)){\
printf("Cannot open " #nodename " Board (%%s,%%s)\n",nodename##Board.busname, nodename##Board.baudrate);\
- __cleanup_%(locstr)s();\
return -1;\
}\
init_level++;
@@ -50,26 +56,41 @@
/*************************** INIT *****************************************/
int __init_%(locstr)s(int argc,char **argv)
{
+#ifndef NOT_USE_DYNAMIC_LOADING
+ if( !LoadCanDriver("libcanfestival_can_%(candriver)s.so") ){
+ fprintf(stderr, "Cannot load CAN interface library for CanFestival (%(candriver)s)\n");\
+ return -1;
+ }
+#endif
%(nodes_open)s
-#ifndef NOT_USE_DYNAMIC_LOADING
- LoadCanDriver("libcanfestival_can_%(candriver)s.so");
-#endif
// Start timer thread
StartTimerLoop(&InitNodes);
+ init_level++;
return 0;
}
+#define NODE_SEND_SYNC(nodename)\
+ sendSYNCMessage(&nodename##_Data);
+
void __retrive_%(locstr)s()
{
- /*TODO: Send Sync */
+ /* Locks the stack, so that no changes occurs while PLC access variables
+ * TODO : implement buffers to avoid such a big lock
+ * */
EnterMutex();
+ /*Send Sync */
+ %(nodes_send_sync)s
}
+#define NODE_PROCEED_SYNC(nodename)\
+ proceedSYNC(&nodename##_Data);
+
void __publish_%(locstr)s()
{
- /*TODO: Call SendPDOEvent */
+ /*Call SendPDOEvent */
+ %(nodes_proceed_sync)s
LeaveMutex();
}