master/slave.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  *  s l a v e . c
       
     4  *
       
     5  *  EtherCAT slave methods.
       
     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    EtherCAT slave methods.
       
    27 */
       
    28 
       
    29 /*****************************************************************************/
    10 
    30 
    11 #include <linux/module.h>
    31 #include <linux/module.h>
    12 #include <linux/delay.h>
    32 #include <linux/delay.h>
    13 
    33 
    14 #include "globals.h"
    34 #include "globals.h"
    25 int ec_slave_fetch_pdo(ec_slave_t *, const uint8_t *, size_t, ec_pdo_type_t);
    45 int ec_slave_fetch_pdo(ec_slave_t *, const uint8_t *, size_t, ec_pdo_type_t);
    26 int ec_slave_locate_string(ec_slave_t *, unsigned int, char **);
    46 int ec_slave_locate_string(ec_slave_t *, unsigned int, char **);
    27 ssize_t ec_show_slave_attribute(struct kobject *, struct attribute *, char *);
    47 ssize_t ec_show_slave_attribute(struct kobject *, struct attribute *, char *);
    28 
    48 
    29 /*****************************************************************************/
    49 /*****************************************************************************/
       
    50 
       
    51 /** \cond */
    30 
    52 
    31 EC_SYSFS_READ_ATTR(ring_position);
    53 EC_SYSFS_READ_ATTR(ring_position);
    32 EC_SYSFS_READ_ATTR(coupler_address);
    54 EC_SYSFS_READ_ATTR(coupler_address);
    33 EC_SYSFS_READ_ATTR(vendor_name);
    55 EC_SYSFS_READ_ATTR(vendor_name);
    34 EC_SYSFS_READ_ATTR(product_name);
    56 EC_SYSFS_READ_ATTR(product_name);
    53 static struct kobj_type ktype_ec_slave = {
    75 static struct kobj_type ktype_ec_slave = {
    54     .release = ec_slave_clear,
    76     .release = ec_slave_clear,
    55     .sysfs_ops = &sysfs_ops,
    77     .sysfs_ops = &sysfs_ops,
    56     .default_attrs = def_attrs
    78     .default_attrs = def_attrs
    57 };
    79 };
       
    80 
       
    81 /** \endcond */
    58 
    82 
    59 /*****************************************************************************/
    83 /*****************************************************************************/
    60 
    84 
    61 const ec_code_msg_t al_status_messages[];
    85 const ec_code_msg_t al_status_messages[];
    62 
    86 
   720 /*****************************************************************************/
   744 /*****************************************************************************/
   721 
   745 
   722 /**
   746 /**
   723    Searches the string list for an index and allocates a new string.
   747    Searches the string list for an index and allocates a new string.
   724    \return 0 in case of success, else < 0
   748    \return 0 in case of success, else < 0
   725 */
   749    \todo documentation
   726 
   750 */
   727 int ec_slave_locate_string(ec_slave_t *slave, unsigned int index, char **ptr)
   751 
       
   752 int ec_slave_locate_string(ec_slave_t *slave, /**< EtherCAT slave */
       
   753                            unsigned int index, /**< string index */
       
   754                            char **ptr /**< Address of the string pointer */
       
   755                            )
   728 {
   756 {
   729     ec_eeprom_string_t *string;
   757     ec_eeprom_string_t *string;
   730     char *err_string;
   758     char *err_string;
   731 
   759 
   732     // Erst alten Speicher freigeben
   760     // Erst alten Speicher freigeben
   820 /*****************************************************************************/
   848 /*****************************************************************************/
   821 
   849 
   822 /**
   850 /**
   823    Reads the AL status code of a slave and displays it.
   851    Reads the AL status code of a slave and displays it.
   824    If the AL status code is not supported, or if no error occurred (both
   852    If the AL status code is not supported, or if no error occurred (both
   825    resulting in code=0), nothing is displayed.
   853    resulting in code = 0), nothing is displayed.
   826 */
   854 */
   827 
   855 
   828 void ec_slave_read_al_status_code(ec_slave_t *slave /**< EtherCAT slave */)
   856 void ec_slave_read_al_status_code(ec_slave_t *slave /**< EtherCAT slave */)
   829 {
   857 {
   830     ec_command_t *command;
   858     ec_command_t *command;
  1177 }
  1205 }
  1178 
  1206 
  1179 /*****************************************************************************/
  1207 /*****************************************************************************/
  1180 
  1208 
  1181 /**
  1209 /**
  1182    Writes the "configured station alias" to the slave's EEPROM.
       
  1183    \return 0 in case of success, else < 0
       
  1184 */
       
  1185 
       
  1186 int ecrt_slave_write_alias(ec_slave_t *slave, /** EtherCAT slave */
       
  1187                            uint16_t alias /** new alias */
       
  1188                            )
       
  1189 {
       
  1190     return ec_slave_sii_write16(slave, 0x0004, alias);
       
  1191 }
       
  1192 
       
  1193 /*****************************************************************************/
       
  1194 
       
  1195 /**
       
  1196    Formats attribute data for SysFS read access.
  1210    Formats attribute data for SysFS read access.
  1197    \return number of bytes to read
  1211    \return number of bytes to read
       
  1212    \ingroup RealTimeInterface
  1198 */
  1213 */
  1199 
  1214 
  1200 ssize_t ec_show_slave_attribute(struct kobject *kobj, /**< slave's kobject */
  1215 ssize_t ec_show_slave_attribute(struct kobject *kobj, /**< slave's kobject */
  1201                                 struct attribute *attr, /**< attribute */
  1216                                 struct attribute *attr, /**< attribute */
  1202                                 char *buffer /**< memory to store data */
  1217                                 char *buffer /**< memory to store data */
  1234 
  1249 
  1235     return 0;
  1250     return 0;
  1236 }
  1251 }
  1237 
  1252 
  1238 /*****************************************************************************/
  1253 /*****************************************************************************/
       
  1254 
       
  1255 /**
       
  1256    Application layer status messages.
       
  1257 */
  1239 
  1258 
  1240 const ec_code_msg_t al_status_messages[] = {
  1259 const ec_code_msg_t al_status_messages[] = {
  1241     {0x0001, "Unspecified error"},
  1260     {0x0001, "Unspecified error"},
  1242     {0x0011, "Invalud requested state change"},
  1261     {0x0011, "Invalud requested state change"},
  1243     {0x0012, "Unknown requested state"},
  1262     {0x0012, "Unknown requested state"},
  1255     {0x0022, "Slave needs PREOP"},
  1274     {0x0022, "Slave needs PREOP"},
  1256     {0x0023, "Slave needs SAVEOP"},
  1275     {0x0023, "Slave needs SAVEOP"},
  1257     {}
  1276     {}
  1258 };
  1277 };
  1259 
  1278 
  1260 /*****************************************************************************/
  1279 /******************************************************************************
       
  1280  *  Realtime interface
       
  1281  *****************************************************************************/
       
  1282 
       
  1283 /**
       
  1284    Writes the "configured station alias" to the slave's EEPROM.
       
  1285    \return 0 in case of success, else < 0
       
  1286    \ingroup RealtimeInterface
       
  1287 */
       
  1288 
       
  1289 int ecrt_slave_write_alias(ec_slave_t *slave, /**< EtherCAT slave */
       
  1290                            uint16_t alias /**< new alias */
       
  1291                            )
       
  1292 {
       
  1293     return ec_slave_sii_write16(slave, 0x0004, alias);
       
  1294 }
       
  1295 
       
  1296 /*****************************************************************************/
       
  1297 
       
  1298 /**< \cond */
  1261 
  1299 
  1262 EXPORT_SYMBOL(ecrt_slave_write_alias);
  1300 EXPORT_SYMBOL(ecrt_slave_write_alias);
  1263 
  1301 
  1264 /*****************************************************************************/
  1302 /**< \endcond */
       
  1303 
       
  1304 /*****************************************************************************/