examples/TestMasterSlave/Master.c
changeset 378 d2abf6c8c27b
parent 362 1134fc19aa74
child 381 854c43cdc24a
equal deleted inserted replaced
377:bea5a1576cbd 378:d2abf6c8c27b
    23 #include "Master.h"
    23 #include "Master.h"
    24 #include "Slave.h"
    24 #include "Slave.h"
    25 #include "TestMasterSlave.h"
    25 #include "TestMasterSlave.h"
    26 
    26 
    27 /*****************************************************************************/
    27 /*****************************************************************************/
    28 void TestMaster_heartbeatError(UNS8 heartbeatID)
    28 void TestMaster_heartbeatError(CO_Data* d, UNS8 heartbeatID)
    29 {
    29 {
    30 	eprintf("TestMaster_heartbeatError %d\n", heartbeatID);
    30 	eprintf("TestMaster_heartbeatError %d\n", heartbeatID);
    31 }
    31 }
    32 
    32 
    33 /********************************************************
    33 /********************************************************
    34  * ConfigureSlaveNode is responsible to
    34  * ConfigureSlaveNode is responsible to
    35  *  - setup master RPDO 1 to receive TPDO 1 from id 2
    35  *  - setup master RPDO 1 to receive TPDO 1 from id 2
    36  *  - setup master RPDO 2 to receive TPDO 2 from id 2
    36  *  - setup master RPDO 2 to receive TPDO 2 from id 2
    37  ********************************************************/
    37  ********************************************************/
    38 void TestMaster_initialisation()
    38 void TestMaster_initialisation(CO_Data* d)
    39 {
    39 {
    40 	UNS32 PDO1_COBID = 0x0182; 
    40 	UNS32 PDO1_COBID = 0x0182; 
    41 	UNS32 PDO2_COBID = 0x0282;
    41 	UNS32 PDO2_COBID = 0x0282;
    42 	UNS8 size = sizeof(UNS32); 
    42 	UNS8 size = sizeof(UNS32); 
    43 	UNS32 SINC_cicle=0;
    43 	UNS32 SINC_cicle=0;
   237 	ConfigureLSSNode(d);
   237 	ConfigureLSSNode(d);
   238 }
   238 }
   239 
   239 
   240 
   240 
   241 /* First ask if there is a node with an invalid nodeID.
   241 /* First ask if there is a node with an invalid nodeID.
   242  * If FastScan is activated it is used to put the node in the state “configuration”.
   242  * If FastScan is activated it is used to put the node in the state “configuration?.
   243  * If FastScan is not activated, identification services are used to identify the node.
   243  * If FastScan is not activated, identification services are used to identify the node.
   244  * Then  switch mode service is used to put it in configuration state.
   244  * Then  switch mode service is used to put it in configuration state.
   245  * Next all the inquire and configuration services are used.
   245  * Next all the inquire and configuration services are used.
   246  * Finally, the node LSS state is restored to “waiting” and all the process is repeated 
   246  * Finally, the node LSS state is restored to “waiting? and all the process is repeated 
   247  * again until there isn't any node with a invalid nodeID.
   247  * again until there isn't any node with a invalid nodeID.
   248  * */
   248  * */
   249 static void ConfigureLSSNode(CO_Data* d)
   249 static void ConfigureLSSNode(CO_Data* d)
   250 {
   250 {
   251 	UNS32 Vendor_ID=0x12345678;
   251 	UNS32 Vendor_ID=0x12345678;
   342 			break;
   342 			break;
   343 	}
   343 	}
   344 }
   344 }
   345 #endif
   345 #endif
   346 
   346 
   347 void TestMaster_preOperational()
   347 void TestMaster_preOperational(CO_Data* d)
   348 {
   348 {
   349 	eprintf("TestMaster_preOperational\n");
   349 	eprintf("TestMaster_preOperational\n");
   350 #ifdef CO_ENABLE_LSS
   350 #ifdef CO_ENABLE_LSS
   351 	/* Ask slave node to go in stop mode */
   351 	/* Ask slave node to go in stop mode */
   352 	masterSendNMTstateChange (&TestMaster_Data, 0, NMT_Stop_Node);
   352 	masterSendNMTstateChange (&TestMaster_Data, 0, NMT_Stop_Node);
   353 	ConfigureLSSNode(&TestMaster_Data);
   353 	ConfigureLSSNode(&TestMaster_Data);
   354 #endif
   354 #endif
   355 }
   355 }
   356 
   356 
   357 void TestMaster_operational()
   357 void TestMaster_operational(CO_Data* d)
   358 {
   358 {
   359 	eprintf("TestMaster_operational\n");
   359 	eprintf("TestMaster_operational\n");
   360 }
   360 }
   361 
   361 
   362 void TestMaster_stopped()
   362 void TestMaster_stopped(CO_Data* d)
   363 {
   363 {
   364 	eprintf("TestMaster_stopped\n");
   364 	eprintf("TestMaster_stopped\n");
   365 }
   365 }
   366 
   366 
   367 void TestMaster_post_sync()
   367 void TestMaster_post_sync(CO_Data* d)
   368 {
   368 {
   369 	eprintf("TestMaster_post_sync\n");
   369 	eprintf("TestMaster_post_sync\n");
   370 	eprintf("Master: %d %d %d %d %d %d %d %d %d %x %x %d %d\n",
   370 	eprintf("Master: %d %d %d %d %d %d %d %d %d %x %x %d %d\n",
   371 		MasterMap1,
   371 		MasterMap1,
   372 		MasterMap2,
   372 		MasterMap2,
   381 		MasterMap11,
   381 		MasterMap11,
   382 		MasterMap12,
   382 		MasterMap12,
   383 		MasterMap13);
   383 		MasterMap13);
   384 }
   384 }
   385 
   385 
   386 void TestMaster_post_emcy(UNS8 nodeID, UNS16 errCode, UNS8 errReg)
   386 void TestMaster_post_emcy(CO_Data* d, UNS8 nodeID, UNS16 errCode, UNS8 errReg)
   387 {
   387 {
   388 	eprintf("Master received EMCY message. Node: %2.2x  ErrorCode: %4.4x  ErrorRegister: %2.2x\n", nodeID, errCode, errReg);
   388 	eprintf("Master received EMCY message. Node: %2.2x  ErrorCode: %4.4x  ErrorRegister: %2.2x\n", nodeID, errCode, errReg);
   389 }
   389 }
   390 
   390 
   391 char query_result = 0;
   391 char query_result = 0;
   401 	closeSDOtransfer(&TestMaster_Data, nodeId, SDO_CLIENT);
   401 	closeSDOtransfer(&TestMaster_Data, nodeId, SDO_CLIENT);
   402 }
   402 }
   403 
   403 
   404 
   404 
   405 static int MasterSyncCount = 0;
   405 static int MasterSyncCount = 0;
   406 void TestMaster_post_TPDO()
   406 void TestMaster_post_TPDO(CO_Data* d)
   407 {
   407 {
   408 	eprintf("TestMaster_post_TPDO MasterSyncCount = %d \n", MasterSyncCount);
   408 	eprintf("TestMaster_post_TPDO MasterSyncCount = %d \n", MasterSyncCount);
   409 //
   409 //
   410 //	{
   410 //	{
   411 //		char zero = 0;
   411 //		char zero = 0;
   488 					CheckSDO); /*SDOCallback_t Callback*/
   488 					CheckSDO); /*SDOCallback_t Callback*/
   489 	}
   489 	}
   490 	MasterSyncCount++;
   490 	MasterSyncCount++;
   491 }
   491 }
   492 
   492 
   493 void TestMaster_post_SlaveBootup(UNS8 nodeid)
   493 void TestMaster_post_SlaveBootup(CO_Data* d, UNS8 nodeid)
   494 {
   494 {
   495 	eprintf("TestMaster_post_SlaveBootup %x\n", nodeid);
   495 	eprintf("TestMaster_post_SlaveBootup %x\n", nodeid);
   496 	
   496 	
   497 	ConfigureSlaveNode(&TestMaster_Data, nodeid);
   497 	ConfigureSlaveNode(&TestMaster_Data, nodeid);
   498 }
   498 }