diff options
Diffstat (limited to 'firmware/usb.c')
-rw-r--r-- | firmware/usb.c | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/firmware/usb.c b/firmware/usb.c index d59cbc3d15..7c43a8ba90 100644 --- a/firmware/usb.c +++ b/firmware/usb.c | |||
@@ -227,6 +227,18 @@ static void usb_thread(void) | |||
227 | num_acks_to_expect); | 227 | num_acks_to_expect); |
228 | } | 228 | } |
229 | break; | 229 | break; |
230 | case USB_RELEASE_DISK: | ||
231 | if(!waiting_for_ack) | ||
232 | { | ||
233 | /* Tell all threads that they have to back off the ATA. | ||
234 | We subtract one for our own thread. */ | ||
235 | num_acks_to_expect = | ||
236 | queue_broadcast(SYS_USB_DISCONNECTED, 0) - 1; | ||
237 | waiting_for_ack = true; | ||
238 | DEBUGF("USB inserted. Waiting for ack from %d threads...\n", | ||
239 | num_acks_to_expect); | ||
240 | } | ||
241 | break; | ||
230 | #endif | 242 | #endif |
231 | case SYS_USB_CONNECTED_ACK: | 243 | case SYS_USB_CONNECTED_ACK: |
232 | if(waiting_for_ack) | 244 | if(waiting_for_ack) |
@@ -264,7 +276,6 @@ static void usb_thread(void) | |||
264 | case USB_EXTRACTED: | 276 | case USB_EXTRACTED: |
265 | #ifdef HAVE_USBSTACK | 277 | #ifdef HAVE_USBSTACK |
266 | usb_enable(false); | 278 | usb_enable(false); |
267 | exclusive_ata_access = false; | ||
268 | #ifdef HAVE_PRIORITY_SCHEDULING | 279 | #ifdef HAVE_PRIORITY_SCHEDULING |
269 | thread_set_priority(usb_thread_entry,PRIORITY_SYSTEM); | 280 | thread_set_priority(usb_thread_entry,PRIORITY_SYSTEM); |
270 | #endif | 281 | #endif |
@@ -292,13 +303,16 @@ static void usb_thread(void) | |||
292 | #endif | 303 | #endif |
293 | 304 | ||
294 | usb_state = USB_EXTRACTED; | 305 | usb_state = USB_EXTRACTED; |
295 | 306 | if(exclusive_ata_access) | |
296 | /* Tell all threads that we are back in business */ | 307 | { |
297 | num_acks_to_expect = | 308 | exclusive_ata_access = false; |
298 | queue_broadcast(SYS_USB_DISCONNECTED, 0) - 1; | 309 | /* Tell all threads that we are back in business */ |
299 | waiting_for_ack = true; | 310 | num_acks_to_expect = |
300 | DEBUGF("USB extracted. Waiting for ack from %d threads...\n", | 311 | queue_broadcast(SYS_USB_DISCONNECTED, 0) - 1; |
301 | num_acks_to_expect); | 312 | waiting_for_ack = true; |
313 | DEBUGF("USB extracted. Waiting for ack from %d threads...\n", | ||
314 | num_acks_to_expect); | ||
315 | } | ||
302 | break; | 316 | break; |
303 | 317 | ||
304 | case SYS_USB_DISCONNECTED_ACK: | 318 | case SYS_USB_DISCONNECTED_ACK: |
@@ -319,15 +333,19 @@ static void usb_thread(void) | |||
319 | } | 333 | } |
320 | break; | 334 | break; |
321 | 335 | ||
322 | #ifdef HAVE_MMC | 336 | #ifdef HAVE_HOTSWAP |
323 | case SYS_HOTSWAP_INSERTED: | 337 | case SYS_HOTSWAP_INSERTED: |
324 | case SYS_HOTSWAP_EXTRACTED: | 338 | case SYS_HOTSWAP_EXTRACTED: |
339 | #ifdef HAVE_USBSTACK | ||
340 | usb_core_hotswap_event(1,ev.id == SYS_HOTSWAP_INSERTED); | ||
341 | #else | ||
325 | if(usb_state == USB_INSERTED) | 342 | if(usb_state == USB_INSERTED) |
326 | { | 343 | { |
327 | usb_enable(false); | 344 | usb_enable(false); |
328 | usb_mmc_countdown = HZ/2; /* re-enable after 0.5 sec */ | 345 | usb_mmc_countdown = HZ/2; /* re-enable after 0.5 sec */ |
329 | } | 346 | } |
330 | break; | 347 | break; |
348 | #endif | ||
331 | 349 | ||
332 | case USB_REENABLE: | 350 | case USB_REENABLE: |
333 | if(usb_state == USB_INSERTED) | 351 | if(usb_state == USB_INSERTED) |
@@ -512,6 +530,14 @@ void usb_request_exclusive_ata(void) | |||
512 | } | 530 | } |
513 | } | 531 | } |
514 | 532 | ||
533 | void usb_release_exclusive_ata(void) | ||
534 | { | ||
535 | if(exclusive_ata_access) { | ||
536 | queue_post(&usb_queue, USB_RELEASE_DISK, 0); | ||
537 | exclusive_ata_access = false; | ||
538 | } | ||
539 | } | ||
540 | |||
515 | bool usb_exclusive_ata(void) | 541 | bool usb_exclusive_ata(void) |
516 | { | 542 | { |
517 | return exclusive_ata_access; | 543 | return exclusive_ata_access; |