summaryrefslogtreecommitdiff
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.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)
172 } 172 }
173} 173}
174 174
175static void handle_usb(int connect_timeout)
176{
177 long end_tick = 0;
178
179 if (usb_detect() != USB_INSERTED)
180 {
181 return;
182 }
183
184 usb_init();
185 usb_start_monitoring();
186
187 printf("USB: Connecting");
188
189 if (connect_timeout != TIMEOUT_BLOCK)
190 {
191 end_tick = current_tick + connect_timeout;
192 }
193
194 while (usb_detect() == USB_INSERTED)
195 {
196 if (button_get_w_tmo(HZ/2) == SYS_USB_CONNECTED)
197 {
198 printf("Bootloader USB mode");
199 usb_acknowledge(SYS_USB_CONNECTED_ACK);
200 while (button_get_w_tmo(HZ/2) != SYS_USB_DISCONNECTED)
201 {
202 storage_spin();
203 }
204 break;
205 }
206
207 if (connect_timeout != TIMEOUT_BLOCK &&
208 TIME_AFTER(current_tick, end_tick))
209 {
210 printf("USB: Timed out");
211 break;
212 }
213 }
214
215 usb_close();
216}
217
175extern void show_logo(void); 218extern void show_logo(void);
176 219
177void main(void) 220void main(void)
@@ -203,12 +246,8 @@ void main(void)
203 reset_screen(); 246 reset_screen();
204 show_logo(); 247 show_logo();
205 248
206 btn = button_read_device();
207
208 printf("Rockbox boot loader"); 249 printf("Rockbox boot loader");
209 printf("Version %s", rbversion); 250 printf("Version %s", rbversion);
210 usb_init();
211 usb_start_monitoring();
212 251
213 clear_recoverzap(); 252 clear_recoverzap();
214 253
@@ -218,21 +257,14 @@ void main(void)
218 257
219 filesystem_init(); 258 filesystem_init();
220 259
221 if (usb_detect() == USB_INSERTED) 260 handle_usb(2*HZ);
222 {
223 usb_enable(true);
224 while (usb_detect() == USB_INSERTED)
225 {
226 sleep(HZ);
227 storage_spin();
228 }
229 usb_enable(false);
230 }
231 261
232 ret = disk_mount_all(); 262 ret = disk_mount_all();
233 if (ret <= 0) 263 if (ret <= 0)
234 error(EDISK, ret, true); 264 error(EDISK, ret, true);
235 265
266 btn = button_read_device();
267
236 if (btn & BUTTON_PREV) 268 if (btn & BUTTON_PREV)
237 { 269 {
238 printf("Loading OF firmware..."); 270 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 */
902#define INCLUDE_TIMEOUT_API 902#define INCLUDE_TIMEOUT_API
903#define USB_DRIVER_CLOSE 903#define USB_DRIVER_CLOSE
904#endif 904#endif
905#if defined(HAVE_USBSTACK) && CONFIG_USBOTG == USBOTG_TNETV105
906#define INCLUDE_TIMEOUT_API
907#define USB_DRIVER_CLOSE
908#endif
905#endif 909#endif
906 910
907#else /* !BOOTLOADER */ 911#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)
374 while (1) 374 while (1)
375 { 375 {
376 queue_wait(&btn_queue, &ev); 376 queue_wait(&btn_queue, &ev);
377 377
378 if (ev.id == SYS_USB_CONNECTED)
379 {
380 /* Allow USB to gain exclusive storage access */
381 usb_acknowledge(SYS_USB_CONNECTED_ACK);
382 }
383
378 /* Ignore all messages except BTN_INTERRUPT */ 384 /* Ignore all messages except BTN_INTERRUPT */
379 if (ev.id != BTN_INTERRUPT) 385 if (ev.id != BTN_INTERRUPT)
380 continue; 386 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)
1034 int flags = disable_irq_save(); 1034 int flags = disable_irq_save();
1035 bool requeue = tnetv_handle_cppi(); 1035 bool requeue = tnetv_handle_cppi();
1036 restore_irq(flags); 1036 restore_irq(flags);
1037 return requeue ? HZ/10 : 0; 1037 return requeue ? 1 : 0;
1038} 1038}
1039 1039
1040void VLYNQ(void) __attribute__ ((section(".icode"))); 1040void VLYNQ(void) __attribute__ ((section(".icode")));
@@ -1205,7 +1205,7 @@ void VLYNQ(void)
1205 1205
1206 if (tnetv_handle_cppi()) 1206 if (tnetv_handle_cppi())
1207 { 1207 {
1208 timeout_register(&cppi_timeout, cppi_timeout_cb, HZ/10, 0); 1208 timeout_register(&cppi_timeout, cppi_timeout_cb, 1, 0);
1209 } 1209 }
1210 } 1210 }
1211} 1211}
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,
781int sd_write_sectors(IF_MD(int card_no,) unsigned long start, int count, 781int sd_write_sectors(IF_MD(int card_no,) unsigned long start, int count,
782 const void* outbuf) 782 const void* outbuf)
783{ 783{
784#ifndef BOOTLOADER
785#ifndef HAVE_MULTIDRIVE 784#ifndef HAVE_MULTIDRIVE
786 const int card_no = 0; 785 const int card_no = 0;
787#endif 786#endif
788 return sd_transfer_sectors(card_no, start, count, (void*)outbuf, true); 787 return sd_transfer_sectors(card_no, start, count, (void*)outbuf, true);
789#else /* we don't need write support in bootloader */
790#ifdef HAVE_MULTIDRIVE
791 (void)card_no;
792#endif
793 (void)start;
794 (void)count;
795 (void)outbuf;
796 return 0;
797#endif
798} 788}
799 789
800int sd_init(void) 790int sd_init(void)
@@ -809,9 +799,7 @@ int sd_init(void)
809 799
810 mutex_lock(&sd_mtx); 800 mutex_lock(&sd_mtx);
811 801
812#ifndef BOOTLOADER
813 enable_controller(false); 802 enable_controller(false);
814#endif
815 803
816 /* based on linux/drivers/mmc/dm320mmc.c 804 /* based on linux/drivers/mmc/dm320mmc.c
817 Copyright (C) 2006 ZSI, All Rights Reserved. 805 Copyright (C) 2006 ZSI, All Rights Reserved.
@@ -859,8 +847,6 @@ int sd_init(void)
859#endif 847#endif
860#endif 848#endif
861 849
862 sd_select_device(1);
863
864 /* Disable Memory Card CLK - it is enabled on demand by TMS320DM320 */ 850 /* Disable Memory Card CLK - it is enabled on demand by TMS320DM320 */
865 bitclr16(&IO_MMC_MEM_CLK_CONTROL, (1 << 8)); 851 bitclr16(&IO_MMC_MEM_CLK_CONTROL, (1 << 8));
866 mutex_unlock(&sd_mtx); 852 mutex_unlock(&sd_mtx);