fp@145: /****************************************************************************** fp@145: * fp@145: * e t h e r n e t . c fp@145: * fp@145: * Ethernet-over-EtherCAT (EoE) fp@145: * fp@145: * $Id$ fp@145: * fp@145: *****************************************************************************/ fp@145: 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@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@145: void ec_eoe_clear(ec_eoe_t *eoe) fp@145: { fp@145: } fp@145: fp@145: /*****************************************************************************/ fp@145: 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@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: /*****************************************************************************/