fp@39: /****************************************************************************** fp@0: * fp@39: * $Id$ fp@0: * fp@197: * Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH fp@197: * fp@197: * This file is part of the IgH EtherCAT Master. fp@197: * fp@197: * The IgH EtherCAT Master is free software; you can redistribute it fp@197: * and/or modify it under the terms of the GNU General Public License fp@246: * as published by the Free Software Foundation; either version 2 of the fp@246: * License, or (at your option) any later version. fp@197: * fp@197: * The IgH EtherCAT Master is distributed in the hope that it will be fp@197: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of fp@197: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the fp@197: * GNU General Public License for more details. fp@197: * fp@197: * You should have received a copy of the GNU General Public License fp@197: * along with the IgH EtherCAT Master; if not, write to the Free Software fp@197: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA fp@197: * fp@246: * The right to use EtherCAT Technology is granted and comes free of fp@246: * charge under condition of compatibility of product made by fp@246: * Licensee. People intending to distribute/sell products based on the fp@246: * code, have to sign an agreement to guarantee that products using fp@246: * software based on IgH EtherCAT master stay compatible with the actual fp@246: * EtherCAT specification (which are released themselves as an open fp@246: * standard) as the (only) precondition to have the right to use EtherCAT fp@246: * Technology, IP and trade marks. fp@246: * fp@39: *****************************************************************************/ fp@0: fp@199: /** fp@199: \file fp@199: EtherCAT master structure. fp@199: */ fp@199: fp@199: /*****************************************************************************/ fp@199: fp@0: #ifndef _EC_MASTER_H_ fp@0: #define _EC_MASTER_H_ fp@0: fp@95: #include fp@178: #include fp@191: #include fp@1728: #include fp@1731: #include fp@95: fp@54: #include "device.h" fp@54: #include "domain.h" fp@1739: #include "fsm_master.h" fp@0: fp@39: /*****************************************************************************/ fp@0: fp@0: /** fp@191: EtherCAT master mode. fp@191: */ fp@191: fp@191: typedef enum fp@191: { fp@1715: EC_MASTER_MODE_ORPHANED, fp@191: EC_MASTER_MODE_IDLE, fp@1715: EC_MASTER_MODE_OPERATION fp@191: } fp@191: ec_master_mode_t; fp@191: fp@191: /*****************************************************************************/ fp@191: fp@191: /** fp@199: Cyclic statistics. fp@98: */ fp@98: fp@98: typedef struct fp@98: { fp@293: unsigned int timeouts; /**< datagram timeouts */ fp@195: unsigned int corrupted; /**< corrupted frames */ fp@1716: unsigned int skipped; /**< skipped datagrams (the ones that were fp@1716: requeued when not yet received) */ fp@1716: unsigned int unmatched; /**< unmatched datagrams (received, but not fp@1716: queued any longer) */ fp@1719: unsigned long output_jiffies; /**< time of last output */ fp@98: } fp@98: ec_stats_t; fp@98: fp@98: /*****************************************************************************/ fp@98: fp@98: /** fp@199: EtherCAT master. fp@195: Manages slaves, domains and IO. fp@0: */ fp@0: fp@55: struct ec_master fp@0: { fp@241: struct list_head list; /**< list item for module's master list */ fp@1728: atomic_t available; /**< zero, if the master is reserved for RT */ fp@241: unsigned int index; /**< master index */ fp@241: fp@195: struct kobject kobj; /**< kobject */ fp@241: fp@1716: ec_device_t *device; /**< EtherCAT device */ fp@1731: struct semaphore device_sem; /**< device semaphore */ fp@1716: fp@1739: ec_fsm_master_t fsm; /**< master state machine */ fp@1739: ec_datagram_t fsm_datagram; /**< datagram used for state machines */ fp@1716: ec_master_mode_t mode; /**< master mode */ fp@1716: fp@195: struct list_head slaves; /**< list of slaves on the bus */ fp@195: unsigned int slave_count; /**< number of slaves on the bus */ fp@241: fp@293: struct list_head datagram_queue; /**< datagram queue */ fp@293: uint8_t datagram_index; /**< current datagram index */ fp@241: fp@195: struct list_head domains; /**< list of domains */ fp@241: fp@195: int debug_level; /**< master debug level */ fp@195: ec_stats_t stats; /**< cyclic statistics */ fp@241: fp@1739: int thread_id; /**< master thread PID */ fp@1739: struct completion thread_exit; /**< thread completion object */ fp@1716: uint32_t idle_cycle_times[HZ]; /**< Idle cycle times ring */ fp@1716: unsigned int idle_cycle_time_pos; /**< time ring buffer position */ fp@241: fp@286: struct timer_list eoe_timer; /**< EoE timer object */ fp@1716: uint32_t eoe_cycle_times[HZ]; /**< EoE cycle times ring */ fp@1716: unsigned int eoe_cycle_time_pos; /**< time ring buffer position */ fp@251: unsigned int eoe_running; /**< non-zero, if EoE processing is active. */ fp@1716: unsigned int eoe_checked; /**< non-zero, if EoE processing is not fp@1716: necessary. */ fp@251: struct list_head eoe_handlers; /**< Ethernet-over-EtherCAT handlers */ fp@1716: fp@1715: spinlock_t internal_lock; /**< spinlock used in idle mode */ fp@204: int (*request_cb)(void *); /**< lock request callback */ fp@204: void (*release_cb)(void *); /**< lock release callback */ fp@204: void *cb_data; /**< data parameter of locking callbacks */ fp@268: fp@268: uint8_t eeprom_write_enable; /**< allow write operations to EEPROMs */ fp@1732: fp@1732: ec_sdo_request_t *sdo_request; /**< pointer to the current SDO request */ fp@1732: unsigned int sdo_seq_user; /**< sequence number for user space */ fp@1732: unsigned int sdo_seq_master; /**< sequence number for master */ fp@1732: struct semaphore sdo_sem; /**< SDO semaphore */ fp@1732: struct timer_list sdo_timer; /**< timer for polling sdo processing */ fp@1732: struct completion sdo_complete; /**< SDO request completion object */ fp@55: }; fp@0: fp@39: /*****************************************************************************/ fp@0: fp@1732: // master creation/deletion fp@251: int ec_master_init(ec_master_t *, unsigned int, unsigned int); fp@1732: void ec_master_destroy(ec_master_t *); fp@98: fp@1732: // mode transitions fp@1732: int ec_master_enter_idle_mode(ec_master_t *); fp@1732: void ec_master_leave_idle_mode(ec_master_t *); fp@1732: int ec_master_enter_operation_mode(ec_master_t *); fp@1732: void ec_master_leave_operation_mode(ec_master_t *); fp@191: fp@251: // EoE fp@251: void ec_master_eoe_start(ec_master_t *); fp@251: void ec_master_eoe_stop(ec_master_t *); fp@251: fp@1732: // datagram IO fp@1716: void ec_master_receive_datagrams(ec_master_t *, const uint8_t *, size_t); fp@293: void ec_master_queue_datagram(ec_master_t *, ec_datagram_t *); fp@0: fp@195: // misc. fp@1715: void ec_master_output_stats(ec_master_t *); fp@1732: void ec_master_destroy_slaves(ec_master_t *); fp@1732: void ec_master_calc_addressing(ec_master_t *); fp@1715: fp@39: /*****************************************************************************/ fp@0: fp@0: #endif