rt/msr_rt.c
author Florian Pose <fp@igh-essen.com>
Tue, 18 Apr 2006 13:41:17 +0000
changeset 193 1053a25af575
parent 191 ca805255a935
child 197 b9a6e2c22745
permissions -rw-r--r--
README: Requirements and realtime.
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
 *  Autor: Wilhelm Hagemeister, Florian Pose
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  (C) Copyright IgH 2002
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  Ingenieurgemeinschaft IgH
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  Heinz-Bäcker Str. 34
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *  D-45356 Essen
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *  Tel.: +49 201/61 99 31
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  Fax.: +49 201/61 98 36
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  E-mail: hm@igh-essen.com
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *  $Id$
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *****************************************************************************/
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
// Linux
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
#include <linux/module.h>
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
#include <linux/ipipe.h>
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
#include <linux/slab.h>
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
#include <linux/vmalloc.h>
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
#include <linux/delay.h>
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
// RT_lib
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
#include <msr_main.h>
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
#include <msr_utils.h>
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
#include <msr_messages.h>
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
#include <msr_float.h>
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
#include <msr_reg.h>
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
#include <msr_time.h>
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
#include "msr_param.h"
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
// EtherCAT
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
#include "../include/ecrt.h"
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#define ASYNC
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
// Defines/Makros
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#define HZREDUCTION (MSR_ABTASTFREQUENZ / HZ)
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
/*****************************************************************************/
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
/* Globale Variablen */
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
// Adeos
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
static struct ipipe_domain this_domain;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
static struct ipipe_sysinfo sys_info;
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
// EtherCAT
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
ec_master_t *master = NULL;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
ec_domain_t *domain1 = NULL;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
// Prozessdaten
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
void *r_ssi;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
void *r_ssi_st;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
// KanŽäle
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
uint32_t k_ssi;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
uint32_t k_ssi_st;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
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
    65
    {&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
    66
    {&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
    67
    {}
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
};
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
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
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
static void msr_controller_run(void)
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
{
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
#ifdef ASYNC
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
    // Empfangen
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
    ecrt_master_async_receive(master);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
    ecrt_domain_process(domain1);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
#else
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
    // Senden und empfangen
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
    ecrt_domain_queue(domain1);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
    ecrt_master_run(master);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
    ecrt_master_sync_io(master);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
    ecrt_domain_process(domain1);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
#endif
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
    // Prozessdaten verarbeiten
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
    k_ssi =    EC_READ_U32(r_ssi);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
    k_ssi_st = EC_READ_U8 (r_ssi_st);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
#ifdef ASYNC
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
    // Senden
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
    ecrt_domain_queue(domain1);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
    ecrt_master_run(master);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
    ecrt_master_async_send(master);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
#endif
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
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
/*****************************************************************************/
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
int msr_globals_register(void)
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
{
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
    msr_reg_kanal("/ssi_position", "", &k_ssi,    TUINT);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
    msr_reg_kanal("/ssi_status",   "", &k_ssi_st, TUINT);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
    return 0;
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
/*****************************************************************************/
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
void msr_run(unsigned irq)
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
{
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
    static int counter = 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
    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
   114
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
    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
   116
    if (++counter >= HZREDUCTION) {
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
	ipipe_propagate_irq(irq);  // und weiterreichen
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
	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
}
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
/*****************************************************************************/
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
void domain_entry(void)
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
{
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
    printk("Domain %s started.\n", ipipe_current_domain->name);
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
    ipipe_get_sysinfo(&sys_info);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
    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
   130
			 &msr_run, NULL, IPIPE_HANDLE_MASK);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
    ipipe_tune_timer(1000000000UL / MSR_ABTASTFREQUENZ, 0);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
}
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
/*****************************************************************************/
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
int __init init_rt_module(void)
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
    struct ipipe_domain_attr attr; //ipipe
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
#if 1
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
    ec_slave_t *slave;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
#endif
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
    // Als allererstes die RT-Lib initialisieren
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
    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
   146
        printk(KERN_ERR "Failed to initialize rtlib!\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
        goto out_return;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
    }
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
    if ((master = ecrt_request_master(0)) == NULL) {
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
        printk(KERN_ERR "Failed to request master 0!\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
        goto out_msr_cleanup;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
    }
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
    //ecrt_master_print(master, 2);
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
    printk(KERN_INFO "Creating domains...\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
    if (!(domain1 = ecrt_master_create_domain(master))) {
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
        printk(KERN_ERR "Failed to create domains!\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
        goto out_release_master;
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
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
    printk(KERN_INFO "Registering domain fields...\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
    if (ecrt_domain_register_field_list(domain1, domain1_fields)) {
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
        printk(KERN_ERR "Failed to register domain fields.\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
        goto out_release_master;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
    }
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
    printk(KERN_INFO "Activating master...\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
    if (ecrt_master_activate(master)) {
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
        printk(KERN_ERR "Could not activate master!\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
        goto out_release_master;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
    }
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
#if 0
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
    if (ecrt_master_fetch_sdo_lists(master)) {
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
        printk(KERN_ERR "Failed to fetch SDO lists!\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
        goto out_deactivate;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
    }
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
    ecrt_master_print(master, 2);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
#else
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   182
    ecrt_master_print(master, 0);
181
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
#endif
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
#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
   186
    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
   187
        printk(KERN_ERR "Failed to get slave!\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
        goto out_deactivate;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
    }
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
    if (
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
        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
   193
        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
   194
        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
   195
        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
   196
        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
   197
        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
   198
        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
   199
        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
   200
        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
   201
        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
   202
        ) {
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
        printk(KERN_ERR "Failed to configure SSI slave!\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
        goto out_deactivate;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
    }
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
#endif
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
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
   208
#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
   209
    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
   210
        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
   211
        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
   212
    }
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
   213
    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
   214
        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
   215
        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
   216
    }
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
#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
   218
181
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   219
#ifdef ASYNC
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
    // Einmal senden und warten...
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
    ecrt_master_prepare_async_io(master);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
#endif
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
    ipipe_init_attr(&attr);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
    attr.name = "IPIPE-MSR-MODULE";
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
    attr.priority = IPIPE_ROOT_PRIO + 1;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
    attr.entry = &domain_entry;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
    ipipe_register_domain(&this_domain, &attr);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
    return 0;
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
#if 1
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   232
 out_deactivate:
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
    ecrt_master_deactivate(master);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
#endif
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
 out_release_master:
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
    ecrt_release_master(master);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
 out_msr_cleanup:
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
    msr_rtlib_cleanup();
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   239
 out_return:
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
    return -1;
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   241
}
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   242
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   243
/*****************************************************************************/
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   244
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   245
void __exit cleanup_rt_module(void)
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   246
{
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   247
    printk(KERN_INFO "Cleanign up rt module...\n");
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
    ipipe_tune_timer(1000000000UL / HZ, 0); // Alten Timertakt wiederherstellen
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   250
    ipipe_unregister_domain(&this_domain);
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
    printk(KERN_INFO "=== Stopping EtherCAT environment... ===\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   253
    ecrt_master_deactivate(master);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   254
    ecrt_release_master(master);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   255
    printk(KERN_INFO "=== EtherCAT environment stopped. ===\n");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   256
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
    msr_rtlib_cleanup();
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
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   260
/*****************************************************************************/
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   261
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   262
#define EC_LIT(X) #X
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   263
#define EC_STR(X) EC_LIT(X)
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   264
#define COMPILE_INFO "Revision " EC_STR(SVNREV) \
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   265
                     ", compiled by " EC_STR(USER) \
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   266
                     " at " __DATE__ " " __TIME__
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
MODULE_LICENSE("GPL");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   269
MODULE_AUTHOR ("Florian Pose <fp@igh-essen.com>");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   270
MODULE_DESCRIPTION ("EtherCAT real-time test environment");
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   271
MODULE_VERSION(COMPILE_INFO);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   272
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   273
module_init(init_rt_module);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   274
module_exit(cleanup_rt_module);
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   275
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   276
/*****************************************************************************/
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   277
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   278
/* Emacs-Konfiguration
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   279
;;; Local Variables: ***
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   280
;;; c-basic-offset:4 ***
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   281
;;; End: ***
3e9155836bc7 Install script for realtime software
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   282
*/