2 This file is part of CanFestival, a library implementing CanOpen Stack.
4 Copyright (C): Edouard TISSERANT and Francis DUPIN
6 See COPYING file for copyrights details.
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "TestMasterSlave.h"
26 #include "can_driver.h"
28 extern s_BOARD MasterBoard;
29 /*****************************************************************************/
30 void TestMaster_heartbeatError(CO_Data* d, UNS8 heartbeatID)
32 eprintf("TestMaster_heartbeatError %d\n", heartbeatID);
35 /********************************************************
36 * ConfigureSlaveNode is responsible to
37 * - setup master RPDO 1 to receive TPDO 1 from id 2
38 * - setup master RPDO 2 to receive TPDO 2 from id 2
39 ********************************************************/
40 void TestMaster_initialisation(CO_Data* d)
42 UNS32 PDO1_COBID = 0x0182;
43 UNS32 PDO2_COBID = 0x0282;
44 UNS8 size = sizeof(UNS32);
45 // UNS32 SINC_cicle=0;
46 // UNS8 data_type = 0;
48 eprintf("TestMaster_initialisation\n");
50 /*****************************************
51 * Define RPDOs to match slave ID=2 TPDOs*
52 *****************************************/
53 writeLocalDict( &TestMaster_Data, /*CO_Data* d*/
54 0x1400, /*UNS16 index*/
56 &PDO1_COBID, /*void * pSourceData,*/
57 &size, /* UNS8 * pExpectedSize*/
58 RW); /* UNS8 checkAccess */
60 writeLocalDict( &TestMaster_Data, /*CO_Data* d*/
61 0x1401, /*UNS16 index*/
63 &PDO2_COBID, /*void * pSourceData,*/
64 &size, /* UNS8 * pExpectedSize*/
65 RW); /* UNS8 checkAccess */
69 // Step counts number of times ConfigureSlaveNode is called
70 static int init_step = 0;
72 /*Froward declaration*/
73 static void ConfigureSlaveNode(CO_Data* d, UNS8 nodeId);
76 static void CheckSDOAndContinue(CO_Data* d, UNS8 nodeId)
79 if(getWriteResultNetworkDict (d, nodeId, &abortCode) != SDO_FINISHED)
80 eprintf("Master : Failed in initializing slave %2.2x, step %d, AbortCode :%4.4x \n", nodeId, init_step, abortCode);
82 /* Finalise last SDO transfer with this node */
83 closeSDOtransfer(&TestMaster_Data, nodeId, SDO_CLIENT);
85 ConfigureSlaveNode(d, nodeId);
88 /********************************************************
89 * ConfigureSlaveNode is responsible to
90 * - setup slave TPDO 1 transmit type
91 * - setup slave TPDO 2 transmit type
92 * - switch to operational mode
94 ********************************************************
95 * This an example of :
96 * Network Dictionary Access (SDO) with Callback
97 * Slave node state change request (NMT)
98 ********************************************************
99 * This is called first by TestMaster_post_SlaveBootup
100 * then it called again each time a SDO exchange is
102 ********************************************************/
104 static void ConfigureSlaveNode(CO_Data* d, UNS8 nodeId)
106 /* Master configure heartbeat producer time at 1000 ms
107 * for slave node-id 0x02 by DCF concise */
109 UNS8 Transmission_Type = 0x01;
112 eprintf("Master : ConfigureSlaveNode %2.2x\n", nodeId);
115 case 1: /*First step : setup Slave's TPDO 1 to be transmitted on SYNC*/
116 eprintf("Master : set slave %2.2x TPDO 1 transmit type\n", nodeId);
117 res = writeNetworkDictCallBack (d, /*CO_Data* d*/
118 nodeId, /*UNS8 nodeId*/
119 0x1800, /*UNS16 index*/
120 0x02, /*UNS8 subindex*/
123 &Transmission_Type,/*void *data*/
124 CheckSDOAndContinue); /*SDOCallback_t Callback*/
127 case 2: /*Second step*/
128 eprintf("Master : set slave %2.2x TPDO 2 transmit type\n", nodeId);
129 writeNetworkDictCallBack (d, /*CO_Data* d*/
130 nodeId, /*UNS8 nodeId*/
131 0x1801, /*UNS16 index*/
132 0x02, /*UNS16 index*/
135 &Transmission_Type,/*void *data*/
136 CheckSDOAndContinue); /*SDOCallback_t Callback*/
140 /****************************** START *******************************/
142 /* Put the master in operational mode */
143 setState(d, Operational);
145 /* Ask slave node to go in operational mode */
146 masterSendNMTstateChange (d, nodeId, NMT_Start_Node);
152 void TestMaster_preOperational(CO_Data* d)
154 eprintf("TestMaster_preOperational\n");
157 void TestMaster_operational(CO_Data* d)
159 eprintf("TestMaster_operational\n");
162 void TestMaster_stopped(CO_Data* d)
164 eprintf("TestMaster_stopped\n");
167 void TestMaster_post_sync(CO_Data* d)
169 eprintf("TestMaster_post_sync\n");
170 eprintf("Master: %d %d %d %d %d %d %d %d %d %x %x %d %d\n",
186 void TestMaster_post_emcy(CO_Data* d, UNS8 nodeID, UNS16 errCode, UNS8 errReg)
188 eprintf("Master received EMCY message. Node: %2.2x ErrorCode: %4.4x ErrorRegister: %2.2x\n", nodeID, errCode, errReg);
191 char query_result = 0;
192 char waiting_answer = 0;
194 static void CheckSDO(CO_Data* d, UNS8 nodeId)
197 if(getWriteResultNetworkDict (d, nodeId, &abortCode) != SDO_FINISHED)
198 eprintf("Master : Failed in changing Slave's transmit type AbortCode :%4.4x \n", abortCode);
200 /* Finalise last SDO transfer with this node */
201 closeSDOtransfer(&TestMaster_Data, nodeId, SDO_CLIENT);
205 static int MasterSyncCount = 0;
206 void TestMaster_post_TPDO(CO_Data* d)
208 eprintf("TestMaster_post_TPDO MasterSyncCount = %d \n", MasterSyncCount);
212 // if(MasterMap4 > 0x80){
213 // writeNetworkDict (
215 // TestSlave_Data->bDeviceNodeId,
228 switch(getReadResultNetworkDict (
236 /* Do something with result here !!*/
237 eprintf("Got SDO answer (0x2002, 0x00), %d %d\n",query_result,size);
238 case SDO_ABORTED_RCV:
239 case SDO_ABORTED_INTERNAL:
247 case SDO_DOWNLOAD_IN_PROGRESS:
248 case SDO_UPLOAD_IN_PROGRESS:
251 }else if(MasterSyncCount % 10 == 0){
261 if(MasterSyncCount % 17 == 0){
262 eprintf("Master : Ask RTR PDO (0x1402)\n");
263 sendPDOrequest(&TestMaster_Data, 0x1402 );
264 sendPDOrequest(&TestMaster_Data, 0x1403 );
266 if(MasterSyncCount % 50 == 0){
267 eprintf("Master : Change slave's transmit type to 0xFF\n");
268 UNS8 transmitiontype = 0xFF;
269 writeNetworkDictCallBack (&TestMaster_Data, /*CO_Data* d*/
271 0x1802, /*UNS16 index*/
272 0x02, /*UNS16 index*/
275 &transmitiontype,/*void *data*/
276 CheckSDO); /*SDOCallback_t Callback*/
278 if(MasterSyncCount % 50 == 25){
279 eprintf("Master : Change slave's transmit type to 0x00\n");
280 UNS8 transmitiontype = 0x00;
281 writeNetworkDictCallBack (&TestMaster_Data, /*CO_Data* d*/
283 0x1802, /*UNS16 index*/
284 0x02, /*UNS16 index*/
287 &transmitiontype,/*void *data*/
288 CheckSDO); /*SDOCallback_t Callback*/
293 void TestMaster_post_SlaveBootup(CO_Data* d, UNS8 nodeid)
295 eprintf("TestMaster_post_SlaveBootup %x\n", nodeid);
297 ConfigureSlaveNode(d, nodeid);