15
15
* limitations under the License.
16
16
*/
17
17
18
+ #include " Arduino.h"
18
19
#include < stdint.h>
19
20
#include < stdlib.h>
20
21
#include " PluggableUSBMSD.h"
@@ -68,18 +69,20 @@ enum Status {
68
69
69
70
USBMSD::USBMSD (mbed::BlockDevice *bd, bool connect_blocking, uint16_t vendor_id, uint16_t product_id, uint16_t product_release)
70
71
: arduino::internal::PluggableUSBModule(1 ),
71
- _initialized(false ), _media_removed(false ), _in_task(&_queue), _out_task(&_queue), _reset_task(&_queue), _configure_task(&_queue), _bd(bd)
72
+ _initialized(false ), _media_removed(false ), _bd(bd)
72
73
{
73
74
PluggableUSBD ().plug (this );
74
75
}
75
76
76
77
USBMSD::USBMSD (USBPhy *phy, mbed::BlockDevice *bd, uint16_t vendor_id, uint16_t product_id, uint16_t product_release)
77
78
: arduino::internal::PluggableUSBModule(1 ),
78
- _initialized(false ), _media_removed(false ), _in_task(&_queue), _out_task(&_queue), _reset_task(&_queue), _configure_task(&_queue), _bd(bd)
79
+ _initialized(false ), _media_removed(false ), _bd(bd)
79
80
{
80
81
PluggableUSBD ().plug (this );
81
82
}
82
83
84
+ static rtos::Thread _t (osPriorityHigh, 64 * 1024 );
85
+ static events::EventQueue _queue (64 *sizeof (int ));
83
86
84
87
void USBMSD::init (EndpointResolver& resolver)
85
88
{
@@ -99,6 +102,8 @@ void USBMSD::init(EndpointResolver& resolver)
99
102
memset ((void *)&_csw, 0 , sizeof (CSW));
100
103
_page = NULL ;
101
104
connect ();
105
+
106
+ _t.start (callback (&_queue, &events::EventQueue::dispatch_forever));
102
107
}
103
108
104
109
USBMSD::~USBMSD ()
@@ -169,21 +174,6 @@ void USBMSD::disconnect()
169
174
// USBDevice::disconnect();
170
175
_initialized = false ;
171
176
172
- _in_task.cancel ();
173
- _out_task.cancel ();
174
- _reset_task.cancel ();
175
- _configure_task.cancel ();
176
-
177
- _mutex.unlock ();
178
-
179
- // object mutex must be unlocked for waiting
180
- _in_task.wait ();
181
- _out_task.wait ();
182
- _reset_task.wait ();
183
- _configure_task.wait ();
184
-
185
- _mutex.lock ();
186
-
187
177
// De-allocate MSD page size:
188
178
free (_page);
189
179
_page = NULL ;
@@ -199,11 +189,6 @@ void USBMSD::process()
199
189
200
190
void USBMSD::attach (mbed::Callback<void ()> cb)
201
191
{
202
- lock ();
203
-
204
- _queue.attach (cb);
205
-
206
- unlock ();
207
192
}
208
193
209
194
bool USBMSD::media_removed ()
@@ -253,21 +238,20 @@ int USBMSD::disk_status()
253
238
254
239
void USBMSD::_isr_out ()
255
240
{
256
- _out_task .call ();
241
+ _queue .call (_out_task );
257
242
}
258
243
259
244
void USBMSD::_isr_in ()
260
245
{
261
- _in_task .call ();
246
+ _queue .call (_in_task );
262
247
}
263
248
264
249
void USBMSD::callback_state_change (USBDevice::DeviceState new_state)
265
250
{
266
251
// called in ISR context
267
252
268
253
if (new_state != USBDevice::Configured) {
269
- _reset_task.cancel ();
270
- _reset_task.call ();
254
+ _queue.call (_reset_task);
271
255
}
272
256
}
273
257
@@ -301,7 +285,7 @@ bool USBMSD::callback_set_configuration(uint8_t configuration)
301
285
{
302
286
// called in ISR context
303
287
304
- _configure ( );
288
+ _queue. call (_configure_task );
305
289
return true ;
306
290
}
307
291
@@ -417,7 +401,7 @@ void USBMSD::_reset()
417
401
418
402
uint32_t USBMSD::_control (const USBDevice::setup_packet_t *setup, USBDevice::RequestResult *result, uint8_t ** data)
419
403
{
420
- _mutex.lock ();
404
+ // _mutex.lock();
421
405
422
406
static const uint8_t maxLUN[1 ] = {0 };
423
407
@@ -440,7 +424,7 @@ uint32_t USBMSD::_control(const USBDevice::setup_packet_t *setup, USBDevice::Req
440
424
}
441
425
}
442
426
443
- _mutex.unlock ();
427
+ // _mutex.unlock();
444
428
return size;
445
429
}
446
430
0 commit comments