diff options
author | Karl Kurbjun <kkurbjun@gmail.com> | 2008-11-12 03:57:32 +0000 |
---|---|---|
committer | Karl Kurbjun <kkurbjun@gmail.com> | 2008-11-12 03:57:32 +0000 |
commit | d42041043b95617244ffdb9150c5e2f2720a8a83 (patch) | |
tree | 71acbd2f8d8d51423d29ddbb2349ed23f77c3151 /bootloader/gigabeat.c | |
parent | 68c686957b1b62671d727116e5c167cd8f080148 (diff) |
Add in the needed crt0.S code for the wakeup alarm also
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19094 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'bootloader/gigabeat.c')
-rw-r--r-- | bootloader/gigabeat.c | 77 |
1 files changed, 73 insertions, 4 deletions
diff --git a/bootloader/gigabeat.c b/bootloader/gigabeat.c index 6b3a68be6e..575e61c2fa 100644 --- a/bootloader/gigabeat.c +++ b/bootloader/gigabeat.c @@ -44,11 +44,29 @@ #include "rbunicode.h" #include "usb.h" #include "mmu-arm.h" +#include "rtc.h" #include <stdarg.h> char version[] = APPSVERSION; +void shutdown(void) +{ + /* We need to gracefully spin down the disk to prevent clicks. */ + if (ide_powered()) + { + /* Make sure ATA has been initialized. */ + ata_init(); + + /* And put the disk into sleep immediately. */ + ata_sleepnow(); + } + + _backlight_off(); + + power_off(); +} + void main(void) { unsigned char* loadbuffer; @@ -56,14 +74,67 @@ void main(void) int rc; int(*kernel_entry)(void); - power_init(); system_init(); lcd_init(); backlight_init(); + button_init(); font_init(); + kernel_init(); /* Need the kernel to sleep */ + adc_init(); lcd_setfont(FONT_SYSFIXED); + + if(!(GPGDAT&BUTTON_POWER) && charger_inserted()) + { + while(!(GPGDAT&BUTTON_POWER) && charger_inserted()) + { + char msg[20]; + if(charging_state()) + { + snprintf(msg,sizeof(msg),"Charging"); + } + else + { + snprintf(msg,sizeof(msg),"Charge Complete"); + } + reset_screen(); + lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2, + (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg); + lcd_update(); + +#if defined(HAVE_RTC_ALARM) + /* Check if the alarm went off while charging */ + if(rtc_check_alarm_flag()) + { + GSTATUS4=1; /* Normally this is set in crt0.s */ + break; + } +#endif + } + if(!(GPGDAT&BUTTON_POWER) +#if defined(HAVE_RTC_ALARM) + && !GSTATUS4 +#endif + ) + { + shutdown(); + } + } + + if(button_hold()) + { + const char msg[] = "HOLD is enabled"; + reset_screen(); + lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2, + (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg); + lcd_update(); + + sleep(2*HZ); + + shutdown(); + } + power_init(); usb_init(); /* Enter USB mode without USB thread */ @@ -88,9 +159,7 @@ void main(void) lcd_update(); } - kernel_init(); - adc_init(); - button_init(); + reset_screen(); /* Show debug messages if button is pressed */ if(button_read_device()) |