examples/mini/mini.c
author Florian Pose <fp@igh-essen.com>
Thu, 28 Sep 2006 08:31:33 +0000
branchstable-1.1
changeset 1730 27a1aee7e254
parent 1719 42ed27ae6785
child 416 4f007cd2a79d
child 1732 1cc865ba17c2
permissions -rw-r--r--
MERGE trunk -r571:572 -> branches/stable-1.1 (INSTALL file)
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
 *  m i n i . c
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
 *  Minimal module for EtherCAT.
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
 *  $Id$
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
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  This file is part of the IgH EtherCAT Master.
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *  The IgH EtherCAT Master is free software; you can redistribute it
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  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
    15
 *  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
    16
 *  License, or (at your option) any later version.
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *  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
    19
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *  GNU General Public License for more details.
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *  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
    24
 *  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
    25
 *  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
    26
 *
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 226
diff changeset
    27
 *  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
    28
 *  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
    29
 *  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
    30
 *  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
    31
 *  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
    32
 *  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
    33
 *  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
    34
 *  Technology, IP and trade marks.
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 226
diff changeset
    35
 *
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
 *****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
#include <linux/module.h>
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
#include <linux/delay.h>
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#include <linux/timer.h>
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include <linux/spinlock.h>
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include <linux/interrupt.h>
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
223
daa5e5656b35 Applied new path information to example modules.
Florian Pose <fp@igh-essen.com>
parents: 220
diff changeset
    44
#include "../../include/ecrt.h" // EtherCAT realtime interface
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 280
diff changeset
    45
#include "../../include/ecdb.h" // EtherCAT slave database
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
#define FREQUENCY 100
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
/*****************************************************************************/
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
struct timer_list timer;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
// EtherCAT
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
ec_master_t *master = NULL;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
ec_domain_t *domain1 = NULL;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
spinlock_t master_lock = SPIN_LOCK_UNLOCKED;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
// data fields
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 280
diff changeset
    59
void *r_ana_out;
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
// channels
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
uint32_t k_pos;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
uint8_t k_stat;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 280
diff changeset
    65
ec_pdo_reg_t domain1_pdos[] = {
1719
42ed27ae6785 MERGE trunk -r516:527 -> branches/stable-1.1 (jiffies, bugfixes, pdo defines)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
    66
    {"2", Beckhoff_EL4132_Output1, &r_ana_out},
42ed27ae6785 MERGE trunk -r516:527 -> branches/stable-1.1 (jiffies, bugfixes, pdo defines)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
    67
    {"3", Beckhoff_EL5001_Value, NULL},
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
    {}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
};
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
void run(unsigned long data)
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
{
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
    static unsigned int counter = 0;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
    spin_lock(&master_lock);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
    // receive
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 280
diff changeset
    80
    ecrt_master_receive(master);
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
    ecrt_domain_process(domain1);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
    // process data
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
    //k_pos = EC_READ_U32(r_ssi);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
    // send
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
    ecrt_master_run(master);
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 280
diff changeset
    88
    ecrt_master_send(master);
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
    spin_unlock(&master_lock);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
    if (counter) {
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
        counter--;
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
    else {
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
        counter = FREQUENCY;
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 280
diff changeset
    97
        //printk(KERN_INFO "input = ");
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 280
diff changeset
    98
        //for (i = 0; i < 22; i++)
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 280
diff changeset
    99
        //    printk("%02X ", *((uint8_t *) r_kbus_in + i));
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 280
diff changeset
   100
        //printk("\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
    }
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
    // restart timer
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
    timer.expires += HZ / FREQUENCY;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
    add_timer(&timer);
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
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
int request_lock(void *data)
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
{
226
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   112
    spin_lock_bh(&master_lock);
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   113
    return 0; // access allowed
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
void release_lock(void *data)
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
{
226
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   120
    spin_unlock_bh(&master_lock);
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
int __init init_mini_module(void)
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
{
1716
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
   127
    ec_slave_t *slave;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
   128
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
    printk(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
    if ((master = ecrt_request_master(0)) == NULL) {
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
        printk(KERN_ERR "Requesting master 0 failed!\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
        goto out_return;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
    }
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
    ecrt_master_callbacks(master, request_lock, release_lock, NULL);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
    printk(KERN_INFO "Registering domain...\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
    if (!(domain1 = ecrt_master_create_domain(master)))
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
    {
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
        printk(KERN_ERR "Domain creation failed!\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
        goto out_release_master;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
    }
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 280
diff changeset
   145
    printk(KERN_INFO "Registering PDOs...\n");
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 280
diff changeset
   146
    if (ecrt_domain_register_pdo_list(domain1, domain1_pdos)) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 280
diff changeset
   147
        printk(KERN_ERR "PDO registration failed!\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
        goto out_release_master;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
    }
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
1719
42ed27ae6785 MERGE trunk -r516:527 -> branches/stable-1.1 (jiffies, bugfixes, pdo defines)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   151
    if (!(slave = ecrt_master_get_slave(master, "3")))
1716
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
   152
        goto out_release_master;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
   153
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
   154
    if (ecrt_slave_conf_sdo8(slave, 0x4061, 1, 0))
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
   155
        goto out_release_master;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
   156
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
    printk(KERN_INFO "Activating master...\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
    if (ecrt_master_activate(master)) {
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
        printk(KERN_ERR "Failed to activate master!\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
        goto out_release_master;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
    }
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 280
diff changeset
   163
    ecrt_master_prepare(master);
220
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
    printk("Starting cyclic sample thread.\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
    init_timer(&timer);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
    timer.function = run;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
    timer.expires = jiffies + 10;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
    add_timer(&timer);
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
    printk(KERN_INFO "=== Minimal EtherCAT environment started. ===\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
    return 0;
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
 out_release_master:
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
    ecrt_release_master(master);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
 out_return:
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
    return -1;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
void __exit cleanup_mini_module(void)
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
{
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
    printk(KERN_INFO "=== Stopping Minimal EtherCAT environment... ===\n");
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
    if (master) {
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
        del_timer_sync(&timer);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
        printk(KERN_INFO "Deactivating master...\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
        ecrt_master_deactivate(master);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
        ecrt_release_master(master);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
    }
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
    printk(KERN_INFO "=== Minimal EtherCAT environment stopped. ===\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
MODULE_LICENSE("GPL");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
MODULE_AUTHOR ("Florian Pose <fp@igh-essen.com>");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
MODULE_DESCRIPTION ("EtherCAT minimal test environment");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
module_init(init_mini_module);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
module_exit(cleanup_mini_module);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206