rt/msr_module.c
changeset 56 36d1fa37f5e1
parent 55 059a9e712aa7
child 57 bae4965439b8
equal deleted inserted replaced
55:059a9e712aa7 56:36d1fa37f5e1
    31 #include "msr_param.h"
    31 #include "msr_param.h"
    32 #include "msr_jitter.h"
    32 #include "msr_jitter.h"
    33 
    33 
    34 // EtherCAT
    34 // EtherCAT
    35 #include "../include/EtherCAT_rt.h"
    35 #include "../include/EtherCAT_rt.h"
       
    36 #include "../eclib/eclib.h"
    36 
    37 
    37 // Defines/Makros
    38 // Defines/Makros
    38 #define TSC2US(T1, T2) ((T2 - T1) * 1000UL / cpu_khz)
    39 #define TSC2US(T1, T2) ((T2 - T1) * 1000UL / cpu_khz)
    39 #define HZREDUCTION (MSR_ABTASTFREQUENZ / HZ)
    40 #define HZREDUCTION (MSR_ABTASTFREQUENZ / HZ)
    40 
    41 
    53 
    54 
    54 ec_master_t *master = NULL;
    55 ec_master_t *master = NULL;
    55 static unsigned int ecat_bus_time = 0;
    56 static unsigned int ecat_bus_time = 0;
    56 static unsigned int ecat_timeouts = 0;
    57 static unsigned int ecat_timeouts = 0;
    57 
    58 
    58 ec_slave_t *s_controller;
    59 ec_slave_t *s_in1, *s_out1, *s_out2, *s_out3;
    59 ec_slave_t *s_analog_in;
       
    60 
    60 
    61 double value;
    61 double value;
    62 int dig1;
    62 int dig1;
    63 
    63 
    64 /*****************************************************************************/
    64 /*****************************************************************************/
    65 
    65 
    66 static int register_slaves(void)
    66 static int register_slaves(void)
    67 {
    67 {
    68     s_controller = EtherCAT_rt_register_slave(master, 0,
    68     s_in1 = EtherCAT_rt_register_slave(master, 1, "Beckhoff", "EL3102", 0);
    69                                               "Beckhoff", "EK1100", 0);
    69     s_out1 = EtherCAT_rt_register_slave(master, 8, "Beckhoff", "EL2004", 0);
    70     s_analog_in = EtherCAT_rt_register_slave(master, 1,
    70     s_out2 = EtherCAT_rt_register_slave(master, 9, "Beckhoff", "EL2004", 0);
    71                                              "Beckhoff", "EL3102", 0);
    71     s_out3 = EtherCAT_rt_register_slave(master, 10, "Beckhoff", "EL2004", 0);
    72 
    72 
    73     return !s_controller || !s_analog_in;
    73     return !s_in1 || !s_out1 || !s_out2 || !s_out3;
    74 }
    74 }
    75 
    75 
    76 /******************************************************************************
    76 /******************************************************************************
    77  *
    77  *
    78  * Function: msr_controller_run()
    78  * Function: msr_controller_run()
    79  *
    79  *
    80  *****************************************************************************/
    80  *****************************************************************************/
    81 
    81 
    82 static void msr_controller_run(void)
    82 static void msr_controller_run(void)
    83 {
    83 {
    84     static unsigned int debug_counter = 0;
    84     static unsigned int counter = 0;
    85 
    85 
    86     // Prozessdaten lesen
       
    87     msr_jitter_run(MSR_ABTASTFREQUENZ);
    86     msr_jitter_run(MSR_ABTASTFREQUENZ);
    88 
    87 
    89 #if 0
    88     if (counter) {
    90     if (debug_counter == 0) {
    89         counter--;
    91         master->debug_level = 2;
    90     }
    92     }
    91     else {
    93 #endif
    92         // "Star Trek"-Effekte
       
    93         *((unsigned char *) s_out1->process_data) = jiffies;
       
    94         *((unsigned char *) s_out2->process_data) = jiffies >> 4;
       
    95         *((unsigned char *) s_out3->process_data) = jiffies >> 8;
       
    96 
       
    97         counter = MSR_ABTASTFREQUENZ / 4;
       
    98     }
       
    99 
       
   100     if (((char *) s_in1->process_data)[2] < 0)
       
   101         ((unsigned char *) s_out3->process_data)[0] |= 8;
       
   102     else
       
   103         ((unsigned char *) s_out3->process_data)[0] &= ~8;
       
   104 
    94 
   105 
    95     // Prozessdaten lesen und schreiben
   106     // Prozessdaten lesen und schreiben
    96     EtherCAT_rt_exchange_io(master, 0, 40);
   107     EtherCAT_rt_domain_xio(master, 0, 40);
    97 
       
    98 #if 0
       
    99     if (debug_counter == 0) {
       
   100         master->debug_level = 0;
       
   101     }
       
   102 #endif
       
   103 
       
   104     //    value = EtherCAT_read_value(&ecat_slaves[1], 0);
       
   105 
       
   106     debug_counter++;
       
   107     if (debug_counter >= MSR_ABTASTFREQUENZ * 5) debug_counter = 0;
       
   108 }
   108 }
   109 
   109 
   110 /******************************************************************************
   110 /******************************************************************************
   111  *
   111  *
   112  *  Function: msr_run(_interrupt)
   112  *  Function: msr_run(_interrupt)
   123  *****************************************************************************/
   123  *****************************************************************************/
   124 
   124 
   125 void msr_run(unsigned irq)
   125 void msr_run(unsigned irq)
   126 {
   126 {
   127     static int counter = 0;
   127     static int counter = 0;
   128 
       
   129     // Schreibe Kanal1 von Klemme X auf 1
       
   130 
   128 
   131     timeval_add(&process_time, &process_time, &msr_time_increment);
   129     timeval_add(&process_time, &process_time, &msr_time_increment);
   132     MSR_ADEOS_INTERRUPT_CODE(msr_controller_run(); msr_write_kanal_list(););
   130     MSR_ADEOS_INTERRUPT_CODE(msr_controller_run(); msr_write_kanal_list(););
   133 
   131 
   134     ipipe_control_irq(irq,0,IPIPE_ENABLE_MASK);  //Interrupt bestˇätigen
   132     ipipe_control_irq(irq,0,IPIPE_ENABLE_MASK);  //Interrupt bestˇätigen