master/canopen.c
changeset 199 04ecf40fc2e9
parent 197 b9a6e2c22745
child 246 0bf7c769de06
equal deleted inserted replaced
198:f7dff1ed01ba 199:04ecf40fc2e9
     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  *
     9  *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
     5  *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
    10  *
     6  *
    23  *  along with the IgH EtherCAT Master; if not, write to the Free Software
    19  *  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
    20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    25  *
    21  *
    26  *****************************************************************************/
    22  *****************************************************************************/
    27 
    23 
       
    24 /**
       
    25    \file
       
    26    Canopen-over-EtherCAT functions.
       
    27 */
       
    28 
       
    29 /*****************************************************************************/
       
    30 
    28 #include <linux/delay.h>
    31 #include <linux/delay.h>
    29 #include <linux/slab.h>
    32 #include <linux/slab.h>
    30 #include <linux/module.h>
    33 #include <linux/module.h>
    31 
    34 
    32 #include "master.h"
    35 #include "master.h"
    45 /*****************************************************************************/
    48 /*****************************************************************************/
    46 
    49 
    47 /**
    50 /**
    48    Reads 32 bit of a CANopen SDO in expedited mode.
    51    Reads 32 bit of a CANopen SDO in expedited mode.
    49    \return 0 in case of success, else < 0
    52    \return 0 in case of success, else < 0
    50    \ingroup Slave
       
    51 */
    53 */
    52 
    54 
    53 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 */
    54                           uint16_t sdo_index, /**< SDO index */
    56                           uint16_t sdo_index, /**< SDO index */
    55                           uint8_t sdo_subindex, /**< SDO subindex */
    57                           uint8_t sdo_subindex, /**< SDO subindex */
    95 /*****************************************************************************/
    97 /*****************************************************************************/
    96 
    98 
    97 /**
    99 /**
    98    Writes a CANopen SDO using expedited mode.
   100    Writes a CANopen SDO using expedited mode.
    99    \return 0 in case of success, else < 0
   101    \return 0 in case of success, else < 0
   100    \ingroup Slave
       
   101 */
   102 */
   102 
   103 
   103 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 */
   104                            uint16_t sdo_index, /**< SDO index */
   105                            uint16_t sdo_index, /**< SDO index */
   105                            uint8_t sdo_subindex, /**< SDO subindex */
   106                            uint8_t sdo_subindex, /**< SDO subindex */
   155 /*****************************************************************************/
   156 /*****************************************************************************/
   156 
   157 
   157 /**
   158 /**
   158    Reads a CANopen SDO in normal mode.
   159    Reads a CANopen SDO in normal mode.
   159    \return 0 in case of success, else < 0
   160    \return 0 in case of success, else < 0
   160    \ingroup Slave
   161    \ingroup RealtimeInterface
   161    \todo size
   162    \todo Make size non-pointer.
   162 */
   163 */
   163 
   164 
   164 int ecrt_slave_sdo_read(ec_slave_t *slave, /**< EtherCAT slave */
   165 int ecrt_slave_sdo_read(ec_slave_t *slave, /**< EtherCAT slave */
   165                         uint16_t sdo_index, /**< SDO index */
   166                         uint16_t sdo_index, /**< SDO index */
   166                         uint8_t sdo_subindex, /**< SDO subindex */
   167                         uint8_t sdo_subindex, /**< SDO subindex */
   226 /*****************************************************************************/
   227 /*****************************************************************************/
   227 
   228 
   228 /**
   229 /**
   229    Fetches the SDO dictionary of a slave.
   230    Fetches the SDO dictionary of a slave.
   230    \return 0 in case of success, else < 0
   231    \return 0 in case of success, else < 0
   231    \ingroup Slave
       
   232 */
   232 */
   233 
   233 
   234 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 */)
   235 {
   235 {
   236     uint8_t *data;
   236     uint8_t *data;
   309 /*****************************************************************************/
   309 /*****************************************************************************/
   310 
   310 
   311 /**
   311 /**
   312    Fetches the SDO descriptions for the known SDOs.
   312    Fetches the SDO descriptions for the known SDOs.
   313    \return 0 in case of success, else < 0
   313    \return 0 in case of success, else < 0
   314    \ingroup Slave
       
   315 */
   314 */
   316 
   315 
   317 int ec_slave_fetch_sdo_descriptions(ec_slave_t *slave /**< EtherCAT slave */)
   316 int ec_slave_fetch_sdo_descriptions(ec_slave_t *slave /**< EtherCAT slave */)
   318 {
   317 {
   319     uint8_t *data;
   318     uint8_t *data;
   388 /*****************************************************************************/
   387 /*****************************************************************************/
   389 
   388 
   390 /**
   389 /**
   391    Fetches all entries (subindices) to an SDO.
   390    Fetches all entries (subindices) to an SDO.
   392    \return 0 in case of success, else < 0
   391    \return 0 in case of success, else < 0
   393    \ingroup Slave
       
   394 */
   392 */
   395 
   393 
   396 int ec_slave_fetch_sdo_entries(ec_slave_t *slave, /**< EtherCAT slave */
   394 int ec_slave_fetch_sdo_entries(ec_slave_t *slave, /**< EtherCAT slave */
   397                                ec_sdo_t *sdo, /**< SDO */
   395                                ec_sdo_t *sdo, /**< SDO */
   398                                uint8_t subindices /**< number of subindices */
   396                                uint8_t subindices /**< number of subindices */
   536 
   534 
   537 /**
   535 /**
   538    Reads an 8-bit SDO in expedited mode.
   536    Reads an 8-bit SDO in expedited mode.
   539    See ec_slave_sdo_read_exp()
   537    See ec_slave_sdo_read_exp()
   540    \return 0 in case of success, else < 0
   538    \return 0 in case of success, else < 0
   541    \ingroup Slave
   539    \ingroup RealtimeInterface
   542 */
   540 */
   543 
   541 
   544 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 */
   545                              uint16_t sdo_index, /**< SDO index */
   543                              uint16_t sdo_index, /**< SDO index */
   546                              uint8_t sdo_subindex, /**< SDO subindex */
   544                              uint8_t sdo_subindex, /**< SDO subindex */
   557 
   555 
   558 /**
   556 /**
   559    Reads a 16-bit SDO in expedited mode.
   557    Reads a 16-bit SDO in expedited mode.
   560    See ec_slave_sdo_read_exp()
   558    See ec_slave_sdo_read_exp()
   561    \return 0 in case of success, else < 0
   559    \return 0 in case of success, else < 0
   562    \ingroup Slave
   560    \ingroup RealtimeInterface
   563 */
   561 */
   564 
   562 
   565 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 */
   566                               uint16_t sdo_index, /**< SDO index */
   564                               uint16_t sdo_index, /**< SDO index */
   567                               uint8_t sdo_subindex, /**< SDO subindex */
   565                               uint8_t sdo_subindex, /**< SDO subindex */
   578 
   576 
   579 /**
   577 /**
   580    Reads a 32-bit SDO in expedited mode.
   578    Reads a 32-bit SDO in expedited mode.
   581    See ec_slave_sdo_read_exp()
   579    See ec_slave_sdo_read_exp()
   582    \return 0 in case of success, else < 0
   580    \return 0 in case of success, else < 0
   583    \ingroup Slave
   581    \ingroup RealtimeInterface
   584 */
   582 */
   585 
   583 
   586 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 */
   587                               uint16_t sdo_index, /**< SDO index */
   585                               uint16_t sdo_index, /**< SDO index */
   588                               uint8_t sdo_subindex, /**< SDO subindex */
   586                               uint8_t sdo_subindex, /**< SDO subindex */
   598 /*****************************************************************************/
   596 /*****************************************************************************/
   599 
   597 
   600 /**
   598 /**
   601    Writes an 8-bit SDO in expedited mode.
   599    Writes an 8-bit SDO in expedited mode.
   602    \return 0 in case of success, else < 0
   600    \return 0 in case of success, else < 0
   603    \ingroup Slave
   601    \ingroup RealtimeInterface
   604 */
   602 */
   605 
   603 
   606 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 */
   607                               uint16_t sdo_index, /**< SDO index */
   605                               uint16_t sdo_index, /**< SDO index */
   608                               uint8_t sdo_subindex, /**< SDO subindex */
   606                               uint8_t sdo_subindex, /**< SDO subindex */
   615 /*****************************************************************************/
   613 /*****************************************************************************/
   616 
   614 
   617 /**
   615 /**
   618    Writes a 16-bit SDO in expedited mode.
   616    Writes a 16-bit SDO in expedited mode.
   619    \return 0 in case of success, else < 0
   617    \return 0 in case of success, else < 0
   620    \ingroup Slave
   618    \ingroup RealtimeInterface
   621 */
   619 */
   622 
   620 
   623 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 */
   624                                uint16_t sdo_index, /**< SDO index */
   622                                uint16_t sdo_index, /**< SDO index */
   625                                uint8_t sdo_subindex, /**< SDO subindex */
   623                                uint8_t sdo_subindex, /**< SDO subindex */
   634 /*****************************************************************************/
   632 /*****************************************************************************/
   635 
   633 
   636 /**
   634 /**
   637    Writes a 32-bit SDO in expedited mode.
   635    Writes a 32-bit SDO in expedited mode.
   638    \return 0 in case of success, else < 0
   636    \return 0 in case of success, else < 0
   639    \ingroup Slave
   637    \ingroup RealtimeInterface
   640 */
   638 */
   641 
   639 
   642 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 */
   643                                uint16_t sdo_index, /**< SDO index */
   641                                uint16_t sdo_index, /**< SDO index */
   644                                uint8_t sdo_subindex, /**< SDO subindex */
   642                                uint8_t sdo_subindex, /**< SDO subindex */
   649     EC_WRITE_U32(data, value);
   647     EC_WRITE_U32(data, value);
   650     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);
   651 }
   649 }
   652 
   650 
   653 /*****************************************************************************/
   651 /*****************************************************************************/
       
   652 
       
   653 /** \cond */
   654 
   654 
   655 EXPORT_SYMBOL(ecrt_slave_sdo_read_exp8);
   655 EXPORT_SYMBOL(ecrt_slave_sdo_read_exp8);
   656 EXPORT_SYMBOL(ecrt_slave_sdo_read_exp16);
   656 EXPORT_SYMBOL(ecrt_slave_sdo_read_exp16);
   657 EXPORT_SYMBOL(ecrt_slave_sdo_read_exp32);
   657 EXPORT_SYMBOL(ecrt_slave_sdo_read_exp32);
   658 EXPORT_SYMBOL(ecrt_slave_sdo_write_exp8);
   658 EXPORT_SYMBOL(ecrt_slave_sdo_write_exp8);
   659 EXPORT_SYMBOL(ecrt_slave_sdo_write_exp16);
   659 EXPORT_SYMBOL(ecrt_slave_sdo_write_exp16);
   660 EXPORT_SYMBOL(ecrt_slave_sdo_write_exp32);
   660 EXPORT_SYMBOL(ecrt_slave_sdo_write_exp32);
   661 EXPORT_SYMBOL(ecrt_slave_sdo_read);
   661 EXPORT_SYMBOL(ecrt_slave_sdo_read);
   662 
   662 
   663 /*****************************************************************************/
   663 /** \endcond */
       
   664 
       
   665 /*****************************************************************************/