19
19
#include " USBCDC_ECM.h"
20
20
#include " EndpointResolver.h"
21
21
#include " usb_phy_api.h"
22
+ #include " mbed_interface.h"
23
+ #include " mbed_assert.h"
22
24
23
25
#define MAX_SEGMENT_SIZE (1514 )
24
26
#define FLAG_WRITE_DONE (1 << 0 )
41
43
#define CS_INTERFACE 0x24
42
44
#define NETWORK_CONNECTION 0x00
43
45
#define CONNECTION_SPEED_CHANGE 0x2A
46
+ #define LINK_SPEED (10000000 )
44
47
45
48
USBCDC_ECM::USBCDC_ECM (bool connect_blocking, uint16_t vendor_id, uint16_t product_id, uint16_t product_release)
46
- : USBDevice(get_usb_phy(), vendor_id, product_id, product_release)
49
+ : USBDevice(get_usb_phy(), vendor_id, product_id, product_release), _queue( 4 * EVENTS_EVENT_SIZE)
47
50
{
48
51
_init ();
49
52
@@ -57,7 +60,7 @@ USBCDC_ECM::USBCDC_ECM(bool connect_blocking, uint16_t vendor_id, uint16_t produ
57
60
}
58
61
59
62
USBCDC_ECM::USBCDC_ECM (USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release)
60
- : USBDevice(phy, vendor_id, product_id, product_release)
63
+ : USBDevice(phy, vendor_id, product_id, product_release), _queue( 4 * EVENTS_EVENT_SIZE)
61
64
{
62
65
63
66
_init ();
@@ -77,6 +80,8 @@ void USBCDC_ECM::_init()
77
80
_bulk_out = resolver.endpoint_out (USB_EP_TYPE_BULK, MAX_PACKET_SIZE_BULK);
78
81
79
82
MBED_ASSERT (resolver.valid ());
83
+
84
+ _thread.start (callback (&_queue, &events::EventQueue::dispatch_forever));
80
85
}
81
86
82
87
void USBCDC_ECM::callback_reset ()
@@ -100,12 +105,6 @@ void USBCDC_ECM::callback_set_configuration(uint8_t configuration)
100
105
101
106
bool ret = false ;
102
107
if (configuration == DEFAULT_CONFIGURATION) {
103
- // Configure endpoints > 0
104
- endpoint_add (_int_in, MAX_PACKET_SIZE_INT, USB_EP_TYPE_INT, &USBCDC_ECM::_int_callback);
105
- endpoint_add (_bulk_in, MAX_PACKET_SIZE_BULK, USB_EP_TYPE_BULK, &USBCDC_ECM::_bulk_in_callback);
106
- endpoint_add (_bulk_out, MAX_PACKET_SIZE_BULK, USB_EP_TYPE_BULK, &USBCDC_ECM::_bulk_out_callback);
107
-
108
- read_start (_bulk_out, _bulk_buf, MAX_PACKET_SIZE_BULK);
109
108
ret = true ;
110
109
}
111
110
@@ -180,6 +179,12 @@ bool USBCDC_ECM::_notify_connection_speed_change(uint32_t up, uint32_t down)
180
179
return ret;
181
180
}
182
181
182
+ void USBCDC_ECM::_notify_connect ()
183
+ {
184
+ _notify_network_connection (1 );
185
+ _notify_connection_speed_change (LINK_SPEED, LINK_SPEED);
186
+ }
187
+
183
188
bool USBCDC_ECM::_write_bulk (uint8_t *buffer, uint32_t size)
184
189
{
185
190
bool ret = true ;
@@ -281,6 +286,16 @@ void USBCDC_ECM::callback_set_interface(uint16_t interface, uint8_t alternate)
281
286
assert_locked ();
282
287
/* Called in ISR context */
283
288
289
+ if (alternate) {
290
+ endpoint_add (_int_in, MAX_PACKET_SIZE_INT, USB_EP_TYPE_INT, &USBCDC_ECM::_int_callback);
291
+ endpoint_add (_bulk_in, MAX_PACKET_SIZE_BULK, USB_EP_TYPE_BULK, &USBCDC_ECM::_bulk_in_callback);
292
+ endpoint_add (_bulk_out, MAX_PACKET_SIZE_BULK, USB_EP_TYPE_BULK, &USBCDC_ECM::_bulk_out_callback);
293
+
294
+ read_start (_bulk_out, _bulk_buf, MAX_PACKET_SIZE_BULK);
295
+
296
+ _queue.call (static_cast <USBCDC_ECM *>(this ), &USBCDC_ECM::_notify_connect);
297
+ }
298
+
284
299
complete_set_interface (true );
285
300
}
286
301
0 commit comments