master/master.h
branchstable-1.0
changeset 1619 0d4119024f55
parent 1618 5cff10efb927
child 1621 4bbe090553f7
equal deleted inserted replaced
1618:5cff10efb927 1619:0d4119024f55
     6  *
     6  *
     7  *  This file is part of the IgH EtherCAT Master.
     7  *  This file is part of the IgH EtherCAT Master.
     8  *
     8  *
     9  *  The IgH EtherCAT Master is free software; you can redistribute it
     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
    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.
    11  *  as published by the Free Software Foundation; either version 2 of the
       
    12  *  License, or (at your option) any later version.
    12  *
    13  *
    13  *  The IgH EtherCAT Master is distributed in the hope that it will be
    14  *  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  *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  *  GNU General Public License for more details.
    17  *  GNU General Public License for more details.
    17  *
    18  *
    18  *  You should have received a copy of the GNU General Public License
    19  *  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  *  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  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
       
    22  *
       
    23  *  The right to use EtherCAT Technology is granted and comes free of
       
    24  *  charge under condition of compatibility of product made by
       
    25  *  Licensee. People intending to distribute/sell products based on the
       
    26  *  code, have to sign an agreement to guarantee that products using
       
    27  *  software based on IgH EtherCAT master stay compatible with the actual
       
    28  *  EtherCAT specification (which are released themselves as an open
       
    29  *  standard) as the (only) precondition to have the right to use EtherCAT
       
    30  *  Technology, IP and trade marks.
    21  *
    31  *
    22  *****************************************************************************/
    32  *****************************************************************************/
    23 
    33 
    24 /**
    34 /**
    25    \file
    35    \file
    35 #include <linux/sysfs.h>
    45 #include <linux/sysfs.h>
    36 #include <linux/timer.h>
    46 #include <linux/timer.h>
    37 
    47 
    38 #include "device.h"
    48 #include "device.h"
    39 #include "domain.h"
    49 #include "domain.h"
       
    50 #include "fsm.h"
    40 
    51 
    41 /*****************************************************************************/
    52 /*****************************************************************************/
    42 
    53 
    43 /**
    54 /**
    44    EtherCAT master mode.
    55    EtherCAT master mode.
    62 {
    73 {
    63     unsigned int timeouts; /**< command timeouts */
    74     unsigned int timeouts; /**< command timeouts */
    64     unsigned int delayed; /**< delayed commands */
    75     unsigned int delayed; /**< delayed commands */
    65     unsigned int corrupted; /**< corrupted frames */
    76     unsigned int corrupted; /**< corrupted frames */
    66     unsigned int unmatched; /**< unmatched commands */
    77     unsigned int unmatched; /**< unmatched commands */
    67     unsigned int eoe_errors; /**< Ethernet-over-EtherCAT errors */
       
    68     cycles_t t_last; /**< time of last output */
    78     cycles_t t_last; /**< time of last output */
    69 }
    79 }
    70 ec_stats_t;
    80 ec_stats_t;
    71 
    81 
    72 /*****************************************************************************/
    82 /*****************************************************************************/
    76    Manages slaves, domains and IO.
    86    Manages slaves, domains and IO.
    77 */
    87 */
    78 
    88 
    79 struct ec_master
    89 struct ec_master
    80 {
    90 {
    81     struct list_head list; /**< list item */
    91     struct list_head list; /**< list item for module's master list */
       
    92     unsigned int reserved; /**< non-zero, if the master is reserved for RT */
       
    93     unsigned int index; /**< master index */
       
    94 
    82     struct kobject kobj; /**< kobject */
    95     struct kobject kobj; /**< kobject */
    83     unsigned int index; /**< master index */
    96 
    84     struct list_head slaves; /**< list of slaves on the bus */
    97     struct list_head slaves; /**< list of slaves on the bus */
    85     unsigned int slave_count; /**< number of slaves on the bus */
    98     unsigned int slave_count; /**< number of slaves on the bus */
       
    99 
    86     ec_device_t *device; /**< EtherCAT device */
   100     ec_device_t *device; /**< EtherCAT device */
       
   101 
    87     struct list_head command_queue; /**< command queue */
   102     struct list_head command_queue; /**< command queue */
    88     uint8_t command_index; /**< current command index */
   103     uint8_t command_index; /**< current command index */
       
   104 
    89     struct list_head domains; /**< list of domains */
   105     struct list_head domains; /**< list of domains */
       
   106 
    90     ec_command_t simple_command; /**< command structure for initialization */
   107     ec_command_t simple_command; /**< command structure for initialization */
    91     ec_command_t watch_command; /**< command for watching the slaves */
   108     unsigned int timeout; /**< timeout in synchronous IO */
    92     unsigned int slaves_responding; /**< number of responding slaves */
   109 
    93     ec_slave_state_t slave_states; /**< states of the responding slaves */
       
    94     int debug_level; /**< master debug level */
   110     int debug_level; /**< master debug level */
    95     ec_stats_t stats; /**< cyclic statistics */
   111     ec_stats_t stats; /**< cyclic statistics */
    96     unsigned int timeout; /**< timeout in synchronous IO */
   112 
    97     struct list_head eoe_slaves; /**< Ethernet-over-EtherCAT slaves */
   113     struct workqueue_struct *workqueue; /**< master workqueue */
    98     unsigned int reserved; /**< true, if the master is reserved for RT */
   114     struct work_struct freerun_work; /**< free run work object */
    99     struct timer_list freerun_timer; /**< timer object for free run mode */
   115     ec_fsm_t fsm; /**< master state machine */
   100     ec_master_mode_t mode; /**< master mode */
   116     ec_master_mode_t mode; /**< master mode */
       
   117 
       
   118     struct timer_list eoe_timer; /** EoE timer object */
       
   119     unsigned int eoe_running; /**< non-zero, if EoE processing is active. */
       
   120     struct list_head eoe_handlers; /**< Ethernet-over-EtherCAT handlers */
       
   121     spinlock_t internal_lock; /**< spinlock used in freerun mode */
       
   122     int (*request_cb)(void *); /**< lock request callback */
       
   123     void (*release_cb)(void *); /**< lock release callback */
       
   124     void *cb_data; /**< data parameter of locking callbacks */
   101 };
   125 };
   102 
   126 
   103 /*****************************************************************************/
   127 /*****************************************************************************/
   104 
   128 
   105 // master creation and deletion
   129 // master creation and deletion
   106 int ec_master_init(ec_master_t *, unsigned int);
   130 int ec_master_init(ec_master_t *, unsigned int, unsigned int);
   107 void ec_master_clear(struct kobject *);
   131 void ec_master_clear(struct kobject *);
   108 void ec_master_reset(ec_master_t *);
   132 void ec_master_reset(ec_master_t *);
   109 
   133 
   110 // free run
   134 // free run
   111 void ec_master_freerun_start(ec_master_t *);
   135 void ec_master_freerun_start(ec_master_t *);
   112 void ec_master_freerun_stop(ec_master_t *);
   136 void ec_master_freerun_stop(ec_master_t *);
       
   137 
       
   138 // EoE
       
   139 void ec_master_eoe_start(ec_master_t *);
       
   140 void ec_master_eoe_stop(ec_master_t *);
   113 
   141 
   114 // IO
   142 // IO
   115 void ec_master_receive(ec_master_t *, const uint8_t *, size_t);
   143 void ec_master_receive(ec_master_t *, const uint8_t *, size_t);
   116 void ec_master_queue_command(ec_master_t *, ec_command_t *);
   144 void ec_master_queue_command(ec_master_t *, ec_command_t *);
   117 int ec_master_simple_io(ec_master_t *, ec_command_t *);
   145 int ec_master_simple_io(ec_master_t *, ec_command_t *);
   118 
   146 
   119 // slave management
   147 // slave management
   120 int ec_master_bus_scan(ec_master_t *);
   148 int ec_master_bus_scan(ec_master_t *);
   121 
   149 
   122 // misc.
   150 // misc.
       
   151 void ec_master_clear_slaves(ec_master_t *);
       
   152 void ec_sync_config(const ec_sync_t *, uint8_t *);
       
   153 void ec_eeprom_sync_config(const ec_eeprom_sync_t *, uint8_t *);
       
   154 void ec_fmmu_config(const ec_fmmu_t *, uint8_t *);
   123 void ec_master_output_stats(ec_master_t *);
   155 void ec_master_output_stats(ec_master_t *);
   124 void ec_master_run_eoe(ec_master_t *);
       
   125 
   156 
   126 /*****************************************************************************/
   157 /*****************************************************************************/
   127 
   158 
   128 #endif
   159 #endif