Skip to content

Commit fc00718

Browse files
committed
USBCDC_ECM: send connection notifications to the host
Fix build issues after rebase
1 parent e7416db commit fc00718

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

usb/device/USBCDC_ECM/USBCDC_ECM.cpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "USBCDC_ECM.h"
2020
#include "EndpointResolver.h"
2121
#include "usb_phy_api.h"
22+
#include "mbed_interface.h"
23+
#include "mbed_assert.h"
2224

2325
#define MAX_SEGMENT_SIZE (1514)
2426
#define FLAG_WRITE_DONE (1 << 0)
@@ -41,9 +43,10 @@
4143
#define CS_INTERFACE 0x24
4244
#define NETWORK_CONNECTION 0x00
4345
#define CONNECTION_SPEED_CHANGE 0x2A
46+
#define LINK_SPEED (10000000)
4447

4548
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)
4750
{
4851
_init();
4952

@@ -57,7 +60,7 @@ USBCDC_ECM::USBCDC_ECM(bool connect_blocking, uint16_t vendor_id, uint16_t produ
5760
}
5861

5962
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)
6164
{
6265

6366
_init();
@@ -77,6 +80,8 @@ void USBCDC_ECM::_init()
7780
_bulk_out = resolver.endpoint_out(USB_EP_TYPE_BULK, MAX_PACKET_SIZE_BULK);
7881

7982
MBED_ASSERT(resolver.valid());
83+
84+
_thread.start(callback(&_queue, &events::EventQueue::dispatch_forever));
8085
}
8186

8287
void USBCDC_ECM::callback_reset()
@@ -100,12 +105,6 @@ void USBCDC_ECM::callback_set_configuration(uint8_t configuration)
100105

101106
bool ret = false;
102107
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);
109108
ret = true;
110109
}
111110

@@ -180,6 +179,12 @@ bool USBCDC_ECM::_notify_connection_speed_change(uint32_t up, uint32_t down)
180179
return ret;
181180
}
182181

182+
void USBCDC_ECM::_notify_connect()
183+
{
184+
_notify_network_connection(1);
185+
_notify_connection_speed_change(LINK_SPEED, LINK_SPEED);
186+
}
187+
183188
bool USBCDC_ECM::_write_bulk(uint8_t *buffer, uint32_t size)
184189
{
185190
bool ret = true;
@@ -281,6 +286,16 @@ void USBCDC_ECM::callback_set_interface(uint16_t interface, uint8_t alternate)
281286
assert_locked();
282287
/* Called in ISR context */
283288

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+
284299
complete_set_interface(true);
285300
}
286301

usb/device/USBCDC_ECM/USBCDC_ECM.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
#include "USBDescriptor.h"
2222
#include "USBDevice.h"
2323

24+
#include "Mutex.h"
25+
#include "EventFlags.h"
26+
#include "EventQueue.h"
27+
#include "Thread.h"
28+
2429
#define MAX_PACKET_SIZE_INT (64)
2530
#define MAX_PACKET_SIZE_BULK (64)
2631
#define MAX_PACKET_SIZE_EP0 (64)
@@ -200,13 +205,17 @@ class USBCDC_ECM: public USBDevice {
200205
rtos::EventFlags _flags;
201206
rtos::Mutex _write_mutex;
202207

208+
events::EventQueue _queue;
209+
rtos::Thread _thread;
210+
203211
void _init();
204212
void _int_callback();
205213
void _bulk_in_callback();
206214
void _bulk_out_callback();
207215
bool _notify_network_connection(uint8_t value);
208216
bool _notify_connection_speed_change(uint32_t up, uint32_t down);
209217
bool _write_bulk(uint8_t *buffer, uint32_t size);
218+
void _notify_connect();
210219
};
211220

212221
#endif

0 commit comments

Comments
 (0)