fp@145: /****************************************************************************** fp@145: * fp@145: * $Id$ fp@145: * fp@1618: * Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH fp@1618: * fp@1618: * This file is part of the IgH EtherCAT Master. fp@1618: * fp@1618: * The IgH EtherCAT Master is free software; you can redistribute it fp@1618: * and/or modify it under the terms of the GNU General Public License fp@1618: * as published by the Free Software Foundation; version 2 of the License. fp@1618: * fp@1618: * The IgH EtherCAT Master is distributed in the hope that it will be fp@1618: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of fp@1618: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the fp@1618: * GNU General Public License for more details. fp@1618: * fp@1618: * You should have received a copy of the GNU General Public License fp@1618: * along with the IgH EtherCAT Master; if not, write to the Free Software fp@1618: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA fp@1618: * fp@145: *****************************************************************************/ fp@145: fp@1618: /** fp@1618: \file fp@1618: Ethernet-over-EtherCAT (EoE). fp@1618: */ fp@1618: fp@1618: /*****************************************************************************/ fp@1618: fp@145: #include "../include/ecrt.h" fp@145: #include "globals.h" fp@145: #include "master.h" fp@145: #include "slave.h" fp@145: #include "mailbox.h" fp@145: #include "ethernet.h" fp@145: fp@145: /*****************************************************************************/ fp@145: fp@1618: /** fp@1618: EoE constructor. fp@1618: */ fp@1618: fp@145: void ec_eoe_init(ec_eoe_t *eoe, ec_slave_t *slave) fp@145: { fp@145: eoe->slave = slave; fp@145: eoe->rx_state = EC_EOE_IDLE; fp@145: } fp@145: fp@145: /*****************************************************************************/ fp@145: fp@1618: /** fp@1618: EoE destructor. fp@1618: */ fp@1618: fp@145: void ec_eoe_clear(ec_eoe_t *eoe) fp@145: { fp@145: } fp@145: fp@145: /*****************************************************************************/ fp@145: fp@1618: /** fp@1618: Runs the EoE state machine. fp@1618: */ fp@1618: fp@145: void ec_eoe_run(ec_eoe_t *eoe) fp@145: { fp@145: uint8_t *data; fp@145: ec_master_t *master; fp@145: size_t rec_size; fp@146: #if 0 fp@146: unsigned int i; fp@146: uint8_t fragment_number; fp@146: uint8_t complete_size; fp@146: uint8_t frame_number; fp@146: uint8_t last_fragment; fp@146: #endif fp@145: fp@145: master = eoe->slave->master; fp@145: fp@145: if (eoe->rx_state == EC_EOE_IDLE) { fp@145: ec_slave_mbox_prepare_check(eoe->slave); fp@145: ec_master_queue_command(master, &eoe->slave->mbox_command); fp@145: eoe->rx_state = EC_EOE_CHECKING; fp@145: return; fp@145: } fp@145: fp@145: if (eoe->rx_state == EC_EOE_CHECKING) { fp@145: if (eoe->slave->mbox_command.state != EC_CMD_RECEIVED) { fp@145: master->stats.eoe_errors++; fp@145: eoe->rx_state = EC_EOE_IDLE; fp@145: return; fp@145: } fp@145: if (!ec_slave_mbox_check(eoe->slave)) { fp@145: eoe->rx_state = EC_EOE_IDLE; fp@145: return; fp@145: } fp@145: ec_slave_mbox_prepare_fetch(eoe->slave); fp@145: ec_master_queue_command(master, &eoe->slave->mbox_command); fp@145: eoe->rx_state = EC_EOE_FETCHING; fp@145: return; fp@145: } fp@145: fp@145: if (eoe->rx_state == EC_EOE_FETCHING) { fp@145: if (eoe->slave->mbox_command.state != EC_CMD_RECEIVED) { fp@145: master->stats.eoe_errors++; fp@145: eoe->rx_state = EC_EOE_IDLE; fp@145: return; fp@145: } fp@145: if (!(data = ec_slave_mbox_fetch(eoe->slave, 0x02, &rec_size))) { fp@145: master->stats.eoe_errors++; fp@145: eoe->rx_state = EC_EOE_IDLE; fp@145: return; fp@145: } fp@146: fp@146: #if 0 fp@146: fragment_number = EC_READ_U16(data + 2) & 0x003F; fp@146: complete_size = (EC_READ_U16(data + 2) >> 6) & 0x003F; fp@146: frame_number = (EC_READ_U16(data + 2) >> 12) & 0x0003; fp@146: last_fragment = (EC_READ_U16(data + 2) >> 15) & 0x0001; fp@146: fp@146: EC_DBG("EOE %s received, fragment: %i, complete size: %i (0x%02X)," fp@146: " frame %i%s\n", fp@146: fragment_number ? "fragment" : "initiate", fragment_number, fp@146: (complete_size - 31) / 32, complete_size, frame_number, fp@146: last_fragment ? ", last fragment" : ""); fp@146: EC_DBG(""); fp@146: for (i = 0; i < rec_size - 2; i++) { fp@146: printk("%02X ", data[i + 2]); fp@146: if ((i + 1) % 16 == 0) { fp@146: printk("\n"); fp@146: EC_DBG(""); fp@146: } fp@146: } fp@146: printk("\n"); fp@146: #endif fp@146: fp@145: eoe->rx_state = EC_EOE_IDLE; fp@145: return; fp@145: } fp@145: } fp@145: fp@145: /*****************************************************************************/ fp@145: fp@1618: /** fp@1618: Prints EoE object information. fp@1618: */ fp@1618: fp@145: void ec_eoe_print(const ec_eoe_t *eoe) fp@145: { fp@145: EC_INFO(" EoE slave %i\n", eoe->slave->ring_position); fp@145: EC_INFO(" RX State %i\n", eoe->rx_state); fp@145: } fp@145: fp@145: /*****************************************************************************/