master/canopen.c
branchstable-1.0
changeset 1618 5cff10efb927
parent 195 674071846ee3
child 1619 0d4119024f55
equal deleted inserted replaced
1617:9f83a343ae75 1618:5cff10efb927
     1 /******************************************************************************
     1 /******************************************************************************
     2  *
       
     3  *  c a n o p e n . c
       
     4  *
       
     5  *  CANopen over EtherCAT
       
     6  *
     2  *
     7  *  $Id$
     3  *  $Id$
     8  *
     4  *
       
     5  *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
       
     6  *
       
     7  *  This file is part of the IgH EtherCAT Master.
       
     8  *
       
     9  *  The IgH EtherCAT Master is free software; you can redistribute it
       
    10  *  and/or modify it under the terms of the GNU General Public License
       
    11  *  as published by the Free Software Foundation; version 2 of the License.
       
    12  *
       
    13  *  The IgH EtherCAT Master is distributed in the hope that it will be
       
    14  *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    16  *  GNU General Public License for more details.
       
    17  *
       
    18  *  You should have received a copy of the GNU General Public License
       
    19  *  along with the IgH EtherCAT Master; if not, write to the Free Software
       
    20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
       
    21  *
     9  *****************************************************************************/
    22  *****************************************************************************/
       
    23 
       
    24 /**
       
    25    \file
       
    26    Canopen-over-EtherCAT functions.
       
    27 */
       
    28 
       
    29 /*****************************************************************************/
    10 
    30 
    11 #include <linux/delay.h>
    31 #include <linux/delay.h>
    12 #include <linux/slab.h>
    32 #include <linux/slab.h>
    13 #include <linux/module.h>
    33 #include <linux/module.h>
    14 
    34 
    28 /*****************************************************************************/
    48 /*****************************************************************************/
    29 
    49 
    30 /**
    50 /**
    31    Reads 32 bit of a CANopen SDO in expedited mode.
    51    Reads 32 bit of a CANopen SDO in expedited mode.
    32    \return 0 in case of success, else < 0
    52    \return 0 in case of success, else < 0
    33  */
    53 */
    34 
    54 
    35 int ec_slave_sdo_read_exp(ec_slave_t *slave, /**< EtherCAT slave */
    55 int ec_slave_sdo_read_exp(ec_slave_t *slave, /**< EtherCAT slave */
    36                           uint16_t sdo_index, /**< SDO index */
    56                           uint16_t sdo_index, /**< SDO index */
    37                           uint8_t sdo_subindex, /**< SDO subindex */
    57                           uint8_t sdo_subindex, /**< SDO subindex */
    38                           uint8_t *target /**< 4-byte memory */
    58                           uint8_t *target /**< 4-byte memory */
    77 /*****************************************************************************/
    97 /*****************************************************************************/
    78 
    98 
    79 /**
    99 /**
    80    Writes a CANopen SDO using expedited mode.
   100    Writes a CANopen SDO using expedited mode.
    81    \return 0 in case of success, else < 0
   101    \return 0 in case of success, else < 0
    82  */
   102 */
    83 
   103 
    84 int ec_slave_sdo_write_exp(ec_slave_t *slave, /**< EtherCAT slave */
   104 int ec_slave_sdo_write_exp(ec_slave_t *slave, /**< EtherCAT slave */
    85                            uint16_t sdo_index, /**< SDO index */
   105                            uint16_t sdo_index, /**< SDO index */
    86                            uint8_t sdo_subindex, /**< SDO subindex */
   106                            uint8_t sdo_subindex, /**< SDO subindex */
    87                            const uint8_t *sdo_data, /**< new value */
   107                            const uint8_t *sdo_data, /**< new value */
    88                            size_t size
   108                            size_t size /**< Data size in bytes (1 - 4) */
    89                            )
   109                            )
    90 {
   110 {
    91     uint8_t *data;
   111     uint8_t *data;
    92     size_t rec_size;
   112     size_t rec_size;
    93 
   113 
   136 /*****************************************************************************/
   156 /*****************************************************************************/
   137 
   157 
   138 /**
   158 /**
   139    Reads a CANopen SDO in normal mode.
   159    Reads a CANopen SDO in normal mode.
   140    \return 0 in case of success, else < 0
   160    \return 0 in case of success, else < 0
   141 
   161    \ingroup RealtimeInterface
   142    \todo size
   162    \todo Make size non-pointer.
   143  */
   163 */
   144 
   164 
   145 int ecrt_slave_sdo_read(ec_slave_t *slave, /**< EtherCAT slave */
   165 int ecrt_slave_sdo_read(ec_slave_t *slave, /**< EtherCAT slave */
   146                         uint16_t sdo_index, /**< SDO index */
   166                         uint16_t sdo_index, /**< SDO index */
   147                         uint8_t sdo_subindex, /**< SDO subindex */
   167                         uint8_t sdo_subindex, /**< SDO subindex */
   148                         uint8_t *target, /**< memory for value */
   168                         uint8_t *target, /**< memory for value */
   514 
   534 
   515 /**
   535 /**
   516    Reads an 8-bit SDO in expedited mode.
   536    Reads an 8-bit SDO in expedited mode.
   517    See ec_slave_sdo_read_exp()
   537    See ec_slave_sdo_read_exp()
   518    \return 0 in case of success, else < 0
   538    \return 0 in case of success, else < 0
   519  */
   539    \ingroup RealtimeInterface
       
   540 */
   520 
   541 
   521 int ecrt_slave_sdo_read_exp8(ec_slave_t *slave, /**< EtherCAT slave */
   542 int ecrt_slave_sdo_read_exp8(ec_slave_t *slave, /**< EtherCAT slave */
   522                              uint16_t sdo_index, /**< SDO index */
   543                              uint16_t sdo_index, /**< SDO index */
   523                              uint8_t sdo_subindex, /**< SDO subindex */
   544                              uint8_t sdo_subindex, /**< SDO subindex */
   524                              uint8_t *target /**< memory for read value */
   545                              uint8_t *target /**< memory for read value */
   534 
   555 
   535 /**
   556 /**
   536    Reads a 16-bit SDO in expedited mode.
   557    Reads a 16-bit SDO in expedited mode.
   537    See ec_slave_sdo_read_exp()
   558    See ec_slave_sdo_read_exp()
   538    \return 0 in case of success, else < 0
   559    \return 0 in case of success, else < 0
   539  */
   560    \ingroup RealtimeInterface
       
   561 */
   540 
   562 
   541 int ecrt_slave_sdo_read_exp16(ec_slave_t *slave, /**< EtherCAT slave */
   563 int ecrt_slave_sdo_read_exp16(ec_slave_t *slave, /**< EtherCAT slave */
   542                               uint16_t sdo_index, /**< SDO index */
   564                               uint16_t sdo_index, /**< SDO index */
   543                               uint8_t sdo_subindex, /**< SDO subindex */
   565                               uint8_t sdo_subindex, /**< SDO subindex */
   544                               uint16_t *target /**< memory for read value */
   566                               uint16_t *target /**< memory for read value */
   554 
   576 
   555 /**
   577 /**
   556    Reads a 32-bit SDO in expedited mode.
   578    Reads a 32-bit SDO in expedited mode.
   557    See ec_slave_sdo_read_exp()
   579    See ec_slave_sdo_read_exp()
   558    \return 0 in case of success, else < 0
   580    \return 0 in case of success, else < 0
   559  */
   581    \ingroup RealtimeInterface
       
   582 */
   560 
   583 
   561 int ecrt_slave_sdo_read_exp32(ec_slave_t *slave, /**< EtherCAT slave */
   584 int ecrt_slave_sdo_read_exp32(ec_slave_t *slave, /**< EtherCAT slave */
   562                               uint16_t sdo_index, /**< SDO index */
   585                               uint16_t sdo_index, /**< SDO index */
   563                               uint8_t sdo_subindex, /**< SDO subindex */
   586                               uint8_t sdo_subindex, /**< SDO subindex */
   564                               uint32_t *target /**< memory for read value */
   587                               uint32_t *target /**< memory for read value */
   573 /*****************************************************************************/
   596 /*****************************************************************************/
   574 
   597 
   575 /**
   598 /**
   576    Writes an 8-bit SDO in expedited mode.
   599    Writes an 8-bit SDO in expedited mode.
   577    \return 0 in case of success, else < 0
   600    \return 0 in case of success, else < 0
   578  */
   601    \ingroup RealtimeInterface
       
   602 */
   579 
   603 
   580 int ecrt_slave_sdo_write_exp8(ec_slave_t *slave, /**< EtherCAT slave */
   604 int ecrt_slave_sdo_write_exp8(ec_slave_t *slave, /**< EtherCAT slave */
   581                               uint16_t sdo_index, /**< SDO index */
   605                               uint16_t sdo_index, /**< SDO index */
   582                               uint8_t sdo_subindex, /**< SDO subindex */
   606                               uint8_t sdo_subindex, /**< SDO subindex */
   583                               uint8_t value /**< new value */
   607                               uint8_t value /**< new value */
   589 /*****************************************************************************/
   613 /*****************************************************************************/
   590 
   614 
   591 /**
   615 /**
   592    Writes a 16-bit SDO in expedited mode.
   616    Writes a 16-bit SDO in expedited mode.
   593    \return 0 in case of success, else < 0
   617    \return 0 in case of success, else < 0
   594  */
   618    \ingroup RealtimeInterface
       
   619 */
   595 
   620 
   596 int ecrt_slave_sdo_write_exp16(ec_slave_t *slave, /**< EtherCAT slave */
   621 int ecrt_slave_sdo_write_exp16(ec_slave_t *slave, /**< EtherCAT slave */
   597                                uint16_t sdo_index, /**< SDO index */
   622                                uint16_t sdo_index, /**< SDO index */
   598                                uint8_t sdo_subindex, /**< SDO subindex */
   623                                uint8_t sdo_subindex, /**< SDO subindex */
   599                                uint16_t value /**< new value */
   624                                uint16_t value /**< new value */
   607 /*****************************************************************************/
   632 /*****************************************************************************/
   608 
   633 
   609 /**
   634 /**
   610    Writes a 32-bit SDO in expedited mode.
   635    Writes a 32-bit SDO in expedited mode.
   611    \return 0 in case of success, else < 0
   636    \return 0 in case of success, else < 0
   612  */
   637    \ingroup RealtimeInterface
       
   638 */
   613 
   639 
   614 int ecrt_slave_sdo_write_exp32(ec_slave_t *slave, /**< EtherCAT slave */
   640 int ecrt_slave_sdo_write_exp32(ec_slave_t *slave, /**< EtherCAT slave */
   615                                uint16_t sdo_index, /**< SDO index */
   641                                uint16_t sdo_index, /**< SDO index */
   616                                uint8_t sdo_subindex, /**< SDO subindex */
   642                                uint8_t sdo_subindex, /**< SDO subindex */
   617                                uint32_t value /**< new value */
   643                                uint32_t value /**< new value */
   621     EC_WRITE_U32(data, value);
   647     EC_WRITE_U32(data, value);
   622     return ec_slave_sdo_write_exp(slave, sdo_index, sdo_subindex, data, 4);
   648     return ec_slave_sdo_write_exp(slave, sdo_index, sdo_subindex, data, 4);
   623 }
   649 }
   624 
   650 
   625 /*****************************************************************************/
   651 /*****************************************************************************/
       
   652 
       
   653 /** \cond */
   626 
   654 
   627 EXPORT_SYMBOL(ecrt_slave_sdo_read_exp8);
   655 EXPORT_SYMBOL(ecrt_slave_sdo_read_exp8);
   628 EXPORT_SYMBOL(ecrt_slave_sdo_read_exp16);
   656 EXPORT_SYMBOL(ecrt_slave_sdo_read_exp16);
   629 EXPORT_SYMBOL(ecrt_slave_sdo_read_exp32);
   657 EXPORT_SYMBOL(ecrt_slave_sdo_read_exp32);
   630 EXPORT_SYMBOL(ecrt_slave_sdo_write_exp8);
   658 EXPORT_SYMBOL(ecrt_slave_sdo_write_exp8);
   631 EXPORT_SYMBOL(ecrt_slave_sdo_write_exp16);
   659 EXPORT_SYMBOL(ecrt_slave_sdo_write_exp16);
   632 EXPORT_SYMBOL(ecrt_slave_sdo_write_exp32);
   660 EXPORT_SYMBOL(ecrt_slave_sdo_write_exp32);
   633 EXPORT_SYMBOL(ecrt_slave_sdo_read);
   661 EXPORT_SYMBOL(ecrt_slave_sdo_read);
   634 
   662 
   635 /*****************************************************************************/
   663 /** \endcond */
       
   664 
       
   665 /*****************************************************************************/