summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Moń <desowin@gmail.com>2021-06-09 20:50:30 +0200
committerTomasz Moń <desowin@gmail.com>2021-06-09 20:52:36 +0200
commit163e3507f87b7de7b9e1bdfc7b2c5d5e0357da51 (patch)
tree78c666fe344cb9491870a1162fd69dd3bf25a58e
parenta11c88e0df66b4020ef4d9025b9fb07f04402852 (diff)
downloadrockbox-163e3507f87b7de7b9e1bdfc7b2c5d5e0357da51.tar.gz
rockbox-163e3507f87b7de7b9e1bdfc7b2c5d5e0357da51.tar.bz2
rockbox-163e3507f87b7de7b9e1bdfc7b2c5d5e0357da51.zip
Sansa Connect: Working USB Mass Storage
Acknowledge SYS_USB_CONNECTED in all queues so USB task can gain exclusive access to the storage. Reduce CPPI requeue timeout to speed up disk access. Change-Id: I322aae4cac679696bb8186ccacf838a18f0715e9
-rw-r--r--bootloader/sansaconnect.c60
-rw-r--r--firmware/export/config.h4
-rw-r--r--firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c8
-rw-r--r--firmware/target/arm/tms320dm320/sansa-connect/tnetv105_usb_drv.c4
-rw-r--r--firmware/target/arm/tms320dm320/sdmmc-dm320.c14
5 files changed, 59 insertions, 31 deletions
diff --git a/bootloader/sansaconnect.c b/bootloader/sansaconnect.c
index c5dbca717d..a60fa71800 100644
--- a/bootloader/sansaconnect.c
+++ b/bootloader/sansaconnect.c
@@ -172,6 +172,49 @@ static void clear_recoverzap(void)
}
}
+static void handle_usb(int connect_timeout)
+{
+ long end_tick = 0;
+
+ if (usb_detect() != USB_INSERTED)
+ {
+ return;
+ }
+
+ usb_init();
+ usb_start_monitoring();
+
+ printf("USB: Connecting");
+
+ if (connect_timeout != TIMEOUT_BLOCK)
+ {
+ end_tick = current_tick + connect_timeout;
+ }
+
+ while (usb_detect() == USB_INSERTED)
+ {
+ if (button_get_w_tmo(HZ/2) == SYS_USB_CONNECTED)
+ {
+ printf("Bootloader USB mode");
+ usb_acknowledge(SYS_USB_CONNECTED_ACK);
+ while (button_get_w_tmo(HZ/2) != SYS_USB_DISCONNECTED)
+ {
+ storage_spin();
+ }
+ break;
+ }
+
+ if (connect_timeout != TIMEOUT_BLOCK &&
+ TIME_AFTER(current_tick, end_tick))
+ {
+ printf("USB: Timed out");
+ break;
+ }
+ }
+
+ usb_close();
+}
+
extern void show_logo(void);
void main(void)
@@ -203,12 +246,8 @@ void main(void)
reset_screen();
show_logo();
- btn = button_read_device();
-
printf("Rockbox boot loader");
printf("Version %s", rbversion);
- usb_init();
- usb_start_monitoring();
clear_recoverzap();
@@ -218,21 +257,14 @@ void main(void)
filesystem_init();
- if (usb_detect() == USB_INSERTED)
- {
- usb_enable(true);
- while (usb_detect() == USB_INSERTED)
- {
- sleep(HZ);
- storage_spin();
- }
- usb_enable(false);
- }
+ handle_usb(2*HZ);
ret = disk_mount_all();
if (ret <= 0)
error(EDISK, ret, true);
+ btn = button_read_device();
+
if (btn & BUTTON_PREV)
{
printf("Loading OF firmware...");
diff --git a/firmware/export/config.h b/firmware/export/config.h
index 0242045450..623ef8b4ff 100644
--- a/firmware/export/config.h
+++ b/firmware/export/config.h
@@ -902,6 +902,10 @@ Lyre prototype 1 */
#define INCLUDE_TIMEOUT_API
#define USB_DRIVER_CLOSE
#endif
+#if defined(HAVE_USBSTACK) && CONFIG_USBOTG == USBOTG_TNETV105
+#define INCLUDE_TIMEOUT_API
+#define USB_DRIVER_CLOSE
+#endif
#endif
#else /* !BOOTLOADER */
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c
index 611bdbfde5..1af9789174 100644
--- a/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c
+++ b/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c
@@ -374,7 +374,13 @@ void btn_thread(void)
while (1)
{
queue_wait(&btn_queue, &ev);
-
+
+ if (ev.id == SYS_USB_CONNECTED)
+ {
+ /* Allow USB to gain exclusive storage access */
+ usb_acknowledge(SYS_USB_CONNECTED_ACK);
+ }
+
/* Ignore all messages except BTN_INTERRUPT */
if (ev.id != BTN_INTERRUPT)
continue;
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/tnetv105_usb_drv.c b/firmware/target/arm/tms320dm320/sansa-connect/tnetv105_usb_drv.c
index 56251a96db..00c9c2b80d 100644
--- a/firmware/target/arm/tms320dm320/sansa-connect/tnetv105_usb_drv.c
+++ b/firmware/target/arm/tms320dm320/sansa-connect/tnetv105_usb_drv.c
@@ -1034,7 +1034,7 @@ static int cppi_timeout_cb(struct timeout *tmo)
int flags = disable_irq_save();
bool requeue = tnetv_handle_cppi();
restore_irq(flags);
- return requeue ? HZ/10 : 0;
+ return requeue ? 1 : 0;
}
void VLYNQ(void) __attribute__ ((section(".icode")));
@@ -1205,7 +1205,7 @@ void VLYNQ(void)
if (tnetv_handle_cppi())
{
- timeout_register(&cppi_timeout, cppi_timeout_cb, HZ/10, 0);
+ timeout_register(&cppi_timeout, cppi_timeout_cb, 1, 0);
}
}
}
diff --git a/firmware/target/arm/tms320dm320/sdmmc-dm320.c b/firmware/target/arm/tms320dm320/sdmmc-dm320.c
index fdc3e041a0..cc5c4a822e 100644
--- a/firmware/target/arm/tms320dm320/sdmmc-dm320.c
+++ b/firmware/target/arm/tms320dm320/sdmmc-dm320.c
@@ -781,20 +781,10 @@ int sd_read_sectors(IF_MD(int card_no,) unsigned long start, int incount,
int sd_write_sectors(IF_MD(int card_no,) unsigned long start, int count,
const void* outbuf)
{
-#ifndef BOOTLOADER
#ifndef HAVE_MULTIDRIVE
const int card_no = 0;
#endif
return sd_transfer_sectors(card_no, start, count, (void*)outbuf, true);
-#else /* we don't need write support in bootloader */
-#ifdef HAVE_MULTIDRIVE
- (void)card_no;
-#endif
- (void)start;
- (void)count;
- (void)outbuf;
- return 0;
-#endif
}
int sd_init(void)
@@ -809,9 +799,7 @@ int sd_init(void)
mutex_lock(&sd_mtx);
-#ifndef BOOTLOADER
enable_controller(false);
-#endif
/* based on linux/drivers/mmc/dm320mmc.c
Copyright (C) 2006 ZSI, All Rights Reserved.
@@ -859,8 +847,6 @@ int sd_init(void)
#endif
#endif
- sd_select_device(1);
-
/* Disable Memory Card CLK - it is enabled on demand by TMS320DM320 */
bitclr16(&IO_MMC_MEM_CLK_CONTROL, (1 << 8));
mutex_unlock(&sd_mtx);