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 @@ #include "kernel.h" #include "thread.h" #include "ata.h" +#include "usb.h" #include "disk.h" #include "font.h" #include "adc.h" @@ -47,32 +48,6 @@ int usb_screen(void) char version[] = APPSVERSION; -static void usb_enable(bool on) -{ - and_l(~0x01000000, &GPIO_OUT); /* GPIO24 is the Cypress chip power */ - or_l(0x01000000, &GPIO_ENABLE); - or_l(0x01000000, &GPIO_FUNCTION); - - or_l(0x00000080, &GPIO1_FUNCTION); /* GPIO39 is the USB detect input */ - - if(on) - { - /* Power on the Cypress chip */ - or_l(0x01000000, &GPIO_OUT); - sleep(2); - } - else - { - /* Power off the Cypress chip */ - and_l(~0x01000000, &GPIO_OUT); - } -} - -bool usb_detect(void) -{ - return (GPIO1_READ & 0x80)?true:false; -} - void start_iriver_fw(void) { asm(" move.w #0x2700,%sr"); @@ -285,6 +260,8 @@ void main(void) power_off(); } + usb_init(); + adc_battery = adc_read(ADC_BATTERY); battery_voltage = (adc_battery * BATTERY_SCALE_FACTOR) / 10000; @@ -318,13 +295,17 @@ void main(void) /* A hack to enter USB mode without using the USB thread */ if(usb_detect()) { + const char msg[] = "Bootloader USB mode"; + int w, h; + font_getstringsize(msg, &w, &h, FONT_SYSFIXED); lcd_clear_display(); - lcd_puts(0, 7, " Bootloader USB mode"); + lcd_putsxy((LCD_WIDTH-w)/2, (LCD_HEIGHT-h)/2, msg); lcd_update(); ata_spin(); ata_enable(false); usb_enable(true); + cpu_idle_mode(true); while(usb_detect()) { ata_spin(); /* Prevent the drive from spinning down */ @@ -334,6 +315,7 @@ void main(void) or_l(0x00020000, &GPIO1_OUT); } + cpu_idle_mode(false); usb_enable(false); ata_init(); /* Reinitialize ATA and continue booting */ @@ -385,14 +367,6 @@ void mpeg_stop(void) { } -void usb_acknowledge(void) -{ -} - -void usb_wait_for_disconnect(void) -{ -} - void sys_poweroff(void) { } 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 @@ #include "kernel.h" void usb_init(void); +void usb_enable(bool on); void usb_start_monitoring(void); void usb_acknowledge(long id); 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; /* FIXME: The extra 0x800 is consumed by fat_mount() when the fsinfo needs updating */ +#ifndef BOOTLOADER static long usb_stack[(DEFAULT_STACK_SIZE + 0x800)/sizeof(long)]; static const char usb_thread_name[] = "usb"; +#endif static struct event_queue usb_queue; static bool last_usb_status; static bool usb_monitor_enabled; - -static void usb_enable(bool on) +void usb_enable(bool on) { #ifdef USB_ENABLE_ONDIOSTYLE PACR2 &= ~0x04C0; /* use PA3, PA5 as GPIO */ @@ -173,6 +174,7 @@ static void usb_enable(bool on) #endif } +#ifndef BOOTLOADER static void usb_slave_mode(bool on) { int rc; @@ -347,6 +349,7 @@ static void usb_thread(void) } } } +#endif bool usb_detect(void) { @@ -378,7 +381,7 @@ bool usb_detect(void) return current_status; } - +#ifndef BOOTLOADER static void usb_tick(void) { bool current_status; @@ -431,6 +434,7 @@ static void usb_tick(void) } #endif } +#endif void usb_acknowledge(long id) { @@ -468,10 +472,12 @@ void usb_init(void) /* We assume that the USB cable is extracted */ last_usb_status = false; +#ifndef BOOTLOADER queue_init(&usb_queue); create_thread(usb_thread, usb_stack, sizeof(usb_stack), usb_thread_name); tick_add_task(usb_tick); +#endif } void usb_wait_for_disconnect(struct event_queue *q)