examples/TestMasterSlave/Master.c
changeset 154 1b3165f2d17d
parent 149 fe50ada8020b
child 172 0248c2b148bb
equal deleted inserted replaced
153:1c1ad874fe8f 154:1b3165f2d17d
    34 void TestMaster_SDOtimeoutError (UNS8 line)
    34 void TestMaster_SDOtimeoutError (UNS8 line)
    35 {
    35 {
    36 	eprintf("TestMaster_SDOtimeoutError %d\n", line);
    36 	eprintf("TestMaster_SDOtimeoutError %d\n", line);
    37 }
    37 }
    38 
    38 
    39 /*****************************************************************************/
    39 /********************************************************
       
    40  * ConfigureSlaveNode is responsible to
       
    41  *  - setup master RPDO 1 to receive TPDO 1 from id 2
       
    42  *  - setup master RPDO 2 to receive TPDO 2 from id 2
       
    43  ********************************************************/
    40 void TestMaster_initialisation()
    44 void TestMaster_initialisation()
    41 {
    45 {
       
    46 	UNS32 PDO1_COBID = 0x0182; 
       
    47 	UNS32 PDO2_COBID = 0x0282;
       
    48 	UNS8 size = sizeof(UNS32); 
       
    49 
    42 	eprintf("TestMaster_initialisation\n");
    50 	eprintf("TestMaster_initialisation\n");
       
    51 
       
    52 	/*****************************************
       
    53 	 * Define RPDOs to match slave ID=2 TPDOs*
       
    54 	 *****************************************/
       
    55 	setODentry( &TestMaster_Data, /*CO_Data* d*/
       
    56 			0x1400, /*UNS16 index*/
       
    57 			0x01, /*UNS8 subind*/ 
       
    58 			&PDO1_COBID, /*void * pSourceData,*/ 
       
    59 			&size, /* UNS8 * pExpectedSize*/
       
    60 			RW);  /* UNS8 checkAccess */
       
    61 			
       
    62 	setODentry( &TestMaster_Data, /*CO_Data* d*/
       
    63 			0x1401, /*UNS16 index*/
       
    64 			0x01, /*UNS8 subind*/ 
       
    65 			&PDO2_COBID, /*void * pSourceData,*/ 
       
    66 			&size, /* UNS8 * pExpectedSize*/
       
    67 			RW);  /* UNS8 checkAccess */
       
    68 }
       
    69 
       
    70 /********************************************************
       
    71  * ConfigureSlaveNode is responsible to
       
    72  *  - setup slave TPDO 1 transmit time
       
    73  *  - setup slave TPDO 2 transmit time
       
    74  *  - switch to operational mode
       
    75  *  - send NMT to slave
       
    76  ********************************************************
       
    77  * This an example of :
       
    78  * Network Dictionary Access (SDO) with Callback 
       
    79  * Slave node state change request (NMT) 
       
    80  ********************************************************
       
    81  * This is called first by TestMaster_preOperational
       
    82  * then it called again each time a SDO exchange is
       
    83  * finished.
       
    84  ********************************************************/
       
    85 static void ConfigureSlaveNode(CO_Data* d, UNS8 nodeId)
       
    86 {
       
    87 	// Step counts number of times ConfigureSlaveNode is called
       
    88 	static step = 1;
       
    89 	
       
    90 	UNS8 Transmission_Type = 0x01; 
       
    91 	UNS32 abortCode;
       
    92 	UNS8 res;
       
    93 	eprintf("Master : ConfigureSlaveNode %2.2x\n", nodeId);
       
    94 
       
    95 	switch(step++){
       
    96 		case 1: /*First step : setup Slave's TPDO 1 to be transmitted on SYNC*/
       
    97 			eprintf("Master : set slave %2.2x TPDO 1 transmit type\n", nodeId);
       
    98 			res = writeNetworkDictCallBack (d, /*CO_Data* d*/
       
    99 					*TestSlave_Data.bDeviceNodeId, /*UNS8 nodeId*/
       
   100 					0x1800, /*UNS16 index*/
       
   101 					0x02, /*UNS8 subindex*/
       
   102 					1, /*UNS8 count*/
       
   103 					0, /*UNS8 dataType*/
       
   104 					&Transmission_Type,/*void *data*/
       
   105 					ConfigureSlaveNode); /*SDOCallback_t Callback*/			break;
       
   106 		case 2:	/*Second step*/
       
   107 			/*check and warn for previous slave OD access error*/
       
   108 			if(getWriteResultNetworkDict (d, nodeId, &abortCode) != SDO_FINISHED)
       
   109 				eprintf("Master : Couldn't set slave %2.2x TPDO 1 transmit type. AbortCode :%4.4x \n", nodeId, abortCode);
       
   110 
       
   111 			/* Finalise last SDO transfer with this node */
       
   112 			closeSDOtransfer(&TestMaster_Data,
       
   113 					*TestSlave_Data.bDeviceNodeId,
       
   114 					SDO_CLIENT);
       
   115 					
       
   116 			/*Setup Slave's TPDO 1 to be transmitted on SYNC*/
       
   117 			eprintf("Master : set slave %2.2x TPDO 2 transmit type\n", nodeId);
       
   118 			writeNetworkDictCallBack (d, /*CO_Data* d*/
       
   119 					*TestSlave_Data.bDeviceNodeId, /*UNS8 nodeId*/
       
   120 					0x1801, /*UNS16 index*/
       
   121 					0x02, /*UNS16 index*/
       
   122 					1, /*UNS8 count*/
       
   123 					0, /*UNS8 dataType*/
       
   124 					&Transmission_Type,/*void *data*/
       
   125 					ConfigureSlaveNode); /*SDOCallback_t Callback*/
       
   126 			break;
       
   127 		case 3: /*Last step*/
       
   128 			/*check and warn for previous slave OD access error*/
       
   129 			if(getWriteResultNetworkDict (d, nodeId, &abortCode) != SDO_FINISHED)
       
   130 				eprintf("Master : Couldn't set slave %2.2x TPDO 2 transmit type. AbortCode :%4.4x \n", nodeId, abortCode);
       
   131 
       
   132 			/* Finalise last SDO transfer with this node */
       
   133 			closeSDOtransfer(&TestMaster_Data,
       
   134 					*TestSlave_Data.bDeviceNodeId,
       
   135 					SDO_CLIENT);
       
   136 
       
   137 			/* Put the master in operational mode */
       
   138 			setState(d, Operational);
       
   139 			  
       
   140 			/* Ask slave node to go in operational mode */
       
   141 			masterSendNMTstateChange (d, nodeId, NMT_Start_Node);
       
   142 	}
       
   143 			
    43 }
   144 }
    44 
   145 
    45 void TestMaster_preOperational()
   146 void TestMaster_preOperational()
    46 {
   147 {
       
   148 
    47 	eprintf("TestMaster_preOperational\n");
   149 	eprintf("TestMaster_preOperational\n");
       
   150 	ConfigureSlaveNode(&TestMaster_Data, 2);
       
   151 	
    48 }
   152 }
    49 
   153 
    50 void TestMaster_operational()
   154 void TestMaster_operational()
    51 {
   155 {
    52 	eprintf("TestMaster_operational\n");
   156 	eprintf("TestMaster_operational\n");