examples/rtai/rtai_sample.c
author Florian Pose <fp@igh-essen.com>
Thu, 15 Sep 2011 16:45:58 +0200
changeset 2110 455126b35650
parent 2024 96e2ae6cce95
child 2589 2b9c78543663
permissions -rw-r--r--
Fixed compiler error; added SDO debugging.
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
 *
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
     3
 *  RTAI sample for the IgH EtherCAT master.
220
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
 *  $Id$
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1239
diff changeset
     7
 *  Copyright (C) 2006-2008  Florian Pose, Ingenieurgemeinschaft IgH
220
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
 *  This file is part of the IgH EtherCAT Master.
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1239
diff changeset
    11
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1239
diff changeset
    12
 *  modify it under the terms of the GNU General Public License version 2, as
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1239
diff changeset
    13
 *  published by the Free Software Foundation.
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1239
diff changeset
    14
 *
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1239
diff changeset
    15
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1239
diff changeset
    16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1239
diff changeset
    17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1239
diff changeset
    18
 *  Public License for more details.
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1239
diff changeset
    19
 *
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1239
diff changeset
    20
 *  You should have received a copy of the GNU General Public License along
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1239
diff changeset
    21
 *  with the IgH EtherCAT Master; if not, write to the Free Software
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *  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
    23
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    24
 *  ---
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    25
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    26
 *  The license mentioned above concerns the source code only. Using the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    27
 *  EtherCAT technology and brand is only permitted in compliance with the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    28
 *  industrial property and similar rights of Beckhoff Automation GmbH.
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 233
diff changeset
    29
 *
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
 *****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
233
31d327ce38d3 Smaller fixes on RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 230
diff changeset
    32
// Linux
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
#include <linux/module.h>
1239
b50b93faaf3e Used ERR_PTR() macro for return value of ecrt_request_master().
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
    34
#include <linux/err.h>
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
230
382bdb9138ec RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents: 227
diff changeset
    36
// RTAI
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    37
#include <rtai_sched.h>
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    38
#include <rtai_sem.h>
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
    39
233
31d327ce38d3 Smaller fixes on RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 230
diff changeset
    40
// EtherCAT
230
382bdb9138ec RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents: 227
diff changeset
    41
#include "../../include/ecrt.h"
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    42
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    43
/*****************************************************************************/
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    44
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    45
// Module parameters
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    46
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    47
#define FREQUENCY 2000 // task frequency in Hz
342
cbcff2f19e99 RTAI example with INHIBIT time.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    48
#define INHIBIT_TIME 20
cbcff2f19e99 RTAI example with INHIBIT time.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    49
230
382bdb9138ec RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents: 227
diff changeset
    50
#define TIMERTICKS (1000000000 / FREQUENCY)
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
    51
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    52
// Optional features (comment to disable)
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    53
#define CONFIGURE_PDOS
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    54
643
78929d878b2c Removed X:Y addressing scheme, ec_slave_is_coupler(),
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
    55
#define PFX "ec_rtai_sample: "
78929d878b2c Removed X:Y addressing scheme, ec_slave_is_coupler(),
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
    56
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
    57
/*****************************************************************************/
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
    58
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    59
// EtherCAT
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    60
static ec_master_t *master = NULL;
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    61
static ec_master_state_t master_state = {};
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    62
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    63
static ec_domain_t *domain1 = NULL;
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    64
static ec_domain_state_t domain1_state = {};
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    65
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    66
static ec_slave_config_t *sc_ana_in = NULL;
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    67
static ec_slave_config_state_t sc_ana_in_state = {};
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    68
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
    69
// RTAI
643
78929d878b2c Removed X:Y addressing scheme, ec_slave_is_coupler(),
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
    70
static RT_TASK task;
78929d878b2c Removed X:Y addressing scheme, ec_slave_is_coupler(),
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
    71
static SEM master_sem;
78929d878b2c Removed X:Y addressing scheme, ec_slave_is_coupler(),
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
    72
static cycles_t t_last_cycle = 0, t_critical;
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    74
/*****************************************************************************/
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    75
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    76
// process data
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    77
static uint8_t *domain1_pd; // process data memory
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    78
1935
8ea1033bd4c2 Fixed NULL pointer dereference on request error in RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
    79
#define AnaInSlavePos  0, 3
8ea1033bd4c2 Fixed NULL pointer dereference on request error in RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
    80
