examples/mini/mini.c
author Florian Pose <fp@igh-essen.com>
Tue, 19 Feb 2008 16:18:01 +0000
changeset 802 b947d0b09f9a
parent 799 068a58b96965
child 809 ec4ef8911824
permissions -rw-r--r--
Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 226
diff changeset
    11
 *  as published by the Free Software Foundation; either version 2 of the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 226
diff changeset
    12
 *  License, or (at your option) any later version.
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *  GNU General Public License for more details.
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 226
diff changeset
    23
 *  The right to use EtherCAT Technology is granted and comes free of
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 226
diff changeset
    24
 *  charge under condition of compatibility of product made by
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 226
diff changeset
    25
 *  Licensee. People intending to distribute/sell products based on the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 226
diff changeset
    26
 *  code, have to sign an agreement to guarantee that products using
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 226
diff changeset
    27
 *  software based on IgH EtherCAT master stay compatible with the actual
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 226
diff changeset
    28
 *  EtherCAT specification (which are released themselves as an open
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 226
diff changeset
    29
 *  standard) as the (only) precondition to have the right to use EtherCAT
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 226
diff changeset
    30
 *  Technology, IP and trade marks.
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 226
diff changeset
    31
 *
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
 *****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
#include <linux/module.h>
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
#include <linux/timer.h>
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
#include <linux/spinlock.h>
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include <linux/interrupt.h>
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
223
daa5e5656b35 Applied new path information to example modules.
Florian Pose <fp@igh-essen.com>
parents: 220
diff changeset
    39
#include "../../include/ecrt.h" // EtherCAT realtime interface
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 280
diff changeset
    40
#include "../../include/ecdb.h" // EtherCAT slave database
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
    42
#define PFX "ec_mini: "
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
    43
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
#define FREQUENCY 100
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
516
f703e33ee395 Adjusted examples to EtherLab starter kit hardware.
Florian Pose <fp@igh-essen.com>
parents: 513
diff changeset
    46
//#define KBUS
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
    47
#define PDOS
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
    48
#define MAPPING
457
2b4ba84b6058 Minor changes to minimal example.
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
    49
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
    52
static struct timer_list timer;
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
// EtherCAT
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
    55
static ec_master_t *master = NULL;
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
    56
static ec_domain_t *domain1 = NULL;
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
spinlock_t master_lock = SPIN_LOCK_UNLOCKED;
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
    58
static ec_master_state_t master_state, old_state = {};
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
// data fields
457
2b4ba84b6058 Minor changes to minimal example.
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
    61
#ifdef KBUS
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
    62
static void *r_inputs;
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
    63
static void *r_outputs;
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
    64
#endif
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
    65
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
    66
#ifdef MAPPING
793
3b297ff8284f Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
    67
const ec_pdo_entry_info_t el3162_channel1[] = {
3b297ff8284f Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
    68
    {0x3101, 1,  8}, // status
3b297ff8284f Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
    69
    {0x3101, 2, 16}  // value
3b297ff8284f Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
    70
};
3b297ff8284f Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
    71
3b297ff8284f Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
    72
const ec_pdo_entry_info_t el3162_channel2[] = {
3b297ff8284f Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
    73
    {0x3102, 1,  8}, // status
3b297ff8284f Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
    74
    {0x3102, 2, 16}  // value
3b297ff8284f Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
    75
};
3b297ff8284f Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
    76
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
    77
const ec_pdo_info_t mapping[] = {
793
3b297ff8284f Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
    78
    {EC_DIR_INPUT, 0x1A00, 2, el3162_channel1},
3b297ff8284f Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
    79
    {EC_DIR_INPUT, 0x1A01, 2, el3162_channel2},
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
    80
};
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
    81
#endif
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
    82
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
    83
#ifdef PDOS
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
    84
static uint8_t off_ana_in;
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 794
diff changeset
    85
//static uint8_t off_ana_out;
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
    86
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
    87
