master/canopen.c
changeset 197 b9a6e2c22745
parent 195 674071846ee3
child 199 04ecf40fc2e9
equal deleted inserted replaced
196:f8a1e9f364a3 197:b9a6e2c22745
     3  *  c a n o p e n . c
     3  *  c a n o p e n . c
     4  *
     4  *
     5  *  CANopen over EtherCAT
     5  *  CANopen over EtherCAT
     6  *
     6  *
     7  *  $Id$
     7  *  $Id$
       
     8  *
       
     9  *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
       
    10  *
       
    11  *  This file is part of the IgH EtherCAT Master.
       
    12  *
       
    13  *  The IgH EtherCAT Master is free software; you can redistribute it
       
    14  *  and/or modify it under the terms of the GNU General Public License
       
    15  *  as published by the Free Software Foundation; version 2 of the License.
       
    16  *
       
    17  *  The IgH EtherCAT Master is distributed in the hope that it will be
       
    18  *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    20  *  GNU General Public License for more details.
       
    21  *
       
    22  *  You should have received a copy of the GNU General Public License
       
    23  *  along with the IgH EtherCAT Master; if not, write to the Free Software
       
    24  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     8  *
    25  *
     9  *****************************************************************************/
    26  *****************************************************************************/
    10 
    27 
    11 #include <linux/delay.h>
    28 #include <linux/delay.h>
    12 #include <linux/slab.h>
    29 #include <linux/slab.h>
    28 /*****************************************************************************/
    45 /*****************************************************************************/
    29 
    46 
    30 /**
    47 /**
    31    Reads 32 bit of a CANopen SDO in expedited mode.
    48    Reads 32 bit of a CANopen SDO in expedited mode.
    32    \return 0 in case of success, else < 0
    49    \return 0 in case of success, else < 0
    33  */
    50    \ingroup Slave
       
    51 */
    34 
    52 
    35 int ec_slave_sdo_read_exp(ec_slave_t *slave, /**< EtherCAT slave */
    53 int ec_slave_sdo_read_exp(ec_slave_t *slave, /**< EtherCAT slave */
    36                           uint16_t sdo_index, /**< SDO index */
    54                           uint16_t sdo_index, /**< SDO index */
    37                           uint8_t sdo_subindex, /**< SDO subindex */
    55                           uint8_t sdo_subindex, /**< SDO subindex */
    38                           uint8_t *target /**< 4-byte memory */
    56                           uint8_t *target /**< 4-byte memory */
    77 /*****************************************************************************/
    95 /*****************************************************************************/
    78 
    96 
    79 /**
    97 /**
    80    Writes a CANopen SDO using expedited mode.
    98    Writes a CANopen SDO using expedited mode.
    81    \return 0 in case of success, else < 0
    99    \return 0 in case of success, else < 0
    82  */
   100    \ingroup Slave
       
   101 */
    83 
   102 
    84 int ec_slave_sdo_write_exp(ec_slave_t *slave, /**< EtherCAT slave */
   103 int ec_slave_sdo_write_exp(ec_slave_t *slave, /**< EtherCAT slave */
    85                            uint16_t sdo_index, /**< SDO index */
   104                            uint16_t sdo_index, /**< SDO index */
    86                            uint8_t sdo_subindex, /**< SDO subindex */
   105                            uint8_t sdo_subindex, /**< SDO subindex */
    87                            const uint8_t *sdo_data, /**< new value */
   106                            const uint8_t *sdo_data, /**< new value */
    88                            size_t size
   107                            size_t size /**< Data size in bytes (1 - 4) */
    89                            )
   108                            )
    90 {
   109 {
    91     uint8_t *data;
   110     uint8_t *data;
    92     size_t rec_size;
   111     size_t rec_size;
    93 
   112 
   136 /*****************************************************************************/
   155 /*****************************************************************************/
   137 
   156 
   138 /**
   157 /**
   139    Reads a CANopen SDO in normal mode.
   158    Reads a CANopen SDO in normal mode.
   140    \return 0 in case of success, else < 0
   159    \return 0 in case of success, else < 0
   141 
   160    \ingroup Slave
   142    \todo size
   161    \todo size
   143  */
   162 */
   144 
   163 
   145 int ecrt_slave_sdo_read(ec_slave_t *slave, /**< EtherCAT slave */
   164 int ecrt_slave_sdo_read(ec_slave_t *slave, /**< EtherCAT slave */
   146                         uint16_t sdo_index, /**< SDO index */
   165                         uint16_t sdo_index, /**< SDO index */
   147                         uint8_t sdo_subindex, /**< SDO subindex */
   166                         uint8_t sdo_subindex, /**< SDO subindex */
   148                         uint8_t *target, /**< memory for value */
   167                         uint8_t *target, /**< memory for value */
   207 /*****************************************************************************/
   226 /*****************************************************************************/
   208 
   227 
   209 /**
   228 /**
   210    Fetches the SDO dictionary of a slave.
   229    Fetches the SDO dictionary of a slave.
   211    \return 0 in case of success, else < 0
   230    \return 0 in case of success, else < 0
       
   231    \ingroup Slave
   212 */
   232 */
   213 
   233 
   214 int ec_slave_fetch_sdo_list(ec_slave_t *slave /**< EtherCAT slave */)
   234 int ec_slave_fetch_sdo_list(ec_slave_t *slave /**< EtherCAT slave */)
   215 {
   235 {
   216     uint8_t *data;
   236     uint8_t *data;
   289 /*****************************************************************************/
   309 /*****************************************************************************/
   290 
   310 
   291 /**
   311 /**
   292    Fetches the SDO descriptions for the known SDOs.
   312    Fetches the SDO descriptions for the known SDOs.
   293    \return 0 in case of success, else < 0
   313    \return 0 in case of success, else < 0
       
   314    \ingroup Slave
   294 */
   315 */
   295 
   316 
   296 int ec_slave_fetch_sdo_descriptions(ec_slave_t *slave /**< EtherCAT slave */)
   317 int ec_slave_fetch_sdo_descriptions(ec_slave_t *slave /**< EtherCAT slave */)
   297 {
   318 {
   298     uint8_t *data;
   319     uint8_t *data;
   367 /*****************************************************************************/
   388 /*****************************************************************************/
   368 
   389 
   369 /**
   390 /**
   370    Fetches all entries (subindices) to an SDO.
   391    Fetches all entries (subindices) to an SDO.
   371    \return 0 in case of success, else < 0
   392    \return 0 in case of success, else < 0
       
   393    \ingroup Slave
   372 */
   394 */
   373 
   395 
   374 int ec_slave_fetch_sdo_entries(ec_slave_t *slave, /**< EtherCAT slave */
   396 int ec_slave_fetch_sdo_entries(ec_slave_t *slave, /**< EtherCAT slave */
   375                                ec_sdo_t *sdo, /**< SDO */
   397                                ec_sdo_t *sdo, /**< SDO */
   376                                uint8_t subindices /**< number of subindices */
   398                                uint8_t subindices /**< number of subindices */
   514 
   536 
   515 /**
   537 /**
   516    Reads an 8-bit SDO in expedited mode.
   538    Reads an 8-bit SDO in expedited mode.
   517    See ec_slave_sdo_read_exp()
   539    See ec_slave_sdo_read_exp()
   518    \return 0 in case of success, else < 0
   540    \return 0 in case of success, else < 0
   519  */
   541    \ingroup Slave
       
   542 */
   520 
   543 
   521 int ecrt_slave_sdo_read_exp8(ec_slave_t *slave, /**< EtherCAT slave */
   544 int ecrt_slave_sdo_read_exp8(ec_slave_t *slave, /**< EtherCAT slave */
   522                              uint16_t sdo_index, /**< SDO index */
   545                              uint16_t sdo_index, /**< SDO index */
   523                              uint8_t sdo_subindex, /**< SDO subindex */
   546                              uint8_t sdo_subindex, /**< SDO subindex */
   524                              uint8_t *target /**< memory for read value */
   547                              uint8_t *target /**< memory for read value */
   534 
   557 
   535 /**
   558 /**
   536    Reads a 16-bit SDO in expedited mode.
   559    Reads a 16-bit SDO in expedited mode.
   537    See ec_slave_sdo_read_exp()
   560    See ec_slave_sdo_read_exp()
   538    \return 0 in case of success, else < 0
   561    \return 0 in case of success, else < 0
   539  */
   562    \ingroup Slave
       
   563 */
   540 
   564 
   541 int ecrt_slave_sdo_read_exp16(ec_slave_t *slave, /**< EtherCAT slave */
   565 int ecrt_slave_sdo_read_exp16(ec_slave_t *slave, /**< EtherCAT slave */
   542                               uint16_t sdo_index, /**< SDO index */
   566                               uint16_t sdo_index, /**< SDO index */
   543                               uint8_t sdo_subindex, /**< SDO subindex */
   567                               uint8_t sdo_subindex, /**< SDO subindex */
   544                               uint16_t *target /**< memory for read value */
   568                               uint16_t *target /**< memory for read value */
   554 
   578 
   555 /**
   579 /**
   556    Reads a 32-bit SDO in expedited mode.
   580    Reads a 32-bit SDO in expedited mode.
   557    See ec_slave_sdo_read_exp()
   581    See ec_slave_sdo_read_exp()
   558    \return 0 in case of success, else < 0
   582    \return 0 in case of success, else < 0
   559  */
   583    \ingroup Slave
       
   584 */
   560 
   585 
   561 int ecrt_slave_sdo_read_exp32(ec_slave_t *slave, /**< EtherCAT slave */
   586 int ecrt_slave_sdo_read_exp32(ec_slave_t *slave, /**< EtherCAT slave */
   562                               uint16_t sdo_index, /**< SDO index */
   587                               uint16_t sdo_index, /**< SDO index */
   563                               uint8_t sdo_subindex, /**< SDO subindex */
   588                               uint8_t sdo_subindex, /**< SDO subindex */
   564                               uint32_t *target /**< memory for read value */
   589                               uint32_t *target /**< memory for read value */
   573 /*****************************************************************************/
   598 /*****************************************************************************/
   574 
   599 
   575 /**
   600 /**
   576    Writes an 8-bit SDO in expedited mode.
   601    Writes an 8-bit SDO in expedited mode.
   577    \return 0 in case of success, else < 0
   602    \return 0 in case of success, else < 0
   578  */
   603    \ingroup Slave
       
   604 */
   579 
   605 
   580 int ecrt_slave_sdo_write_exp8(ec_slave_t *slave, /**< EtherCAT slave */
   606 int ecrt_slave_sdo_write_exp8(ec_slave_t *slave, /**< EtherCAT slave */
   581                               uint16_t sdo_index, /**< SDO index */
   607                               uint16_t sdo_index, /**< SDO index */
   582                               uint8_t sdo_subindex, /**< SDO subindex */
   608                               uint8_t sdo_subindex, /**< SDO subindex */
   583                               uint8_t value /**< new value */
   609                               uint8_t value /**< new value */
   589 /*****************************************************************************/
   615 /*****************************************************************************/
   590 
   616 
   591 /**
   617 /**
   592    Writes a 16-bit SDO in expedited mode.
   618    Writes a 16-bit SDO in expedited mode.
   593    \return 0 in case of success, else < 0
   619    \return 0 in case of success, else < 0
   594  */
   620    \ingroup Slave
       
   621 */
   595 
   622 
   596 int ecrt_slave_sdo_write_exp16(ec_slave_t *slave, /**< EtherCAT slave */
   623 int ecrt_slave_sdo_write_exp16(ec_slave_t *slave, /**< EtherCAT slave */
   597                                uint16_t sdo_index, /**< SDO index */
   624                                uint16_t sdo_index, /**< SDO index */
   598                                uint8_t sdo_subindex, /**< SDO subindex */
   625                                uint8_t sdo_subindex, /**< SDO subindex */
   599                                uint16_t value /**< new value */
   626                                uint16_t value /**< new value */
   607 /*****************************************************************************/
   634 /*****************************************************************************/
   608 
   635 
   609 /**
   636 /**
   610    Writes a 32-bit SDO in expedited mode.
   637    Writes a 32-bit SDO in expedited mode.
   611    \return 0 in case of success, else < 0
   638    \return 0 in case of success, else < 0
   612  */
   639    \ingroup Slave
       
   640 */
   613 
   641 
   614 int ecrt_slave_sdo_write_exp32(ec_slave_t *slave, /**< EtherCAT slave */
   642 int ecrt_slave_sdo_write_exp32(ec_slave_t *slave, /**< EtherCAT slave */
   615                                uint16_t sdo_index, /**< SDO index */
   643                                uint16_t sdo_index, /**< SDO index */
   616                                uint8_t sdo_subindex, /**< SDO subindex */
   644                                uint8_t sdo_subindex, /**< SDO subindex */
   617                                uint32_t value /**< new value */
   645                                uint32_t value /**< new value */