Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ports/atmel-samd/asf4_conf/samd51/hpl_nvmctrl_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
// <i> Indicate whether AHB0 cache is disable or not
// <id> nvm_arch_cache0
#ifndef CONF_NVM_CACHE0
#define CONF_NVM_CACHE0 0
#define CONF_NVM_CACHE0 1
#endif

// <q> AHB1 Cache Disable
// <i> Indicate whether AHB1 cache is disable or not
// <id> nvm_arch_cache1
#ifndef CONF_NVM_CACHE1
#define CONF_NVM_CACHE1 0
#define CONF_NVM_CACHE1 1
#endif

// </h>
Expand Down
28 changes: 19 additions & 9 deletions ports/atmel-samd/usb_mass_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ static fs_user_mount_t* get_vfs(int lun) {
/* Inquiry Information */
// This is designed to handle the common case where we have an internal file
// system and an optional SD card.
static uint8_t inquiry_info[2][36];
COMPILER_ALIGNED(4) static uint8_t inquiry_info[2][36];

/* Capacities of Disk */
static uint8_t format_capa[2][8];
COMPILER_ALIGNED(4) static uint8_t format_capa[2][8];

/**
* \brief Eject Disk
Expand Down Expand Up @@ -256,30 +256,34 @@ int32_t usb_msc_xfer_done(uint8_t lun) {
return ERR_DENIED;
}

CRITICAL_SECTION_ENTER();
if (active_read) {
active_addr += 1;
active_nblocks--;
if (active_nblocks == 0) {
active_read = false;
}
}

if (active_write) {
sector_loaded = true;
}
usb_busy = false;
CRITICAL_SECTION_LEAVE();

return ERR_NONE;
}

// The start_read callback begins a read transaction which we accept but delay our response until the "main thread" calls usb_msc_background. Once it does, we read immediately from the drive into our cache and trigger the USB DMA to output the 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);
// TODO(tannewt): Check the read result.
mscdf_xfer_blocks(true, sector_buffer, 1);
usb_busy = true;
CRITICAL_SECTION_ENTER();
int32_t result = mscdf_xfer_blocks(true, sector_buffer, 1);
usb_busy = result == ERR_NONE;
CRITICAL_SECTION_LEAVE();
}
if (active_write && !usb_busy) {
if (sector_loaded) {
Expand All @@ -306,8 +310,14 @@ void usb_msc_background(void) {
}
// Load more blocks from USB if they are needed.
if (active_nblocks > 0) {
// Turn off interrupts because with them on,
// usb_msc_xfer_done could be called before we update
// usb_busy. If that happened, we'd overwrite the fact that
// the transfer actually already finished.
CRITICAL_SECTION_ENTER();
int32_t result = mscdf_xfer_blocks(false, sector_buffer, 1);
usb_busy = result != ERR_NONE;
usb_busy = result == ERR_NONE;
CRITICAL_SECTION_LEAVE();
} else {
mscdf_xfer_blocks(false, NULL, 0);
active_write = false;
Expand Down