const static ec_pdo_entry_reg_t domain1_regs[] = {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
    88
    {0, 1, Beckhoff_EL3162, 0x3101, 2, &off_ana_in},
794
684dea874956 Allow bus configuration when link is down.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
    89
    //{0, 2, Beckhoff_EL4102, 0x3001, 1, &off_ana_out},
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
    {}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
};
416
4f007cd2a79d ecrt_domain_register_pdo_range() implemented.
Florian Pose <fp@igh-essen.com>
parents: 348
diff changeset
    92
#endif
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
void run(unsigned long data)
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
{
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
    static unsigned int counter = 0;
512
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
    99
    static unsigned int blink = 0;
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   100
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   101
    // receive
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
    spin_lock(&master_lock);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 280
diff changeset
   103
    ecrt_master_receive(master);
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
    ecrt_domain_process(domain1);
512
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   105
    spin_unlock(&master_lock);
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
    // process data
512
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   108
    // k_pos = EC_READ_U32(r_ssi);
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   109
    //EC_WRITE_U8(r_dig_out, blink ? 0x0F : 0x00);
512
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   110
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   111
    if (counter) {
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   112
        counter--;
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   113
    }
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   114
    else {
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   115
        counter = FREQUENCY;
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   116
        blink = !blink;
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   117
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   118
        spin_lock(&master_lock);
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   119
        ecrt_master_state(master, &master_state);
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   120
        spin_unlock(&master_lock);
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   121
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   122
        if (master_state.bus_state != old_state.bus_state) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   123
            printk(KERN_INFO PFX "bus state changed to %i.\n",
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   124
                    master_state.bus_state);
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   125
        }
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   126
        if (master_state.bus_tainted != old_state.bus_tainted) {
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   127
            printk(KERN_INFO PFX "tainted flag changed to %u.\n",
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   128
                    master_state.bus_tainted);
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   129
        }
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   130
        if (master_state.slaves_responding !=
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   131
                old_state.slaves_responding) {
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   132
            printk(KERN_INFO PFX "slaves_responding changed to %u.\n",
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   133
                    master_state.slaves_responding);
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   134
        }
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   135
       
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   136
        old_state = master_state;
512
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   137
    }
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   138
457
2b4ba84b6058 Minor changes to minimal example.
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   139
#ifdef KBUS
512
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   140
    EC_WRITE_U8(r_outputs + 2, blink ? 0xFF : 0x00);
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   141
#endif
513
d91976aea8c8 Minor changes in minimal example.
Florian Pose <fp@igh-essen.com>
parents: 512
diff changeset
   142
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
    // send
512
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   144
    spin_lock(&master_lock);
509
87baea61d0c7 Adjusted examples to 1.2.0 interface changes.
Florian Pose <fp@igh-essen.com>
parents: 472
diff changeset
   145
    ecrt_domain_queue(domain1);
516
f703e33ee395 Adjusted examples to EtherLab starter kit hardware.
Florian Pose <fp@igh-essen.com>
parents: 513
diff changeset
   146
    spin_unlock(&master_lock);
f703e33ee395 Adjusted examples to EtherLab starter kit hardware.
Florian Pose <fp@igh-essen.com>
parents: 513
diff changeset
   147
f703e33ee395 Adjusted examples to EtherLab starter kit hardware.
Florian Pose <fp@igh-essen.com>
parents: 513
diff changeset
   148
    spin_lock(&master_lock);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 280
diff changeset
   149
    ecrt_master_send(master);
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
    spin_unlock(&master_lock);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
    // restart timer
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
    timer.expires += HZ / FREQUENCY;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
    add_timer(&timer);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
