etisserant@0: /* etisserant@0: This file is part of CanFestival, a library implementing CanOpen Stack. etisserant@0: etisserant@0: Copyright (C): Edouard TISSERANT and Francis DUPIN etisserant@0: etisserant@0: See COPYING file for copyrights details. etisserant@0: etisserant@0: This library is free software; you can redistribute it and/or etisserant@0: modify it under the terms of the GNU Lesser General Public etisserant@0: License as published by the Free Software Foundation; either etisserant@0: version 2.1 of the License, or (at your option) any later version. etisserant@0: etisserant@0: This library is distributed in the hope that it will be useful, etisserant@0: but WITHOUT ANY WARRANTY; without even the implied warranty of etisserant@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU etisserant@0: Lesser General Public License for more details. etisserant@0: etisserant@0: You should have received a copy of the GNU Lesser General Public etisserant@0: License along with this library; if not, write to the Free Software etisserant@0: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA etisserant@0: */ etisserant@0: greg@528: /** @file greg@528: * @brief Responsible for accessing the object dictionary. etisserant@0: * etisserant@0: * This file contains functions for accessing the object dictionary and etisserant@0: * variables that are contained by the object dictionary. etisserant@0: * Accessing the object dictionary contains setting local variables etisserant@0: * as PDOs and accessing (read/write) all entries of the object dictionary greg@528: * @warning Only the basic entries of an object dictionary are included etisserant@0: * at the moment. etisserant@0: */ etisserant@0: greg@528: /** @defgroup od Object Dictionary Management greg@529: * @brief The Object Dictionary is the heart of each CANopen device containing all communication and application objects. greg@528: * @ingroup userapi greg@528: */ greg@528: etisserant@0: #ifndef __objacces_h__ etisserant@0: #define __objacces_h__ etisserant@0: etisserant@0: #include etisserant@0: greg@588: greg@588: #ifdef __cplusplus greg@588: extern "C" { greg@588: #endif greg@588: greg@588: etisserant@0: typedef UNS32 (*valueRangeTest_t)(UNS8 typeValue, void *Value); etisserant@378: typedef void (* storeODSubIndex_t)(CO_Data* d, UNS16 wIndex, UNS8 bSubindex); etisserant@378: void _storeODSubIndex (CO_Data* d, UNS16 wIndex, UNS8 bSubindex); etisserant@0: greg@528: /** greg@528: * @brief Print MSG_WAR (s) if error to the access to the object dictionary occurs. greg@528: * greg@528: * You must uncomment the lines in the file objaccess.c :\n greg@528: * //#define DEBUG_CAN\n greg@528: * //#define DEBUG_WAR_CONSOLE_ON\n greg@528: * //#define DEBUG_ERR_CONSOLE_ON\n\n greg@528: * Beware that sometimes, we force the sizeDataDict or sizeDataGiven to 0, when we wants to use greg@528: * this function but we do not have the access to the right value. One example is greg@528: * getSDOerror(). So do not take attention to these variables if they are null. greg@528: * @param index greg@528: * @param subIndex greg@528: * @param sizeDataDict Size of the data defined in the dictionary greg@528: * @param sizeDataGiven Size data given by the user. greg@528: * @param code error code to print. (SDO abort code. See file def.h) greg@528: * @return greg@528: */ etisserant@0: UNS8 accessDictionaryError(UNS16 index, UNS8 subIndex, etisserant@539: UNS32 sizeDataDict, UNS32 sizeDataGiven, UNS32 code); frdupin@75: etisserant@0: etisserant@469: /* _getODentry() Reads an entry from the object dictionary.\n etisserant@469: * etisserant@469: * use getODentry() macro to read from object and endianize etisserant@469: * use readLocalDict() macro to read from object and not endianize etisserant@469: * greg@528: * @code greg@528: * // Example usage: greg@528: * UNS8 *pbData; greg@528: * UNS8 length; greg@528: * UNS32 returnValue; greg@528: * greg@528: * returnValue = getODentry( (UNS16)0x100B, (UNS8)1, greg@528: * (void * *)&pbData, (UNS8 *)&length ); greg@528: * if( returnValue != SUCCESSFUL ) greg@528: * { greg@528: * // error handling greg@528: * } greg@528: * @endcode greg@561: * @param *d Pointer to a CAN object data structure greg@528: * @param wIndex The index in the object dictionary where you want to read greg@528: * an entry greg@528: * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is greg@528: * used to tell you how many valid entries you can find greg@528: * in this index. Look at the canopen standard for further greg@528: * information greg@528: * @param *pDestData Pointer to the pointer which points to the variable where greg@528: * the value of this object dictionary entry should be copied greg@528: * @param pExpectedSize This function writes the size of the copied value (in Byte) greg@528: * into this variable. greg@561: * @param *pDataType Pointer to the type of the data. See objdictdef.h greg@528: * @param CheckAccess if other than 0, do not read if the data is Write Only greg@528: * [Not used today. Put always 0]. greg@528: * @param Endianize When not 0, data is endianized into network byte order greg@528: * when 0, data is not endianized and copied in machine native greg@528: * endianness greg@561: * @return greg@561: * - OD_SUCCESSFUL is returned upon success. greg@561: * - SDO abort code is returned if error occurs . (See file def.h) etisserant@0: */ greg@588: UNS32 _getODentry( CO_Data* d, greg@588: UNS16 wIndex, greg@588: UNS8 bSubindex, greg@588: void * pDestData, greg@588: UNS32 * pExpectedSize, greg@588: UNS8 * pDataType, greg@588: UNS8 checkAccess, greg@588: UNS8 endianize); greg@588: greg@528: /** greg@528: * @ingroup od greg@528: * @brief getODentry() to read from object and endianize greg@561: * @param OD Pointer to a CAN object data structure greg@528: * @param wIndex The index in the object dictionary where you want to read greg@528: * an entry greg@528: * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is greg@528: * used to tell you how many valid entries you can find greg@528: * in this index. Look at the canopen standard for further greg@528: * information greg@528: * @param *pDestData Pointer to the pointer which points to the variable where greg@528: * the value of this object dictionary entry should be copied greg@528: * @param pExpectedSize This function writes the size of the copied value (in Byte) greg@528: * into this variable. greg@561: * @param *pDataType Pointer to the type of the data. See objdictdef.h greg@561: * @param checkAccess Flag that indicate if a check rights must be perfomed (0 : no , other than 0 : yes) greg@528: * @param endianize Set to 1 : endianized into network byte order greg@561: * @return greg@561: * - OD_SUCCESSFUL is returned upon success. greg@561: * - SDO abort code is returned if error occurs . (See file def.h) greg@528: */ gregory@594: #define getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \ gregory@594: pDataType, checkAccess) \ gregory@594: _getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \ gregory@594: pDataType, checkAccess, 1) etisserant@469: greg@528: /** greg@528: * @ingroup od greg@528: * @brief readLocalDict() reads an entry from the object dictionary, but in etisserant@469: * contrast to getODentry(), readLocalDict() doesn't endianize entry and reads greg@528: * entry in machine native endianness. greg@561: * @param OD Pointer to a CAN object data structure greg@528: * @param wIndex The index in the object dictionary where you want to read greg@528: * an entry greg@528: * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is greg@528: * used to tell you how many valid entries you can find greg@528: * in this index. Look at the canopen standard for further greg@528: * information greg@528: * @param *pDestData Pointer to the pointer which points to the variable where greg@528: * the value of this object dictionary entry should be copied greg@528: * @param pExpectedSize This function writes the size of the copied value (in Byte) greg@528: * into this variable. greg@561: * @param *pDataType Pointer to the type of the data. See objdictdef.h greg@528: * @param checkAccess if other than 0, do not read if the data is Write Only greg@528: * [Not used today. Put always 0]. greg@528: * @param endianize Set to 0, data is not endianized and copied in machine native greg@528: * endianness greg@561: * @return greg@561: * - OD_SUCCESSFUL is returned upon success. greg@561: * - SDO abort code is returned if error occurs . (See file def.h) etisserant@469: */ gregory@594: #define readLocalDict( OD, wIndex, bSubindex, pDestData, pExpectedSize, \ gregory@594: pDataType, checkAccess) \ gregory@594: _getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \ gregory@594: pDataType, checkAccess, 0) etisserant@0: greg@561: /* By this function you can write an entry into the object dictionary greg@561: * @param *d Pointer to a CAN object data structure greg@528: * @param wIndex The index in the object dictionary where you want to write greg@528: * an entry greg@528: * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is greg@528: * used to tell you how many valid entries you can find greg@528: * in this index. Look at the canopen standard for further greg@528: * information greg@528: * @param *pSourceData Pointer to the variable that holds the value that should greg@528: * be copied into the object dictionary greg@528: * @param *pExpectedSize The size of the value (in Byte). greg@561: * @param checkAccess Flag that indicate if a check rights must be perfomed (0 : no , other than 0 : yes) greg@528: * @param endianize When not 0, data is endianized into network byte order greg@528: * when 0, data is not endianized and copied in machine native greg@528: * endianness greg@561: * @return greg@561: * - OD_SUCCESSFUL is returned upon success. greg@561: * - SDO abort code is returned if error occurs . (See file def.h) etisserant@0: */ etisserant@469: UNS32 _setODentry( CO_Data* d, etisserant@469: UNS16 wIndex, etisserant@469: UNS8 bSubindex, etisserant@469: void * pSourceData, etisserant@539: UNS32 * pExpectedSize, etisserant@469: UNS8 checkAccess, etisserant@469: UNS8 endianize); etisserant@0: greg@528: /** greg@528: * @ingroup od greg@528: * @brief setODentry converts SourceData from network byte order to machine native greg@528: * format, and writes that to OD. greg@528: * @code greg@528: * // Example usage: greg@528: * UNS8 B; greg@528: * B = 0xFF; // set transmission type greg@528: * greg@528: * retcode = setODentry( (UNS16)0x1800, (UNS8)2, &B, sizeof(UNS8), 1 ); greg@528: * @endcode greg@561: * @param d Pointer to a CAN object data structure greg@528: * @param wIndex The index in the object dictionary where you want to write greg@528: * an entry greg@528: * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is greg@528: * used to tell you how many valid entries you can find greg@528: * in this index. Look at the canopen standard for further greg@528: * information greg@528: * @param *pSourceData Pointer to the variable that holds the value that should greg@528: * be copied into the object dictionary greg@528: * @param *pExpectedSize The size of the value (in Byte). greg@561: * @param checkAccess Flag that indicate if a check rights must be perfomed (0 : no , other than 0 : yes) greg@528: * @param endianize Set to 1 : endianized into network byte order greg@561: * @return greg@561: * - OD_SUCCESSFUL is returned upon success. greg@561: * - SDO abort code is returned if error occurs . (See file def.h) greg@561: */ gregory@594: #define setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, \ gregory@594: checkAccess) \ gregory@594: _setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, \ gregory@594: checkAccess, 1) greg@561: greg@561: /** @fn UNS32 writeLocalDict(d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess) greg@561: * @ingroup od greg@561: * @hideinitializer greg@528: * @brief Writes machine native SourceData to OD. greg@561: * @param d Pointer to a CAN object data structure greg@561: * @param wIndex The index in the object dictionary where you want to write greg@561: * an entry greg@561: * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is greg@561: * used to tell you how many valid entries you can find greg@561: * in this index. Look at the canopen standard for further greg@561: * information greg@561: * @param *pSourceData Pointer to the variable that holds the value that should greg@561: * be copied into the object dictionary greg@561: * @param *pExpectedSize The size of the value (in Byte). greg@561: * @param checkAccess Flag that indicate if a check rights must be perfomed (0 : no , other than 0 : yes) greg@561: * @param endianize Data is not endianized and copied in machine native endianness greg@561: * @return greg@561: * - OD_SUCCESSFUL is returned upon success. greg@561: * - SDO abort code is returned if error occurs . (See file def.h) greg@561: * \n\n greg@528: * @code greg@528: * // Example usage: greg@528: * UNS8 B; greg@528: * B = 0xFF; // set transmission type greg@528: * greg@528: * retcode = writeLocalDict( (UNS16)0x1800, (UNS8)2, &B, sizeof(UNS8), 1 ); greg@528: * @endcode etisserant@469: */ gregory@594: #define writeLocalDict( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess) \ gregory@594: _setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess, 0) gregory@594: gregory@594: gregory@594: greg@528: /** greg@528: * @brief Scan the index of object dictionary. Used only by setODentry and getODentry. greg@561: * @param *d Pointer to a CAN object data structure greg@528: * @param wIndex greg@528: * @param *errorCode : OD_SUCCESSFUL if index foundor SDO abort code. (See file def.h) greg@528: * @param **Callback greg@528: * @return NULL if index not found. Else : return the table part of the object dictionary. etisserant@0: */ etisserant@0: const indextable * scanIndexOD (CO_Data* d, UNS16 wIndex, UNS32 *errorCode, ODCallback_t **Callback); etisserant@0: etisserant@0: UNS32 RegisterSetODentryCallBack(CO_Data* d, UNS16 wIndex, UNS8 bSubindex, ODCallback_t Callback); etisserant@0: greg@588: #ifdef __cplusplus greg@588: } greg@588: #endif greg@588: frdupin@71: #endif /* __objacces_h__ */