# HG changeset patch # User luis # Date 1190815320 -7200 # Node ID 24bf3d692993e418e735f5ddd53ee2d4c9915033 # Parent e0b3096230e5731c7f7d7da4ed8780ea77c22fca Implemented EMCY objects. Added emcy.c and emcy.h Modified data.h for necessary variables. Added some EMCY message sendings in TestMasterSlave example. Modified configure script to define EMCY_MAX_ERRORS. Modified python scripts to make 1003h object always available (with a callback). diff -r e0b3096230e5 -r 24bf3d692993 CONTRIBUTORS --- a/CONTRIBUTORS Tue Sep 25 15:29:37 2007 +0200 +++ b/CONTRIBUTORS Wed Sep 26 16:02:00 2007 +0200 @@ -11,5 +11,6 @@ David DUMINY (sté A6R) Laurent ROMIEUX Zakaria BELAMRI + Luis JIMENEZ Many thanks to the main contributors for their great work. diff -r e0b3096230e5 -r 24bf3d692993 configure --- a/configure Tue Sep 25 15:29:37 2007 +0200 +++ b/configure Wed Sep 26 16:02:00 2007 +0200 @@ -55,6 +55,9 @@ # Default to little-endian CANOPEN_BIG_ENDIAN= +# Max number of active errors managed in error_data structure. +EMCY_MAX_ERRORS=8 + ########################################################################### # DEFAULT BUILD OPTIONS # ########################################################################### @@ -108,6 +111,7 @@ --SDO_TIMEOUT_MS=*) SDO_TIMEOUT_MS=$1;; --CANOPEN_BIG_ENDIAN=*) CANOPEN_BIG_ENDIAN=$1;; --MAX_NB_TIMER=*) MAX_NB_TIMER=$1;; + --EMCY_MAX_ERRORS=*) EMCY_MAX_ERRORS=$1;; --help) echo "Usage: ./configure [options]" echo "Options:" echo " --cc=foo Use compiler 'foo' instead of defaults ${CC1} or ${CC2}." @@ -143,6 +147,7 @@ echo " --SDO_MAX_SIMULTANEOUS_TRANSFERTS [=4] Number of SDO that the node can manage concurrently" echo " --NMT_MAX_NODE_ID [=128] can be reduced to gain memory on small network" echo " --SDO_TIMEOUT_MS [=3000] Timeout in milliseconds for SDO (None to disable the feature)" + echo " --EMCY_MAX_ERRORS [=8] Max number of active errors managed in error_data structure" exit 0;; *) echo "Unknown argument ${1}"; exit -1;; esac @@ -574,7 +579,8 @@ US_TO_TIMEVAL_FACTOR\ TIMEVAL\ TIMEVAL_MAX\ - RTCAN_SOCKET; do + RTCAN_SOCKET\ + EMCY_MAX_ERRORS; do if [ "${!i}" = "" ]; then echo "/* $i is not defined */" >> include/config.h else @@ -585,7 +591,8 @@ for i in \ SDO_MAX_SIMULTANEOUS_TRANSFERTS\ - NMT_MAX_NODE_ID; do + NMT_MAX_NODE_ID\ + EMCY_MAX_ERRORS; do echo "#define REPEAT_"$i"_TIMES(repeat)\\">> include/config.h times=${!i} result="" diff -r e0b3096230e5 -r 24bf3d692993 doc/manual/en/manual.tex --- a/doc/manual/en/manual.tex Tue Sep 25 15:29:37 2007 +0200 +++ b/doc/manual/en/manual.tex Wed Sep 26 16:02:00 2007 +0200 @@ -198,7 +198,7 @@ producer or receiver. \item NMT NodeGuard implemented : Not fully implemented. \item TIME (time Stamp) : Not implemented. -\item EMCY (emergency objects) : Not implemented. +\item EMCY (emergency objects) : Sending and reception of EMCY objectos (without manufacturer specific error field). \item PDO Mapping bit per bit implemented. \end{enumerate} {\bfseries\upshape diff -r e0b3096230e5 -r 24bf3d692993 examples/TestMasterMicroMod/TestMaster.c --- a/examples/TestMasterMicroMod/TestMaster.c Tue Sep 25 15:29:37 2007 +0200 +++ b/examples/TestMasterMicroMod/TestMaster.c Wed Sep 26 16:02:00 2007 +0200 @@ -62,6 +62,23 @@ { RO, uint8, sizeof (UNS8), (void*)&TestMaster_obj1001 } }; +/* index 0x1003 : Pre-defined Error Field */ + UNS8 TestMaster_highestSubIndex_obj1003 = 0; /* number of subindex - 1*/ + UNS32 TestMaster_obj1003[] = + { + 0x0 /* 0 */ + }; + ODCallback_t TestMaster_Index1003_callbacks[] = + { + NULL, + NULL, + }; + subindex TestMaster_Index1003[] = + { + { RW, uint8, sizeof (UNS8), (void*)&TestMaster_highestSubIndex_obj1003 }, + { RO, uint32, sizeof (UNS32), (void*)&TestMaster_obj1003[0] } + }; + /* index 0x1005 : SYNC COB ID. */ UNS32 TestMaster_obj1005 = 0x40000080; /* 1073741952 */ ODCallback_t TestMaster_Index1005_callbacks[] = @@ -118,13 +135,13 @@ UNS8 TestMaster_highestSubIndex_obj1280 = 3; /* number of subindex - 1*/ UNS32 TestMaster_obj1280_COB_ID_Client_to_Server_Transmit_SDO = 0x640; /* 1600 */ UNS32 TestMaster_obj1280_COB_ID_Server_to_Client_Receive_SDO = 0x5C0; /* 1472 */ - INTEGER32 TestMaster_obj1280_Node_ID_of_the_SDO_Server = 0x40; /* 64 */ + UNS8 TestMaster_obj1280_Node_ID_of_the_SDO_Server = 0x40; /* 64 */ subindex TestMaster_Index1280[] = { { RO, uint8, sizeof (UNS8), (void*)&TestMaster_highestSubIndex_obj1280 }, { RW, uint32, sizeof (UNS32), (void*)&TestMaster_obj1280_COB_ID_Client_to_Server_Transmit_SDO }, { RW, uint32, sizeof (UNS32), (void*)&TestMaster_obj1280_COB_ID_Server_to_Client_Receive_SDO }, - { RW, int32, sizeof (INTEGER32), (void*)&TestMaster_obj1280_Node_ID_of_the_SDO_Server } + { RW, uint8, sizeof (UNS8), (void*)&TestMaster_obj1280_Node_ID_of_the_SDO_Server } }; /* index 0x1400 : Receive PDO 1 Parameter. */ @@ -177,6 +194,15 @@ UNS16 TestMaster_obj1800_Inhibit_Time = 0x0; /* 0 */ UNS8 TestMaster_obj1800_Compatibility_Entry = 0x0; /* 0 */ UNS16 TestMaster_obj1800_Event_Timer = 0x0; /* 0 */ + ODCallback_t TestMaster_Index1800_callbacks[] = + { + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + }; subindex TestMaster_Index1800[] = { { RO, uint8, sizeof (UNS8), (void*)&TestMaster_highestSubIndex_obj1800 }, @@ -291,7 +317,7 @@ case 0x1280: i = 6;break; case 0x1400: i = 7;break; case 0x1600: i = 8;break; - case 0x1800: i = 9;break; + case 0x1800: i = 9;*callbacks = TestMaster_Index1800_callbacks; break; case 0x1A00: i = 10;break; case 0x2000: i = 11;break; case 0x200F: i = 12;break; diff -r e0b3096230e5 -r 24bf3d692993 examples/TestMasterMicroMod/TestMaster.h --- a/examples/TestMasterMicroMod/TestMaster.h Tue Sep 25 15:29:37 2007 +0200 +++ b/examples/TestMasterMicroMod/TestMaster.h Wed Sep 26 16:02:00 2007 +0200 @@ -12,6 +12,7 @@ /* Master node data struct */ extern CO_Data TestMaster_Data; +extern ODCallback_t Transmit_PDO_1_Parameter_callbacks[]; /* Callbacks of index0x1800 */ extern UNS8 DO; /* Mapped at index 0x2000, subindex 0x00*/ extern UNS8 DI1; /* Mapped at index 0x200F, subindex 0x00*/ extern UNS8 DI2; /* Mapped at index 0x2010, subindex 0x00*/ diff -r e0b3096230e5 -r 24bf3d692993 examples/TestMasterSlave/Master.c --- a/examples/TestMasterSlave/Master.c Tue Sep 25 15:29:37 2007 +0200 +++ b/examples/TestMasterSlave/Master.c Wed Sep 26 16:02:00 2007 +0200 @@ -180,10 +180,14 @@ MasterMap13); } +void TestMaster_post_emcy(UNS8 nodeID, UNS16 errCode, UNS8 errReg) +{ + eprintf("Master received EMCY message. Node: %2.2x ErrorCode: %4.4x ErrorRegister: %2.2x\n", nodeID, errCode, errReg); +} + char query_result = 0; char waiting_answer = 0; - static void CheckSDO(CO_Data* d, UNS8 nodeId) { UNS32 abortCode; diff -r e0b3096230e5 -r 24bf3d692993 examples/TestMasterSlave/Master.h --- a/examples/TestMasterSlave/Master.h Tue Sep 25 15:29:37 2007 +0200 +++ b/examples/TestMasterSlave/Master.h Wed Sep 26 16:02:00 2007 +0200 @@ -11,3 +11,4 @@ void TestMaster_post_sync(void); void TestMaster_post_TPDO(void); +void TestMaster_post_emcy(UNS8 nodeID, UNS16 errCode, UNS8 errReg); diff -r e0b3096230e5 -r 24bf3d692993 examples/TestMasterSlave/Slave.c --- a/examples/TestMasterSlave/Slave.c Tue Sep 25 15:29:37 2007 +0200 +++ b/examples/TestMasterSlave/Slave.c Wed Sep 26 16:02:00 2007 +0200 @@ -86,6 +86,13 @@ { SlaveMap13 += 1; eprintf("TestSlave_post_TPDO\n"); + + /* send an error and recover inmediately every 12 cycles */ + if(SlaveMap13 % 12 == 0) + { + EMCY_setError(&TestSlave_Data, 0x4200, 0x08); + EMCY_errorRecovered(&TestSlave_Data, 0x4200); + } } void TestSlave_storeODSubIndex(UNS16 wIndex, UNS8 bSubindex) @@ -101,3 +108,8 @@ * */ eprintf("TestSlave_storeODSubIndex : %4.4x %2.2x\n", wIndex, bSubindex); } + +void TestSlave_post_emcy(UNS8 nodeID, UNS16 errCode, UNS8 errReg) +{ + eprintf("Slave received EMCY message. Node: %2.2x ErrorCode: %4.4x ErrorRegister: %2.2x\n", nodeID, errCode, errReg); +} diff -r e0b3096230e5 -r 24bf3d692993 examples/TestMasterSlave/Slave.h --- a/examples/TestMasterSlave/Slave.h Tue Sep 25 15:29:37 2007 +0200 +++ b/examples/TestMasterSlave/Slave.h Wed Sep 26 16:02:00 2007 +0200 @@ -12,3 +12,4 @@ void TestSlave_post_sync(void); void TestSlave_post_TPDO(void); void TestSlave_storeODSubIndex(UNS16 wIndex, UNS8 bSubindex); +void TestSlave_post_emcy(UNS8 nodeID, UNS16 errCode, UNS8 errReg); diff -r e0b3096230e5 -r 24bf3d692993 examples/TestMasterSlave/TestMaster.c --- a/examples/TestMasterSlave/TestMaster.c Tue Sep 25 15:29:37 2007 +0200 +++ b/examples/TestMasterSlave/TestMaster.c Wed Sep 26 16:02:00 2007 +0200 @@ -66,6 +66,23 @@ { RO, uint8, sizeof (UNS8), (void*)&TestMaster_obj1001 } }; +/* index 0x1003 : Pre-defined Error Field */ + UNS8 TestMaster_highestSubIndex_obj1003 = 0; /* number of subindex - 1*/ + UNS32 TestMaster_obj1003[] = + { + 0x0 /* 0 */ + }; + ODCallback_t TestMaster_Index1003_callbacks[] = + { + NULL, + NULL, + }; + subindex TestMaster_Index1003[] = + { + { RW, uint8, sizeof (UNS8), (void*)&TestMaster_highestSubIndex_obj1003 }, + { RO, uint32, sizeof (UNS32), (void*)&TestMaster_obj1003[0] } + }; + /* index 0x1005 : SYNC COB ID. */ UNS32 TestMaster_obj1005 = 0x40000080; /* 1073741952 */ ODCallback_t TestMaster_Index1005_callbacks[] = @@ -152,13 +169,13 @@ UNS8 TestMaster_highestSubIndex_obj1280 = 3; /* number of subindex - 1*/ UNS32 TestMaster_obj1280_COB_ID_Client_to_Server_Transmit_SDO = 0x602; /* 1538 */ UNS32 TestMaster_obj1280_COB_ID_Server_to_Client_Receive_SDO = 0x582; /* 1410 */ - INTEGER32 TestMaster_obj1280_Node_ID_of_the_SDO_Server = 0x2; /* 2 */ + UNS8 TestMaster_obj1280_Node_ID_of_the_SDO_Server = 0x2; /* 2 */ subindex TestMaster_Index1280[] = { { RO, uint8, sizeof (UNS8), (void*)&TestMaster_highestSubIndex_obj1280 }, { RW, uint32, sizeof (UNS32), (void*)&TestMaster_obj1280_COB_ID_Client_to_Server_Transmit_SDO }, { RW, uint32, sizeof (UNS32), (void*)&TestMaster_obj1280_COB_ID_Server_to_Client_Receive_SDO }, - { RW, int32, sizeof (INTEGER32), (void*)&TestMaster_obj1280_Node_ID_of_the_SDO_Server } + { RW, uint8, sizeof (UNS8), (void*)&TestMaster_obj1280_Node_ID_of_the_SDO_Server } }; /* index 0x1400 : Receive PDO 1 Parameter. */ diff -r e0b3096230e5 -r 24bf3d692993 examples/TestMasterSlave/TestMaster.od --- a/examples/TestMasterSlave/TestMaster.od Tue Sep 25 15:29:37 2007 +0200 +++ b/examples/TestMasterSlave/TestMaster.od Wed Sep 26 16:02:00 2007 +0200 @@ -1,18 +1,18 @@ - - + + - - - - - - - - - + + + + + + + + + @@ -30,7 +30,7 @@ - + @@ -66,15 +66,15 @@ - - - - - - - - - + + + + + + + + + @@ -92,7 +92,7 @@ - + @@ -128,15 +128,15 @@ - - - - - - - - - + + + + + + + + + @@ -154,7 +154,7 @@ - + @@ -190,15 +190,15 @@ - - - - - - - - - + + + + + + + + + @@ -216,7 +216,7 @@ - + @@ -252,15 +252,15 @@ - - - - - - - - - + + + + + + + + + @@ -278,7 +278,7 @@ - + @@ -314,15 +314,15 @@ - - - - - - - - - + + + + + + + + + @@ -354,15 +354,15 @@ - - - - - - - - - + + + + + + + + + @@ -380,7 +380,7 @@ - + @@ -416,15 +416,15 @@ - - - - - - - - - + + + + + + + + + @@ -442,7 +442,7 @@ - + @@ -478,15 +478,15 @@ - - - - - - - - - + + + + + + + + + @@ -504,7 +504,7 @@ - + @@ -540,15 +540,15 @@ - - - - - - - - - + + + + + + + + + @@ -566,7 +566,7 @@ - + @@ -602,15 +602,15 @@ - - - - - - - - - + + + + + + + + + @@ -628,7 +628,7 @@ - + @@ -664,15 +664,15 @@ - - - - - - - - - + + + + + + + + + @@ -690,7 +690,7 @@ - + @@ -726,15 +726,15 @@ - - - - - - - - - + + + + + + + + + @@ -752,7 +752,7 @@ - + @@ -788,15 +788,15 @@ - - - - - - - - - + + + + + + + + + @@ -814,7 +814,7 @@ - + @@ -850,15 +850,15 @@ - - - - - - - - - + + + + + + + + + @@ -876,7 +876,7 @@ - + @@ -912,15 +912,15 @@ - - - - - - - - - + + + + + + + + + @@ -938,7 +938,7 @@ - + @@ -974,15 +974,15 @@ - - - - - - - - - + + + + + + + + + @@ -1000,7 +1000,7 @@ - + @@ -1036,15 +1036,15 @@ - - - - - - - - - + + + + + + + + + @@ -1062,7 +1062,7 @@ - + @@ -1098,15 +1098,15 @@ - - - - - - - - - + + + + + + + + + @@ -1124,7 +1124,7 @@ - + @@ -1160,7 +1160,7 @@ - + @@ -1175,8 +1175,8 @@ - - + + @@ -1194,7 +1194,7 @@ - + @@ -1230,15 +1230,15 @@ - - - - - - - - - + + + + + + + + + @@ -1256,7 +1256,7 @@ - + @@ -1292,15 +1292,15 @@ - - - - - - - - - + + + + + + + + + @@ -1318,7 +1318,7 @@ - + @@ -1354,15 +1354,15 @@ - - - - - - - - - + + + + + + + + + @@ -1380,7 +1380,7 @@ - + @@ -1416,15 +1416,15 @@ - - - - - - - - - + + + + + + + + + @@ -1442,7 +1442,7 @@ - + @@ -1478,15 +1478,15 @@ - - - - - - - - - + + + + + + + + + @@ -1504,7 +1504,7 @@ - + @@ -1540,15 +1540,15 @@ - - - - - - - - - + + + + + + + + + @@ -1566,7 +1566,7 @@ - + @@ -1602,15 +1602,15 @@ - - - - - - - - - + + + + + + + + + @@ -1628,7 +1628,7 @@ - + @@ -1664,15 +1664,15 @@ - - - - - - - - - + + + + + + + + + @@ -1690,7 +1690,7 @@ - + @@ -1726,15 +1726,15 @@ - - - - - - - - - + + + + + + + + + @@ -1752,7 +1752,7 @@ - + @@ -1788,15 +1788,15 @@ - - - - - - - - - + + + + + + + + + @@ -1814,7 +1814,7 @@ - + @@ -1850,15 +1850,15 @@ - - - - - - - - - + + + + + + + + + @@ -1876,7 +1876,7 @@ - + @@ -1912,15 +1912,15 @@ - - - - - - - - - + + + + + + + + + @@ -1938,7 +1938,7 @@ - + @@ -1974,15 +1974,15 @@ - - - - - - - - - + + + + + + + + + @@ -2000,7 +2000,7 @@ - + @@ -2036,15 +2036,15 @@ - - - - - - - - - + + + + + + + + + @@ -2062,7 +2062,7 @@ - + @@ -2098,15 +2098,15 @@ - - - - - - - - - + + + + + + + + + @@ -2124,7 +2124,7 @@ - + @@ -2160,7 +2160,7 @@ - + @@ -2175,8 +2175,8 @@ - - + + @@ -2194,7 +2194,7 @@ - + @@ -2230,15 +2230,15 @@ - - - - - - - - - + + + + + + + + + @@ -2256,7 +2256,7 @@ - + @@ -2292,15 +2292,15 @@ - - - - - - - - - + + + + + + + + + @@ -2318,7 +2318,7 @@ - + @@ -2354,15 +2354,15 @@ - - - - - - - - - + + + + + + + + + @@ -2380,7 +2380,7 @@ - + @@ -2416,15 +2416,15 @@ - - - - - - - - - + + + + + + + + + @@ -2442,7 +2442,7 @@ - + @@ -2478,7 +2478,7 @@ - + @@ -2493,8 +2493,8 @@ - - + + @@ -2512,7 +2512,7 @@ - + @@ -2548,15 +2548,15 @@ - - - - - - - - - + + + + + + + + + @@ -2574,7 +2574,7 @@ - + @@ -2609,70 +2609,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -2687,8 +2625,8 @@ - - + + @@ -2706,7 +2644,7 @@ - + @@ -2742,15 +2680,15 @@ - - - - - - - - - + + + + + + + + + @@ -2768,7 +2706,7 @@ - + @@ -2804,15 +2742,15 @@ - - - - - - - - - + + + + + + + + + @@ -2830,7 +2768,7 @@ - + @@ -2866,15 +2804,15 @@ - - - - - - - - - + + + + + + + + + @@ -2892,7 +2830,7 @@ - + @@ -2928,15 +2866,15 @@ - - - - - - - - - + + + + + + + + + @@ -2954,7 +2892,7 @@ - + @@ -2990,15 +2928,15 @@ - - - - - - - - - + + + + + + + + + @@ -3016,7 +2954,7 @@ - + @@ -3052,15 +2990,15 @@ - - - - - - - - - + + + + + + + + + @@ -3078,7 +3016,7 @@ - + @@ -3114,15 +3052,15 @@ - - - - - - - - - + + + + + + + + + @@ -3140,7 +3078,7 @@ - + @@ -3176,7 +3114,7 @@ - + @@ -3191,8 +3129,8 @@ - - + + @@ -3210,7 +3148,7 @@ - + @@ -3246,15 +3184,15 @@ - - - - - - - - - + + + + + + + + + @@ -3272,7 +3210,7 @@ - + @@ -3307,16 +3245,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + @@ -3334,7 +3334,7 @@ - + @@ -3370,15 +3370,15 @@ - - - - - - - - - + + + + + + + + + @@ -3396,7 +3396,7 @@ - + @@ -3431,234 +3431,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -3673,26 +3447,26 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + @@ -3707,7 +3481,7 @@ - + @@ -3722,83 +3496,21 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -3816,7 +3528,7 @@ - + @@ -3831,152 +3543,130 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -3991,8 +3681,8 @@ - - + + @@ -4010,7 +3700,7 @@ - + @@ -4025,7 +3715,7 @@ - + @@ -4040,13 +3730,261 @@ - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -4061,26 +3999,26 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + @@ -4095,7 +4033,7 @@ - + @@ -4110,385 +4048,13 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + @@ -4503,8 +4069,8 @@ - - + + @@ -4522,7 +4088,7 @@ - + @@ -4537,7 +4103,7 @@ - + @@ -4552,21 +4118,83 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -4584,7 +4212,7 @@ - + @@ -4599,90 +4227,276 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -4697,8 +4511,8 @@ - - + + @@ -4716,7 +4530,7 @@ - + @@ -4731,7 +4545,7 @@ - + @@ -4746,21 +4560,207 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + @@ -4778,7 +4778,7 @@ - + @@ -4814,15 +4814,15 @@ - - - - - - - - - + + + + + + + + + @@ -4840,7 +4840,7 @@ - + @@ -4876,15 +4876,15 @@ - - - - - - - - - + + + + + + + + + @@ -4902,7 +4902,7 @@ - + @@ -4938,7 +4938,7 @@ - + @@ -4953,8 +4953,8 @@ - - + + @@ -4972,7 +4972,7 @@ - + @@ -5007,8 +5007,8 @@ - - + + @@ -5063,7 +5063,7 @@ - + @@ -5073,7 +5073,7 @@ - + @@ -5082,7 +5082,7 @@ - + @@ -5091,7 +5091,7 @@ - + @@ -5101,13 +5101,13 @@ - + - + @@ -5116,7 +5116,7 @@ - + @@ -5128,7 +5128,7 @@ - + @@ -5143,7 +5143,7 @@ - + @@ -5153,7 +5153,7 @@ - + @@ -5172,7 +5172,7 @@ - + @@ -5182,27 +5182,27 @@ - + - + - + - - + + - + @@ -5211,9 +5211,9 @@ - + - + @@ -5222,20 +5222,20 @@ - + - + - - - - - - - - - + + + + + + + + + @@ -5267,15 +5267,15 @@ - - - - - - - - - + + + + + + + + + @@ -5307,15 +5307,15 @@ - - - - - - - - - + + + + + + + + + @@ -5347,15 +5347,15 @@ - - - - - - - - - + + + + + + + + + @@ -5387,15 +5387,15 @@ - - - - - - - - - + + + + + + + + + @@ -5427,15 +5427,15 @@ - - - - - - - - - + + + + + + + + + @@ -5467,15 +5467,15 @@ - - - - - - - - - + + + + + + + + + @@ -5507,15 +5507,15 @@ - - - - - - - - - + + + + + + + + + @@ -5547,15 +5547,15 @@ - - - - - - - - - + + + + + + + + + @@ -5587,15 +5587,15 @@ - - - - - - - - - + + + + + + + + + @@ -5627,15 +5627,15 @@ - - - - - - - - - + + + + + + + + + @@ -5667,15 +5667,15 @@ - - - - - - - - - + + + + + + + + + @@ -5707,15 +5707,15 @@ - - - - - - - - - + + + + + + + + + @@ -5746,18 +5746,18 @@ - + - - - - - - - - - + + + + + + + + + @@ -5775,7 +5775,7 @@ - + @@ -5811,15 +5811,15 @@ - - - - - - - - - + + + + + + + + + @@ -5837,7 +5837,7 @@ - + @@ -5873,15 +5873,15 @@ - - - - - - - - - + + + + + + + + + @@ -5899,7 +5899,7 @@ - + diff -r e0b3096230e5 -r 24bf3d692993 examples/TestMasterSlave/TestMasterSlave.c --- a/examples/TestMasterSlave/TestMasterSlave.c Tue Sep 25 15:29:37 2007 +0200 +++ b/examples/TestMasterSlave/TestMasterSlave.c Wed Sep 26 16:02:00 2007 +0200 @@ -193,7 +193,8 @@ TestSlave_Data.stopped = TestSlave_stopped; TestSlave_Data.post_sync = TestSlave_post_sync; TestSlave_Data.post_TPDO = TestSlave_post_TPDO; - TestSlave_Data.storeODSubIndex = TestSlave_storeODSubIndex; + TestSlave_Data.storeODSubIndex = TestSlave_storeODSubIndex; + TestSlave_Data.post_emcy = TestSlave_post_emcy; if(!canOpen(&SlaveBoard,&TestSlave_Data)){ eprintf("Cannot open Slave Board (%s,%s)\n",SlaveBoard.busname, SlaveBoard.baudrate); @@ -209,6 +210,7 @@ TestMaster_Data.stopped = TestMaster_stopped; TestMaster_Data.post_sync = TestMaster_post_sync; TestMaster_Data.post_TPDO = TestMaster_post_TPDO; + TestMaster_Data.post_emcy = TestMaster_post_emcy; if(!canOpen(&MasterBoard,&TestMaster_Data)){ eprintf("Cannot open Master Board (%s,%s)\n",MasterBoard.busname, MasterBoard.baudrate); diff -r e0b3096230e5 -r 24bf3d692993 examples/TestMasterSlave/TestSlave.c --- a/examples/TestMasterSlave/TestSlave.c Tue Sep 25 15:29:37 2007 +0200 +++ b/examples/TestMasterSlave/TestSlave.c Wed Sep 26 16:02:00 2007 +0200 @@ -66,6 +66,44 @@ { RO, uint8, sizeof (UNS8), (void*)&TestSlave_obj1001 } }; +/* index 0x1003 : Pre-defined Error Field. */ + UNS8 TestSlave_highestSubIndex_obj1003 = 8; /* number of subindex - 1*/ + UNS32 TestSlave_obj1003[] = + { + 0x0, /* 0 */ + 0x0, /* 0 */ + 0x0, /* 0 */ + 0x0, /* 0 */ + 0x0, /* 0 */ + 0x0, /* 0 */ + 0x0, /* 0 */ + 0x0 /* 0 */ + }; + ODCallback_t TestSlave_Index1003_callbacks[] = + { + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + }; + subindex TestSlave_Index1003[] = + { + { RW, uint8, sizeof (UNS8), (void*)&TestSlave_highestSubIndex_obj1003 }, + { RO, uint32, sizeof (UNS32), (void*)&TestSlave_obj1003[0] }, + { RO, uint32, sizeof (UNS32), (void*)&TestSlave_obj1003[1] }, + { RO, uint32, sizeof (UNS32), (void*)&TestSlave_obj1003[2] }, + { RO, uint32, sizeof (UNS32), (void*)&TestSlave_obj1003[3] }, + { RO, uint32, sizeof (UNS32), (void*)&TestSlave_obj1003[4] }, + { RO, uint32, sizeof (UNS32), (void*)&TestSlave_obj1003[5] }, + { RO, uint32, sizeof (UNS32), (void*)&TestSlave_obj1003[6] }, + { RO, uint32, sizeof (UNS32), (void*)&TestSlave_obj1003[7] } + }; + /* index 0x1005 : SYNC COB ID. */ UNS32 TestSlave_obj1005 = 0x80; /* 128 */ ODCallback_t TestSlave_Index1005_callbacks[] = @@ -465,6 +503,7 @@ { { (subindex*)TestSlave_Index1000,sizeof(TestSlave_Index1000)/sizeof(TestSlave_Index1000[0]), 0x1000}, { (subindex*)TestSlave_Index1001,sizeof(TestSlave_Index1001)/sizeof(TestSlave_Index1001[0]), 0x1001}, + { (subindex*)TestSlave_Index1003,sizeof(TestSlave_Index1003)/sizeof(TestSlave_Index1003[0]), 0x1003}, { (subindex*)TestSlave_Index1005,sizeof(TestSlave_Index1005)/sizeof(TestSlave_Index1005[0]), 0x1005}, { (subindex*)TestSlave_Index1006,sizeof(TestSlave_Index1006)/sizeof(TestSlave_Index1006[0]), 0x1006}, { (subindex*)TestSlave_Index1010,sizeof(TestSlave_Index1010)/sizeof(TestSlave_Index1010[0]), 0x1010}, @@ -504,36 +543,37 @@ switch(wIndex){ case 0x1000: i = 0;break; case 0x1001: i = 1;break; - case 0x1005: i = 2;*callbacks = TestSlave_Index1005_callbacks; break; - case 0x1006: i = 3;*callbacks = TestSlave_Index1006_callbacks; break; - case 0x1010: i = 4;*callbacks = TestSlave_Index1010_callbacks; break; - case 0x1011: i = 5;*callbacks = TestSlave_Index1011_callbacks; break; - case 0x1017: i = 6;*callbacks = TestSlave_Index1017_callbacks; break; - case 0x1018: i = 7;break; - case 0x1200: i = 8;break; - case 0x1800: i = 9;*callbacks = TestSlave_Index1800_callbacks; break; - case 0x1801: i = 10;*callbacks = TestSlave_Index1801_callbacks; break; - case 0x1802: i = 11;*callbacks = TestSlave_Index1802_callbacks; break; - case 0x1803: i = 12;*callbacks = TestSlave_Index1803_callbacks; break; - case 0x1804: i = 13;*callbacks = TestSlave_Index1804_callbacks; break; - case 0x1A00: i = 14;break; - case 0x1A01: i = 15;break; - case 0x1A02: i = 16;break; - case 0x1A03: i = 17;break; - case 0x1A04: i = 18;break; - case 0x2000: i = 19;break; - case 0x2001: i = 20;break; - case 0x2002: i = 21;break; - case 0x2003: i = 22;break; - case 0x2004: i = 23;break; - case 0x2005: i = 24;break; - case 0x2006: i = 25;break; - case 0x2007: i = 26;break; - case 0x2008: i = 27;break; - case 0x2009: i = 28;break; - case 0x200A: i = 29;break; - case 0x200B: i = 30;break; - case 0x200C: i = 31;break; + case 0x1003: i = 2;*callbacks = TestSlave_Index1003_callbacks; break; + case 0x1005: i = 3;*callbacks = TestSlave_Index1005_callbacks; break; + case 0x1006: i = 4;*callbacks = TestSlave_Index1006_callbacks; break; + case 0x1010: i = 5;*callbacks = TestSlave_Index1010_callbacks; break; + case 0x1011: i = 6;*callbacks = TestSlave_Index1011_callbacks; break; + case 0x1017: i = 7;*callbacks = TestSlave_Index1017_callbacks; break; + case 0x1018: i = 8;break; + case 0x1200: i = 9;break; + case 0x1800: i = 10;*callbacks = TestSlave_Index1800_callbacks; break; + case 0x1801: i = 11;*callbacks = TestSlave_Index1801_callbacks; break; + case 0x1802: i = 12;*callbacks = TestSlave_Index1802_callbacks; break; + case 0x1803: i = 13;*callbacks = TestSlave_Index1803_callbacks; break; + case 0x1804: i = 14;*callbacks = TestSlave_Index1804_callbacks; break; + case 0x1A00: i = 15;break; + case 0x1A01: i = 16;break; + case 0x1A02: i = 17;break; + case 0x1A03: i = 18;break; + case 0x1A04: i = 19;break; + case 0x2000: i = 20;break; + case 0x2001: i = 21;break; + case 0x2002: i = 22;break; + case 0x2003: i = 23;break; + case 0x2004: i = 24;break; + case 0x2005: i = 25;break; + case 0x2006: i = 26;break; + case 0x2007: i = 27;break; + case 0x2008: i = 28;break; + case 0x2009: i = 29;break; + case 0x200A: i = 30;break; + case 0x200B: i = 31;break; + case 0x200C: i = 32;break; default: *errorCode = OD_NO_SUCH_OBJECT; return NULL; @@ -550,21 +590,21 @@ s_PDO_status TestSlave_PDO_status[5] = {s_PDO_staus_Initializer,s_PDO_staus_Initializer,s_PDO_staus_Initializer,s_PDO_staus_Initializer,s_PDO_staus_Initializer}; quick_index TestSlave_firstIndex = { - 8, /* SDO_SVR */ + 9, /* SDO_SVR */ 0, /* SDO_CLT */ 0, /* PDO_RCV */ 0, /* PDO_RCV_MAP */ - 9, /* PDO_TRS */ - 14 /* PDO_TRS_MAP */ + 10, /* PDO_TRS */ + 15 /* PDO_TRS_MAP */ }; quick_index TestSlave_lastIndex = { - 8, /* SDO_SVR */ + 9, /* SDO_SVR */ 0, /* SDO_CLT */ 0, /* PDO_RCV */ 0, /* PDO_RCV_MAP */ - 13, /* PDO_TRS */ - 18 /* PDO_TRS_MAP */ + 14, /* PDO_TRS */ + 19 /* PDO_TRS_MAP */ }; UNS16 TestSlave_ObjdictSize = sizeof(TestSlave_objdict)/sizeof(TestSlave_objdict[0]); diff -r e0b3096230e5 -r 24bf3d692993 examples/TestMasterSlave/TestSlave.od --- a/examples/TestMasterSlave/TestSlave.od Tue Sep 25 15:29:37 2007 +0200 +++ b/examples/TestMasterSlave/TestSlave.od Wed Sep 26 16:02:00 2007 +0200 @@ -1,10 +1,10 @@ - - + + TestSlave - + @@ -59,7 +59,7 @@ - + @@ -69,7 +69,7 @@ - + @@ -78,7 +78,7 @@ - + @@ -87,13 +87,13 @@ - + - + @@ -103,7 +103,7 @@ - + @@ -114,7 +114,7 @@ - + @@ -123,7 +123,7 @@ - + @@ -145,7 +145,7 @@ - + @@ -155,7 +155,7 @@ - + @@ -165,13 +165,13 @@ - + - + @@ -185,8 +185,21 @@ + + + + + + + + + + + + + - + @@ -196,17 +209,17 @@ - + - + - + - + @@ -215,10 +228,10 @@ - + - + @@ -227,7 +240,7 @@ - + @@ -238,10 +251,10 @@ - + - + EVENT @@ -250,7 +263,7 @@ - + 5000*100 µC = 500 ms @@ -259,7 +272,7 @@ - + @@ -268,7 +281,7 @@ - + 1000 ms @@ -279,10 +292,10 @@ - + - + RTR_SYNC @@ -293,10 +306,10 @@ - + - + RTR @@ -307,7 +320,7 @@ - + @@ -316,7 +329,7 @@ - + @@ -324,27 +337,36 @@ - - + + + + + + + + + + + - + - - - - - - - - - + + + + + + + + + @@ -376,15 +398,15 @@ - - - - - - - - - + + + + + + + + + @@ -416,15 +438,15 @@ - - - - - - - - - + + + + + + + + + @@ -456,15 +478,15 @@ - - - - - - - - - + + + + + + + + + @@ -496,15 +518,15 @@ - - - - - - - - - + + + + + + + + + @@ -536,15 +558,15 @@ - - - - - - - - - + + + + + + + + + @@ -576,15 +598,15 @@ - - - - - - - - - + + + + + + + + + @@ -616,15 +638,15 @@ - - - - - - - - - + + + + + + + + + @@ -656,15 +678,15 @@ - - - - - - - - - + + + + + + + + + @@ -696,15 +718,15 @@ - - - - - - - - - + + + + + + + + + @@ -736,15 +758,15 @@ - - - - - - - - - + + + + + + + + + @@ -776,15 +798,15 @@ - - - - - - - - - + + + + + + + + + @@ -816,15 +838,15 @@ - - - - - - - - - + + + + + + + + + @@ -855,10 +877,10 @@ - + slave - + diff -r e0b3096230e5 -r 24bf3d692993 include/data.h --- a/include/data.h Tue Sep 25 15:29:37 2007 +0200 +++ b/include/data.h Wed Sep 26 16:02:00 2007 +0200 @@ -43,6 +43,7 @@ #include "lifegrd.h" #include "sync.h" #include "nmtMaster.h" +#include "emcy.h" /* This structurs contains all necessary information for a CanOpen node */ struct struct_CO_Data { @@ -95,6 +96,15 @@ UNS8* dcf_cursor; UNS32 dcf_count_targets; + /* EMCY */ + e_errorState error_state; + UNS8 error_history_size; + UNS8* error_number; + UNS32* error_first_element; + UNS8* error_register; + s_errors error_data[EMCY_MAX_ERRORS]; + post_emcy_t post_emcy; + }; #define NMTable_Initializer Unknown_state, @@ -115,6 +125,13 @@ NULL /* Callback */\ }, +#define ERROR_DATA_INITIALIZER \ + {\ + 0, /* errCode */\ + 0, /* errRegMask */\ + 0 /* active */\ + }, + /* A macro to initialize the data in client app.*/ /* CO_Data structure */ #define CANOPEN_NODE_DATA_INITIALIZER(NODE_PREFIX) {\ @@ -174,7 +191,19 @@ NODE_PREFIX ## _scanIndexOD, /* scanIndexOD */\ _storeODSubIndex, /* storeODSubIndex */\ NULL, /*dcf_cursor*/\ - 1 /*dcf_count_targets*/\ + 1, /*dcf_count_targets*/\ + \ + /* EMCY */\ + Error_free, /* error_state */\ + sizeof(NODE_PREFIX ## _obj1003) / sizeof(NODE_PREFIX ## _obj1003[0]), /* error_history_size */\ + & NODE_PREFIX ## _highestSubIndex_obj1003, /* error_number */\ + & NODE_PREFIX ## _obj1003[0], /* error_first_element */\ + & NODE_PREFIX ## _obj1001, /* error_register */\ + /* error_data: structure s_errors */\ + {\ + REPEAT_EMCY_MAX_ERRORS_TIMES(ERROR_DATA_INITIALIZER)\ + },\ + _post_emcy /* post_emcy */\ } #ifdef __cplusplus diff -r e0b3096230e5 -r 24bf3d692993 include/emcy.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/emcy.h Wed Sep 26 16:02:00 2007 +0200 @@ -0,0 +1,83 @@ +/* +This file is part of CanFestival, a library implementing CanOpen Stack. + +Copyright (C): Edouard TISSERANT and Francis DUPIN + +See COPYING file for copyrights details. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/*! +** @file emcy.h +** @author Luis Jimenez +** @date Wed Sep 26 2007 +** +** @brief Declarations of the functions that manage EMCY (emergency) messages +** +** +*/ + +#ifndef __emcy_h__ +#define __emcy_h__ + + +#include + +/* The error states + * ----------------- */ +typedef enum enum_errorState { + Error_free = 0x00, + Error_occurred = 0x01 +} e_errorState; + +typedef struct { + UNS16 errCode; + UNS8 errRegMask; + UNS8 active; +} s_errors; + +#include "data.h" + + +typedef void (*post_emcy_t)(UNS8 nodeID, UNS16 errCode, UNS8 errReg); +void _post_emcy(UNS8 nodeID, UNS16 errCode, UNS8 errReg); + +/************************************************************************* + * Functions + *************************************************************************/ + +/** Sets a new error with code errCode. Also sets corresponding bits in Error register (1001h) + */ +UNS8 EMCY_setError(CO_Data* d, UNS16 errCode, UNS8 errRegMask); + +/** Indicates it has recovered from error errCode. Also clears corresponding bits in Error register (1001h) + */ +void EMCY_errorRecovered(CO_Data* d, UNS16 errCode); + +/** Start EMCY consumer and producer + */ +void emergencyInit(CO_Data* d); + +/** Stop EMCY producer and consumer + */ +void emergencyStop(CO_Data* d); + +/** This function is responsible to process an EMCY canopen-message + * \param Message The CAN-message which has to be analysed. + */ +void proceedEMCY(CO_Data* d, Message* m); + +#endif /*__emcy_h__ */ diff -r e0b3096230e5 -r 24bf3d692993 objdictgen/gen_cfile.py --- a/objdictgen/gen_cfile.py Tue Sep 25 15:29:37 2007 +0200 +++ b/objdictgen/gen_cfile.py Wed Sep 26 16:02:00 2007 +0200 @@ -317,6 +317,27 @@ # Declaration of Particular Parameters #------------------------------------------------------------------------------- + if 0x1003 not in communicationlist: + entry_infos = Node.GetEntryInfos(0x1003) + texts["EntryName"] = entry_infos["name"] + indexContents[0x1003] = """\n/* index 0x1003 : %(EntryName)s */ + UNS8 %(NodeName)s_highestSubIndex_obj1003 = 0; /* number of subindex - 1*/ + UNS32 %(NodeName)s_obj1003[] = + { + 0x0 /* 0 */ + }; + ODCallback_t %(NodeName)s_Index1003_callbacks[] = + { + NULL, + NULL, + }; + subindex %(NodeName)s_Index1003[] = + { + { RW, uint8, sizeof (UNS8), (void*)&%(NodeName)s_highestSubIndex_obj1003 }, + { RO, uint32, sizeof (UNS32), (void*)&%(NodeName)s_obj1003[0] } + }; +"""%texts + if 0x1005 not in communicationlist: entry_infos = Node.GetEntryInfos(0x1005) texts["EntryName"] = entry_infos["name"] diff -r e0b3096230e5 -r 24bf3d692993 objdictgen/node.py --- a/objdictgen/node.py Tue Sep 25 15:29:37 2007 +0200 +++ b/objdictgen/node.py Wed Sep 26 16:02:00 2007 +0200 @@ -104,7 +104,7 @@ [{"name" : "Error Register", "type" : 0x05, "access": 'ro', "pdo" : True}]}, 0x1002 : {"name" : "Manufacturer Status Register", "struct" : var, "need" : False, "values" : [{"name" : "Manufacturer Status Register", "type" : 0x07, "access" : 'ro', "pdo" : True}]}, - 0x1003 : {"name" : "Pre-defined Error Field", "struct" : rec, "need" : False, "values" : + 0x1003 : {"name" : "Pre-defined Error Field", "struct" : rec, "need" : False, "callback" : True, "values" : [{"name" : "Number of Errors", "type" : 0x05, "access" : 'rw', "pdo" : False}, {"name" : "Standard Error Field", "type" : 0x07, "access" : 'ro', "pdo" : False, "nbmax" : 0xFE}]}, 0x1005 : {"name" : "SYNC COB ID", "struct" : var, "need" : False, "callback" : True, "values" : diff -r e0b3096230e5 -r 24bf3d692993 src/Makefile.in --- a/src/Makefile.in Tue Sep 25 15:29:37 2007 +0200 +++ b/src/Makefile.in Wed Sep 26 16:02:00 2007 +0200 @@ -34,7 +34,7 @@ INCLUDES = -I../include -I../include/$(TARGET) -I../include/$(TIMERS_DRIVER) -I../drivers/$(TARGET) OBJS = $(TARGET)_objacces.o $(TARGET)_lifegrd.o $(TARGET)_sdo.o\ - $(TARGET)_pdo.o $(TARGET)_sync.o $(TARGET)_nmtSlave.o $(TARGET)_nmtMaster.o $(TARGET)_states.o $(TARGET)_timer.o $(TARGET)_dcf.o + $(TARGET)_pdo.o $(TARGET)_sync.o $(TARGET)_nmtSlave.o $(TARGET)_nmtMaster.o $(TARGET)_states.o $(TARGET)_timer.o $(TARGET)_dcf.o $(TARGET)_emcy.o # # # # Target specific paramters # # # # diff -r e0b3096230e5 -r 24bf3d692993 src/emcy.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/emcy.c Wed Sep 26 16:02:00 2007 +0200 @@ -0,0 +1,247 @@ +/* + This file is part of CanFestival, a library implementing CanOpen + Stack. + + Copyright (C): Edouard TISSERANT and Francis DUPIN + + See COPYING file for copyrights details. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA +*/ + +/*! +** @file emcy.c +** @author Luis Jimenez +** @date Wed Sep 26 2007 +** +** @brief Definitions of the functions that manage EMCY (emergency) messages +** +** +*/ + +#include +#include "emcy.h" +#include "canfestival.h" + + + +UNS32 OnNumberOfErrorsUpdate(CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex); +UNS8 sendEMCY(CO_Data* d, UNS32 cob_id, UNS16 errCode, UNS8 errRegister); + + +/*! This is called when Index 0x1003 is updated. +** +** +** @param d +** @param unsused_indextable +** @param unsused_bSubindex +** +** @return +**/ +UNS32 OnNumberOfErrorsUpdate(CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex) +{ + UNS8 index; + // if 0, reset Pre-defined Error Field + // else, don't change and give an abort message (eeror code: 0609 0030h) + if (*d->error_number == 0) + for (index = 0; index < d->error_history_size; ++index) + *(d->error_first_element + index) = 0; /* clear all the fields in Pre-defined Error Field (1003h) */ + else + ;// abort message + return 0; +} + +/*! start the EMCY mangagement. +** +** +** @param d +**/ +void emergencyInit(CO_Data* d) +{ + RegisterSetODentryCallBack(d, 0x1003, 0x00, &OnNumberOfErrorsUpdate); + + *d->error_number = 0; +} + +/*! +** +** +** @param d +**/ +void emergencyStop(CO_Data* d) +{ + +} + +/*! + ** + ** + ** @param d + ** @param cob_id + ** + ** @return + **/ +UNS8 sendEMCY(CO_Data* d, UNS32 cob_id, UNS16 errCode, UNS8 errRegister) +{ + Message m; + + MSG_WAR(0xA001, "sendEMCY", 0); + + m.cob_id.w = cob_id ; + m.rtr = NOT_A_REQUEST; + m.len = 8; + m.data[0] = errCode & 0xFF; /* LSB */ + m.data[1] = (errCode >> 8) & 0xFF; /* MSB */ + m.data[2] = errRegister; + m.data[3] = 0; /* Manufacturer specific Error Field still not implemented */ + m.data[4] = 0; + m.data[5] = 0; + m.data[6] = 0; + m.data[7] = 0; + + return canSend(d->canHandle,&m); +} + +/*! Sets a new error with code errCode. Also sets corresponding bits in Error register (1001h) + ** + ** + ** @param d + ** @param errCode Code of the error + ** @param errRegister Bits of Error register (1001h) to be set. + ** @return 1 if error, 0 if successful + */ +UNS8 EMCY_setError(CO_Data* d, UNS16 errCode, UNS8 errRegMask) +{ + UNS8 index; + UNS8 errRegister_tmp; + + for (index = 0; index < EMCY_MAX_ERRORS; ++index) + { + if (d->error_data[index].errCode == errCode) /* error already registered */ + { + if (d->error_data[index].active) + { + MSG_WAR(0xA002, "EMCY message already sent", 0); + return 0; + } else d->error_data[index].active = 1; /* set as active error */ + break; + } + } + + if (index == EMCY_MAX_ERRORS) /* if errCode not already registered */ + for (index = 0; index < EMCY_MAX_ERRORS; ++index) if (d->error_data[index].active == 0) break; /* find first inactive error */ + + if (index == EMCY_MAX_ERRORS) /* error_data full */ + { + MSG_ERR(0xA003, "error_data full", 0); + return 1; + } + + d->error_data[index].errCode = errCode; + d->error_data[index].errRegMask = 1; + d->error_data[index].active = 1; + + /* set the new state in the error state machine */ + d->error_state = Error_occurred; + + /* set Error Register (1001h) */ + for (index = 0, errRegister_tmp = 0; index < EMCY_MAX_ERRORS; ++index) + if (d->error_data[index].active == 1) errRegister_tmp |= d->error_data[index].errRegMask; + *d->error_register = errRegister_tmp; + + /* set Pre-defined Error Field (1003h) */ + for (index = d->error_history_size - 1; index > 0; --index) + *(d->error_first_element + index) = *(d->error_first_element + index - 1); + *(d->error_first_element) = (UNS32)errCode; + if(*d->error_number < d->error_history_size) ++(*d->error_number); + + /* send EMCY message */ + if (d->CurrentCommunicationState.csEmergency) + return sendEMCY(d, *d->bDeviceNodeId + 0x080, errCode, *d->error_register); + else return 1; +} + +/*! Deletes error errCode. Also clears corresponding bits in Error register (1001h) + ** + ** + ** @param d + ** @param errCode Code of the error + ** @param errRegister Bits of Error register (1001h) to be set. + ** @return 1 if error, 0 if successful + */ +void EMCY_errorRecovered(CO_Data* d, UNS16 errCode) +{ + UNS8 index; + UNS8 errRegister_tmp; + UNS8 anyActiveError = 0; + + for (index = 0; index < EMCY_MAX_ERRORS; ++index) + if (d->error_data[index].errCode == errCode) break; /* find the position of the error */ + + + if ((index != EMCY_MAX_ERRORS) && (d->error_data[index].active == 1)) + { + d->error_data[index].active = 0; + + /* set Error Register (1001h) and check error state machine */ + for (index = 0, errRegister_tmp = 0; index < EMCY_MAX_ERRORS; ++index) + if (d->error_data[index].active == 1) + { + anyActiveError = 1; + errRegister_tmp |= d->error_data[index].errRegMask; + } + if(anyActiveError == 0) + { + d->error_state = Error_free; + /* send a EMCY message with code "Error Reset or No Error" */ + if (d->CurrentCommunicationState.csEmergency) + sendEMCY(d, *d->bDeviceNodeId + 0x080, 0x0000, 0x00); + } + *d->error_register = errRegister_tmp; + } + else + MSG_WAR(0xA004, "recovered error was not active", 0); +} + +/*! This function is responsible to process an EMCY canopen-message. + ** + ** + ** @param d + ** @param m The CAN-message which has to be analysed. + ** + **/ +void proceedEMCY(CO_Data* d, Message* m) +{ + UNS8 nodeID; + UNS16 errCode; + UNS8 errReg; + + MSG_WAR(0xA005, "EMCY received. Proceed. ", 0); + + /* Test if the size of the EMCY is ok */ + if ( m->len != 8) { + MSG_ERR(0xA006, "Error size EMCY. CobId : ", m->cob_id.w); + return; + } + + /* post the received EMCY */ + nodeID = m->cob_id.w & 0x7F; + errCode = m->data[0] | ((UNS16)m->data[1] << 8); + errReg = m->data[2]; + (*d->post_emcy)(nodeID, errCode, errReg); +} + +void _post_emcy(UNS8 nodeID, UNS16 errCode, UNS8 errReg){} diff -r e0b3096230e5 -r 24bf3d692993 src/states.c --- a/src/states.c Tue Sep 25 15:29:37 2007 +0200 +++ b/src/states.c Wed Sep 26 16:02:00 2007 +0200 @@ -33,6 +33,7 @@ #include "def.h" #include "dcf.h" #include "nmtSlave.h" +#include "emcy.h" /** Prototypes for internals functions */ /*! @@ -66,9 +67,14 @@ { switch(m->cob_id.w >> 7) { - case SYNC: - if(d->CurrentCommunicationState.csSYNC) - proceedSYNC(d); + case SYNC: /* can be a SYNC or a EMCY message */ + if(m->cob_id.w == 0x080) /* SYNC */ + { + if(d->CurrentCommunicationState.csSYNC) + proceedSYNC(d); + } else /* EMCY */ + if(d->CurrentCommunicationState.csEmergency) + proceedEMCY(d,m); break; /* case TIME_STAMP: */ case PDO1tx: @@ -122,7 +128,7 @@ StartOrStop(csSDO, None, resetSDO(d)) StartOrStop(csSYNC, startSYNC(d), stopSYNC(d)) StartOrStop(csHeartbeat, heartbeatInit(d), heartbeatStop(d)) -/* StartOrStop(Emergency,,) */ + StartOrStop(csEmergency, emergencyInit(d), emergencyStop(d)) StartOrStop(csPDO, PDOInit(d), PDOStop(d)) StartOrStop(csBoot_Up, None, slaveSendBootUp(d)) }