int request_lock(void *data)
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
{
516
f703e33ee395 Adjusted examples to EtherLab starter kit hardware.
Florian Pose <fp@igh-essen.com>
parents: 513
diff changeset
   161
    spin_lock(&master_lock);
226
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   162
    return 0; // access allowed
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
void release_lock(void *data)
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
{
516
f703e33ee395 Adjusted examples to EtherLab starter kit hardware.
Florian Pose <fp@igh-essen.com>
parents: 513
diff changeset
   169
    spin_unlock(&master_lock);
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
int __init init_mini_module(void)
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
{
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   176
#ifdef MAPPING
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   177
    ec_slave_config_t *sc;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   178
#endif
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   179
    
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   180
    printk(KERN_INFO PFX "Starting...\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
509
87baea61d0c7 Adjusted examples to 1.2.0 interface changes.
Florian Pose <fp@igh-essen.com>
parents: 472
diff changeset
   182
    if (!(master = ecrt_request_master(0))) {
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   183
        printk(KERN_ERR PFX "Requesting master 0 failed!\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
        goto out_return;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
    }
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
    ecrt_master_callbacks(master, request_lock, release_lock, NULL);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   189
    printk(KERN_INFO PFX "Registering domain...\n");
509
87baea61d0c7 Adjusted examples to 1.2.0 interface changes.
Florian Pose <fp@igh-essen.com>
parents: 472
diff changeset
   190
    if (!(domain1 = ecrt_master_create_domain(master))) {
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   191
        printk(KERN_ERR PFX "Domain creation failed!\n");
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   192
        goto out_release_master;
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   193
    }
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   194
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   195
#ifdef MAPPING
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   196
    printk(KERN_INFO PFX "Configuring Pdo mapping...\n");
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   197
    if (!(sc = ecrt_master_slave_config(master, 0, 1, Beckhoff_EL3162))) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   198
        printk(KERN_ERR PFX "Failed to get slave configuration.\n");
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   199
        goto out_release_master;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   200
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   201
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   202
    if (ecrt_slave_config_mapping(sc, 2, mapping)) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   203
        printk(KERN_ERR PFX "Failed to configure Pdo mapping.\n");
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   204
        goto out_release_master;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   205
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   206
#endif
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   207
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   208
    printk(KERN_INFO PFX "Registering PDO entries...\n");
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   209
#ifdef PDOS
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   210
    if (ecrt_domain_reg_pdo_entry_list(domain1, domain1_regs)) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   211
        printk(KERN_ERR PFX "PDO entry registration failed!\n");
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   212
        goto out_release_master;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   213
    }
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   214
#endif
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   215
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   216
    printk(KERN_INFO PFX "Activating master...\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   217
    if (ecrt_master_activate(master)) {
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   218
        printk(KERN_ERR PFX "Failed to activate master!\n");
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   219
        goto out_release_master;
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   220
    }
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   221
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   222
    printk(KERN_INFO PFX "Starting cyclic sample thread.\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
    init_timer(&timer);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
    timer.function = run;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
    timer.expires = jiffies + 10;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
    add_timer(&timer);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   228
    printk(KERN_INFO PFX "Started.\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
    return 0;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   231
 out_release_master:
654
8278e1e27010 Minor changes in minimal example.
Florian Pose <fp@igh-essen.com>
parents: 643
diff changeset
   232
    printk(KERN_ERR PFX "Releasing master...\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
    ecrt_release_master(master);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
 out_return:
654
8278e1e27010 Minor changes in minimal example.
Florian Pose <fp@igh-essen.com>
parents: 643
diff changeset
   235
    printk(KERN_ERR PFX "Failed to load. Aborting.\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
    return -1;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   239
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   241
void __exit cleanup_mini_module(void)
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   242
{
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   243
    printk(KERN_INFO PFX "Stopping...\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   244
449
3caf8ff4d8a2 Moved functionality of ecrt_master_deactivate() (now deprecated) to ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   245
    del_timer_sync(&timer);
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   246
    printk(KERN_INFO PFX "Releasing master...\n");
449
3caf8ff4d8a2 Moved functionality of ecrt_master_deactivate() (now deprecated) to ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   247
    ecrt_release_master(master);
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   248
654
8278e1e27010 Minor changes in minimal example.
Florian Pose <fp@igh-essen.com>
parents: 643
diff changeset
   249
    printk(KERN_INFO PFX "Unloading.\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   250
}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   251
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   252
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   253
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   254
MODULE_LICENSE("GPL");
512
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   255
MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>");
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   256
MODULE_DESCRIPTION("EtherCAT minimal test environment");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   258
module_init(init_mini_module);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   259
module_exit(cleanup_mini_module);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   260
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   261
/*****************************************************************************/