fp@98: /****************************************************************************** fp@98: * fp@98: * $Id$ fp@98: * fp@1326: * Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH fp@197: * fp@197: * This file is part of the IgH EtherCAT Master. fp@197: * fp@1326: * The IgH EtherCAT Master is free software; you can redistribute it and/or fp@1326: * modify it under the terms of the GNU General Public License version 2, as fp@1326: * published by the Free Software Foundation. fp@197: * fp@1326: * The IgH EtherCAT Master is distributed in the hope that it will be useful, fp@1326: * but WITHOUT ANY WARRANTY; without even the implied warranty of fp@1326: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General fp@1326: * Public License for more details. fp@197: * fp@1326: * You should have received a copy of the GNU General Public License along fp@1326: * 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@1363: * --- fp@1363: * fp@1363: * The license mentioned above concerns the source code only. Using the fp@1363: * EtherCAT technology and brand is only permitted in compliance with the fp@1363: * industrial property and similar rights of Beckhoff Automation GmbH. fp@246: * fp@98: *****************************************************************************/ fp@98: fp@199: /** fp@199: \file fp@293: EtherCAT datagram structure. fp@199: */ fp@199: fp@199: /*****************************************************************************/ fp@199: fp@883: #ifndef __EC_DATAGRAM_H__ fp@883: #define __EC_DATAGRAM_H__ fp@98: fp@98: #include fp@294: #include fp@208: #include fp@98: fp@98: #include "globals.h" fp@98: fp@98: /*****************************************************************************/ fp@98: fp@809: /** EtherCAT datagram type. fp@809: */ fp@809: typedef enum { fp@809: EC_DATAGRAM_NONE = 0x00, /**< Dummy. */ fp@815: EC_DATAGRAM_APRD = 0x01, /**< Auto Increment Physical Read. */ fp@815: EC_DATAGRAM_APWR = 0x02, /**< Auto Increment Physical Write. */ fp@815: EC_DATAGRAM_APRW = 0x03, /**< Auto Increment Physical ReadWrite. */ fp@815: EC_DATAGRAM_FPRD = 0x04, /**< Configured Address Physical Read. */ fp@815: EC_DATAGRAM_FPWR = 0x05, /**< Configured Address Physical Write. */ fp@815: EC_DATAGRAM_FPRW = 0x06, /**< Configured Address Physical ReadWrite. */ fp@815: EC_DATAGRAM_BRD = 0x07, /**< Broadcast Read. */ fp@815: EC_DATAGRAM_BWR = 0x08, /**< Broadcast Write. */ fp@815: EC_DATAGRAM_BRW = 0x09, /**< Broadcast ReadWrite. */ fp@815: EC_DATAGRAM_LRD = 0x0A, /**< Logical Read. */ fp@815: EC_DATAGRAM_LWR = 0x0B, /**< Logical Write. */ fp@815: EC_DATAGRAM_LRW = 0x0C, /**< Logical ReadWrite. */ fp@815: EC_DATAGRAM_ARMW = 0x0D, /**< Auto Increment Physical Read Multiple fp@815: Write. */ fp@815: EC_DATAGRAM_FRMW = 0x0E, /**< Configured Address Physical Read Multiple fp@815: Write. */ fp@809: } ec_datagram_type_t; fp@98: fp@98: /*****************************************************************************/ fp@98: fp@809: /** EtherCAT datagram state. fp@809: */ fp@809: typedef enum { fp@809: EC_DATAGRAM_INIT, /**< Initial state of a new datagram. */ fp@809: EC_DATAGRAM_QUEUED, /**< Queued for sending. */ fp@809: EC_DATAGRAM_SENT, /**< Sent (still in the queue). */ fp@809: EC_DATAGRAM_RECEIVED, /**< Received (dequeued). */ fp@809: EC_DATAGRAM_TIMED_OUT, /**< Timed out (dequeued). */ fp@809: EC_DATAGRAM_ERROR /**< Error while sending/receiving (dequeued). */ fp@809: } ec_datagram_state_t; fp@98: fp@809: /*****************************************************************************/ fp@809: fp@809: /** EtherCAT datagram. fp@809: */ fp@809: typedef struct { fp@809: struct list_head queue; /**< Master datagram queue item. */ fp@809: struct list_head sent; /**< Master list item for sent datagrams. */ fp@2268: ec_device_index_t device_index; /**< Device via which the datagram shall fp@2268: be / was sent. */ fp@809: ec_datagram_type_t type; /**< Datagram type (APRD, BWR, etc.). */ fp@809: uint8_t address[EC_ADDR_LEN]; /**< Recipient address. */ fp@809: uint8_t *data; /**< Datagram payload. */ fp@809: ec_origin_t data_origin; /**< Origin of the \a data memory. */ fp@809: size_t mem_size; /**< Datagram \a data memory size. */ fp@809: size_t data_size; /**< Size of the data in \a data. */ fp@809: uint8_t index; /**< Index (set by master). */ fp@809: uint16_t working_counter; /**< Working counter. */ fp@809: ec_datagram_state_t state; /**< State. */ fp@1040: #ifdef EC_HAVE_CYCLES fp@809: cycles_t cycles_sent; /**< Time, when the datagram was sent. */ fp@1040: #endif fp@809: unsigned long jiffies_sent; /**< Jiffies, when the datagram was sent. */ fp@1040: #ifdef EC_HAVE_CYCLES fp@809: cycles_t cycles_received; /**< Time, when the datagram was received. */ fp@1040: #endif fp@809: unsigned long jiffies_received; /**< Jiffies, when the datagram was fp@809: received. */ fp@809: unsigned int skip_count; /**< Number of requeues when not yet received. */ fp@809: unsigned long stats_output_jiffies; /**< Last statistics output. */ fp@809: char name[EC_DATAGRAM_NAME_SIZE]; /**< Description of the datagram. */ fp@809: } ec_datagram_t; fp@98: fp@98: /*****************************************************************************/ fp@98: fp@293: void ec_datagram_init(ec_datagram_t *); fp@293: void ec_datagram_clear(ec_datagram_t *); fp@1553: void ec_datagram_unqueue(ec_datagram_t *); fp@293: int ec_datagram_prealloc(ec_datagram_t *, size_t); fp@1225: void ec_datagram_zero(ec_datagram_t *); fp@144: fp@293: int ec_datagram_aprd(ec_datagram_t *, uint16_t, uint16_t, size_t); fp@293: int ec_datagram_apwr(ec_datagram_t *, uint16_t, uint16_t, size_t); fp@815: int ec_datagram_aprw(ec_datagram_t *, uint16_t, uint16_t, size_t); fp@815: int ec_datagram_armw(ec_datagram_t *, uint16_t, uint16_t, size_t); fp@815: int ec_datagram_fprd(ec_datagram_t *, uint16_t, uint16_t, size_t); fp@815: int ec_datagram_fpwr(ec_datagram_t *, uint16_t, uint16_t, size_t); fp@815: int ec_datagram_fprw(ec_datagram_t *, uint16_t, uint16_t, size_t); fp@815: int ec_datagram_frmw(ec_datagram_t *, uint16_t, uint16_t, size_t); fp@293: int ec_datagram_brd(ec_datagram_t *, uint16_t, size_t); fp@293: int ec_datagram_bwr(ec_datagram_t *, uint16_t, size_t); fp@815: int ec_datagram_brw(ec_datagram_t *, uint16_t, size_t); fp@2269: int ec_datagram_lrd(ec_datagram_t *, uint32_t, size_t); fp@2269: int ec_datagram_lwr(ec_datagram_t *, uint32_t, size_t); fp@2269: int ec_datagram_lrw(ec_datagram_t *, uint32_t, size_t); fp@2269: int ec_datagram_lrd_ext(ec_datagram_t *, uint32_t, size_t, uint8_t *); fp@2269: int ec_datagram_lwr_ext(ec_datagram_t *, uint32_t, size_t, uint8_t *); fp@2269: int ec_datagram_lrw_ext(ec_datagram_t *, uint32_t, size_t, uint8_t *); fp@98: fp@1822: void ec_datagram_print_state(const ec_datagram_t *); fp@713: void ec_datagram_print_wc_error(const ec_datagram_t *); fp@816: void ec_datagram_output_stats(ec_datagram_t *); fp@816: const char *ec_datagram_type_string(const ec_datagram_t *); fp@713: fp@98: /*****************************************************************************/ fp@98: fp@98: #endif