rt/msr_rt.c
author Florian Pose <fp@igh-essen.com>
Tue, 25 Apr 2006 11:39:33 +0000
changeset 203 c1f305e339c6
parent 197 b9a6e2c22745
child 206 60a10d85c20b
permissions -rw-r--r--
EoE net_device implementation.
181
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  m s r _ r t . c
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Kernelmodul für 2.6 Kernel zur Meßdatenerfassung, Steuerung und Regelung.
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  $Id$
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
     9
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    10
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    11
 *  This file is part of the IgH EtherCAT Master.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    12
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    13
 *  The IgH EtherCAT Master is free software; you can redistribute it
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    14
 *  and/or modify it under the terms of the GNU General Public License
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    15
 *  as published by the Free Software Foundation; version 2 of the License.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    16
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    17
 *  The IgH EtherCAT Master is distributed in the hope that it will be
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    18
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    19
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    20
 *  GNU General Public License for more details.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    21
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    22
 *  You should have received a copy of the GNU General Public License
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    23
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    24
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    25
 *
181
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *****************************************************************************/
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
// Linux
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
#include <linux/module.h>
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
#include <linux/ipipe.h>
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
#include <linux/slab.h>
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
#include <linux/vmalloc.h>
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
#include <linux/delay.h>
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
// RT_lib
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
#include <msr_main.h>
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include <msr_utils.h>
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
#include <msr_messages.h>
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
#include <msr_float.h>
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#include <msr_reg.h>
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include <msr_time.h>
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include "msr_param.h"
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
// EtherCAT
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
#include "../include/ecrt.h"
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
#define ASYNC
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
// Defines/Makros
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
#define HZREDUCTION (MSR_ABTASTFREQUENZ / HZ)
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
/*****************************************************************************/
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
/* Globale Variablen */
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
// Adeos
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
static struct ipipe_domain this_domain;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
static struct ipipe_sysinfo sys_info;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
// EtherCAT
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
ec_master_t *master = NULL;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
ec_domain_t *domain1 = NULL;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
// Prozessdaten
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
void *r_ssi;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
void *r_ssi_st;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
// KanŽäle
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
uint32_t k_ssi;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
uint32_t k_ssi_st;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
ec_field_init_t domain1_fields[] = {
188
c0e49f4a1c07 Better calc. of coupler address; coupler address in SysFS; better output of ec_list
Florian Pose <fp@igh-essen.com>
parents: 181
diff changeset
    72
    {&r_ssi,    "0:3", "Beckhoff", "EL5001", "InputValue", 0},
c0e49f4a1c07 Better calc. of coupler address; coupler address in SysFS; better output of ec_list
Florian Pose <fp@igh-essen.com>
parents: 181
diff changeset
    73
    {&r_ssi_st, "0:3", "Beckhoff", "EL5001", "Status",     0},
181
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
    {}
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
};
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
/*****************************************************************************/
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
static void msr_controller_run(void)
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
{
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
#ifdef ASYNC
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
    // Empfangen
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
    ecrt_master_async_receive(master);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
    ecrt_domain_process(domain1);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
#else
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
    // Senden und empfangen
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
    ecrt_domain_queue(domain1);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
    ecrt_master_run(master);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
    ecrt_master_sync_io(master);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
    ecrt_domain_process(domain1);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
#endif
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
    // Prozessdaten verarbeiten
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
    k_ssi =    EC_READ_U32(r_ssi);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
    k_ssi_st = EC_READ_U8 (r_ssi_st);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
#ifdef ASYNC
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
    // Senden
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
    ecrt_domain_queue(domain1);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
    ecrt_master_run(master);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
    ecrt_master_async_send(master);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
#endif
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
}
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
/*****************************************************************************/
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
int msr_globals_register(void)
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
{
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
    msr_reg_kanal("/ssi_position", "", &k_ssi,    TUINT);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
    msr_reg_kanal("/ssi_status",   "", &k_ssi_st, TUINT);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
    return 0;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
}
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
/*****************************************************************************/
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
void msr_run(unsigned irq)
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
{
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
    static int counter = 0;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
    MSR_ADEOS_INTERRUPT_CODE(msr_controller_run(); msr_write_kanal_list(););
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
    ipipe_control_irq(irq, 0, IPIPE_ENABLE_MASK); // Interrupt bestŽätigen
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
    if (++counter >= HZREDUCTION) {
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
	ipipe_propagate_irq(irq);  // und weiterreichen
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
	counter = 0;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
    }
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
}
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
/*****************************************************************************/
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
void domain_entry(void)
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
{
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
    printk("Domain %s started.\n", ipipe_current_domain->name);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
    ipipe_get_sysinfo(&sys_info);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
    ipipe_virtualize_irq(ipipe_current_domain,sys_info.archdep.tmirq,
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
			 &msr_run, NULL, IPIPE_HANDLE_MASK);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
    ipipe_tune_timer(1000000000UL / MSR_ABTASTFREQUENZ, 0);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
}
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
/*****************************************************************************/
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
int __init init_rt_module(void)
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
{
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
    struct ipipe_domain_attr attr; //ipipe
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
#if 1
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
    ec_slave_t *slave;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
#endif
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
    // Als allererstes die RT-Lib initialisieren
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
    if (msr_rtlib_init(1, MSR_ABTASTFREQUENZ, 10, &msr_globals_register) < 0) {
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
        printk(KERN_ERR "Failed to initialize rtlib!\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
        goto out_return;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
    }
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
    if ((master = ecrt_request_master(0)) == NULL) {
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
        printk(KERN_ERR "Failed to request master 0!\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
        goto out_msr_cleanup;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
    }
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
    //ecrt_master_print(master, 2);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
    printk(KERN_INFO "Creating domains...\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
    if (!(domain1 = ecrt_master_create_domain(master))) {
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
        printk(KERN_ERR "Failed to create domains!\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
        goto out_release_master;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
    }
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
    printk(KERN_INFO "Registering domain fields...\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
    if (ecrt_domain_register_field_list(domain1, domain1_fields)) {
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
        printk(KERN_ERR "Failed to register domain fields.\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
        goto out_release_master;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
    }
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
    printk(KERN_INFO "Activating master...\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
    if (ecrt_master_activate(master)) {
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
        printk(KERN_ERR "Could not activate master!\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
        goto out_release_master;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
    }
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
#if 0
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
    if (ecrt_master_fetch_sdo_lists(master)) {
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
        printk(KERN_ERR "Failed to fetch SDO lists!\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
        goto out_deactivate;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
    }
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
    ecrt_master_print(master, 2);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
#else
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   189
    ecrt_master_print(master, 0);
181
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
#endif
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
#if 1
188
c0e49f4a1c07 Better calc. of coupler address; coupler address in SysFS; better output of ec_list
Florian Pose <fp@igh-essen.com>
parents: 181
diff changeset
   193
    if (!(slave = ecrt_master_get_slave(master, "0:3"))) {
181
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
        printk(KERN_ERR "Failed to get slave!\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
        goto out_deactivate;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
    }
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
    if (
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
        ecrt_slave_sdo_write_exp8(slave, 0x4061, 1,  1) || // disable frame error bit
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
        ecrt_slave_sdo_write_exp8(slave, 0x4061, 2,  0) || // power failure bit
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
        ecrt_slave_sdo_write_exp8(slave, 0x4061, 3,  1) || // inhibit time
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
        ecrt_slave_sdo_write_exp8(slave, 0x4061, 4,  0) || // test mode
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
        ecrt_slave_sdo_write_exp8(slave, 0x4066, 0,  1) || // dualcode
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
        ecrt_slave_sdo_write_exp8(slave, 0x4067, 0,  5) || // 125kbaud
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
        ecrt_slave_sdo_write_exp8(slave, 0x4068, 0,  0) || // single-turn
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
        ecrt_slave_sdo_write_exp8(slave, 0x4069, 0, 25) || // frame size
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
        ecrt_slave_sdo_write_exp8(slave, 0x406A, 0, 25) || // data length
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
        ecrt_slave_sdo_write_exp16(slave, 0x406B, 0, 30000) // inhibit time in us
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
        ) {
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
        printk(KERN_ERR "Failed to configure SSI slave!\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
        goto out_deactivate;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
    }
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
#endif
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   214
188
c0e49f4a1c07 Better calc. of coupler address; coupler address in SysFS; better output of ec_list
Florian Pose <fp@igh-essen.com>
parents: 181
diff changeset
   215
#if 0
c0e49f4a1c07 Better calc. of coupler address; coupler address in SysFS; better output of ec_list
Florian Pose <fp@igh-essen.com>
parents: 181
diff changeset
   216
    if (!(slave = ecrt_master_get_slave(master, "1:0"))) {
c0e49f4a1c07 Better calc. of coupler address; coupler address in SysFS; better output of ec_list
Florian Pose <fp@igh-essen.com>
parents: 181
diff changeset
   217
        printk(KERN_ERR "Failed to get slave!\n");
c0e49f4a1c07 Better calc. of coupler address; coupler address in SysFS; better output of ec_list
Florian Pose <fp@igh-essen.com>
parents: 181
diff changeset
   218
        goto out_deactivate;
c0e49f4a1c07 Better calc. of coupler address; coupler address in SysFS; better output of ec_list
Florian Pose <fp@igh-essen.com>
parents: 181
diff changeset
   219
    }
c0e49f4a1c07 Better calc. of coupler address; coupler address in SysFS; better output of ec_list
Florian Pose <fp@igh-essen.com>
parents: 181
diff changeset
   220
    if (ecrt_slave_write_alias(slave, 0x5678)) {
c0e49f4a1c07 Better calc. of coupler address; coupler address in SysFS; better output of ec_list
Florian Pose <fp@igh-essen.com>
parents: 181
diff changeset
   221
        printk(KERN_ERR "Failed to write alias!\n");
c0e49f4a1c07 Better calc. of coupler address; coupler address in SysFS; better output of ec_list
Florian Pose <fp@igh-essen.com>
parents: 181
diff changeset
   222
        goto out_deactivate;
c0e49f4a1c07 Better calc. of coupler address; coupler address in SysFS; better output of ec_list
Florian Pose <fp@igh-essen.com>
parents: 181
diff changeset
   223
    }
c0e49f4a1c07 Better calc. of coupler address; coupler address in SysFS; better output of ec_list
Florian Pose <fp@igh-essen.com>
parents: 181
diff changeset
   224
#endif
c0e49f4a1c07 Better calc. of coupler address; coupler address in SysFS; better output of ec_list
Florian Pose <fp@igh-essen.com>
parents: 181
diff changeset
   225
181
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
#ifdef ASYNC
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
    // Einmal senden und warten...
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
    ecrt_master_prepare_async_io(master);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
#endif
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   231
    ipipe_init_attr(&attr);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   232
    attr.name = "IPIPE-MSR-MODULE";
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
    attr.priority = IPIPE_ROOT_PRIO + 1;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
    attr.entry = &domain_entry;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
    ipipe_register_domain(&this_domain, &attr);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
    return 0;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
#if 1
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   239
 out_deactivate:
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
    ecrt_master_deactivate(master);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   241
#endif
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   242
 out_release_master:
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   243
    ecrt_release_master(master);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   244
 out_msr_cleanup:
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   245
    msr_rtlib_cleanup();
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   246
 out_return:
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   247
    return -1;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   248
}
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   249
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   250
/*****************************************************************************/
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   251
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   252
void __exit cleanup_rt_module(void)
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   253
{
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   254
    printk(KERN_INFO "Cleanign up rt module...\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   255
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   256
    ipipe_tune_timer(1000000000UL / HZ, 0); // Alten Timertakt wiederherstellen
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
    ipipe_unregister_domain(&this_domain);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   258
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   259
    printk(KERN_INFO "=== Stopping EtherCAT environment... ===\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   260
    ecrt_master_deactivate(master);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   261
    ecrt_release_master(master);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   262
    printk(KERN_INFO "=== EtherCAT environment stopped. ===\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   263
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   264
    msr_rtlib_cleanup();
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   265
}
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   266
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   267
/*****************************************************************************/
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   269
#define EC_LIT(X) #X
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   270
#define EC_STR(X) EC_LIT(X)
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   271
#define COMPILE_INFO "Revision " EC_STR(SVNREV) \
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   272
                     ", compiled by " EC_STR(USER) \
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   273
                     " at " __DATE__ " " __TIME__
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   274
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   275
MODULE_LICENSE("GPL");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   276
MODULE_AUTHOR ("Florian Pose <fp@igh-essen.com>");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   277
MODULE_DESCRIPTION ("EtherCAT real-time test environment");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   278
MODULE_VERSION(COMPILE_INFO);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   279
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   280
module_init(init_rt_module);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   281
module_exit(cleanup_rt_module);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   282
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   283
/*****************************************************************************/
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   284
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   285
/* Emacs-Konfiguration
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   286
;;; Local Variables: ***
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   287
;;; c-basic-offset:4 ***
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   288
;;; End: ***
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   289
*/