master/ethernet.c
author Florian Pose <fp@igh-essen.com>
Thu, 20 Apr 2006 14:38:41 +0000
branchstable-1.0
changeset 1617 9f83a343ae75
parent 195 674071846ee3
child 197 b9a6e2c22745
child 1618 5cff10efb927
permissions -rw-r--r--
MERGE trunk -r354:355 -> branches/stable-1.0 (version numbers)
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  e t h e r n e t . c
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Ethernet-over-EtherCAT (EoE)
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  $Id$
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *****************************************************************************/
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
#include "../include/ecrt.h"
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
#include "globals.h"
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
#include "master.h"
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
#include "slave.h"
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
#include "mailbox.h"
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
#include "ethernet.h"
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
/*****************************************************************************/
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
void ec_eoe_init(ec_eoe_t *eoe, ec_slave_t *slave)
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
{
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
    eoe->slave = slave;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
    eoe->rx_state = EC_EOE_IDLE;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
}
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
/*****************************************************************************/
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
void ec_eoe_clear(ec_eoe_t *eoe)
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
{
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
}
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
/*****************************************************************************/
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
void ec_eoe_run(ec_eoe_t *eoe)
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
{
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
    uint8_t *data;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
    ec_master_t *master;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
    size_t rec_size;
146
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
    39
#if 0
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
    40
    unsigned int i;
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
    41
    uint8_t fragment_number;
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
    42
    uint8_t complete_size;
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
    43
    uint8_t frame_number;
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
    44
    uint8_t last_fragment;
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
    45
#endif
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
    master = eoe->slave->master;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
    if (eoe->rx_state == EC_EOE_IDLE) {
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
        ec_slave_mbox_prepare_check(eoe->slave);
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
        ec_master_queue_command(master, &eoe->slave->mbox_command);
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
        eoe->rx_state = EC_EOE_CHECKING;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
        return;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
    }
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
    if (eoe->rx_state == EC_EOE_CHECKING) {
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
        if (eoe->slave->mbox_command.state != EC_CMD_RECEIVED) {
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
            master->stats.eoe_errors++;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
            eoe->rx_state = EC_EOE_IDLE;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
            return;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
        }
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
        if (!ec_slave_mbox_check(eoe->slave)) {
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
            eoe->rx_state = EC_EOE_IDLE;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
            return;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
        }
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
        ec_slave_mbox_prepare_fetch(eoe->slave);
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
        ec_master_queue_command(master, &eoe->slave->mbox_command);
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
        eoe->rx_state = EC_EOE_FETCHING;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
        return;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
    }
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
    if (eoe->rx_state == EC_EOE_FETCHING) {
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
        if (eoe->slave->mbox_command.state != EC_CMD_RECEIVED) {
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
            master->stats.eoe_errors++;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
            eoe->rx_state = EC_EOE_IDLE;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
            return;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
        }
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
        if (!(data = ec_slave_mbox_fetch(eoe->slave, 0x02, &rec_size))) {
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
            master->stats.eoe_errors++;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
            eoe->rx_state = EC_EOE_IDLE;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
            return;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
        }
146
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
    83
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
    84
#if 0
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
    85
        fragment_number = EC_READ_U16(data + 2) & 0x003F;
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
    86
        complete_size = (EC_READ_U16(data + 2) >> 6) & 0x003F;
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
    87
        frame_number = (EC_READ_U16(data + 2) >> 12) & 0x0003;
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
    88
        last_fragment = (EC_READ_U16(data + 2) >> 15) & 0x0001;
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
    89
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
    90
        EC_DBG("EOE %s received, fragment: %i, complete size: %i (0x%02X),"
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
    91
               " frame %i%s\n",
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
    92
               fragment_number ? "fragment" : "initiate", fragment_number,
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
    93
               (complete_size - 31) / 32, complete_size, frame_number,
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
    94
               last_fragment ? ", last fragment" : "");
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
    95
        EC_DBG("");
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
    96
        for (i = 0; i < rec_size - 2; i++) {
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
    97
            printk("%02X ", data[i + 2]);
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
    98
            if ((i + 1) % 16 == 0) {
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
    99
                printk("\n");
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   100
                EC_DBG("");
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   101
            }
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   102
        }
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   103
        printk("\n");
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   104
#endif
73a5f7dd3024 Versuche mit EoE.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   105
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
        eoe->rx_state = EC_EOE_IDLE;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
        return;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
    }
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
}
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
/*****************************************************************************/
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
void ec_eoe_print(const ec_eoe_t *eoe)
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
{
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
    EC_INFO("  EoE slave %i\n", eoe->slave->ring_position);
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
    EC_INFO("    RX State %i\n", eoe->rx_state);
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
}
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
/*****************************************************************************/