2 This file is part of CanFestival, a library implementing CanOpen Stack.
4 Copyright (C): Edouard TISSERANT and Francis DUPIN
6 See COPYING file for copyrights details.
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * @brief Responsible for accessing the object dictionary.
26 * This file contains functions for accessing the object dictionary and
27 * variables that are contained by the object dictionary.
28 * Accessing the object dictionary contains setting local variables
29 * as PDOs and accessing (read/write) all entries of the object dictionary
30 * @warning Only the basic entries of an object dictionary are included
34 /** @defgroup od Object Dictionary Management
38 #ifndef __objacces_h__
39 #define __objacces_h__
43 typedef UNS32 (*valueRangeTest_t)(UNS8 typeValue, void *Value);
44 typedef void (* storeODSubIndex_t)(CO_Data* d, UNS16 wIndex, UNS8 bSubindex);
45 void _storeODSubIndex (CO_Data* d, UNS16 wIndex, UNS8 bSubindex);
49 * @brief Print MSG_WAR (s) if error to the access to the object dictionary occurs.
51 * You must uncomment the lines in the file objaccess.c :\n
52 * //#define DEBUG_CAN\n
53 * //#define DEBUG_WAR_CONSOLE_ON\n
54 * //#define DEBUG_ERR_CONSOLE_ON\n\n
55 * Beware that sometimes, we force the sizeDataDict or sizeDataGiven to 0, when we wants to use
56 * this function but we do not have the access to the right value. One example is
57 * getSDOerror(). So do not take attention to these variables if they are null.
60 * @param sizeDataDict Size of the data defined in the dictionary
61 * @param sizeDataGiven Size data given by the user.
62 * @param code error code to print. (SDO abort code. See file def.h)
65 UNS8 accessDictionaryError(UNS16 index, UNS8 subIndex,
66 UNS8 sizeDataDict, UNS8 sizeDataGiven, UNS32 code);
69 /* _getODentry() Reads an entry from the object dictionary.\n
71 * use getODentry() macro to read from object and endianize
72 * use readLocalDict() macro to read from object and not endianize
80 * returnValue = getODentry( (UNS16)0x100B, (UNS8)1,
81 * (void * *)&pbData, (UNS8 *)&length );
82 * if( returnValue != SUCCESSFUL )
87 * @param *d Pointer on a CAN object data structure
88 * @param wIndex The index in the object dictionary where you want to read
90 * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is
91 * used to tell you how many valid entries you can find
92 * in this index. Look at the canopen standard for further
94 * @param *pDestData Pointer to the pointer which points to the variable where
95 * the value of this object dictionary entry should be copied
96 * @param pExpectedSize This function writes the size of the copied value (in Byte)
98 * @param *pDataType Pointer on the type of the data. See objdictdef.h
99 * @param CheckAccess if other than 0, do not read if the data is Write Only
100 * [Not used today. Put always 0].
101 * @param Endianize When not 0, data is endianized into network byte order
102 * when 0, data is not endianized and copied in machine native
104 * @return OD_SUCCESSFUL or SDO abort code. (See file def.h)
106 UNS32 _getODentry( CO_Data* d,
110 UNS8 * pExpectedSize,
117 * @brief getODentry() to read from object and endianize
118 * @param OD Pointer on a CAN object data structure
119 * @param wIndex The index in the object dictionary where you want to read
121 * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is
122 * used to tell you how many valid entries you can find
123 * in this index. Look at the canopen standard for further
125 * @param *pDestData Pointer to the pointer which points to the variable where
126 * the value of this object dictionary entry should be copied
127 * @param pExpectedSize This function writes the size of the copied value (in Byte)
128 * into this variable.
129 * @param *pDataType Pointer on the type of the data. See objdictdef.h
130 * @param checkAccess if other than 0, do not read if the data is Write Only
131 * [Not used today. Put always 0].
132 * @param endianize Set to 1 : endianized into network byte order
133 * @return OD_SUCCESSFUL or SDO abort code. (See file def.h)
135 #define getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \
136 pDataType, checkAccess) \
137 _getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \
138 pDataType, checkAccess, 1)
142 * @brief readLocalDict() reads an entry from the object dictionary, but in
143 * contrast to getODentry(), readLocalDict() doesn't endianize entry and reads
144 * entry in machine native endianness.
145 * @param OD Pointer on a CAN object data structure
146 * @param wIndex The index in the object dictionary where you want to read
148 * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is
149 * used to tell you how many valid entries you can find
150 * in this index. Look at the canopen standard for further
152 * @param *pDestData Pointer to the pointer which points to the variable where
153 * the value of this object dictionary entry should be copied
154 * @param pExpectedSize This function writes the size of the copied value (in Byte)
155 * into this variable.
156 * @param *pDataType Pointer on the type of the data. See objdictdef.h
157 * @param checkAccess if other than 0, do not read if the data is Write Only
158 * [Not used today. Put always 0].
159 * @param endianize Set to 0, data is not endianized and copied in machine native
161 * @return OD_SUCCESSFUL or SDO abort code. (See file def.h)
163 #define readLocalDict( OD, wIndex, bSubindex, pDestData, pExpectedSize, \
164 pDataType, checkAccess) \
165 _getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \
166 pDataType, checkAccess, 0)
169 * @brief By this function you can write an entry into the object dictionary
170 * @param *d Pointer on a CAN object data structure
171 * @param wIndex The index in the object dictionary where you want to write
173 * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is
174 * used to tell you how many valid entries you can find
175 * in this index. Look at the canopen standard for further
177 * @param *pSourceData Pointer to the variable that holds the value that should
178 * be copied into the object dictionary
179 * @param *pExpectedSize The size of the value (in Byte).
180 * @param checkAccess if other than 0, do not read if the data is Read Only or Constant
181 * @param endianize When not 0, data is endianized into network byte order
182 * when 0, data is not endianized and copied in machine native
184 * @return OD_SUCCESSFUL or SDO abort code. (See file def.h)
186 UNS32 _setODentry( CO_Data* d,
190 UNS8 * pExpectedSize,
196 * @brief setODentry converts SourceData from network byte order to machine native
197 * format, and writes that to OD.
201 * B = 0xFF; // set transmission type
203 * retcode = setODentry( (UNS16)0x1800, (UNS8)2, &B, sizeof(UNS8), 1 );
205 * @param d Pointer on a CAN object data structure
206 * @param wIndex The index in the object dictionary where you want to write
208 * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is
209 * used to tell you how many valid entries you can find
210 * in this index. Look at the canopen standard for further
212 * @param *pSourceData Pointer to the variable that holds the value that should
213 * be copied into the object dictionary
214 * @param *pExpectedSize The size of the value (in Byte).
215 * @param checkAccess if other than 0, do not read if the data is Read Only or Constant
216 * @param endianize Set to 1 : endianized into network byte order
217 * @return OD_SUCCESSFUL or SDO abort code. (See file def.h)
219 #define setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess) \
220 _setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess, 1)
224 * @brief Writes machine native SourceData to OD.
228 * B = 0xFF; // set transmission type
230 * retcode = writeLocalDict( (UNS16)0x1800, (UNS8)2, &B, sizeof(UNS8), 1 );
232 * @param d Pointer on a CAN object data structure
233 * @param wIndex The index in the object dictionary where you want to write
235 * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is
236 * used to tell you how many valid entries you can find
237 * in this index. Look at the canopen standard for further
239 * @param *pSourceData Pointer to the variable that holds the value that should
240 * be copied into the object dictionary
241 * @param *pExpectedSize The size of the value (in Byte).
242 * @param checkAccess if other than 0, do not read if the data is Read Only or Constant
243 * @param endianize Data is not endianized and copied in machine native endianness
244 * @return OD_SUCCESSFUL or SDO abort code. (See file def.h)
246 #define writeLocalDict( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess) \
247 _setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess, 0)
252 * @brief Scan the index of object dictionary. Used only by setODentry and getODentry.
253 * @param *d Pointer on a CAN object data structure
255 * @param *errorCode : OD_SUCCESSFUL if index foundor SDO abort code. (See file def.h)
257 * @return NULL if index not found. Else : return the table part of the object dictionary.
259 const indextable * scanIndexOD (CO_Data* d, UNS16 wIndex, UNS32 *errorCode, ODCallback_t **Callback);
261 UNS32 RegisterSetODentryCallBack(CO_Data* d, UNS16 wIndex, UNS8 bSubindex, ODCallback_t Callback);
263 #endif /* __objacces_h__ */