CANfestival - an open source CANopen framework

Dependencies:   mbed

Committer:
sam_grove
Date:
Mon May 30 07:36:47 2011 +0000
Revision:
0:9dd7c6129683
Initial public release of master node example

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 0:9dd7c6129683 1 /*
sam_grove 0:9dd7c6129683 2 This file is part of CanFestival, a library implementing CanOpen Stack.
sam_grove 0:9dd7c6129683 3
sam_grove 0:9dd7c6129683 4 Copyright (C): Edouard TISSERANT and Francis DUPIN
sam_grove 0:9dd7c6129683 5
sam_grove 0:9dd7c6129683 6 See COPYING file for copyrights details.
sam_grove 0:9dd7c6129683 7
sam_grove 0:9dd7c6129683 8 This library is free software; you can redistribute it and/or
sam_grove 0:9dd7c6129683 9 modify it under the terms of the GNU Lesser General Public
sam_grove 0:9dd7c6129683 10 License as published by the Free Software Foundation; either
sam_grove 0:9dd7c6129683 11 version 2.1 of the License, or (at your option) any later version.
sam_grove 0:9dd7c6129683 12
sam_grove 0:9dd7c6129683 13 This library is distributed in the hope that it will be useful,
sam_grove 0:9dd7c6129683 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
sam_grove 0:9dd7c6129683 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
sam_grove 0:9dd7c6129683 16 Lesser General Public License for more details.
sam_grove 0:9dd7c6129683 17
sam_grove 0:9dd7c6129683 18 You should have received a copy of the GNU Lesser General Public
sam_grove 0:9dd7c6129683 19 License along with this library; if not, write to the Free Software
sam_grove 0:9dd7c6129683 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
sam_grove 0:9dd7c6129683 21 */
sam_grove 0:9dd7c6129683 22
sam_grove 0:9dd7c6129683 23 /** @file
sam_grove 0:9dd7c6129683 24 * @brief Responsible for accessing the object dictionary.
sam_grove 0:9dd7c6129683 25 *
sam_grove 0:9dd7c6129683 26 * This file contains functions for accessing the object dictionary and
sam_grove 0:9dd7c6129683 27 * variables that are contained by the object dictionary.
sam_grove 0:9dd7c6129683 28 * Accessing the object dictionary contains setting local variables
sam_grove 0:9dd7c6129683 29 * as PDOs and accessing (read/write) all entries of the object dictionary
sam_grove 0:9dd7c6129683 30 * @warning Only the basic entries of an object dictionary are included
sam_grove 0:9dd7c6129683 31 * at the moment.
sam_grove 0:9dd7c6129683 32 */
sam_grove 0:9dd7c6129683 33
sam_grove 0:9dd7c6129683 34 /** @defgroup od Object Dictionary Management
sam_grove 0:9dd7c6129683 35 * @brief The Object Dictionary is the heart of each CANopen device containing all communication and application objects.
sam_grove 0:9dd7c6129683 36 * @ingroup userapi
sam_grove 0:9dd7c6129683 37 */
sam_grove 0:9dd7c6129683 38
sam_grove 0:9dd7c6129683 39 #ifndef __objacces_h__
sam_grove 0:9dd7c6129683 40 #define __objacces_h__
sam_grove 0:9dd7c6129683 41
sam_grove 0:9dd7c6129683 42 #include <applicfg.h>
sam_grove 0:9dd7c6129683 43
sam_grove 0:9dd7c6129683 44
sam_grove 0:9dd7c6129683 45 #ifdef __cplusplus
sam_grove 0:9dd7c6129683 46 extern "C" {
sam_grove 0:9dd7c6129683 47 #endif
sam_grove 0:9dd7c6129683 48
sam_grove 0:9dd7c6129683 49
sam_grove 0:9dd7c6129683 50 typedef UNS32 (*valueRangeTest_t)(UNS8 typeValue, void *Value);
sam_grove 0:9dd7c6129683 51 typedef void (* storeODSubIndex_t)(CO_Data* d, UNS16 wIndex, UNS8 bSubindex);
sam_grove 0:9dd7c6129683 52 void _storeODSubIndex (CO_Data* d, UNS16 wIndex, UNS8 bSubindex);
sam_grove 0:9dd7c6129683 53
sam_grove 0:9dd7c6129683 54 /**
sam_grove 0:9dd7c6129683 55 * @brief Print MSG_WAR (s) if error to the access to the object dictionary occurs.
sam_grove 0:9dd7c6129683 56 *
sam_grove 0:9dd7c6129683 57 * You must uncomment the lines in the file objaccess.c :\n
sam_grove 0:9dd7c6129683 58 * //#define DEBUG_CAN\n
sam_grove 0:9dd7c6129683 59 * //#define DEBUG_WAR_CONSOLE_ON\n
sam_grove 0:9dd7c6129683 60 * //#define DEBUG_ERR_CONSOLE_ON\n\n
sam_grove 0:9dd7c6129683 61 * Beware that sometimes, we force the sizeDataDict or sizeDataGiven to 0, when we wants to use
sam_grove 0:9dd7c6129683 62 * this function but we do not have the access to the right value. One example is
sam_grove 0:9dd7c6129683 63 * getSDOerror(). So do not take attention to these variables if they are null.
sam_grove 0:9dd7c6129683 64 * @param index
sam_grove 0:9dd7c6129683 65 * @param subIndex
sam_grove 0:9dd7c6129683 66 * @param sizeDataDict Size of the data defined in the dictionary
sam_grove 0:9dd7c6129683 67 * @param sizeDataGiven Size data given by the user.
sam_grove 0:9dd7c6129683 68 * @param code error code to print. (SDO abort code. See file def.h)
sam_grove 0:9dd7c6129683 69 * @return
sam_grove 0:9dd7c6129683 70 */
sam_grove 0:9dd7c6129683 71 UNS8 accessDictionaryError(UNS16 index, UNS8 subIndex,
sam_grove 0:9dd7c6129683 72 UNS32 sizeDataDict, UNS32 sizeDataGiven, UNS32 code);
sam_grove 0:9dd7c6129683 73
sam_grove 0:9dd7c6129683 74
sam_grove 0:9dd7c6129683 75 /* _getODentry() Reads an entry from the object dictionary.\n
sam_grove 0:9dd7c6129683 76 *
sam_grove 0:9dd7c6129683 77 * use getODentry() macro to read from object and endianize
sam_grove 0:9dd7c6129683 78 * use readLocalDict() macro to read from object and not endianize
sam_grove 0:9dd7c6129683 79 *
sam_grove 0:9dd7c6129683 80 * @code
sam_grove 0:9dd7c6129683 81 * // Example usage:
sam_grove 0:9dd7c6129683 82 * UNS8 *pbData;
sam_grove 0:9dd7c6129683 83 * UNS8 length;
sam_grove 0:9dd7c6129683 84 * UNS32 returnValue;
sam_grove 0:9dd7c6129683 85 *
sam_grove 0:9dd7c6129683 86 * returnValue = getODentry( (UNS16)0x100B, (UNS8)1,
sam_grove 0:9dd7c6129683 87 * (void * *)&pbData, (UNS8 *)&length );
sam_grove 0:9dd7c6129683 88 * if( returnValue != SUCCESSFUL )
sam_grove 0:9dd7c6129683 89 * {
sam_grove 0:9dd7c6129683 90 * // error handling
sam_grove 0:9dd7c6129683 91 * }
sam_grove 0:9dd7c6129683 92 * @endcode
sam_grove 0:9dd7c6129683 93 * @param *d Pointer to a CAN object data structure
sam_grove 0:9dd7c6129683 94 * @param wIndex The index in the object dictionary where you want to read
sam_grove 0:9dd7c6129683 95 * an entry
sam_grove 0:9dd7c6129683 96 * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is
sam_grove 0:9dd7c6129683 97 * used to tell you how many valid entries you can find
sam_grove 0:9dd7c6129683 98 * in this index. Look at the canopen standard for further
sam_grove 0:9dd7c6129683 99 * information
sam_grove 0:9dd7c6129683 100 * @param *pDestData Pointer to the pointer which points to the variable where
sam_grove 0:9dd7c6129683 101 * the value of this object dictionary entry should be copied
sam_grove 0:9dd7c6129683 102 * @param pExpectedSize This function writes the size of the copied value (in Byte)
sam_grove 0:9dd7c6129683 103 * into this variable.
sam_grove 0:9dd7c6129683 104 * @param *pDataType Pointer to the type of the data. See objdictdef.h
sam_grove 0:9dd7c6129683 105 * @param CheckAccess if other than 0, do not read if the data is Write Only
sam_grove 0:9dd7c6129683 106 * [Not used today. Put always 0].
sam_grove 0:9dd7c6129683 107 * @param Endianize When not 0, data is endianized into network byte order
sam_grove 0:9dd7c6129683 108 * when 0, data is not endianized and copied in machine native
sam_grove 0:9dd7c6129683 109 * endianness
sam_grove 0:9dd7c6129683 110 * @return
sam_grove 0:9dd7c6129683 111 * - OD_SUCCESSFUL is returned upon success.
sam_grove 0:9dd7c6129683 112 * - SDO abort code is returned if error occurs . (See file def.h)
sam_grove 0:9dd7c6129683 113 */
sam_grove 0:9dd7c6129683 114 UNS32 _getODentry( CO_Data* d,
sam_grove 0:9dd7c6129683 115 UNS16 wIndex,
sam_grove 0:9dd7c6129683 116 UNS8 bSubindex,
sam_grove 0:9dd7c6129683 117 void * pDestData,
sam_grove 0:9dd7c6129683 118 UNS32 * pExpectedSize,
sam_grove 0:9dd7c6129683 119 UNS8 * pDataType,
sam_grove 0:9dd7c6129683 120 UNS8 checkAccess,
sam_grove 0:9dd7c6129683 121 UNS8 endianize);
sam_grove 0:9dd7c6129683 122
sam_grove 0:9dd7c6129683 123 /**
sam_grove 0:9dd7c6129683 124 * @ingroup od
sam_grove 0:9dd7c6129683 125 * @brief getODentry() to read from object and endianize
sam_grove 0:9dd7c6129683 126 * @param OD Pointer to a CAN object data structure
sam_grove 0:9dd7c6129683 127 * @param wIndex The index in the object dictionary where you want to read
sam_grove 0:9dd7c6129683 128 * an entry
sam_grove 0:9dd7c6129683 129 * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is
sam_grove 0:9dd7c6129683 130 * used to tell you how many valid entries you can find
sam_grove 0:9dd7c6129683 131 * in this index. Look at the canopen standard for further
sam_grove 0:9dd7c6129683 132 * information
sam_grove 0:9dd7c6129683 133 * @param *pDestData Pointer to the pointer which points to the variable where
sam_grove 0:9dd7c6129683 134 * the value of this object dictionary entry should be copied
sam_grove 0:9dd7c6129683 135 * @param pExpectedSize This function writes the size of the copied value (in Byte)
sam_grove 0:9dd7c6129683 136 * into this variable.
sam_grove 0:9dd7c6129683 137 * @param *pDataType Pointer to the type of the data. See objdictdef.h
sam_grove 0:9dd7c6129683 138 * @param checkAccess Flag that indicate if a check rights must be perfomed (0 : no , other than 0 : yes)
sam_grove 0:9dd7c6129683 139 * @param endianize Set to 1 : endianized into network byte order
sam_grove 0:9dd7c6129683 140 * @return
sam_grove 0:9dd7c6129683 141 * - OD_SUCCESSFUL is returned upon success.
sam_grove 0:9dd7c6129683 142 * - SDO abort code is returned if error occurs . (See file def.h)
sam_grove 0:9dd7c6129683 143 */
sam_grove 0:9dd7c6129683 144 #define getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \
sam_grove 0:9dd7c6129683 145 pDataType, checkAccess) \
sam_grove 0:9dd7c6129683 146 _getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \
sam_grove 0:9dd7c6129683 147 pDataType, checkAccess, 1)
sam_grove 0:9dd7c6129683 148
sam_grove 0:9dd7c6129683 149 /**
sam_grove 0:9dd7c6129683 150 * @ingroup od
sam_grove 0:9dd7c6129683 151 * @brief readLocalDict() reads an entry from the object dictionary, but in
sam_grove 0:9dd7c6129683 152 * contrast to getODentry(), readLocalDict() doesn't endianize entry and reads
sam_grove 0:9dd7c6129683 153 * entry in machine native endianness.
sam_grove 0:9dd7c6129683 154 * @param OD Pointer to a CAN object data structure
sam_grove 0:9dd7c6129683 155 * @param wIndex The index in the object dictionary where you want to read
sam_grove 0:9dd7c6129683 156 * an entry
sam_grove 0:9dd7c6129683 157 * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is
sam_grove 0:9dd7c6129683 158 * used to tell you how many valid entries you can find
sam_grove 0:9dd7c6129683 159 * in this index. Look at the canopen standard for further
sam_grove 0:9dd7c6129683 160 * information
sam_grove 0:9dd7c6129683 161 * @param *pDestData Pointer to the pointer which points to the variable where
sam_grove 0:9dd7c6129683 162 * the value of this object dictionary entry should be copied
sam_grove 0:9dd7c6129683 163 * @param pExpectedSize This function writes the size of the copied value (in Byte)
sam_grove 0:9dd7c6129683 164 * into this variable.
sam_grove 0:9dd7c6129683 165 * @param *pDataType Pointer to the type of the data. See objdictdef.h
sam_grove 0:9dd7c6129683 166 * @param checkAccess if other than 0, do not read if the data is Write Only
sam_grove 0:9dd7c6129683 167 * [Not used today. Put always 0].
sam_grove 0:9dd7c6129683 168 * @param endianize Set to 0, data is not endianized and copied in machine native
sam_grove 0:9dd7c6129683 169 * endianness
sam_grove 0:9dd7c6129683 170 * @return
sam_grove 0:9dd7c6129683 171 * - OD_SUCCESSFUL is returned upon success.
sam_grove 0:9dd7c6129683 172 * - SDO abort code is returned if error occurs . (See file def.h)
sam_grove 0:9dd7c6129683 173 */
sam_grove 0:9dd7c6129683 174 #define readLocalDict( OD, wIndex, bSubindex, pDestData, pExpectedSize, \
sam_grove 0:9dd7c6129683 175 pDataType, checkAccess) \
sam_grove 0:9dd7c6129683 176 _getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \
sam_grove 0:9dd7c6129683 177 pDataType, checkAccess, 0)
sam_grove 0:9dd7c6129683 178
sam_grove 0:9dd7c6129683 179 /* By this function you can write an entry into the object dictionary
sam_grove 0:9dd7c6129683 180 * @param *d Pointer to a CAN object data structure
sam_grove 0:9dd7c6129683 181 * @param wIndex The index in the object dictionary where you want to write
sam_grove 0:9dd7c6129683 182 * an entry
sam_grove 0:9dd7c6129683 183 * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is
sam_grove 0:9dd7c6129683 184 * used to tell you how many valid entries you can find
sam_grove 0:9dd7c6129683 185 * in this index. Look at the canopen standard for further
sam_grove 0:9dd7c6129683 186 * information
sam_grove 0:9dd7c6129683 187 * @param *pSourceData Pointer to the variable that holds the value that should
sam_grove 0:9dd7c6129683 188 * be copied into the object dictionary
sam_grove 0:9dd7c6129683 189 * @param *pExpectedSize The size of the value (in Byte).
sam_grove 0:9dd7c6129683 190 * @param checkAccess Flag that indicate if a check rights must be perfomed (0 : no , other than 0 : yes)
sam_grove 0:9dd7c6129683 191 * @param endianize When not 0, data is endianized into network byte order
sam_grove 0:9dd7c6129683 192 * when 0, data is not endianized and copied in machine native
sam_grove 0:9dd7c6129683 193 * endianness
sam_grove 0:9dd7c6129683 194 * @return
sam_grove 0:9dd7c6129683 195 * - OD_SUCCESSFUL is returned upon success.
sam_grove 0:9dd7c6129683 196 * - SDO abort code is returned if error occurs . (See file def.h)
sam_grove 0:9dd7c6129683 197 */
sam_grove 0:9dd7c6129683 198 UNS32 _setODentry( CO_Data* d,
sam_grove 0:9dd7c6129683 199 UNS16 wIndex,
sam_grove 0:9dd7c6129683 200 UNS8 bSubindex,
sam_grove 0:9dd7c6129683 201 void * pSourceData,
sam_grove 0:9dd7c6129683 202 UNS32 * pExpectedSize,
sam_grove 0:9dd7c6129683 203 UNS8 checkAccess,
sam_grove 0:9dd7c6129683 204 UNS8 endianize);
sam_grove 0:9dd7c6129683 205
sam_grove 0:9dd7c6129683 206 /**
sam_grove 0:9dd7c6129683 207 * @ingroup od
sam_grove 0:9dd7c6129683 208 * @brief setODentry converts SourceData from network byte order to machine native
sam_grove 0:9dd7c6129683 209 * format, and writes that to OD.
sam_grove 0:9dd7c6129683 210 * @code
sam_grove 0:9dd7c6129683 211 * // Example usage:
sam_grove 0:9dd7c6129683 212 * UNS8 B;
sam_grove 0:9dd7c6129683 213 * B = 0xFF; // set transmission type
sam_grove 0:9dd7c6129683 214 *
sam_grove 0:9dd7c6129683 215 * retcode = setODentry( (UNS16)0x1800, (UNS8)2, &B, sizeof(UNS8), 1 );
sam_grove 0:9dd7c6129683 216 * @endcode
sam_grove 0:9dd7c6129683 217 * @param d Pointer to a CAN object data structure
sam_grove 0:9dd7c6129683 218 * @param wIndex The index in the object dictionary where you want to write
sam_grove 0:9dd7c6129683 219 * an entry
sam_grove 0:9dd7c6129683 220 * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is
sam_grove 0:9dd7c6129683 221 * used to tell you how many valid entries you can find
sam_grove 0:9dd7c6129683 222 * in this index. Look at the canopen standard for further
sam_grove 0:9dd7c6129683 223 * information
sam_grove 0:9dd7c6129683 224 * @param *pSourceData Pointer to the variable that holds the value that should
sam_grove 0:9dd7c6129683 225 * be copied into the object dictionary
sam_grove 0:9dd7c6129683 226 * @param *pExpectedSize The size of the value (in Byte).
sam_grove 0:9dd7c6129683 227 * @param checkAccess Flag that indicate if a check rights must be perfomed (0 : no , other than 0 : yes)
sam_grove 0:9dd7c6129683 228 * @param endianize Set to 1 : endianized into network byte order
sam_grove 0:9dd7c6129683 229 * @return
sam_grove 0:9dd7c6129683 230 * - OD_SUCCESSFUL is returned upon success.
sam_grove 0:9dd7c6129683 231 * - SDO abort code is returned if error occurs . (See file def.h)
sam_grove 0:9dd7c6129683 232 */
sam_grove 0:9dd7c6129683 233 #define setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, \
sam_grove 0:9dd7c6129683 234 checkAccess) \
sam_grove 0:9dd7c6129683 235 _setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, \
sam_grove 0:9dd7c6129683 236 checkAccess, 1)
sam_grove 0:9dd7c6129683 237
sam_grove 0:9dd7c6129683 238 /** @fn UNS32 writeLocalDict(d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess)
sam_grove 0:9dd7c6129683 239 * @ingroup od
sam_grove 0:9dd7c6129683 240 * @hideinitializer
sam_grove 0:9dd7c6129683 241 * @brief Writes machine native SourceData to OD.
sam_grove 0:9dd7c6129683 242 * @param d Pointer to a CAN object data structure
sam_grove 0:9dd7c6129683 243 * @param wIndex The index in the object dictionary where you want to write
sam_grove 0:9dd7c6129683 244 * an entry
sam_grove 0:9dd7c6129683 245 * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is
sam_grove 0:9dd7c6129683 246 * used to tell you how many valid entries you can find
sam_grove 0:9dd7c6129683 247 * in this index. Look at the canopen standard for further
sam_grove 0:9dd7c6129683 248 * information
sam_grove 0:9dd7c6129683 249 * @param *pSourceData Pointer to the variable that holds the value that should
sam_grove 0:9dd7c6129683 250 * be copied into the object dictionary
sam_grove 0:9dd7c6129683 251 * @param *pExpectedSize The size of the value (in Byte).
sam_grove 0:9dd7c6129683 252 * @param checkAccess Flag that indicate if a check rights must be perfomed (0 : no , other than 0 : yes)
sam_grove 0:9dd7c6129683 253 * @param endianize Data is not endianized and copied in machine native endianness
sam_grove 0:9dd7c6129683 254 * @return
sam_grove 0:9dd7c6129683 255 * - OD_SUCCESSFUL is returned upon success.
sam_grove 0:9dd7c6129683 256 * - SDO abort code is returned if error occurs . (See file def.h)
sam_grove 0:9dd7c6129683 257 * \n\n
sam_grove 0:9dd7c6129683 258 * @code
sam_grove 0:9dd7c6129683 259 * // Example usage:
sam_grove 0:9dd7c6129683 260 * UNS8 B;
sam_grove 0:9dd7c6129683 261 * B = 0xFF; // set transmission type
sam_grove 0:9dd7c6129683 262 *
sam_grove 0:9dd7c6129683 263 * retcode = writeLocalDict( (UNS16)0x1800, (UNS8)2, &B, sizeof(UNS8), 1 );
sam_grove 0:9dd7c6129683 264 * @endcode
sam_grove 0:9dd7c6129683 265 */
sam_grove 0:9dd7c6129683 266 #define writeLocalDict( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess) \
sam_grove 0:9dd7c6129683 267 _setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess, 0)
sam_grove 0:9dd7c6129683 268
sam_grove 0:9dd7c6129683 269
sam_grove 0:9dd7c6129683 270
sam_grove 0:9dd7c6129683 271 /**
sam_grove 0:9dd7c6129683 272 * @brief Scan the index of object dictionary. Used only by setODentry and getODentry.
sam_grove 0:9dd7c6129683 273 * @param *d Pointer to a CAN object data structure
sam_grove 0:9dd7c6129683 274 * @param wIndex
sam_grove 0:9dd7c6129683 275 * @param *errorCode : OD_SUCCESSFUL if index foundor SDO abort code. (See file def.h)
sam_grove 0:9dd7c6129683 276 * @param **Callback
sam_grove 0:9dd7c6129683 277 * @return NULL if index not found. Else : return the table part of the object dictionary.
sam_grove 0:9dd7c6129683 278 */
sam_grove 0:9dd7c6129683 279 const indextable * scanIndexOD (CO_Data* d, UNS16 wIndex, UNS32 *errorCode, ODCallback_t **Callback);
sam_grove 0:9dd7c6129683 280
sam_grove 0:9dd7c6129683 281 UNS32 RegisterSetODentryCallBack(CO_Data* d, UNS16 wIndex, UNS8 bSubindex, ODCallback_t Callback);
sam_grove 0:9dd7c6129683 282
sam_grove 0:9dd7c6129683 283 #ifdef __cplusplus
sam_grove 0:9dd7c6129683 284 }
sam_grove 0:9dd7c6129683 285 #endif
sam_grove 0:9dd7c6129683 286
sam_grove 0:9dd7c6129683 287 #endif /* __objacces_h__ */