mini/ec_mini.c
branchkernel2.6
changeset 24 d417dd9bdc2f
parent 23 39364fbcd069
child 26 60435f959e5c
equal deleted inserted replaced
23:39364fbcd069 24:d417dd9bdc2f
     7  * $Id$
     7  * $Id$
     8  *
     8  *
     9  ******************************************************************************/
     9  ******************************************************************************/
    10 
    10 
    11 #include <linux/module.h>
    11 #include <linux/module.h>
       
    12 //#include <linux/slab.h>
       
    13 #include <linux/delay.h>
    12 #include <linux/timer.h>
    14 #include <linux/timer.h>
    13 
    15 
    14 #include "../drivers/ec_master.h"
    16 #include "../drivers/ec_master.h"
    15 #include "../drivers/ec_device.h"
    17 #include "../drivers/ec_device.h"
    16 #include "../drivers/ec_types.h"
    18 #include "../drivers/ec_types.h"
    42     // Block 1
    44     // Block 1
    43     ECAT_INIT_SLAVE(Beckhoff_EK1100),
    45     ECAT_INIT_SLAVE(Beckhoff_EK1100),
    44     ECAT_INIT_SLAVE(Beckhoff_EL4102),
    46     ECAT_INIT_SLAVE(Beckhoff_EL4102),
    45     ECAT_INIT_SLAVE(Beckhoff_EL3162),
    47     ECAT_INIT_SLAVE(Beckhoff_EL3162),
    46     ECAT_INIT_SLAVE(Beckhoff_EL1014),
    48     ECAT_INIT_SLAVE(Beckhoff_EL1014),
    47     ECAT_INIT_SLAVE(Beckhoff_EL2004),
    49 
    48     ECAT_INIT_SLAVE(Beckhoff_EL3102),
       
    49     ECAT_INIT_SLAVE(Beckhoff_EL4102),
    50     ECAT_INIT_SLAVE(Beckhoff_EL4102),
    50     ECAT_INIT_SLAVE(Beckhoff_EL4102),
    51     ECAT_INIT_SLAVE(Beckhoff_EL4102),
    51     ECAT_INIT_SLAVE(Beckhoff_EL4102),
    52     ECAT_INIT_SLAVE(Beckhoff_EL4102),
       
    53 
    52     ECAT_INIT_SLAVE(Beckhoff_EL3162),
    54     ECAT_INIT_SLAVE(Beckhoff_EL3162),
    53     ECAT_INIT_SLAVE(Beckhoff_EL3162),
    55     ECAT_INIT_SLAVE(Beckhoff_EL3162),
    54     ECAT_INIT_SLAVE(Beckhoff_EL3162),
    56     ECAT_INIT_SLAVE(Beckhoff_EL3162),
    55     ECAT_INIT_SLAVE(Beckhoff_EL3102),
    57     ECAT_INIT_SLAVE(Beckhoff_EL3102),
    56     ECAT_INIT_SLAVE(Beckhoff_EL3102),
    58     ECAT_INIT_SLAVE(Beckhoff_EL3102),
    57     ECAT_INIT_SLAVE(Beckhoff_EL2004),
    59     ECAT_INIT_SLAVE(Beckhoff_EL3102),
    58     ECAT_INIT_SLAVE(Beckhoff_EL2004),
    60 
    59     ECAT_INIT_SLAVE(Beckhoff_EL2004),
    61 #endif
    60     ECAT_INIT_SLAVE(Beckhoff_EL2004),
    62 
    61 #endif
    63 #if 1
    62 
       
    63     // Block 2
    64     // Block 2
    64     ECAT_INIT_SLAVE(Beckhoff_EK1100),
    65     ECAT_INIT_SLAVE(Beckhoff_EK1100),
    65     ECAT_INIT_SLAVE(Beckhoff_EL4102),
    66     ECAT_INIT_SLAVE(Beckhoff_EL4102),
    66     ECAT_INIT_SLAVE(Beckhoff_EL1014),
    67     ECAT_INIT_SLAVE(Beckhoff_EL1014),
    67     ECAT_INIT_SLAVE(Beckhoff_EL3162),
    68     ECAT_INIT_SLAVE(Beckhoff_EL3162),
    68     ECAT_INIT_SLAVE(Beckhoff_EL2004),
    69     ECAT_INIT_SLAVE(Beckhoff_EL2004),
    69     ECAT_INIT_SLAVE(Beckhoff_EL3102),
    70     ECAT_INIT_SLAVE(Beckhoff_EL3102),
       
    71     ECAT_INIT_SLAVE(Beckhoff_EL2004),
       
    72     ECAT_INIT_SLAVE(Beckhoff_EL2004),
       
    73     ECAT_INIT_SLAVE(Beckhoff_EL2004),
       
    74     ECAT_INIT_SLAVE(Beckhoff_EL2004),
       
    75     ECAT_INIT_SLAVE(Beckhoff_EL2004),
    70 
    76 
    71     // Block 3
    77     // Block 3
    72     ECAT_INIT_SLAVE(Beckhoff_EK1100),
    78     ECAT_INIT_SLAVE(Beckhoff_EK1100),
    73     ECAT_INIT_SLAVE(Beckhoff_EL1014),
    79     ECAT_INIT_SLAVE(Beckhoff_EL1014),
    74     ECAT_INIT_SLAVE(Beckhoff_EL1014),
    80     ECAT_INIT_SLAVE(Beckhoff_EL1014),
    80     ECAT_INIT_SLAVE(Beckhoff_EL2004),
    86     ECAT_INIT_SLAVE(Beckhoff_EL2004),
    81     ECAT_INIT_SLAVE(Beckhoff_EL2004),
    87     ECAT_INIT_SLAVE(Beckhoff_EL2004),
    82     ECAT_INIT_SLAVE(Beckhoff_EL1014),
    88     ECAT_INIT_SLAVE(Beckhoff_EL1014),
    83     ECAT_INIT_SLAVE(Beckhoff_EL1014),
    89     ECAT_INIT_SLAVE(Beckhoff_EL1014),
    84     ECAT_INIT_SLAVE(Beckhoff_EL1014)
    90     ECAT_INIT_SLAVE(Beckhoff_EL1014)
       
    91 #endif
    85 };
    92 };
    86 
    93 
    87 #define ECAT_SLAVES_COUNT (sizeof(ecat_slaves) / sizeof(EtherCAT_slave_t))
    94 #define ECAT_SLAVES_COUNT (sizeof(ecat_slaves) / sizeof(EtherCAT_slave_t))
    88 
    95 
    89 #endif // ECAT_SLAVES
    96 #endif // ECAT_SLAVES
    90 
    97 
    91 #endif // ECAT
    98 #endif // ECAT
    92 
    99 
    93 #ifdef ECAT_CYCLIC_DATA
   100 #ifdef ECAT_CYCLIC_DATA
    94 
   101 
       
   102 int value;
    95 int dig1;
   103 int dig1;
    96 
   104 
    97 struct timer_list timer;
   105 struct timer_list timer;
    98 unsigned long last_start_jiffies;
   106 unsigned long last_start_jiffies;
    99 
   107 
   150     static int ms = 0;
   158     static int ms = 0;
   151     static int cnt = 0;
   159     static int cnt = 0;
   152     static unsigned long int k = 0;
   160     static unsigned long int k = 0;
   153     static int firstrun = 1;
   161     static int firstrun = 1;
   154 
   162 
   155     static int klemme = 12;
   163     static int klemme = 0;
   156     static int kanal = 0;
   164     static int kanal = 0;
   157     static int up_down = 0;
   165     static int up_down = 0;
   158     int wrap = 0;
   166     int wrap = 0;
   159 
   167 
   160     ms++;
   168     ms++;
   172 #endif
   180 #endif
   173 
   181 
   174     // Prozessdaten lesen
   182     // Prozessdaten lesen
   175     if (!firstrun)
   183     if (!firstrun)
   176     {
   184     {
       
   185         EtherCAT_read_process_data(ecat_master);
       
   186 
       
   187         // Daten lesen und skalieren
       
   188 //        value = EtherCAT_read_value(&ecat_master->slaves[5], 0) / 3276; //.7; FIXME kein FP im Kernel ohne Schutz !!
       
   189 //        dig1 = EtherCAT_read_value(&ecat_master->slaves[3], 0);
       
   190     }
       
   191     else
   177         klemme = next2004(&wrap);
   192         klemme = next2004(&wrap);
   178 
   193 
   179         EtherCAT_read_process_data(ecat_master);
       
   180 
       
   181         // Daten lesen und skalieren
       
   182         //value = EtherCAT_read_value(&ecat_master->slaves[5], 0) / 3276.7;
       
   183         dig1 = EtherCAT_read_value(&ecat_master->slaves[3], 0);
       
   184     }
       
   185 
   194 
   186 #if 0
   195 #if 0
   187     // Daten schreiben
   196     // Daten schreiben
   188     EtherCAT_write_value(&ecat_master->slaves[4], 0, ms > 500 ? 1 : 0);
   197     EtherCAT_write_value(&ecat_master->slaves[4], 0, ms > 500 ? 1 : 0);
   189     EtherCAT_write_value(&ecat_master->slaves[4], 1, ms > 500 ? 0 : 1);
   198     EtherCAT_write_value(&ecat_master->slaves[4], 1, ms > 500 ? 0 : 1);
   206                 else up_down = 1;
   215                 else up_down = 1;
   207             }
   216             }
   208         }
   217         }
   209     }
   218     }
   210 
   219 
   211     if (klemme >= 0)
   220     if (klemme >= 0) {
   212         EtherCAT_write_value(&ecat_master->slaves[klemme], kanal,up_down);
   221         EtherCAT_write_value(&ecat_master->slaves[klemme], kanal,up_down);
       
   222 	//printk("ECAT write: Klemme: %d, Kanal: %d, Wert: %d\n",klemme,kanal,up_down); 
       
   223     }
   213 
   224 
   214 #if 0
   225 #if 0
   215     EtherCAT_write_value(&ecat_master->slaves[13], 1, ms > 500 ? 0 : 1);
   226     EtherCAT_write_value(&ecat_master->slaves[13], 1, ms > 500 ? 0 : 1);
   216     EtherCAT_write_value(&ecat_master->slaves[14], 2, ms > 500 ? 0 : 1);
   227     EtherCAT_write_value(&ecat_master->slaves[14], 2, ms > 500 ? 0 : 1);
   217     EtherCAT_write_value(&ecat_master->slaves[15], 3, ms > 500 ? 1 : 0);
   228     EtherCAT_write_value(&ecat_master->slaves[15], 3, ms > 500 ? 1 : 0);
   221     rdtscl(k);
   232     rdtscl(k);
   222     EtherCAT_write_process_data(ecat_master);
   233     EtherCAT_write_process_data(ecat_master);
   223     firstrun = 0;
   234     firstrun = 0;
   224 #endif
   235 #endif
   225 
   236 
   226     timer.expires += HZ / 100;
   237     timer.expires += HZ / 1000;
   227     add_timer(&timer);
   238     add_timer(&timer);
   228 }
   239 }
   229 
   240 
   230 #endif // ECAT_CYCLIC_DATA
   241 #endif // ECAT_CYCLIC_DATA
   231 
   242 
   306 #endif // ECAT
   317 #endif // ECAT
   307 
   318 
   308 #ifdef ECAT_CYCLIC_DATA
   319 #ifdef ECAT_CYCLIC_DATA
   309     EC_DBG("Starting cyclic sample thread.\n");
   320     EC_DBG("Starting cyclic sample thread.\n");
   310 
   321 
       
   322     schedule();
       
   323     mdelay(1000);
       
   324     schedule();
   311     init_timer(&timer);
   325     init_timer(&timer);
   312 
   326 
   313     timer.function = run;
   327     timer.function = run;
   314     timer.data = 0;
   328     timer.data = 0;
   315     timer.expires = jiffies; // Das erste Mal sofort feuern
   329     timer.expires = jiffies+10; // Das erste Mal sofort feuern
   316     last_start_jiffies = timer.expires;
   330     last_start_jiffies = timer.expires;
   317     add_timer(&timer);
   331     add_timer(&timer);
   318 
   332 
   319     EC_DBG("Initialised sample thread.\n");
   333     EC_DBG("Initialised sample thread.\n");
   320 #endif
   334 #endif