| 1 | /**************************************************************************** |
| 2 | |
| 3 | (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29 |
| 4 | www.systec-electronic.com |
| 5 | |
| 6 | Project: openPOWERLINK |
| 7 | |
| 8 | Description: source file for Epl-Obd-Userspace-module |
| 9 | |
| 10 | License: |
| 11 | |
| 12 | Redistribution and use in source and binary forms, with or without |
| 13 | modification, are permitted provided that the following conditions |
| 14 | are met: |
| 15 | |
| 16 | 1. Redistributions of source code must retain the above copyright |
| 17 | notice, this list of conditions and the following disclaimer. |
| 18 | |
| 19 | 2. Redistributions in binary form must reproduce the above copyright |
| 20 | notice, this list of conditions and the following disclaimer in the |
| 21 | documentation and/or other materials provided with the distribution. |
| 22 | |
| 23 | 3. Neither the name of SYSTEC electronic GmbH nor the names of its |
| 24 | contributors may be used to endorse or promote products derived |
| 25 | from this software without prior written permission. For written |
| 26 | permission, please contact info@systec-electronic.com. |
| 27 | |
| 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 29 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 30 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 31 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 32 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 33 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 34 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 35 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 36 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 37 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 38 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 39 | POSSIBILITY OF SUCH DAMAGE. |
| 40 | |
| 41 | Severability Clause: |
| 42 | |
| 43 | If a provision of this License is or becomes illegal, invalid or |
| 44 | unenforceable in any jurisdiction, that shall not affect: |
| 45 | 1. the validity or enforceability in that jurisdiction of any other |
| 46 | provision of this License; or |
| 47 | 2. the validity or enforceability in other jurisdictions of that or |
| 48 | any other provision of this License. |
| 49 | |
| 50 | ------------------------------------------------------------------------- |
| 51 | |
| 52 | $RCSfile: EplObdu.c,v $ |
| 53 | |
| 54 | $Author: D.Krueger $ |
| 55 | |
| 56 | $Revision: 1.5 $ $Date: 2008/10/17 15:32:32 $ |
| 57 | |
| 58 | $State: Exp $ |
| 59 | |
| 60 | Build Environment: |
| 61 | GCC V3.4 |
| 62 | |
| 63 | ------------------------------------------------------------------------- |
| 64 | |
| 65 | Revision History: |
| 66 | |
| 67 | 2006/06/19 k.t.: start of the implementation |
| 68 | |
| 69 | ****************************************************************************/ |
| 70 | |
| 71 | #include "EplInc.h" |
| 72 | #include "user/EplObdu.h" |
| 73 | #include "user/EplObduCal.h" |
| 74 | |
| 75 | #if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDU)) != 0) |
| 76 | /***************************************************************************/ |
| 77 | /* */ |
| 78 | /* */ |
| 79 | /* G L O B A L D E F I N I T I O N S */ |
| 80 | /* */ |
| 81 | /* */ |
| 82 | /***************************************************************************/ |
| 83 | |
| 84 | //--------------------------------------------------------------------------- |
| 85 | // const defines |
| 86 | //--------------------------------------------------------------------------- |
| 87 | |
| 88 | //--------------------------------------------------------------------------- |
| 89 | // local types |
| 90 | //--------------------------------------------------------------------------- |
| 91 | |
| 92 | //--------------------------------------------------------------------------- |
| 93 | // modul globale vars |
| 94 | //--------------------------------------------------------------------------- |
| 95 | |
| 96 | //--------------------------------------------------------------------------- |
| 97 | // local function prototypes |
| 98 | //--------------------------------------------------------------------------- |
| 99 | |
| 100 | //=========================================================================// |
| 101 | // // |
| 102 | // P U B L I C F U N C T I O N S // |
| 103 | // // |
| 104 | //=========================================================================// |
| 105 | |
| 106 | //--------------------------------------------------------------------------- |
| 107 | // |
| 108 | // Function: EplObduWriteEntry() |
| 109 | // |
| 110 | // Description: Function writes data to an OBD entry. Strings |
| 111 | // are stored with added '\0' character. |
| 112 | // |
| 113 | // Parameters: uiIndex_p = Index of the OD entry |
| 114 | // uiSubIndex_p = Subindex of the OD Entry |
| 115 | // pSrcData_p = Pointer to the data to write |
| 116 | // Size_p = Size of the data in Byte |
| 117 | // |
| 118 | // Return: tEplKernel = Errorcode |
| 119 | // |
| 120 | // |
| 121 | // State: |
| 122 | // |
| 123 | //--------------------------------------------------------------------------- |
| 124 | EPLDLLEXPORT tEplKernel PUBLIC EplObduWriteEntry(unsigned int uiIndex_p, |
| 125 | unsigned int uiSubIndex_p, |
| 126 | void *pSrcData_p, |
| 127 | tEplObdSize Size_p) |
| 128 | { |
| 129 | tEplKernel Ret; |
| 130 | |
| 131 | Ret = EplObduCalWriteEntry(uiIndex_p, uiSubIndex_p, pSrcData_p, Size_p); |
| 132 | |
| 133 | return Ret; |
| 134 | } |
| 135 | |
| 136 | //--------------------------------------------------------------------------- |
| 137 | // |
| 138 | // Function: EplObduReadEntry() |
| 139 | // |
| 140 | // Description: The function reads an object entry. The application |
| 141 | // can always read the data even if attrib kEplObdAccRead |
| 142 | // is not set. The attrib is only checked up for SDO transfer. |
| 143 | // |
| 144 | // Parameters: uiIndex_p = Index oof the OD entry to read |
| 145 | // uiSubIndex_p = Subindex to read |
| 146 | // pDstData_p = pointer to the buffer for data |
| 147 | // Offset_p = offset in data for read access |
| 148 | // pSize_p = IN: Size of the buffer |
| 149 | // OUT: number of readed Bytes |
| 150 | // |
| 151 | // Return: tEplKernel = errorcode |
| 152 | // |
| 153 | // State: |
| 154 | // |
| 155 | //--------------------------------------------------------------------------- |
| 156 | EPLDLLEXPORT tEplKernel PUBLIC EplObduReadEntry(unsigned int uiIndex_p, |
| 157 | unsigned int uiSubIndex_p, |
| 158 | void *pDstData_p, |
| 159 | tEplObdSize * pSize_p) |
| 160 | { |
| 161 | tEplKernel Ret; |
| 162 | |
| 163 | Ret = EplObduCalReadEntry(uiIndex_p, uiSubIndex_p, pDstData_p, pSize_p); |
| 164 | |
| 165 | return Ret; |
| 166 | } |
| 167 | |
| 168 | //--------------------------------------------------------------------------- |
| 169 | // |
| 170 | // Function: EplObdAccessOdPart() |
| 171 | // |
| 172 | // Description: restores default values of one part of OD |
| 173 | // |
| 174 | // Parameters: ObdPart_p = od-part to reset |
| 175 | // Direction_p = directory flag for |
| 176 | // |
| 177 | // Return: tEplKernel = errorcode |
| 178 | // |
| 179 | // State: |
| 180 | // |
| 181 | //--------------------------------------------------------------------------- |
| 182 | EPLDLLEXPORT tEplKernel PUBLIC EplObduAccessOdPart(tEplObdPart ObdPart_p, |
| 183 | tEplObdDir Direction_p) |
| 184 | { |
| 185 | tEplKernel Ret; |
| 186 | |
| 187 | Ret = EplObduCalAccessOdPart(ObdPart_p, Direction_p); |
| 188 | |
| 189 | return Ret; |
| 190 | } |
| 191 | |
| 192 | //--------------------------------------------------------------------------- |
| 193 | // |
| 194 | // Function: EplObduDefineVar() |
| 195 | // |
| 196 | // Description: defines a variable in OD |
| 197 | // |
| 198 | // Parameters: pEplVarParam_p = varentry |
| 199 | // |
| 200 | // Return: tEplKernel = errorcode |
| 201 | // |
| 202 | // State: |
| 203 | // |
| 204 | //--------------------------------------------------------------------------- |
| 205 | EPLDLLEXPORT tEplKernel PUBLIC EplObduDefineVar(tEplVarParam MEM * pVarParam_p) |
| 206 | { |
| 207 | tEplKernel Ret; |
| 208 | |
| 209 | Ret = EplObduCalDefineVar(pVarParam_p); |
| 210 | |
| 211 | return Ret; |
| 212 | } |
| 213 | |
| 214 | //--------------------------------------------------------------------------- |
| 215 | // |
| 216 | // Function: EplObduGetObjectDataPtr() |
| 217 | // |
| 218 | // Description: It returnes the current data pointer. But if object is an |
| 219 | // constant object it returnes the default pointer. |
| 220 | // |
| 221 | // Parameters: uiIndex_p = Index of the entry |
| 222 | // uiSubindex_p = Subindex of the entry |
| 223 | // |
| 224 | // Return: void * = pointer to object data |
| 225 | // |
| 226 | // State: |
| 227 | // |
| 228 | //--------------------------------------------------------------------------- |
| 229 | EPLDLLEXPORT void *PUBLIC EplObduGetObjectDataPtr(unsigned int uiIndex_p, |
| 230 | unsigned int uiSubIndex_p) |
| 231 | { |
| 232 | void *pData; |
| 233 | |
| 234 | pData = EplObduCalGetObjectDataPtr(uiIndex_p, uiSubIndex_p); |
| 235 | |
| 236 | return pData; |
| 237 | } |
| 238 | |
| 239 | //--------------------------------------------------------------------------- |
| 240 | // |
| 241 | // Function: EplObduRegisterUserOd() |
| 242 | // |
| 243 | // Description: function registers the user OD |
| 244 | // |
| 245 | // Parameters: pUserOd_p =pointer to user ODd |
| 246 | // |
| 247 | // Return: tEplKernel = errorcode |
| 248 | // |
| 249 | // State: |
| 250 | // |
| 251 | //--------------------------------------------------------------------------- |
| 252 | #if (defined (EPL_OBD_USER_OD) && (EPL_OBD_USER_OD != FALSE)) |
| 253 | EPLDLLEXPORT tEplKernel PUBLIC EplObduRegisterUserOd(tEplObdEntryPtr pUserOd_p) |
| 254 | { |
| 255 | tEplKernel Ret; |
| 256 | |
| 257 | Ret = EplObduCalRegisterUserOd(pUserOd_p); |
| 258 | |
| 259 | return Ret; |
| 260 | |
| 261 | } |
| 262 | #endif |
| 263 | //--------------------------------------------------------------------------- |
| 264 | // |
| 265 | // Function: EplObduInitVarEntry() |
| 266 | // |
| 267 | // Description: function to initialize VarEntry dependened on object type |
| 268 | // |
| 269 | // Parameters: pVarEntry_p = pointer to var entry structure |
| 270 | // bType_p = object type |
| 271 | // ObdSize_p = size of object data |
| 272 | // |
| 273 | // Returns: none |
| 274 | // |
| 275 | // State: |
| 276 | // |
| 277 | //--------------------------------------------------------------------------- |
| 278 | EPLDLLEXPORT void PUBLIC EplObduInitVarEntry(tEplObdVarEntry MEM * pVarEntry_p, |
| 279 | BYTE bType_p, |
| 280 | tEplObdSize ObdSize_p) |
| 281 | { |
| 282 | EplObduCalInitVarEntry(pVarEntry_p, bType_p, ObdSize_p); |
| 283 | } |
| 284 | |
| 285 | //--------------------------------------------------------------------------- |
| 286 | // |
| 287 | // Function: EplObduGetDataSize() |
| 288 | // |
| 289 | // Description: function to initialize VarEntry dependened on object type |
| 290 | // |
| 291 | // gets the data size of an object |
| 292 | // for string objects it returnes the string length |
| 293 | // |
| 294 | // Parameters: uiIndex_p = Index |
| 295 | // uiSubIndex_p= Subindex |
| 296 | // |
| 297 | // Return: tEplObdSize |
| 298 | // |
| 299 | // State: |
| 300 | // |
| 301 | //--------------------------------------------------------------------------- |
| 302 | EPLDLLEXPORT tEplObdSize PUBLIC EplObduGetDataSize(unsigned int uiIndex_p, |
| 303 | unsigned int uiSubIndex_p) |
| 304 | { |
| 305 | tEplObdSize Size; |
| 306 | |
| 307 | Size = EplObduCalGetDataSize(uiIndex_p, uiSubIndex_p); |
| 308 | |
| 309 | return Size; |
| 310 | } |
| 311 | |
| 312 | //--------------------------------------------------------------------------- |
| 313 | // |
| 314 | // Function: EplObduGetNodeId() |
| 315 | // |
| 316 | // Description: function returns nodeid from entry 0x1F93 |
| 317 | // |
| 318 | // |
| 319 | // Parameters: |
| 320 | // |
| 321 | // Return: unsigned int = Node Id |
| 322 | // |
| 323 | // State: |
| 324 | // |
| 325 | //--------------------------------------------------------------------------- |
| 326 | EPLDLLEXPORT unsigned int PUBLIC EplObduGetNodeId() |
| 327 | { |
| 328 | unsigned int uiNodeId; |
| 329 | |
| 330 | uiNodeId = EplObduCalGetNodeId(); |
| 331 | |
| 332 | return uiNodeId; |
| 333 | } |
| 334 | |
| 335 | //--------------------------------------------------------------------------- |
| 336 | // |
| 337 | // Function: EplObduSetNodeId() |
| 338 | // |
| 339 | // Description: function sets nodeid in entry 0x1F93 |
| 340 | // |
| 341 | // |
| 342 | // Parameters: uiNodeId_p = Node Id to set |
| 343 | // NodeIdType_p= Type on which way the Node Id was set |
| 344 | // |
| 345 | // Return: tEplKernel = Errorcode |
| 346 | // |
| 347 | // State: |
| 348 | // |
| 349 | //--------------------------------------------------------------------------- |
| 350 | EPLDLLEXPORT tEplKernel PUBLIC EplObduSetNodeId(unsigned int uiNodeId_p, |
| 351 | tEplObdNodeIdType NodeIdType_p) |
| 352 | { |
| 353 | tEplKernel Ret; |
| 354 | |
| 355 | Ret = EplObduCalSetNodeId(uiNodeId_p, NodeIdType_p); |
| 356 | |
| 357 | return Ret; |
| 358 | } |
| 359 | |
| 360 | //--------------------------------------------------------------------------- |
| 361 | // |
| 362 | // Function: EplObduGetAccessType() |
| 363 | // |
| 364 | // Description: Function returns accesstype of the entry |
| 365 | // |
| 366 | // Parameters: uiIndex_p = Index of the OD entry |
| 367 | // uiSubIndex_p = Subindex of the OD Entry |
| 368 | // pAccessTyp_p = pointer to buffer to store accesstyp |
| 369 | // |
| 370 | // Return: tEplKernel = Errorcode |
| 371 | // |
| 372 | // |
| 373 | // State: |
| 374 | // |
| 375 | //--------------------------------------------------------------------------- |
| 376 | EPLDLLEXPORT tEplKernel PUBLIC EplObduGetAccessType(unsigned int uiIndex_p, |
| 377 | unsigned int uiSubIndex_p, |
| 378 | tEplObdAccess * |
| 379 | pAccessTyp_p) |
| 380 | { |
| 381 | tEplObdAccess AccessType; |
| 382 | |
| 383 | AccessType = |
| 384 | EplObduCalGetAccessType(uiIndex_p, uiSubIndex_p, pAccessTyp_p); |
| 385 | |
| 386 | return AccessType; |
| 387 | } |
| 388 | |
| 389 | //--------------------------------------------------------------------------- |
| 390 | // |
| 391 | // Function: EplObdReaduEntryToLe() |
| 392 | // |
| 393 | // Description: The function reads an object entry from the byteoder |
| 394 | // of the system to the little endian byteorder for numeric values. |
| 395 | // For other types a normal read will be processed. This is usefull for |
| 396 | // the PDO and SDO module. The application |
| 397 | // can always read the data even if attrib kEplObdAccRead |
| 398 | // is not set. The attrib is only checked up for SDO transfer. |
| 399 | // |
| 400 | // Parameters: EPL_MCO_DECL_INSTANCE_PTR_ |
| 401 | // uiIndex_p = Index of the OD entry to read |
| 402 | // uiSubIndex_p = Subindex to read |
| 403 | // pDstData_p = pointer to the buffer for data |
| 404 | // Offset_p = offset in data for read access |
| 405 | // pSize_p = IN: Size of the buffer |
| 406 | // OUT: number of readed Bytes |
| 407 | // |
| 408 | // Return: tEplKernel |
| 409 | // |
| 410 | // State: |
| 411 | // |
| 412 | //--------------------------------------------------------------------------- |
| 413 | EPLDLLEXPORT tEplKernel PUBLIC EplObduReadEntryToLe(unsigned int uiIndex_p, |
| 414 | unsigned int uiSubIndex_p, |
| 415 | void *pDstData_p, |
| 416 | tEplObdSize * pSize_p) |
| 417 | { |
| 418 | tEplKernel Ret; |
| 419 | |
| 420 | Ret = |
| 421 | EplObduCalReadEntryToLe(uiIndex_p, uiSubIndex_p, pDstData_p, |
| 422 | pSize_p); |
| 423 | |
| 424 | return Ret; |
| 425 | } |
| 426 | |
| 427 | //--------------------------------------------------------------------------- |
| 428 | // |
| 429 | // Function: EplObduWriteEntryFromLe() |
| 430 | // |
| 431 | // Description: Function writes data to an OBD entry from a source with |
| 432 | // little endian byteorder to the od with system specuific |
| 433 | // byteorder. Not numeric values will only by copied. Strings |
| 434 | // are stored with added '\0' character. |
| 435 | // |
| 436 | // Parameters: EPL_MCO_DECL_INSTANCE_PTR_ |
| 437 | // uiIndex_p = Index of the OD entry |
| 438 | // uiSubIndex_p = Subindex of the OD Entry |
| 439 | // pSrcData_p = Pointer to the data to write |
| 440 | // Size_p = Size of the data in Byte |
| 441 | // |
| 442 | // Return: tEplKernel = Errorcode |
| 443 | // |
| 444 | // |
| 445 | // State: |
| 446 | // |
| 447 | //--------------------------------------------------------------------------- |
| 448 | EPLDLLEXPORT tEplKernel PUBLIC EplObduWriteEntryFromLe(unsigned int uiIndex_p, |
| 449 | unsigned int |
| 450 | uiSubIndex_p, |
| 451 | void *pSrcData_p, |
| 452 | tEplObdSize Size_p) |
| 453 | { |
| 454 | tEplKernel Ret; |
| 455 | |
| 456 | Ret = |
| 457 | EplObduCalWriteEntryFromLe(uiIndex_p, uiSubIndex_p, pSrcData_p, |
| 458 | Size_p); |
| 459 | |
| 460 | return Ret; |
| 461 | } |
| 462 | |
| 463 | //--------------------------------------------------------------------------- |
| 464 | // |
| 465 | // Function: EplObduSearchVarEntry() |
| 466 | // |
| 467 | // Description: gets variable from OD |
| 468 | // |
| 469 | // Parameters: uiIndex_p = index of the var entry to search |
| 470 | // uiSubindex_p = subindex of var entry to search |
| 471 | // ppVarEntry_p = pointer to the pointer to the varentry |
| 472 | // |
| 473 | // Return: tEplKernel |
| 474 | // |
| 475 | // State: |
| 476 | // |
| 477 | //--------------------------------------------------------------------------- |
| 478 | EPLDLLEXPORT tEplKernel PUBLIC EplObduSearchVarEntry(EPL_MCO_DECL_INSTANCE_PTR_ |
| 479 | unsigned int uiIndex_p, |
| 480 | unsigned int uiSubindex_p, |
| 481 | tEplObdVarEntry MEM ** |
| 482 | ppVarEntry_p) |
| 483 | { |
| 484 | tEplKernel Ret; |
| 485 | |
| 486 | Ret = EplObduCalSearchVarEntry(uiIndex_p, uiSubindex_p, ppVarEntry_p); |
| 487 | |
| 488 | return Ret; |
| 489 | } |
| 490 | |
| 491 | //=========================================================================// |
| 492 | // // |
| 493 | // P R I V A T E F U N C T I O N S // |
| 494 | // // |
| 495 | //=========================================================================// |
| 496 | |
| 497 | //--------------------------------------------------------------------------- |
| 498 | // |
| 499 | // Function: |
| 500 | // |
| 501 | // Description: |
| 502 | // |
| 503 | // |
| 504 | // |
| 505 | // Parameters: |
| 506 | // |
| 507 | // |
| 508 | // Returns: |
| 509 | // |
| 510 | // |
| 511 | // State: |
| 512 | // |
| 513 | //--------------------------------------------------------------------------- |
| 514 | |
| 515 | #endif // #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDU)) != 0) |
| 516 | |
| 517 | // EOF |