rt/msr_module.c
changeset 48 7e75772ea28c
parent 47 ad5f969f263b
child 51 b3beaa00640f
equal deleted inserted replaced
47:ad5f969f263b 48:7e75772ea28c
   133 static void msr_controller_run(void)
   133 static void msr_controller_run(void)
   134 {
   134 {
   135     static int ms = 0;
   135     static int ms = 0;
   136     static int cnt = 0;
   136     static int cnt = 0;
   137     static int firstrun = 1;
   137     static int firstrun = 1;
       
   138     static unsigned int debug_counter = 0;
   138 
   139 
   139     static int klemme = 0;
   140     static int klemme = 0;
   140     static int kanal = 0;
   141     static int kanal = 0;
   141     static int up_down = 0;
   142     static int up_down = 0;
   142     int wrap = 0;
   143     int wrap = 0;
   143 
   144 
   144     static unsigned int debug_counter = 0;
   145     unsigned long t_bus_start, t_bus_end;
   145     unsigned long t1, t2, t3;
       
   146     unsigned int bustime1, bustime2;
       
   147     static unsigned long lt = 0;
       
   148 
       
   149     rdtscl(t1);
       
   150 
   146 
   151     // Prozessdaten lesen
   147     // Prozessdaten lesen
   152     msr_jitter_run(MSR_ABTASTFREQUENZ);
   148     msr_jitter_run(MSR_ABTASTFREQUENZ);
   153 
   149 
   154     if (firstrun) klemme = next2004(&wrap);
   150     if (firstrun) {
       
   151         klemme = next2004(&wrap);
       
   152         firstrun = 0;
       
   153     }
   155 
   154 
   156     ms++;
   155     ms++;
   157     ms %= 1000;
   156     ms %= 1000;
   158     if (cnt++ > 200)
   157     if (cnt++ > 200)
   159     {
   158     {
   174 
   173 
   175     if (klemme >= 0) {
   174     if (klemme >= 0) {
   176         EtherCAT_write_value(&ecat_slaves[klemme], kanal, up_down);
   175         EtherCAT_write_value(&ecat_slaves[klemme], kanal, up_down);
   177     }
   176     }
   178 
   177 
       
   178     if (debug_counter == 0) {
       
   179         ecat_master->debug_level = 0;
       
   180     }
       
   181 
   179     // Prozessdaten schreiben
   182     // Prozessdaten schreiben
   180 
   183 
   181     rdtscl(t2);
   184     rdtscl(t_bus_start);
   182 
   185 
   183     if (EtherCAT_process_data_cycle(ecat_master, 0, 40) < 0)
   186     if (EtherCAT_process_data_cycle(ecat_master, 0, 40) < 0)
   184         ecat_timeouts++;
   187         ecat_timeouts++;
   185     bustime1 = ecat_master->bus_time;
       
   186 
   188 
   187     if (EtherCAT_process_data_cycle(ecat_master, 1, 40) < 0)
   189     if (EtherCAT_process_data_cycle(ecat_master, 1, 40) < 0)
   188         ecat_timeouts++;
   190         ecat_timeouts++;
   189     bustime2 = ecat_master->bus_time;
   191 
   190 
   192     rdtscl(t_bus_end);
   191     rdtscl(t3);
   193     ecat_bus_time = TSC2US(t_bus_start, t_bus_end);
   192 
   194 
   193     ecat_bus_time = TSC2US(t2, t3);
   195     if (debug_counter == 0) {
       
   196         ecat_master->debug_level = 0;
       
   197     }
   194 
   198 
   195     // Daten lesen und skalieren
   199     // Daten lesen und skalieren
   196 #ifdef USE_MSR_LIB
   200 #ifdef USE_MSR_LIB
   197     value = EtherCAT_read_value(&ecat_slaves[5], 0) / 3276.0;
   201     value = EtherCAT_read_value(&ecat_slaves[5], 0) / 3276.0;
   198     dig1 = EtherCAT_read_value(&ecat_slaves[2], 0);
   202     dig1 = EtherCAT_read_value(&ecat_slaves[2], 0);
   199 #endif
   203 #endif
   200 
   204 
   201     if (debug_counter == MSR_ABTASTFREQUENZ) {
       
   202       printk(KERN_DEBUG "%lu: %luŽµs + %uŽµs + %uŽµs = %luŽµs\n", TSC2US(lt, t1),
       
   203              TSC2US(t1, t2), bustime1, bustime2, TSC2US(t1, t3));
       
   204       debug_counter = 0;
       
   205     }
       
   206 
       
   207     lt = t1;
       
   208 
       
   209     firstrun = 0;
       
   210     debug_counter++;
   205     debug_counter++;
       
   206     if (debug_counter >= MSR_ABTASTFREQUENZ * 5) debug_counter = 0;
   211 }
   207 }
   212 
   208 
   213 /******************************************************************************
   209 /******************************************************************************
   214  *
   210  *
   215  *  Function: msr_run(_interrupt)
   211  *  Function: msr_run(_interrupt)