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@883: #ifndef __EC_MASTER_H__ fp@883: #define __EC_MASTER_H__ fp@0: fp@95: #include fp@178: #include fp@191: #include fp@601: #include fp@381: #include fp@95: fp@54: #include "device.h" fp@54: #include "domain.h" fp@528: #include "fsm_master.h" fp@922: #include "cdev.h" fp@0: fp@39: /*****************************************************************************/ fp@0: fp@792: /** EtherCAT master mode. fp@792: */ fp@792: typedef enum { fp@305: EC_MASTER_MODE_ORPHANED, fp@306: EC_MASTER_MODE_IDLE, fp@325: EC_MASTER_MODE_OPERATION fp@849: } ec_master_mode_t; fp@191: fp@191: /*****************************************************************************/ fp@191: fp@792: /** Cyclic statistics. fp@792: */ fp@792: typedef struct { fp@293: unsigned int timeouts; /**< datagram timeouts */ fp@195: unsigned int corrupted; /**< corrupted frames */ fp@332: unsigned int unmatched; /**< unmatched datagrams (received, but not fp@332: queued any longer) */ fp@344: unsigned long output_jiffies; /**< time of last output */ fp@849: } ec_stats_t; fp@98: fp@98: /*****************************************************************************/ fp@98: fp@792: /** EtherCAT master. fp@792: * fp@792: * Manages slaves, domains and IO. fp@792: */ fp@849: struct ec_master { fp@647: struct kobject kobj; /**< kobject */ fp@241: unsigned int index; /**< master index */ fp@647: unsigned int reserved; /**< non-zero, if the master is reserved for RT */ fp@241: fp@922: ec_cdev_t cdev; /**< Master character device. */ fp@922: fp@579: ec_device_t main_device; /**< EtherCAT device */ fp@639: const uint8_t *main_mac; /**< MAC address of main device */ fp@579: ec_device_t backup_device; /**< EtherCAT backup device */ fp@639: const uint8_t *backup_mac; /**< MAC address of backup device */ fp@381: struct semaphore device_sem; /**< device semaphore */ fp@334: fp@528: ec_fsm_master_t fsm; /**< master state machine */ fp@528: ec_datagram_t fsm_datagram; /**< datagram used for state machines */ fp@334: ec_master_mode_t mode; /**< master mode */ fp@637: unsigned int injection_seq_fsm; /**< datagram injection sequence number fp@637: for the FSM side */ fp@637: unsigned int injection_seq_rt; /**< datagram injection sequence number fp@637: for the realtime side */ fp@334: 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@792: fp@792: struct list_head configs; /**< Bus configuration list. */ fp@792: unsigned int configs_attached; /**< Slave configurations were attached. */ fp@656: fp@900: unsigned int scan_busy; /**< Current scan state. */ fp@656: unsigned int allow_scan; /**< non-zero, if slave scanning is allowed */ fp@656: struct semaphore scan_sem; /**< semaphore protecting the scan_state fp@656: variable and the allow_scan flag */ fp@656: wait_queue_head_t scan_queue; /**< queue for processes that wait for fp@656: slave scanning */ fp@656: fp@900: unsigned int config_busy; /**< State of slave configuration. */ fp@656: unsigned int allow_config; /**< non-zero, if slave scanning is allowed */ fp@656: struct semaphore config_sem; /**< semaphore protecting the config_state fp@656: variable and the allow_config flag */ fp@656: wait_queue_head_t config_queue; /**< queue for processes that wait for fp@656: slave configuration */ 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@664: unsigned int frames_timed_out; /**< there were frame timeouts in the last fp@664: call to ecrt_master_receive() */ fp@241: fp@525: int thread_id; /**< master thread PID */ fp@525: struct completion thread_exit; /**< thread completion object */ fp@335: uint32_t idle_cycle_times[HZ]; /**< Idle cycle times ring */ fp@335: unsigned int idle_cycle_time_pos; /**< time ring buffer position */ fp@241: fp@715: #ifdef EC_EOE fp@286: struct timer_list eoe_timer; /**< EoE timer object */ fp@661: unsigned int eoe_running; /**< non-zero, if EoE processing is active. */ fp@661: struct list_head eoe_handlers; /**< Ethernet-over-EtherCAT handlers */ fp@335: uint32_t eoe_cycle_times[HZ]; /**< EoE cycle times ring */ fp@335: unsigned int eoe_cycle_time_pos; /**< time ring buffer position */ fp@715: #endif fp@334: fp@306: 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@661: int (*ext_request_cb)(void *); /**< external lock request callback */ fp@661: void (*ext_release_cb)(void *); /**< externam lock release callback */ fp@661: void *ext_cb_data; /**< data parameter of external locking callbacks */ fp@268: fp@872: struct list_head sii_requests; /**< SII write requests */ fp@872: struct semaphore sii_sem; /**< semaphore protecting the list of fp@872: SII write requests */ fp@872: wait_queue_head_t sii_queue; /**< wait queue for SII fp@601: write requests from user space */ fp@601: fp@849: struct list_head slave_sdo_requests; /**< Sdo access requests. */ fp@646: struct semaphore sdo_sem; /**< semaphore protecting the list of fp@814: Sdo access requests */ fp@814: wait_queue_head_t sdo_queue; /**< wait queue for Sdo access requests fp@646: from user space */ fp@55: }; fp@0: fp@39: /*****************************************************************************/ fp@0: fp@448: // master creation/deletion fp@576: int ec_master_init(ec_master_t *, struct kobject *, unsigned int, fp@922: const uint8_t *, const uint8_t *, dev_t); fp@639: void ec_master_clear(ec_master_t *); fp@98: fp@446: // mode transitions fp@446: int ec_master_enter_idle_mode(ec_master_t *); fp@446: void ec_master_leave_idle_mode(ec_master_t *); fp@446: int ec_master_enter_operation_mode(ec_master_t *); fp@446: void ec_master_leave_operation_mode(ec_master_t *); fp@191: fp@715: #ifdef EC_EOE fp@251: // EoE fp@251: void ec_master_eoe_start(ec_master_t *); fp@251: void ec_master_eoe_stop(ec_master_t *); fp@715: #endif fp@251: fp@446: // datagram IO fp@331: 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@792: int ec_master_attach_slave_configs(ec_master_t *); fp@325: void ec_master_output_stats(ec_master_t *); fp@715: #ifdef EC_EOE fp@661: void ec_master_clear_eoe_handlers(ec_master_t *); fp@715: #endif fp@448: void ec_master_destroy_slaves(ec_master_t *); fp@325: fp@39: /*****************************************************************************/ fp@0: fp@0: #endif