# HG changeset patch # User etisserant # Date 1176387622 -7200 # Node ID 1b3165f2d17d812acd444c2cfc268dfc7a6a4912 # Parent 1c1ad874fe8f8419053895ba0b61dad85a8f4f63 Implemented writeNetworkDictCallBack test in TestMasterSlave example. Fixed callback assignement race condition in sdo.c. diff -r 1c1ad874fe8f -r 1b3165f2d17d examples/TestMasterSlave/Master.c --- a/examples/TestMasterSlave/Master.c Thu Apr 12 16:17:35 2007 +0200 +++ b/examples/TestMasterSlave/Master.c Thu Apr 12 16:20:22 2007 +0200 @@ -36,15 +36,119 @@ eprintf("TestMaster_SDOtimeoutError %d\n", line); } -/*****************************************************************************/ +/******************************************************** + * ConfigureSlaveNode is responsible to + * - setup master RPDO 1 to receive TPDO 1 from id 2 + * - setup master RPDO 2 to receive TPDO 2 from id 2 + ********************************************************/ void TestMaster_initialisation() { + UNS32 PDO1_COBID = 0x0182; + UNS32 PDO2_COBID = 0x0282; + UNS8 size = sizeof(UNS32); + eprintf("TestMaster_initialisation\n"); + + /***************************************** + * Define RPDOs to match slave ID=2 TPDOs* + *****************************************/ + setODentry( &TestMaster_Data, /*CO_Data* d*/ + 0x1400, /*UNS16 index*/ + 0x01, /*UNS8 subind*/ + &PDO1_COBID, /*void * pSourceData,*/ + &size, /* UNS8 * pExpectedSize*/ + RW); /* UNS8 checkAccess */ + + setODentry( &TestMaster_Data, /*CO_Data* d*/ + 0x1401, /*UNS16 index*/ + 0x01, /*UNS8 subind*/ + &PDO2_COBID, /*void * pSourceData,*/ + &size, /* UNS8 * pExpectedSize*/ + RW); /* UNS8 checkAccess */ +} + +/******************************************************** + * ConfigureSlaveNode is responsible to + * - setup slave TPDO 1 transmit time + * - setup slave TPDO 2 transmit time + * - switch to operational mode + * - send NMT to slave + ******************************************************** + * This an example of : + * Network Dictionary Access (SDO) with Callback + * Slave node state change request (NMT) + ******************************************************** + * This is called first by TestMaster_preOperational + * then it called again each time a SDO exchange is + * finished. + ********************************************************/ +static void ConfigureSlaveNode(CO_Data* d, UNS8 nodeId) +{ + // Step counts number of times ConfigureSlaveNode is called + static step = 1; + + UNS8 Transmission_Type = 0x01; + UNS32 abortCode; + UNS8 res; + eprintf("Master : ConfigureSlaveNode %2.2x\n", nodeId); + + switch(step++){ + case 1: /*First step : setup Slave's TPDO 1 to be transmitted on SYNC*/ + eprintf("Master : set slave %2.2x TPDO 1 transmit type\n", nodeId); + res = writeNetworkDictCallBack (d, /*CO_Data* d*/ + *TestSlave_Data.bDeviceNodeId, /*UNS8 nodeId*/ + 0x1800, /*UNS16 index*/ + 0x02, /*UNS8 subindex*/ + 1, /*UNS8 count*/ + 0, /*UNS8 dataType*/ + &Transmission_Type,/*void *data*/ + ConfigureSlaveNode); /*SDOCallback_t Callback*/ break; + case 2: /*Second step*/ + /*check and warn for previous slave OD access error*/ + if(getWriteResultNetworkDict (d, nodeId, &abortCode) != SDO_FINISHED) + eprintf("Master : Couldn't set slave %2.2x TPDO 1 transmit type. AbortCode :%4.4x \n", nodeId, abortCode); + + /* Finalise last SDO transfer with this node */ + closeSDOtransfer(&TestMaster_Data, + *TestSlave_Data.bDeviceNodeId, + SDO_CLIENT); + + /*Setup Slave's TPDO 1 to be transmitted on SYNC*/ + eprintf("Master : set slave %2.2x TPDO 2 transmit type\n", nodeId); + writeNetworkDictCallBack (d, /*CO_Data* d*/ + *TestSlave_Data.bDeviceNodeId, /*UNS8 nodeId*/ + 0x1801, /*UNS16 index*/ + 0x02, /*UNS16 index*/ + 1, /*UNS8 count*/ + 0, /*UNS8 dataType*/ + &Transmission_Type,/*void *data*/ + ConfigureSlaveNode); /*SDOCallback_t Callback*/ + break; + case 3: /*Last step*/ + /*check and warn for previous slave OD access error*/ + if(getWriteResultNetworkDict (d, nodeId, &abortCode) != SDO_FINISHED) + eprintf("Master : Couldn't set slave %2.2x TPDO 2 transmit type. AbortCode :%4.4x \n", nodeId, abortCode); + + /* Finalise last SDO transfer with this node */ + closeSDOtransfer(&TestMaster_Data, + *TestSlave_Data.bDeviceNodeId, + SDO_CLIENT); + + /* Put the master in operational mode */ + setState(d, Operational); + + /* Ask slave node to go in operational mode */ + masterSendNMTstateChange (d, nodeId, NMT_Start_Node); + } + } void TestMaster_preOperational() { + eprintf("TestMaster_preOperational\n"); + ConfigureSlaveNode(&TestMaster_Data, 2); + } void TestMaster_operational() diff -r 1c1ad874fe8f -r 1b3165f2d17d examples/TestMasterSlave/TestMasterSlave.h --- a/examples/TestMasterSlave/TestMasterSlave.h Thu Apr 12 16:17:35 2007 +0200 +++ b/examples/TestMasterSlave/TestMasterSlave.h Thu Apr 12 16:20:22 2007 +0200 @@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifdef USE_XENO +//#define eprintf(...) if(0){} #define eprintf(...) #else #define eprintf(...) printf (__VA_ARGS__) diff -r 1c1ad874fe8f -r 1b3165f2d17d examples/TestMasterSlave/TestSlave.c --- a/examples/TestMasterSlave/TestSlave.c Thu Apr 12 16:17:35 2007 +0200 +++ b/examples/TestMasterSlave/TestSlave.c Thu Apr 12 16:20:22 2007 +0200 @@ -165,7 +165,7 @@ /* index 0x1800 : Transmit PDO 1 Parameter. */ UNS8 TestSlave_highestSubIndex_obj1800 = 5; /* number of subindex - 1*/ UNS32 TestSlave_obj1800_COB_ID_used_by_PDO = 0x182; /* 386 */ - UNS8 TestSlave_obj1800_Transmission_Type = 0x1; /* 1 */ + UNS8 TestSlave_obj1800_Transmission_Type = 0x0; /* 0 */ UNS16 TestSlave_obj1800_Inhibit_Time = 0x0; /* 0 */ UNS16 TestSlave_obj1800_Compatibility_Entry = 0x0; /* 0 */ UNS16 TestSlave_obj1800_Event_Timer = 0x0; /* 0 */ @@ -182,7 +182,7 @@ /* index 0x1801 : Transmit PDO 2 Parameter. */ UNS8 TestSlave_highestSubIndex_obj1801 = 5; /* number of subindex - 1*/ UNS32 TestSlave_obj1801_COB_ID_used_by_PDO = 0x282; /* 642 */ - UNS8 TestSlave_obj1801_Transmission_Type = 0x1; /* 1 */ + UNS8 TestSlave_obj1801_Transmission_Type = 0x0; /* 0 */ UNS16 TestSlave_obj1801_Inhibit_Time = 0x0; /* 0 */ UNS16 TestSlave_obj1801_Compatibility_Entry = 0x0; /* 0 */ UNS16 TestSlave_obj1801_Event_Timer = 0x0; /* 0 */ diff -r 1c1ad874fe8f -r 1b3165f2d17d examples/TestMasterSlave/TestSlave.od --- a/examples/TestMasterSlave/TestSlave.od Thu Apr 12 16:17:35 2007 +0200 +++ b/examples/TestMasterSlave/TestSlave.od Thu Apr 12 16:20:22 2007 +0200 @@ -1,10 +1,10 @@ - - + + - + @@ -22,14 +22,8 @@ - - - - - - - - + + @@ -40,22 +34,22 @@ - - - - - - - - - - - - + + + + + + + + + + + + - + @@ -64,58 +58,64 @@ - - - - - + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - + @@ -124,7 +124,7 @@ - + @@ -133,7 +133,7 @@ - + @@ -141,18 +141,18 @@ - + - + - - + + @@ -184,15 +184,15 @@ - + - - + + @@ -224,15 +224,15 @@ - + - - + + @@ -264,15 +264,15 @@ - + - - + + @@ -303,7 +303,7 @@ - + diff -r 1c1ad874fe8f -r 1b3165f2d17d src/sdo.c --- a/src/sdo.c Thu Apr 12 16:17:35 2007 +0200 +++ b/src/sdo.c Thu Apr 12 16:20:22 2007 +0200 @@ -978,7 +978,7 @@ failedSDO(d, nodeId, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); return 0xFF; } - /* Reset the wathdog */ + /* Reset the watchdog */ RestartSDO_TIMER(line) index = d->transfers[line].index; subIndex = d->transfers[line].subIndex; @@ -1154,7 +1154,9 @@ sdo.body.data[1] = index & 0xFF; /* LSB */ sdo.body.data[2] = (index >> 8) & 0xFF; /* MSB */ sdo.body.data[3] = subIndex; - + + d->transfers[line].Callback = Callback; + err = sendSDO(d, SDO_CLIENT, sdo); if (err) { MSG_ERR(0x1AD1, "SDO. Error while sending SDO to node : ", nodeId); @@ -1162,7 +1164,8 @@ resetSDOline(d, line); return 0xFF; } - d->transfers[line].Callback = Callback; + + return 0; } @@ -1255,6 +1258,7 @@ sdo.body.data[3] = subIndex; for (i = 4 ; i < 8 ; i++) sdo.body.data[i] = 0; + d->transfers[line].Callback = Callback; err = sendSDO(d, SDO_CLIENT, sdo); if (err) { MSG_ERR(0x1AE5, "SDO. Error while sending SDO to node : ", nodeId); @@ -1262,7 +1266,6 @@ resetSDOline(d, line); return 0xFF; } - d->transfers[line].Callback = Callback; return 0; }