equal
deleted
inserted
replaced
37 device->state = EC_DEVICE_STATE_READY; |
37 device->state = EC_DEVICE_STATE_READY; |
38 device->rx_data_size = 0; |
38 device->rx_data_size = 0; |
39 device->isr = NULL; |
39 device->isr = NULL; |
40 device->module = NULL; |
40 device->module = NULL; |
41 device->error_reported = 0; |
41 device->error_reported = 0; |
|
42 device->link_state = 0; // down |
42 |
43 |
43 if ((device->tx_skb = dev_alloc_skb(ETH_HLEN + EC_MAX_FRAME_SIZE)) == NULL) { |
44 if ((device->tx_skb = dev_alloc_skb(ETH_HLEN + EC_MAX_FRAME_SIZE)) == NULL) { |
44 EC_ERR("Error allocating device socket buffer!\n"); |
45 EC_ERR("Error allocating device socket buffer!\n"); |
45 return -1; |
46 return -1; |
46 } |
47 } |
99 // Device could have received frames before |
100 // Device could have received frames before |
100 for (i = 0; i < 4; i++) ec_device_call_isr(device); |
101 for (i = 0; i < 4; i++) ec_device_call_isr(device); |
101 |
102 |
102 // Reset old device state |
103 // Reset old device state |
103 device->state = EC_DEVICE_STATE_READY; |
104 device->state = EC_DEVICE_STATE_READY; |
|
105 device->link_state = 0; |
104 |
106 |
105 if (device->dev->open(device->dev) == 0) device->open = 1; |
107 if (device->dev->open(device->dev) == 0) device->open = 1; |
106 |
108 |
107 return device->open ? 0 : -1; |
109 return device->open ? 0 : -1; |
108 } |
110 } |
163 void ec_device_send(ec_device_t *device, /**< EtherCAT-Gerät */ |
165 void ec_device_send(ec_device_t *device, /**< EtherCAT-Gerät */ |
164 unsigned int length /**< Länge der zu sendenden Daten */ |
166 unsigned int length /**< Länge der zu sendenden Daten */ |
165 ) |
167 ) |
166 { |
168 { |
167 struct ethhdr *eth; |
169 struct ethhdr *eth; |
|
170 |
|
171 if (unlikely(!device->link_state)) { // Link down |
|
172 return; |
|
173 } |
168 |
174 |
169 // Framegröße auf (jetzt bekannte) Länge abschneiden |
175 // Framegröße auf (jetzt bekannte) Länge abschneiden |
170 skb_trim(device->tx_skb, length); |
176 skb_trim(device->tx_skb, length); |
171 |
177 |
172 // Ethernet-II-Header hinzufuegen |
178 // Ethernet-II-Header hinzufuegen |
373 } |
379 } |
374 } |
380 } |
375 |
381 |
376 /*****************************************************************************/ |
382 /*****************************************************************************/ |
377 |
383 |
|
384 /** |
|
385 Setzt einen neuen Verbindungszustand. |
|
386 */ |
|
387 |
|
388 void EtherCAT_dev_link_state(ec_device_t *device, /**< EtherCAT-Gerät */ |
|
389 uint8_t state /**< Verbindungszustand */ |
|
390 ) |
|
391 { |
|
392 if (state != device->link_state) { |
|
393 device->link_state = state; |
|
394 EC_INFO("Link state changed to %s.\n", (state ? "UP" : "DOWN")); |
|
395 } |
|
396 } |
|
397 |
|
398 /*****************************************************************************/ |
|
399 |
378 EXPORT_SYMBOL(EtherCAT_dev_is_ec); |
400 EXPORT_SYMBOL(EtherCAT_dev_is_ec); |
379 EXPORT_SYMBOL(EtherCAT_dev_state); |
401 EXPORT_SYMBOL(EtherCAT_dev_state); |
380 EXPORT_SYMBOL(EtherCAT_dev_receive); |
402 EXPORT_SYMBOL(EtherCAT_dev_receive); |
|
403 EXPORT_SYMBOL(EtherCAT_dev_link_state); |
381 |
404 |
382 /*****************************************************************************/ |
405 /*****************************************************************************/ |
383 |
406 |
384 /* Emacs-Konfiguration |
407 /* Emacs-Konfiguration |
385 ;;; Local Variables: *** |
408 ;;; Local Variables: *** |