diff options
| author | Scott Shawcroft <scott.shawcroft@gmail.com> | 2018-03-13 11:29:29 -0700 |
|---|---|---|
| committer | Scott Shawcroft <scott.shawcroft@gmail.com> | 2018-03-13 11:29:29 -0700 |
| commit | 81572481894bb371a65313ee75b8a9d3fcbbafcd (patch) | |
| tree | 151ede73a2dcb11fde75946283911a50dbb1a6ee | |
| parent | 9d928b5726ee314fb625a79086675d548be12eef (diff) | |
Move usb read finish into interrupt.
Having the `active_read = false` in the background function left
a chance that a new_write occurs before active_read is set to false.
In that case, we'll read the appropriate data rather than write it
and never clear the active write.
Hopefully fixes #655.
| -rw-r--r-- | ports/atmel-samd/usb_mass_storage.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/ports/atmel-samd/usb_mass_storage.c b/ports/atmel-samd/usb_mass_storage.c index 818736a78..b337839d5 100644 --- a/ports/atmel-samd/usb_mass_storage.c +++ b/ports/atmel-samd/usb_mass_storage.c @@ -260,6 +260,9 @@ int32_t usb_msc_xfer_done(uint8_t lun) { if (active_read) { active_addr += 1; active_nblocks--; + if (active_nblocks == 0) { + active_read = false; + } } if (active_write) { @@ -278,10 +281,6 @@ int32_t usb_msc_xfer_done(uint8_t lun) { // sector. Once the sector is transmitted, xfer_done will be called. void usb_msc_background(void) { if (active_read && !usb_busy) { - if (active_nblocks == 0) { - active_read = false; - return; - } fs_user_mount_t * vfs = get_vfs(active_lun); disk_read(vfs, sector_buffer, active_addr, 1); CRITICAL_SECTION_ENTER(); |
