summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2002-07-23 15:02:25 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2002-07-23 15:02:25 +0000
commit2f4b88e9bb157a81cd57b31f8f22dbecc49f368a (patch)
treecb3db8b0dc1821e99890bd22c943a9967e801b81 /firmware
parentadfbc119604e93d94f763b5721f64ecdc2247aa9 (diff)
downloadrockbox-2f4b88e9bb157a81cd57b31f8f22dbecc49f368a.tar.gz
rockbox-2f4b88e9bb157a81cd57b31f8f22dbecc49f368a.zip
Possibly better USB handling
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1419 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/drivers/ata.c46
-rw-r--r--firmware/usb.c13
2 files changed, 27 insertions, 32 deletions
diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c
index 3fdc93669e..6cab3d3872 100644
--- a/firmware/drivers/ata.c
+++ b/firmware/drivers/ata.c
@@ -125,7 +125,6 @@ int ata_read_sectors(unsigned long start,
125 125
126 if ( sleeping ) { 126 if ( sleeping ) {
127 if (ata_soft_reset()) { 127 if (ata_soft_reset()) {
128 mutex_unlock(&ata_mtx);
129 return -1; 128 return -1;
130 } 129 }
131 } 130 }
@@ -184,7 +183,6 @@ int ata_write_sectors(unsigned long start,
184 183
185 if ( sleeping ) { 184 if ( sleeping ) {
186 if (ata_soft_reset()) { 185 if (ata_soft_reset()) {
187 mutex_unlock(&ata_mtx);
188 return -1; 186 return -1;
189 } 187 }
190 } 188 }
@@ -307,14 +305,14 @@ static void ata_thread(void)
307 while (1) { 305 while (1) {
308 queue_wait(&ata_queue, &ev); 306 queue_wait(&ata_queue, &ev);
309 switch ( ev.id ) { 307 switch ( ev.id ) {
310 case SYS_USB_CONNECTED: 308 case SYS_USB_CONNECTED:
311 /* Tell the USB thread that we are safe */ 309 /* Tell the USB thread that we are safe */
312 DEBUGF("backlight_thread got SYS_USB_CONNECTED\n"); 310 DEBUGF("backlight_thread got SYS_USB_CONNECTED\n");
313 usb_acknowledge(SYS_USB_CONNECTED_ACK); 311 usb_acknowledge(SYS_USB_CONNECTED_ACK);
314 312
315 /* Wait until the USB cable is extracted again */ 313 /* Wait until the USB cable is extracted again */
316 usb_wait_for_disconnect(&ata_queue); 314 usb_wait_for_disconnect(&ata_queue);
317 break; 315 break;
318 316
319 case Q_SLEEP: 317 case Q_SLEEP:
320 ata_perform_sleep(); 318 ata_perform_sleep();
@@ -372,7 +370,7 @@ int ata_soft_reset(void)
372 retry_count = 8; 370 retry_count = 8;
373 do 371 do
374 { 372 {
375 ret = wait_for_rdy(); 373 ret = wait_for_rdy();
376 } while(!ret && retry_count--); 374 } while(!ret && retry_count--);
377 375
378 /* Massage the return code so it is 0 on success and -1 on failure */ 376 /* Massage the return code so it is 0 on success and -1 on failure */
@@ -447,9 +445,9 @@ static int io_address_detect(void)
447void ata_enable(bool on) 445void ata_enable(bool on)
448{ 446{
449 if(on) 447 if(on)
450 PADR &= ~0x80; /* enable ATA */ 448 PADR &= ~0x80; /* enable ATA */
451 else 449 else
452 PADR |= 0x80; /* disable ATA */ 450 PADR |= 0x80; /* disable ATA */
453 451
454 PAIOR |= 0x80; 452 PAIOR |= 0x80;
455} 453}
@@ -462,19 +460,19 @@ int ata_init(void)
462 460
463 ata_enable(true); 461 ata_enable(true);
464 462
465 if (master_slave_detect())
466 return -1;
467
468 if (io_address_detect())
469 return -2;
470
471 if (check_registers())
472 return -3;
473
474 if (freeze_lock())
475 return -4;
476
477 if ( !initialized ) { 463 if ( !initialized ) {
464 if (master_slave_detect())
465 return -1;
466
467 if (io_address_detect())
468 return -2;
469
470 if (check_registers())
471 return -3;
472
473 if (freeze_lock())
474 return -4;
475
478 queue_init(&ata_queue); 476 queue_init(&ata_queue);
479 create_thread(ata_thread, ata_stack, 477 create_thread(ata_thread, ata_stack,
480 sizeof(ata_stack), ata_thread_name); 478 sizeof(ata_stack), ata_thread_name);
diff --git a/firmware/usb.c b/firmware/usb.c
index d7112b971f..13bbc173c2 100644
--- a/firmware/usb.c
+++ b/firmware/usb.c
@@ -32,9 +32,7 @@
32#include "button.h" 32#include "button.h"
33#include "sprintf.h" 33#include "sprintf.h"
34 34
35#ifdef ARCHOS_RECORDER 35extern void dbg_ports(void); /* NASTY! defined in apps/ */
36extern void dbg_ports(void);
37#endif
38 36
39#define USB_REALLY_BRAVE 37#define USB_REALLY_BRAVE
40 38
@@ -86,6 +84,7 @@ static void usb_slave_mode(bool on)
86 if(on) 84 if(on)
87 { 85 {
88 DEBUGF("Entering USB slave mode\n"); 86 DEBUGF("Entering USB slave mode\n");
87 ata_soft_reset();
89 ata_enable(false); 88 ata_enable(false);
90 usb_enable(true); 89 usb_enable(true);
91 } 90 }
@@ -101,16 +100,14 @@ static void usb_slave_mode(bool on)
101 rc = ata_init(); 100 rc = ata_init();
102 if(rc) 101 if(rc)
103 { 102 {
104#ifdef ARCHOS_RECORDER
105 char str[32]; 103 char str[32];
106 lcd_clear_display(); 104 lcd_clear_display();
107 snprintf(str, 31, "ATA error: %d", rc); 105 snprintf(str, 31, "ATA error: %d", rc);
108 lcd_puts(0, 1, str); 106 lcd_puts(0, 0, str);
109 lcd_puts(0, 3, "Press ON to debug"); 107 lcd_puts(0, 1, "Press ON to debug");
110 lcd_update(); 108 lcd_update();
111 while(button_get(true) != BUTTON_ON) {}; 109 while(button_get(true) != BUTTON_ON) {};
112 dbg_ports(); 110 dbg_ports();
113#endif
114 panicf("ata: %d",rc); 111 panicf("ata: %d",rc);
115 } 112 }
116 113
@@ -248,7 +245,7 @@ static void usb_tick(void)
248 245
249void usb_acknowledge(int id) 246void usb_acknowledge(int id)
250{ 247{
251 queue_post(&usb_queue, id, NULL); 248 queue_post(&usb_queue, id, NULL);
252} 249}
253 250
254void usb_init(void) 251void usb_init(void)