fp@98: /****************************************************************************** fp@98: * fp@98: * $Id$ fp@98: * 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@98: *****************************************************************************/ fp@98: fp@199: /** fp@199: \file fp@293: EtherCAT datagram structure. fp@199: */ fp@199: fp@199: /*****************************************************************************/ fp@199: fp@293: #ifndef _EC_DATAGRAM_H_ fp@293: #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@719: /** size of the datagram description string */ fp@719: #define EC_DATAGRAM_NAME_SIZE 20 fp@719: fp@719: /*****************************************************************************/ fp@719: fp@809: /** EtherCAT datagram type. fp@809: */ fp@809: typedef enum { fp@809: EC_DATAGRAM_NONE = 0x00, /**< Dummy. */ fp@809: EC_DATAGRAM_APRD = 0x01, /**< Auto-increment physical read. */ fp@809: EC_DATAGRAM_APWR = 0x02, /**< Auto-increment physical write. */ fp@809: EC_DATAGRAM_NPRD = 0x04, /**< Node-addressed physical read. */ fp@809: EC_DATAGRAM_NPWR = 0x05, /**< Node-addressed physical write. */ fp@809: EC_DATAGRAM_BRD = 0x07, /**< Broadcast read. */ fp@809: EC_DATAGRAM_BWR = 0x08, /**< Broadcast write. */ fp@809: EC_DATAGRAM_LRW = 0x0C /**< Logical read/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 list; /**< Needed by domain datagram lists. */ fp@809: struct list_head queue; /**< Master datagram queue item. */ fp@809: struct list_head sent; /**< Master list item for sent datagrams. */ 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@809: cycles_t cycles_sent; /**< Time, when the datagram was sent. */ fp@809: unsigned long jiffies_sent; /**< Jiffies, when the datagram was sent. */ fp@809: cycles_t cycles_received; /**< Time, when the datagram was received. */ 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@293: int ec_datagram_prealloc(ec_datagram_t *, size_t); fp@144: fp@293: int ec_datagram_nprd(ec_datagram_t *, uint16_t, uint16_t, size_t); fp@293: int ec_datagram_npwr(ec_datagram_t *, uint16_t, uint16_t, size_t); 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@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@809: int ec_datagram_lrw(ec_datagram_t *, uint32_t, size_t, uint8_t *); fp@98: fp@713: void ec_datagram_print_wc_error(const ec_datagram_t *); fp@719: void ec_datagram_output_stats(ec_datagram_t *datagram); fp@713: fp@98: /*****************************************************************************/ fp@98: fp@98: #endif