examples/msr/msr_rt.c
author Florian Pose <fp@igh-essen.com>
Thu, 11 May 2006 09:24:15 +0000
changeset 230 382bdb9138ec
parent 224 4828e5e419bf
permissions -rw-r--r--
RTAI sample with optimized jitter.
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 s r _ r t . 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
 *  Kernelmodul für 2.6 Kernel zur Meßdatenerfassung, Steuerung und Regelung.
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
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  as published by the Free Software Foundation; version 2 of the License.
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *  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
    18
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  GNU General Public License for more details.
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *  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
    23
 *  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
    24
 *  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
    25
 *
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
// Linux
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
#include <linux/module.h>
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
#include <linux/ipipe.h>
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
#include <linux/slab.h>
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
#include <linux/vmalloc.h>
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
#include <linux/delay.h>
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
// RT_lib
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
#include <msr_main.h>
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include <msr_utils.h>
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
#include <msr_messages.h>
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
#include <msr_float.h>
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#include <msr_reg.h>
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include <msr_time.h>
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include "msr_param.h"
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
// EtherCAT
223
daa5e5656b35 Applied new path information to example modules.
Florian Pose <fp@igh-essen.com>
parents: 220
diff changeset
    45
#include "../../include/ecrt.h"
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 ASYNC
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
// Defines/Makros
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
#define HZREDUCTION (MSR_ABTASTFREQUENZ / HZ)
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
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
/* Globale Variablen */
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
// Adeos
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
static struct ipipe_domain this_domain;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
static struct ipipe_sysinfo sys_info;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
// EtherCAT
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
ec_master_t *master = NULL;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
ec_domain_t *domain1 = NULL;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
// Prozessdaten
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
void *r_ssi;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
void *r_ssi_st;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
// KanŽäle
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
uint32_t k_ssi;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
uint32_t k_ssi_st;
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
ec_field_init_t domain1_fields[] = {
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
    {&r_ssi,    "0:3", "Beckhoff", "EL5001", "InputValue", 0},
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
    {&r_ssi_st, "0:3", "Beckhoff", "EL5001", "Status",     0},
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
};
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
/*****************************************************************************/
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
static void msr_controller_run(void)
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
{
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
#ifdef ASYNC
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
    // Empfangen
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
    ecrt_master_async_receive(master);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
    ecrt_domain_process(domain1);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
#else
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
    // Senden und empfangen
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
    ecrt_domain_queue(domain1);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
    ecrt_master_run(master);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
    ecrt_master_sync_io(master);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
    ecrt_domain_process(domain1);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
#endif
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
    // Prozessdaten verarbeiten
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
    k_ssi =    EC_READ_U32(r_ssi);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
    k_ssi_st = EC_READ_U8 (r_ssi_st);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
#ifdef ASYNC
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
    // Senden
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
    ecrt_domain_queue(domain1);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
    ecrt_master_run(master);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
    ecrt_master_async_send(master);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
#endif
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
/*****************************************************************************/
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
int msr_globals_register(void)
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
    msr_reg_kanal("/ssi_position", "", &k_ssi,    TUINT);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
    msr_reg_kanal("/ssi_status",   "", &k_ssi_st, TUINT);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
    return 0;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
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
void msr_run(unsigned irq)
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
    static int counter = 0;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
    MSR_ADEOS_INTERRUPT_CODE(msr_controller_run(); msr_write_kanal_list(););
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
    ipipe_control_irq(irq, 0, IPIPE_ENABLE_MASK); // Interrupt bestŽätigen
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
    if (++counter >= HZREDUCTION) {
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
	ipipe_propagate_irq(irq);  // und weiterreichen
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
	counter = 0;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
    }
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
/*****************************************************************************/
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
void domain_entry(void)
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
{
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
    printk("Domain %s started.\n", ipipe_current_domain->name);
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
    ipipe_get_sysinfo(&sys_info);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
    ipipe_virtualize_irq(ipipe_current_domain,sys_info.archdep.tmirq,
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
			 &msr_run, NULL, IPIPE_HANDLE_MASK);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
    ipipe_tune_timer(1000000000UL / MSR_ABTASTFREQUENZ, 0);
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
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
/*****************************************************************************/
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
int __init init_rt_module(void)
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
{
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
    struct ipipe_domain_attr attr; //ipipe
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
#if 1
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
    ec_slave_t *slave;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
#endif
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
    // Als allererstes die RT-Lib initialisieren
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
    if (msr_rtlib_init(1, MSR_ABTASTFREQUENZ, 10, &msr_globals_register) < 0) {
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
        printk(KERN_ERR "Failed to initialize rtlib!\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
        goto out_return;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
    }
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
    if ((master = ecrt_request_master(0)) == NULL) {
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
        printk(KERN_ERR "Failed to request master 0!\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
        goto out_msr_cleanup;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
    }
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
    //ecrt_master_print(master, 2);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
    printk(KERN_INFO "Creating domains...\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
    if (!(domain1 = ecrt_master_create_domain(master))) {
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
        printk(KERN_ERR "Failed to create domains!\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
        goto out_release_master;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
    }
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
    printk(KERN_INFO "Registering domain fields...\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
    if (ecrt_domain_register_field_list(domain1, domain1_fields)) {
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
        printk(KERN_ERR "Failed to register domain fields.\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
        goto out_release_master;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
    }
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
    printk(KERN_INFO "Activating master...\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
    if (ecrt_master_activate(master)) {
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
        printk(KERN_ERR "Could not activate master!\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
        goto out_release_master;
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
#if 0
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
    if (ecrt_master_start_eoe(master)) {
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
        printk(KERN_ERR "Failed to start EoE processing!\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
        goto out_deactivate;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
    }
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
#endif
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
#if 0
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
    if (ecrt_master_fetch_sdo_lists(master)) {
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
        printk(KERN_ERR "Failed to fetch SDO lists!\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
        goto out_deactivate;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
    }
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
    ecrt_master_print(master, 2);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
#else
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
    ecrt_master_print(master, 0);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
#endif
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
#if 1
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
    if (!(slave = ecrt_master_get_slave(master, "0:3"))) {
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
        printk(KERN_ERR "Failed to get slave!\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
        goto out_deactivate;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
    }
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
    if (
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
        ecrt_slave_sdo_write_exp8(slave, 0x4061, 1,  1) || // disable frame error bit
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
        ecrt_slave_sdo_write_exp8(slave, 0x4061, 2,  0) || // power failure bit
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
        ecrt_slave_sdo_write_exp8(slave, 0x4061, 3,  1) || // inhibit time
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
        ecrt_slave_sdo_write_exp8(slave, 0x4061, 4,  0) || // test mode
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
        ecrt_slave_sdo_write_exp8(slave, 0x4066, 0,  1) || // dualcode
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
        ecrt_slave_sdo_write_exp8(slave, 0x4067, 0,  5) || // 125kbaud
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
        ecrt_slave_sdo_write_exp8(slave, 0x4068, 0,  0) || // single-turn
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
        ecrt_slave_sdo_write_exp8(slave, 0x4069, 0, 25) || // frame size
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   214
        ecrt_slave_sdo_write_exp8(slave, 0x406A, 0, 25) || // data length
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   215
        ecrt_slave_sdo_write_exp16(slave, 0x406B, 0, 30000) // inhibit time in us
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
        ) {
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   217
        printk(KERN_ERR "Failed to configure SSI slave!\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   218
        goto out_deactivate;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   219
    }
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
#endif
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
#if 0
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
    if (!(slave = ecrt_master_get_slave(master, "1:0"))) {
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
        printk(KERN_ERR "Failed to get slave!\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
        goto out_deactivate;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
    }
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
    if (ecrt_slave_write_alias(slave, 0x5678)) {
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
        printk(KERN_ERR "Failed to write alias!\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
        goto out_deactivate;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
    }
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   231
#endif
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   232
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
#ifdef ASYNC
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
    // Einmal senden und warten...
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
    ecrt_master_prepare_async_io(master);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
#endif
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
    ipipe_init_attr(&attr);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   239
    attr.name = "IPIPE-MSR-MODULE";
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
    attr.priority = IPIPE_ROOT_PRIO + 1;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   241
    attr.entry = &domain_entry;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   242
    ipipe_register_domain(&this_domain, &attr);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   243
    return 0;
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
#if 1
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   246
 out_deactivate:
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   247
    ecrt_master_deactivate(master);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   248
#endif
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   249
 out_release_master:
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   250
    ecrt_release_master(master);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   251
 out_msr_cleanup:
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   252
    msr_rtlib_cleanup();
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   253
 out_return:
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   254
    return -1;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   255
}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   256
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   258
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   259
void __exit cleanup_rt_module(void)
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   260
{
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   261
    printk(KERN_INFO "Cleanign up rt module...\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   262
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   263
    ipipe_tune_timer(1000000000UL / HZ, 0); // Alten Timertakt wiederherstellen
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   264
    ipipe_unregister_domain(&this_domain);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   265
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   266
    printk(KERN_INFO "=== Stopping EtherCAT environment... ===\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   267
    ecrt_master_deactivate(master);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
    ecrt_release_master(master);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   269
    printk(KERN_INFO "=== EtherCAT environment stopped. ===\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   270
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   271
    msr_rtlib_cleanup();
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   272
}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   273
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   274
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   275
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   276
#define EC_LIT(X) #X
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   277
#define EC_STR(X) EC_LIT(X)
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   278
#define COMPILE_INFO "Revision " EC_STR(SVNREV) \
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   279
                     ", compiled by " EC_STR(USER) \
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   280
                     " at " __DATE__ " " __TIME__
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
MODULE_LICENSE("GPL");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   283
MODULE_AUTHOR ("Florian Pose <fp@igh-essen.com>");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   284
MODULE_DESCRIPTION ("EtherCAT real-time test environment");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   285
MODULE_VERSION(COMPILE_INFO);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   286
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   287
module_init(init_rt_module);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   288
module_exit(cleanup_rt_module);
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
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   291
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   292
/* Emacs-Konfiguration
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   293
;;; Local Variables: ***
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   294
;;; c-basic-offset:4 ***
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   295
;;; End: ***
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   296
*/