#define DigOutSlavePos 0, 2
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    81
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    82
#define Beckhoff_EL2004 0x00000002, 0x07D43052
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    83
#define Beckhoff_EL3162 0x00000002, 0x0C5A3052
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    84
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    85
static unsigned int off_ana_in; // offsets for PDO entries
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    86
static unsigned int off_dig_out;
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    87
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    88
const static ec_pdo_entry_reg_t domain1_regs[] = {
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    89
    {AnaInSlavePos,  Beckhoff_EL3162, 0x3101, 2, &off_ana_in},
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    90
    {DigOutSlavePos, Beckhoff_EL2004, 0x3001, 1, &off_dig_out},
220
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
};
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    94
static unsigned int counter = 0;
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    95
static unsigned int blink = 0;
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    96
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    97
/*****************************************************************************/
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    98
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    99
#ifdef CONFIGURE_PDOS
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   100
static ec_pdo_entry_info_t el3162_channel1[] = {
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   101
    {0x3101, 1,  8}, // status
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   102
    {0x3101, 2, 16}  // value
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   103
};
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   104
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   105
static ec_pdo_entry_info_t el3162_channel2[] = {
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   106
    {0x3102, 1,  8}, // status
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   107
    {0x3102, 2, 16}  // value
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   108
};
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   109
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   110
static ec_pdo_info_t el3162_pdos[] = {
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   111
    {0x1A00, 2, el3162_channel1},
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   112
    {0x1A01, 2, el3162_channel2}
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   113
};
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   114
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   115
static ec_sync_info_t el3162_syncs[] = {
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   116
    {2, EC_DIR_OUTPUT},
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   117
    {3, EC_DIR_INPUT, 2, el3162_pdos},
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   118
    {0xff}
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   119
};
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   120
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   121
static ec_pdo_entry_info_t el2004_channels[] = {
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   122
    {0x3001, 1, 1}, // Value 1
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   123
    {0x3001, 2, 1}, // Value 2
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   124
    {0x3001, 3, 1}, // Value 3
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   125
    {0x3001, 4, 1}  // Value 4
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   126
};
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   127
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   128
static ec_pdo_info_t el2004_pdos[] = {
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   129
    {0x1600, 1, &el2004_channels[0]},
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   130
    {0x1601, 1, &el2004_channels[1]},
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   131
    {0x1602, 1, &el2004_channels[2]},
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   132
    {0x1603, 1, &el2004_channels[3]}
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   133
};
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   134
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   135
static ec_sync_info_t el2004_syncs[] = {
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   136
    {0, EC_DIR_OUTPUT, 4, el2004_pdos},
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   137
    {1, EC_DIR_INPUT},
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   138
    {0xff}
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   139
};
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   140
#endif
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   141
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   142
/*****************************************************************************/
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   143
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   144
void check_domain1_state(void)
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   145
{
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   146
    ec_domain_state_t ds;
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   147
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   148
    rt_sem_wait(&master_sem);
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   149
    ecrt_domain_state(domain1, &ds);
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   150
    rt_sem_signal(&master_sem);
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   151
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   152
    if (ds.working_counter != domain1_state.working_counter)
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   153
        printk(KERN_INFO PFX "Domain1: WC %u.\n", ds.working_counter);
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   154
    if (ds.wc_state != domain1_state.wc_state)
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   155
        printk(KERN_INFO PFX "Domain1: State %u.\n", ds.wc_state);
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   156
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   157
    domain1_state = ds;
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   158
}
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   159
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   160
/*****************************************************************************/
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   161
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   162
void check_master_state(void)
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   163
{
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   164
    ec_master_state_t ms;
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   165
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   166
    rt_sem_wait(&master_sem);
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   167
    ecrt_master_state(master, &ms);
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   168
    rt_sem_signal(&master_sem);
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   169
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   170
    if (ms.slaves_responding != master_state.slaves_responding)
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   171
        printk(KERN_INFO PFX "%u slave(s).\n", ms.slaves_responding);
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   172
    if (ms.al_states != master_state.al_states)
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   173
        printk(KERN_INFO PFX "AL states: 0x%02X.\n", ms.al_states);
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   174
    if (ms.link_up != master_state.link_up)
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   175
        printk(KERN_INFO PFX "Link is %s.\n", ms.link_up ? "up" : "down");
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   176
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   177
    master_state = ms;
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   178
}
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   179
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   180
/*****************************************************************************/
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   181
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   182
void check_slave_config_states(void)
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   183
{
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   184
    ec_slave_config_state_t s;
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   185
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   186
    rt_sem_wait(&master_sem);
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   187
    ecrt_slave_config_state(sc_ana_in, &s);
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   188
    rt_sem_signal(&master_sem);
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   189
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   190
    if (s.al_state != sc_ana_in_state.al_state)
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   191
        printk(KERN_INFO PFX "AnaIn: State 0x%02X.\n", s.al_state);
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   192
    if (s.online != sc_ana_in_state.online)
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   193
        printk(KERN_INFO PFX "AnaIn: %s.\n", s.online ? "online" : "offline");
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   194
    if (s.operational != sc_ana_in_state.operational)
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   195
        printk(KERN_INFO PFX "AnaIn: %soperational.\n",
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   196
                s.operational ? "" : "Not ");
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   197
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   198
    sc_ana_in_state = s;
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   199
}
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   200
220
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
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   203
void run(long data)
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   204
{
512
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   205
    while (1) {
342
cbcff2f19e99 RTAI example with INHIBIT time.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   206
        t_last_cycle = get_cycles();
512
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   207
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   208
        // receive process data
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   209
        rt_sem_wait(&master_sem);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   210
        ecrt_master_receive(master);
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   211
        ecrt_domain_process(domain1);
512
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   212
        rt_sem_signal(&master_sem);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   213
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   214
        // check process data state (optional)
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   215
        check_domain1_state();
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   216
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   217
        if (counter) {
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   218
            counter--;
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   219
        } else { // do this at 1 Hz
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   220
            counter = FREQUENCY;
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   221
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   222
            // calculate new process data
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   223
            blink = !blink;
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   224
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   225
            // check for master state (optional)
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   226
            check_master_state();
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   227
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   228
            // check for islave configuration state(s) (optional)
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   229
            check_slave_config_states();
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   230
        }
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   231
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   232
        // write process data
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   233
        EC_WRITE_U8(domain1_pd + off_dig_out, blink ? 0x06 : 0x09);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   234
512
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   235
        rt_sem_wait(&master_sem);
509
87baea61d0c7 Adjusted examples to 1.2.0 interface changes.
Florian Pose <fp@igh-essen.com>
parents: 449
diff changeset
   236
        ecrt_domain_queue(domain1);
2024
96e2ae6cce95 ecrt_master_callbacks: replaced send/receive callback mechanism with locking mechanism; removed ecrt_master_send_ext
Martin Troxler <ch1010277@ch10pc446>
parents: 1935
diff changeset
   237
        rt_sem_signal(&master_sem);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   238
        ecrt_master_send(master);
1508
60a116ed3897 Removed more tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
   239
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   240
        rt_task_wait_period();
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   241
    }
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   242
}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   243
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   244
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   245
2024
96e2ae6cce95 ecrt_master_callbacks: replaced send/receive callback mechanism with locking mechanism; removed ecrt_master_send_ext
Martin Troxler <ch1010277@ch10pc446>
parents: 1935
diff changeset
   246
