master/master.c
changeset 721 ebc2fd3e09e5
parent 720 9664a19978dd
child 758 8fa6f825eb7d
equal deleted inserted replaced
720:9664a19978dd 721:ebc2fd3e09e5
  1160     ec_eoe_t *eoe;
  1160     ec_eoe_t *eoe;
  1161     unsigned int none_open = 1;
  1161     unsigned int none_open = 1;
  1162     cycles_t cycles_start, cycles_end;
  1162     cycles_t cycles_start, cycles_end;
  1163     unsigned long restart_jiffies;
  1163     unsigned long restart_jiffies;
  1164 
  1164 
  1165 
       
  1166     list_for_each_entry(eoe, &master->eoe_handlers, list) {
  1165     list_for_each_entry(eoe, &master->eoe_handlers, list) {
  1167         if (ec_eoe_is_open(eoe)) {
  1166         if (ec_eoe_is_open(eoe)) {
  1168             none_open = 0;
  1167             none_open = 0;
  1169             break;
  1168             break;
  1170         }
  1169         }
  1171     }
  1170     }
  1172     if (none_open)
  1171     if (none_open)
  1173         goto queue_timer;
  1172         goto queue_timer;
  1174 
  1173 
       
  1174     // receive datagrams
  1175     if (master->request_cb(master->cb_data)) goto queue_timer;
  1175     if (master->request_cb(master->cb_data)) goto queue_timer;
  1176 
       
  1177     // receive datagrams
       
  1178     cycles_start = get_cycles();
  1176     cycles_start = get_cycles();
  1179     ecrt_master_receive(master);
  1177     ecrt_master_receive(master);
       
  1178     master->release_cb(master->cb_data);
  1180 
  1179 
  1181     // actual EoE processing
  1180     // actual EoE processing
  1182     list_for_each_entry(eoe, &master->eoe_handlers, list) {
  1181     list_for_each_entry(eoe, &master->eoe_handlers, list) {
  1183         ec_eoe_run(eoe);
  1182         ec_eoe_run(eoe);
  1184     }
  1183     }
  1185 
  1184 
  1186     // send datagrams
  1185     // send datagrams
       
  1186     if (master->request_cb(master->cb_data)) {
       
  1187         goto queue_timer;
       
  1188     }
       
  1189     list_for_each_entry(eoe, &master->eoe_handlers, list) {
       
  1190         ec_eoe_queue(eoe);
       
  1191     }
  1187     ecrt_master_send(master);
  1192     ecrt_master_send(master);
       
  1193     master->release_cb(master->cb_data);
  1188     cycles_end = get_cycles();
  1194     cycles_end = get_cycles();
  1189 
       
  1190     master->release_cb(master->cb_data);
       
  1191 
  1195 
  1192     master->eoe_cycle_times[master->eoe_cycle_time_pos]
  1196     master->eoe_cycle_times[master->eoe_cycle_time_pos]
  1193         = (u32) (cycles_end - cycles_start) * 1000 / cpu_khz;
  1197         = (u32) (cycles_end - cycles_start) * 1000 / cpu_khz;
  1194     master->eoe_cycle_time_pos++;
  1198     master->eoe_cycle_time_pos++;
  1195     master->eoe_cycle_time_pos %= HZ;
  1199     master->eoe_cycle_time_pos %= HZ;
  1196 
  1200 
  1197  queue_timer:
  1201  queue_timer:
  1198     restart_jiffies = HZ / EC_EOE_FREQUENCY;
  1202     restart_jiffies = HZ / EC_EOE_FREQUENCY;
  1199     if (!restart_jiffies) restart_jiffies = 1;
  1203     if (!restart_jiffies) restart_jiffies = 1;
  1200     master->eoe_timer.expires += restart_jiffies;
  1204     master->eoe_timer.expires = jiffies + restart_jiffies;
  1201     add_timer(&master->eoe_timer);
  1205     add_timer(&master->eoe_timer);
  1202 }
  1206 }
  1203 #endif
  1207 #endif
  1204 
  1208 
  1205 /*****************************************************************************/
  1209 /*****************************************************************************/