diff options
-rw-r--r-- | bootloader/main.c | 44 | ||||
-rw-r--r-- | firmware/export/usb.h | 1 | ||||
-rw-r--r-- | firmware/usb.c | 12 |
3 files changed, 19 insertions, 38 deletions
diff --git a/bootloader/main.c b/bootloader/main.c index 7fa60f961a..31324b50fe 100644 --- a/bootloader/main.c +++ b/bootloader/main.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include "kernel.h" | 26 | #include "kernel.h" |
27 | #include "thread.h" | 27 | #include "thread.h" |
28 | #include "ata.h" | 28 | #include "ata.h" |
29 | #include "usb.h" | ||
29 | #include "disk.h" | 30 | #include "disk.h" |
30 | #include "font.h" | 31 | #include "font.h" |
31 | #include "adc.h" | 32 | #include "adc.h" |
@@ -47,32 +48,6 @@ int usb_screen(void) | |||
47 | 48 | ||
48 | char version[] = APPSVERSION; | 49 | char version[] = APPSVERSION; |
49 | 50 | ||
50 | static void usb_enable(bool on) | ||
51 | { | ||
52 | and_l(~0x01000000, &GPIO_OUT); /* GPIO24 is the Cypress chip power */ | ||
53 | or_l(0x01000000, &GPIO_ENABLE); | ||
54 | or_l(0x01000000, &GPIO_FUNCTION); | ||
55 | |||
56 | or_l(0x00000080, &GPIO1_FUNCTION); /* GPIO39 is the USB detect input */ | ||
57 | |||
58 | if(on) | ||
59 | { | ||
60 | /* Power on the Cypress chip */ | ||
61 | or_l(0x01000000, &GPIO_OUT); | ||
62 | sleep(2); | ||
63 | } | ||
64 | else | ||
65 | { | ||
66 | /* Power off the Cypress chip */ | ||
67 | and_l(~0x01000000, &GPIO_OUT); | ||
68 | } | ||
69 | } | ||
70 | |||
71 | bool usb_detect(void) | ||
72 | { | ||
73 | return (GPIO1_READ & 0x80)?true:false; | ||
74 | } | ||
75 | |||
76 | void start_iriver_fw(void) | 51 | void start_iriver_fw(void) |
77 | { | 52 | { |
78 | asm(" move.w #0x2700,%sr"); | 53 | asm(" move.w #0x2700,%sr"); |
@@ -285,6 +260,8 @@ void main(void) | |||
285 | power_off(); | 260 | power_off(); |
286 | } | 261 | } |
287 | 262 | ||
263 | usb_init(); | ||
264 | |||
288 | adc_battery = adc_read(ADC_BATTERY); | 265 | adc_battery = adc_read(ADC_BATTERY); |
289 | 266 | ||
290 | battery_voltage = (adc_battery * BATTERY_SCALE_FACTOR) / 10000; | 267 | battery_voltage = (adc_battery * BATTERY_SCALE_FACTOR) / 10000; |
@@ -318,13 +295,17 @@ void main(void) | |||
318 | /* A hack to enter USB mode without using the USB thread */ | 295 | /* A hack to enter USB mode without using the USB thread */ |
319 | if(usb_detect()) | 296 | if(usb_detect()) |
320 | { | 297 | { |
298 | const char msg[] = "Bootloader USB mode"; | ||
299 | int w, h; | ||
300 | font_getstringsize(msg, &w, &h, FONT_SYSFIXED); | ||
321 | lcd_clear_display(); | 301 | lcd_clear_display(); |
322 | lcd_puts(0, 7, " Bootloader USB mode"); | 302 | lcd_putsxy((LCD_WIDTH-w)/2, (LCD_HEIGHT-h)/2, msg); |
323 | lcd_update(); | 303 | lcd_update(); |
324 | 304 | ||
325 | ata_spin(); | 305 | ata_spin(); |
326 | ata_enable(false); | 306 | ata_enable(false); |
327 | usb_enable(true); | 307 | usb_enable(true); |
308 | cpu_idle_mode(true); | ||
328 | while(usb_detect()) | 309 | while(usb_detect()) |
329 | { | 310 | { |
330 | ata_spin(); /* Prevent the drive from spinning down */ | 311 | ata_spin(); /* Prevent the drive from spinning down */ |
@@ -334,6 +315,7 @@ void main(void) | |||
334 | or_l(0x00020000, &GPIO1_OUT); | 315 | or_l(0x00020000, &GPIO1_OUT); |
335 | } | 316 | } |
336 | 317 | ||
318 | cpu_idle_mode(false); | ||
337 | usb_enable(false); | 319 | usb_enable(false); |
338 | ata_init(); /* Reinitialize ATA and continue booting */ | 320 | ata_init(); /* Reinitialize ATA and continue booting */ |
339 | 321 | ||
@@ -385,14 +367,6 @@ void mpeg_stop(void) | |||
385 | { | 367 | { |
386 | } | 368 | } |
387 | 369 | ||
388 | void usb_acknowledge(void) | ||
389 | { | ||
390 | } | ||
391 | |||
392 | void usb_wait_for_disconnect(void) | ||
393 | { | ||
394 | } | ||
395 | |||
396 | void sys_poweroff(void) | 370 | void sys_poweroff(void) |
397 | { | 371 | { |
398 | } | 372 | } |
diff --git a/firmware/export/usb.h b/firmware/export/usb.h index e8602e7358..b16c11a9b8 100644 --- a/firmware/export/usb.h +++ b/firmware/export/usb.h | |||
@@ -22,6 +22,7 @@ | |||
22 | #include "kernel.h" | 22 | #include "kernel.h" |
23 | 23 | ||
24 | void usb_init(void); | 24 | void usb_init(void); |
25 | void usb_enable(bool on); | ||
25 | void usb_start_monitoring(void); | 26 | void usb_start_monitoring(void); |
26 | void usb_acknowledge(long id); | 27 | void usb_acknowledge(long id); |
27 | void usb_wait_for_disconnect(struct event_queue *q); | 28 | void usb_wait_for_disconnect(struct event_queue *q); |
diff --git a/firmware/usb.c b/firmware/usb.c index 8f9de111e4..c453cb7a2b 100644 --- a/firmware/usb.c +++ b/firmware/usb.c | |||
@@ -79,14 +79,15 @@ static int usb_mmc_countdown = 0; | |||
79 | 79 | ||
80 | /* FIXME: The extra 0x800 is consumed by fat_mount() when the fsinfo | 80 | /* FIXME: The extra 0x800 is consumed by fat_mount() when the fsinfo |
81 | needs updating */ | 81 | needs updating */ |
82 | #ifndef BOOTLOADER | ||
82 | static long usb_stack[(DEFAULT_STACK_SIZE + 0x800)/sizeof(long)]; | 83 | static long usb_stack[(DEFAULT_STACK_SIZE + 0x800)/sizeof(long)]; |
83 | static const char usb_thread_name[] = "usb"; | 84 | static const char usb_thread_name[] = "usb"; |
85 | #endif | ||
84 | static struct event_queue usb_queue; | 86 | static struct event_queue usb_queue; |
85 | static bool last_usb_status; | 87 | static bool last_usb_status; |
86 | static bool usb_monitor_enabled; | 88 | static bool usb_monitor_enabled; |
87 | 89 | ||
88 | 90 | void usb_enable(bool on) | |
89 | static void usb_enable(bool on) | ||
90 | { | 91 | { |
91 | #ifdef USB_ENABLE_ONDIOSTYLE | 92 | #ifdef USB_ENABLE_ONDIOSTYLE |
92 | PACR2 &= ~0x04C0; /* use PA3, PA5 as GPIO */ | 93 | PACR2 &= ~0x04C0; /* use PA3, PA5 as GPIO */ |
@@ -173,6 +174,7 @@ static void usb_enable(bool on) | |||
173 | #endif | 174 | #endif |
174 | } | 175 | } |
175 | 176 | ||
177 | #ifndef BOOTLOADER | ||
176 | static void usb_slave_mode(bool on) | 178 | static void usb_slave_mode(bool on) |
177 | { | 179 | { |
178 | int rc; | 180 | int rc; |
@@ -347,6 +349,7 @@ static void usb_thread(void) | |||
347 | } | 349 | } |
348 | } | 350 | } |
349 | } | 351 | } |
352 | #endif | ||
350 | 353 | ||
351 | bool usb_detect(void) | 354 | bool usb_detect(void) |
352 | { | 355 | { |
@@ -378,7 +381,7 @@ bool usb_detect(void) | |||
378 | return current_status; | 381 | return current_status; |
379 | } | 382 | } |
380 | 383 | ||
381 | 384 | #ifndef BOOTLOADER | |
382 | static void usb_tick(void) | 385 | static void usb_tick(void) |
383 | { | 386 | { |
384 | bool current_status; | 387 | bool current_status; |
@@ -431,6 +434,7 @@ static void usb_tick(void) | |||
431 | } | 434 | } |
432 | #endif | 435 | #endif |
433 | } | 436 | } |
437 | #endif | ||
434 | 438 | ||
435 | void usb_acknowledge(long id) | 439 | void usb_acknowledge(long id) |
436 | { | 440 | { |
@@ -468,10 +472,12 @@ void usb_init(void) | |||
468 | /* We assume that the USB cable is extracted */ | 472 | /* We assume that the USB cable is extracted */ |
469 | last_usb_status = false; | 473 | last_usb_status = false; |
470 | 474 | ||
475 | #ifndef BOOTLOADER | ||
471 | queue_init(&usb_queue); | 476 | queue_init(&usb_queue); |
472 | create_thread(usb_thread, usb_stack, sizeof(usb_stack), usb_thread_name); | 477 | create_thread(usb_thread, usb_stack, sizeof(usb_stack), usb_thread_name); |
473 | 478 | ||
474 | tick_add_task(usb_tick); | 479 | tick_add_task(usb_tick); |
480 | #endif | ||
475 | } | 481 | } |
476 | 482 | ||
477 | void usb_wait_for_disconnect(struct event_queue *q) | 483 | void usb_wait_for_disconnect(struct event_queue *q) |