# HG changeset patch # User etisserant # Date 1212569826 -7200 # Node ID f2b07ea215b553d5879f25ae82c3bd8a253db470 # Parent 787a54d068d6653b94e7b07488bfdb9c73a551c4 Applied edward's patch for OD acces macros (optimization) and boudaries check (safety). diff -r 787a54d068d6 -r f2b07ea215b5 include/objacces.h --- a/include/objacces.h Wed Jun 04 10:53:41 2008 +0200 +++ b/include/objacces.h Wed Jun 04 10:57:06 2008 +0200 @@ -59,7 +59,11 @@ UNS8 sizeDataDict, UNS8 sizeDataGiven, UNS32 code); -/* Reads an entry from the object dictionary.\n +/* _getODentry() Reads an entry from the object dictionary.\n + * + * use getODentry() macro to read from object and endianize + * use readLocalDict() macro to read from object and not endianize + * * \code * // Example usage: * UNS8 *pbData; @@ -86,16 +90,34 @@ * \param pDataType : The type of the data. See objdictdef.h * \param CheckAccess if other than 0, do not read if the data is Write Only * [Not used today. Put always 0]. + * \param Endianize when not 0, data is endianized into network byte order + * when 0, data is not endianized and copied in machine native + * endianness * \return OD_SUCCESSFUL or SDO abort code. (See file def.h) */ -UNS32 getODentry( CO_Data* d, - UNS16 wIndex, +UNS32 _getODentry( CO_Data* d, + UNS16 wIndex, UNS8 bSubindex, void * pDestData, UNS8 * pExpectedSize, UNS8 * pDataType, - UNS8 checkAccess); + UNS8 checkAccess, + UNS8 endianize); +#define getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \ + pDataType, checkAccess) \ + _getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \ + pDataType, checkAccess, 1) + +/* + * readLocalDict() reads an entry from the object dictionary, but in + * contrast to getODentry(), readLocalDict() doesn't endianize entry and reads + * entry in machine native endianness. + */ +#define readLocalDict( OD, wIndex, bSubindex, pDestData, pExpectedSize, \ + pDataType, checkAccess) \ + _getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \ + pDataType, checkAccess, 0) /* By this function you can write an entry into the object dictionary\n * \code @@ -117,20 +139,27 @@ * \param CheckAccess if other than 0, do not read if the data is Read Only or Constant * \return OD_SUCCESSFUL or SDO abort code. (See file def.h) */ -UNS32 setODentry( CO_Data* d, - UNS16 wIndex, - UNS8 bSubindex, - void * pSourceData, - UNS8 * pExpectedSize, - UNS8 checkAccess); +UNS32 _setODentry( CO_Data* d, + UNS16 wIndex, + UNS8 bSubindex, + void * pSourceData, + UNS8 * pExpectedSize, + UNS8 checkAccess, + UNS8 endianize); -/*The same, without endianisation*/ -UNS32 writeLocalDict( CO_Data* d, - UNS16 wIndex, - UNS8 bSubindex, - void * pSourceData, - UNS8 * pExpectedSize, - UNS8 checkAccess); +/* + * setODentry converts SourceData from network byte order to machine native + * format, and writes that to OD. + */ +#define setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess) \ + _setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess, 1) + +/* + * writeLocalDict writes machine native SourceData to OD. + */ +#define writeLocalDict( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess) \ + _setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess, 0) + /* Scan the index of object dictionary. Used only by setODentry and getODentry. diff -r 787a54d068d6 -r f2b07ea215b5 src/objacces.c --- a/src/objacces.c Wed Jun 04 10:53:41 2008 +0200 +++ b/src/objacces.c Wed Jun 04 10:57:06 2008 +0200 @@ -52,10 +52,10 @@ ** ** @return **/ +#ifdef DEBUG_WAR_CONSOLE_ON UNS8 accessDictionaryError(UNS16 index, UNS8 subIndex, UNS8 sizeDataDict, UNS8 sizeDataGiven, UNS32 code) { -#ifdef DEBUG_WAR_CONSOLE_ON MSG_WAR(0x2B09,"Dictionary index : ", index); MSG_WAR(0X2B10," subindex : ", subIndex); switch (code) { @@ -84,9 +84,11 @@ default : MSG_WAR(0x2B20, "Unknown error code : ", code); } + return 0; +} +#else +#define accessDictionaryError(index, subIndex, sizeDataDict, sizeDataGiven, code) #endif - return 0; -} /*! ** @@ -198,68 +200,6 @@ ** @param d ** @param wIndex ** @param bSubindex -** @param pDestData -** @param pExpectedSize -** @param pDataType -** @param checkAccess -** -** @return -**/ -UNS32 getODentry( CO_Data* d, - UNS16 wIndex, - UNS8 bSubindex, - void * pDestData, - UNS8 * pExpectedSize, - UNS8 * pDataType, - UNS8 checkAccess) -{ - return _getODentry( d, - wIndex, - bSubindex, - pDestData, - pExpectedSize, - pDataType, - checkAccess, - 1);//endianize -} - -/*! -** -** -** @param d -** @param wIndex -** @param bSubindex -** @param pDestData -** @param pExpectedSize -** @param pDataType -** @param checkAccess -** -** @return -**/ -UNS32 readLocalDict( CO_Data* d, - UNS16 wIndex, - UNS8 bSubindex, - void * pDestData, - UNS8 * pExpectedSize, - UNS8 * pDataType, - UNS8 checkAccess) -{ - return _getODentry( d, - wIndex, - bSubindex, - pDestData, - pExpectedSize, - pDataType, - checkAccess, - 0);//do not endianize -} - -/*! -** -** -** @param d -** @param wIndex -** @param bSubindex ** @param pSourceData ** @param pExpectedSize ** @param checkAccess @@ -365,62 +305,6 @@ ** ** @param d ** @param wIndex -** @param bSubindex -** @param pSourceData -** @param pExpectedSize -** @param checkAccess -** -** @return -**/ -UNS32 setODentry( CO_Data* d, - UNS16 wIndex, - UNS8 bSubindex, - void * pSourceData, - UNS8 * pExpectedSize, - UNS8 checkAccess) -{ - return _setODentry( d, - wIndex, - bSubindex, - pSourceData, - pExpectedSize, - checkAccess, - 1);//endianize -} - -/*! -** -** -** @param d -** @param wIndex -** @param bSubindex -** @param pSourceData -** @param pExpectedSize -** @param checkAccess -** -** @return -**/ -UNS32 writeLocalDict( CO_Data* d, - UNS16 wIndex, - UNS8 bSubindex, - void * pSourceData, - UNS8 * pExpectedSize, - UNS8 checkAccess) -{ - return _setODentry( d, - wIndex, - bSubindex, - pSourceData, - pExpectedSize, - checkAccess, - 0);//do not endianize -} - -/*! -** -** -** @param d -** @param wIndex ** @param errorCode ** @param Callback ** @@ -443,11 +327,12 @@ **/ UNS32 RegisterSetODentryCallBack(CO_Data* d, UNS16 wIndex, UNS8 bSubindex, ODCallback_t Callback) { - UNS32 errorCode; - ODCallback_t *CallbackList; - - scanIndexOD (d, wIndex, &errorCode, &CallbackList); - if(errorCode == OD_SUCCESSFUL && CallbackList) +UNS32 errorCode; +ODCallback_t *CallbackList; +const indextable *odentry; + + odentry = scanIndexOD (d, wIndex, &errorCode, &CallbackList); + if(errorCode == OD_SUCCESSFUL && CallbackList && bSubindex < odentry->bSubCount) CallbackList[bSubindex] = Callback; return errorCode; }