fp@1624: /****************************************************************************** fp@1624: * fp@1624: * $Id$ fp@1624: * fp@1624: * Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH fp@1624: * fp@1624: * This file is part of the IgH EtherCAT Master. fp@1624: * fp@1624: * The IgH EtherCAT Master is free software; you can redistribute it fp@1624: * and/or modify it under the terms of the GNU General Public License fp@1624: * as published by the Free Software Foundation; either version 2 of the fp@1624: * License, or (at your option) any later version. fp@1624: * fp@1624: * The IgH EtherCAT Master is distributed in the hope that it will be fp@1624: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of fp@1624: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the fp@1624: * GNU General Public License for more details. fp@1624: * fp@1624: * You should have received a copy of the GNU General Public License fp@1624: * along with the IgH EtherCAT Master; if not, write to the Free Software fp@1624: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA fp@1624: * fp@1624: * The right to use EtherCAT Technology is granted and comes free of fp@1624: * charge under condition of compatibility of product made by fp@1624: * Licensee. People intending to distribute/sell products based on the fp@1624: * code, have to sign an agreement to guarantee that products using fp@1624: * software based on IgH EtherCAT master stay compatible with the actual fp@1624: * EtherCAT specification (which are released themselves as an open fp@1624: * standard) as the (only) precondition to have the right to use EtherCAT fp@1624: * Technology, IP and trade marks. fp@1624: * fp@1624: *****************************************************************************/ fp@1624: fp@1624: /** fp@1624: \file fp@1624: EtherCAT datagram structure. fp@1624: */ fp@1624: fp@1624: /*****************************************************************************/ fp@1624: fp@1624: #ifndef _EC_DATAGRAM_H_ fp@1624: #define _EC_DATAGRAM_H_ fp@1624: fp@1624: #include fp@1624: #include fp@1624: #include fp@1624: fp@1624: #include "globals.h" fp@1624: fp@1624: /*****************************************************************************/ fp@1624: fp@1624: /** fp@1624: EtherCAT datagram type. fp@1624: */ fp@1624: fp@1624: typedef enum fp@1624: { fp@1624: EC_CMD_NONE = 0x00, /**< Dummy */ fp@1624: EC_CMD_APRD = 0x01, /**< Auto-increment physical read */ fp@1624: EC_CMD_APWR = 0x02, /**< Auto-increment physical write */ fp@1624: EC_CMD_NPRD = 0x04, /**< Node-addressed physical read */ fp@1624: EC_CMD_NPWR = 0x05, /**< Node-addressed physical write */ fp@1624: EC_CMD_BRD = 0x07, /**< Broadcast read */ fp@1624: EC_CMD_BWR = 0x08, /**< Broadcast write */ fp@1624: EC_CMD_LRW = 0x0C /**< Logical read/write */ fp@1624: } fp@1624: ec_datagram_type_t; fp@1624: fp@1624: /** fp@1624: EtherCAT datagram state. fp@1624: */ fp@1624: fp@1624: typedef enum fp@1624: { fp@1624: EC_CMD_INIT, /**< new datagram */ fp@1624: EC_CMD_QUEUED, /**< datagram queued by master */ fp@1624: EC_CMD_SENT, /**< datagram has been sent */ fp@1624: EC_CMD_RECEIVED, /**< datagram has been received */ fp@1624: EC_CMD_TIMEOUT, /**< datagram timed out */ fp@1624: EC_CMD_ERROR /**< error while sending/receiving */ fp@1624: } fp@1624: ec_datagram_state_t; fp@1624: fp@1624: /*****************************************************************************/ fp@1624: fp@1624: /** fp@1624: EtherCAT address. fp@1624: */ fp@1624: fp@1624: typedef union fp@1624: { fp@1624: struct fp@1624: { fp@1624: uint16_t slave; /**< configured or autoincrement address */ fp@1624: uint16_t mem; /**< physical memory address */ fp@1624: } fp@1624: physical; /**< physical address */ fp@1624: fp@1624: uint32_t logical; /**< logical address */ fp@1624: } fp@1624: ec_address_t; fp@1624: fp@1624: /*****************************************************************************/ fp@1624: fp@1624: /** fp@1624: EtherCAT datagram. fp@1624: */ fp@1624: fp@1624: typedef struct fp@1624: { fp@1624: struct list_head list; /**< needed by domain datagram lists */ fp@1624: struct list_head queue; /**< master datagram queue item */ fp@1624: ec_datagram_type_t type; /**< datagram type (APRD, BWR, etc) */ fp@1624: ec_address_t address; /**< receipient address */ fp@1624: uint8_t *data; /**< datagram data */ fp@1624: size_t mem_size; /**< datagram \a data memory size */ fp@1624: size_t data_size; /**< size of the data in \a data */ fp@1624: uint8_t index; /**< datagram index (set by master) */ fp@1624: uint16_t working_counter; /**< working counter */ fp@1624: ec_datagram_state_t state; /**< datagram state */ fp@1624: cycles_t t_sent; /**< time, the datagrams was sent */ fp@1624: } fp@1624: ec_datagram_t; fp@1624: fp@1624: /*****************************************************************************/ fp@1624: fp@1624: void ec_datagram_init(ec_datagram_t *); fp@1624: void ec_datagram_clear(ec_datagram_t *); fp@1624: int ec_datagram_prealloc(ec_datagram_t *, size_t); fp@1624: fp@1624: int ec_datagram_nprd(ec_datagram_t *, uint16_t, uint16_t, size_t); fp@1624: int ec_datagram_npwr(ec_datagram_t *, uint16_t, uint16_t, size_t); fp@1624: int ec_datagram_aprd(ec_datagram_t *, uint16_t, uint16_t, size_t); fp@1624: int ec_datagram_apwr(ec_datagram_t *, uint16_t, uint16_t, size_t); fp@1624: int ec_datagram_brd(ec_datagram_t *, uint16_t, size_t); fp@1624: int ec_datagram_bwr(ec_datagram_t *, uint16_t, size_t); fp@1624: int ec_datagram_lrw(ec_datagram_t *, uint32_t, size_t); fp@1624: fp@1624: /*****************************************************************************/ fp@1624: fp@1624: #endif