void request_lock_callback(void *cb_data)
1513
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   247
{
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   248
    ec_master_t *m = (ec_master_t *) cb_data;
2024
96e2ae6cce95 ecrt_master_callbacks: replaced send/receive callback mechanism with locking mechanism; removed ecrt_master_send_ext
Martin Troxler <ch1010277@ch10pc446>
parents: 1935
diff changeset
   249
    rt_sem_wait(&master_sem);
96e2ae6cce95 ecrt_master_callbacks: replaced send/receive callback mechanism with locking mechanism; removed ecrt_master_send_ext
Martin Troxler <ch1010277@ch10pc446>
parents: 1935
diff changeset
   250
}
96e2ae6cce95 ecrt_master_callbacks: replaced send/receive callback mechanism with locking mechanism; removed ecrt_master_send_ext
Martin Troxler <ch1010277@ch10pc446>
parents: 1935
diff changeset
   251
96e2ae6cce95 ecrt_master_callbacks: replaced send/receive callback mechanism with locking mechanism; removed ecrt_master_send_ext
Martin Troxler <ch1010277@ch10pc446>
parents: 1935
diff changeset
   252
/*****************************************************************************/
96e2ae6cce95 ecrt_master_callbacks: replaced send/receive callback mechanism with locking mechanism; removed ecrt_master_send_ext
Martin Troxler <ch1010277@ch10pc446>
parents: 1935
diff changeset
   253
96e2ae6cce95 ecrt_master_callbacks: replaced send/receive callback mechanism with locking mechanism; removed ecrt_master_send_ext
Martin Troxler <ch1010277@ch10pc446>
parents: 1935
diff changeset
   254
void release_lock_callback(void *cb_data)
1513
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   255
{
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   256
    ec_master_t *m = (ec_master_t *) cb_data;
2024
96e2ae6cce95 ecrt_master_callbacks: replaced send/receive callback mechanism with locking mechanism; removed ecrt_master_send_ext
Martin Troxler <ch1010277@ch10pc446>
parents: 1935
diff changeset
   257
    rt_sem_signal(&master_sem);
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   258
}
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   259
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   260
/*****************************************************************************/
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   261
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   262
int __init init_mod(void)
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   263
{
1239
b50b93faaf3e Used ERR_PTR() macro for return value of ecrt_request_master().
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
   264
    int ret = -1;
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   265
    RTIME tick_period, requested_ticks, now;
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   266
#ifdef CONFIGURE_PDOS
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   267
    ec_slave_config_t *sc;
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   268
#endif
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   269
643
78929d878b2c Removed X:Y addressing scheme, ec_slave_is_coupler(),
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   270
    printk(KERN_INFO PFX "Starting...\n");
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   271
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   272
    rt_sem_init(&master_sem, 1);
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   273
342
cbcff2f19e99 RTAI example with INHIBIT time.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   274
    t_critical = cpu_khz * 1000 / FREQUENCY - cpu_khz * INHIBIT_TIME / 1000;
cbcff2f19e99 RTAI example with INHIBIT time.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   275
1239
b50b93faaf3e Used ERR_PTR() macro for return value of ecrt_request_master().
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
   276
    master = ecrt_request_master(0);
1935
8ea1033bd4c2 Fixed NULL pointer dereference on request error in RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   277
    if (!master) {
8ea1033bd4c2 Fixed NULL pointer dereference on request error in RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   278
        ret = -EBUSY; 
643
78929d878b2c Removed X:Y addressing scheme, ec_slave_is_coupler(),
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   279
        printk(KERN_ERR PFX "Requesting master 0 failed!\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   280
        goto out_return;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   281
    }
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   282
2024
96e2ae6cce95 ecrt_master_callbacks: replaced send/receive callback mechanism with locking mechanism; removed ecrt_master_send_ext
Martin Troxler <ch1010277@ch10pc446>
parents: 1935
diff changeset
   283
    ecrt_master_callbacks(master, request_lock_callback, release_lock_callback, master);
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   284
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   285
    printk(KERN_INFO PFX "Registering domain...\n");
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   286
    if (!(domain1 = ecrt_master_create_domain(master))) {
643
78929d878b2c Removed X:Y addressing scheme, ec_slave_is_coupler(),
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   287
        printk(KERN_ERR PFX "Domain creation failed!\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   288
        goto out_release_master;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   289
    }
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   290
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   291
    if (!(sc_ana_in = ecrt_master_slave_config(
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   292
                    master, AnaInSlavePos, Beckhoff_EL3162))) {
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   293
        printk(KERN_ERR PFX "Failed to get slave configuration.\n");
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   294
        goto out_release_master;
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   295
    }
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   296
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   297
#ifdef CONFIGURE_PDOS
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   298
    printk(KERN_INFO PFX "Configuring PDOs...\n");
1082
ff06c58e269c Renamed ecrt_slave_config_sync_managers() to ecrt_slave_config_pdos();
Florian Pose <fp@igh-essen.com>
parents: 1080
diff changeset
   299
    if (ecrt_slave_config_pdos(sc_ana_in, EC_END, el3162_syncs)) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   300
        printk(KERN_ERR PFX "Failed to configure PDOs.\n");
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   301
        goto out_release_master;
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   302
    }
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   303
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   304
    if (!(sc = ecrt_master_slave_config(master, DigOutSlavePos, Beckhoff_EL2004))) {
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   305
        printk(KERN_ERR PFX "Failed to get slave configuration.\n");
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   306
        goto out_release_master;
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   307
    }
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   308
1082
ff06c58e269c Renamed ecrt_slave_config_sync_managers() to ecrt_slave_config_pdos();
Florian Pose <fp@igh-essen.com>
parents: 1080
diff changeset
   309
    if (ecrt_slave_config_pdos(sc, EC_END, el2004_syncs)) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   310
        printk(KERN_ERR PFX "Failed to configure PDOs.\n");
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   311
        goto out_release_master;
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   312
    }
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   313
#endif
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   314
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   315
    printk(KERN_INFO PFX "Registering PDO entries...\n");
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   316
    if (ecrt_domain_reg_pdo_entry_list(domain1, domain1_regs)) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   317
        printk(KERN_ERR PFX "PDO entry registration failed!\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   318
        goto out_release_master;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   319
    }
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   320
643
78929d878b2c Removed X:Y addressing scheme, ec_slave_is_coupler(),
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   321
    printk(KERN_INFO PFX "Activating master...\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   322
    if (ecrt_master_activate(master)) {
643
78929d878b2c Removed X:Y addressing scheme, ec_slave_is_coupler(),
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   323
        printk(KERN_ERR PFX "Failed to activate master!\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   324
        goto out_release_master;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   325
    }
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   326
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   327
    // Get internal process data for domain
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   328
    domain1_pd = ecrt_domain_data(domain1);
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   329
643
78929d878b2c Removed X:Y addressing scheme, ec_slave_is_coupler(),
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   330
    printk(KERN_INFO PFX "Starting cyclic sample thread...\n");
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   331
    requested_ticks = nano2count(TIMERTICKS);
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   332
    tick_period = start_rt_timer(requested_ticks);
643
78929d878b2c Removed X:Y addressing scheme, ec_slave_is_coupler(),
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   333
    printk(KERN_INFO PFX "RT timer started with %i/%i ticks.\n",
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   334
           (int) tick_period, (int) requested_ticks);
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   335
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   336
    if (rt_task_init(&task, run, 0, 2000, 0, 1, NULL)) {
643
78929d878b2c Removed X:Y addressing scheme, ec_slave_is_coupler(),
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   337
        printk(KERN_ERR PFX "Failed to init RTAI task!\n");
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   338
        goto out_stop_timer;
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   339
    }
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   340
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   341
    now = rt_get_time();
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   342
    if (rt_task_make_periodic(&task, now + tick_period, tick_period)) {
643
78929d878b2c Removed X:Y addressing scheme, ec_slave_is_coupler(),
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   343
        printk(KERN_ERR PFX "Failed to run RTAI task!\n");
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   344
        goto out_stop_task;
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   345
    }
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   346
643
78929d878b2c Removed X:Y addressing scheme, ec_slave_is_coupler(),
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   347
    printk(KERN_INFO PFX "Initialized.\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   348
    return 0;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   349
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   350
 out_stop_task:
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   351
    rt_task_delete(&task);
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   352
 out_stop_timer:
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   353
    stop_rt_timer();
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   354
 out_release_master:
655
3702f0d6693b Merged changes of examples/mini/mini.c -r858:859 to
Florian Pose <fp@igh-essen.com>
parents: 643
diff changeset
   355
    printk(KERN_ERR PFX "Releasing master...\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   356
    ecrt_release_master(master);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   357
 out_return:
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   358
    rt_sem_delete(&master_sem);
655
3702f0d6693b Merged changes of examples/mini/mini.c -r858:859 to
Florian Pose <fp@igh-essen.com>
parents: 643
diff changeset
   359
    printk(KERN_ERR PFX "Failed to load. Aborting.\n");
1239
b50b93faaf3e Used ERR_PTR() macro for return value of ecrt_request_master().
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
   360
    return ret;
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   361
}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   362
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   363
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   364
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   365
void __exit cleanup_mod(void)
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   366
{
655
3702f0d6693b Merged changes of examples/mini/mini.c -r858:859 to
Florian Pose <fp@igh-essen.com>
parents: 643
diff changeset
   367
    printk(KERN_INFO PFX "Stopping...\n");
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   368
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   369
    rt_task_delete(&task);
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   370
    stop_rt_timer();
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   371
    ecrt_release_master(master);
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   372
    rt_sem_delete(&master_sem);
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   373
655
3702f0d6693b Merged changes of examples/mini/mini.c -r858:859 to
Florian Pose <fp@igh-essen.com>
parents: 643
diff changeset
   374
    printk(KERN_INFO PFX "Unloading.\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   375
}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   376
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   377
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   378
512
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   379
MODULE_LICENSE("GPL");
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   380
MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>");
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   381
MODULE_DESCRIPTION("EtherCAT RTAI sample module");
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   382
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   383
module_init(init_mod);
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   384
module_exit(cleanup_mod);
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   385
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   386
/*****************************************************************************/