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_hw_off(); power_off(); }
/* * Estimate how much current we are drawing just to run. */ static int runcurrent(void) { int current = CURRENT_NORMAL; #ifndef BOOTLOADER if (usb_inserted() #ifdef HAVE_USB_POWER #if (CURRENT_USB < CURRENT_NORMAL) || usb_powered() #else && !usb_powered() #endif #endif ) { current = CURRENT_USB; } #if defined(HAVE_BACKLIGHT) if (backlight_get_current_timeout() == 0) /* LED always on */ current += CURRENT_BACKLIGHT; #endif #if defined(HAVE_RECORDING) && defined(CURRENT_RECORD) if (audio_status() & AUDIO_STATUS_RECORD) current += CURRENT_RECORD; #endif #ifdef HAVE_SPDIF_POWER if (spdif_powered()) current += CURRENT_SPDIF_OUT; #endif #ifdef HAVE_REMOTE_LCD if (remote_detect()) current += CURRENT_REMOTE; #endif #if defined(HAVE_ATA_POWER_OFF) && defined(CURRENT_ATA) if (ide_powered()) current += CURRENT_ATA; #endif #endif /* BOOTLOADER */ return current; }
void ata_reset(void) { int old_level = disable_irq_save(); if(!ide_powered()) { ide_power_enable(true); sleep_ms(150); } else { IO_GIO_BITSET0 = (1 << 5); IO_GIO_BITCLR0 = (1 << 3); sleep_ms(1); } IO_GIO_BITCLR0 = (1 << 5); sleep_ms(10); IO_GIO_BITSET0 = (1 << 3); while(!(ATA_COMMAND & STATUS_RDY)) sleep_ms(10); restore_irq(old_level); }
static void charging_display_info(bool animate) { unsigned char charging_logo[36]; const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2; const int pox_y = 32; static unsigned phase = 3; unsigned i; #ifdef NEED_ATA_POWER_BATT_MEASURE if (ide_powered()) /* FM and V2 can only measure when ATA power is on */ #endif { int battv = battery_voltage(); lcd_putsf(0, 7, " Batt: %d.%02dV %d%% ", battv / 1000, (battv % 1000) / 10, battery_level()); } #ifdef ARCHOS_RECORDER lcd_puts(0, 2, "Charge mode:"); const char *s; if (charge_state == CHARGING) s = str(LANG_BATTERY_CHARGE); else if (charge_state == TOPOFF) s = str(LANG_BATTERY_TOPOFF_CHARGE); else if (charge_state == TRICKLE) s = str(LANG_BATTERY_TRICKLE_CHARGE); else s = "not charging"; lcd_puts(0, 3, s); if (!charger_enabled()) animate = false; #endif /* ARCHOS_RECORDER */ /* middle part */ memset(charging_logo+3, 0x00, 32); charging_logo[0] = 0x3C; charging_logo[1] = 0x24; charging_logo[2] = charging_logo[35] = 0xFF; if (!animate) { /* draw the outline */ /* middle part */ lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8, sizeof(charging_logo), 8); lcd_set_drawmode(DRMODE_FG); /* upper line */ charging_logo[0] = charging_logo[1] = 0x00; memset(charging_logo+2, 0x80, 34); lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8); /* lower line */ memset(charging_logo+2, 0x01, 34); lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16, sizeof(charging_logo), 8); lcd_set_drawmode(DRMODE_SOLID); } else { /* animate the middle part */ for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++) { if ((i-phase) % 8 == 0) { /* draw a "bubble" here */ unsigned bitpos; bitpos = (phase + i/8) % 15; /* "bounce" effect */ if (bitpos > 7) bitpos = 14 - bitpos; charging_logo[i] = BIT_N(bitpos); } } lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8, sizeof(charging_logo), 8); phase++; } lcd_update(); }
void main(void) { int rc; power_init(); system_init(); kernel_init(); lcd_init(); show_logo(); enable_irq(); adc_init(); usb_init(); button_init(); powermgmt_init(); #if CONFIG_CHARGING && (CONFIG_CPU == SH7034) if (charger_inserted() #ifdef ATA_POWER_PLAYERSTYLE && !ide_powered() /* relies on probing result from bootloader */ #endif ) { charging_screen(); /* display a "charging" screen */ show_logo(); /* again, to provide better visual feedback */ } #endif rc = storage_init(); if(rc) { #ifdef HAVE_LCD_BITMAP char str[32]; lcd_clear_display(); snprintf(str, 31, "ATA error: %d", rc); lcd_puts(0, 1, str); lcd_update(); while(!(button_get(true) & BUTTON_REL)); #endif panicf("storage: %d", rc); } usb_start_monitoring(); while (usb_detect() == USB_INSERTED) { /* enter USB mode early, before trying to mount */ if (button_get_w_tmo(HZ/10) == SYS_USB_CONNECTED) { usb_screen(); } } rc = disk_mount_all(); if (rc<=0) { prompt_usb("No partition", "found."); } { // rolo the firmware static const char filename[] = "/" BOOTFILE; rolo_load((char*)filename); /* won't return if started */ prompt_usb("No firmware", filename); } }
static void init(void) { int rc; bool mounted = false; #if CONFIG_CHARGING && (CONFIG_CPU == SH7034) /* if nobody initialized ATA before, I consider this a cold start */ bool coldstart = (PACR2 & 0x4000) != 0; /* starting from Flash */ #endif system_init(); kernel_init(); #ifdef HAVE_ADJUSTABLE_CPU_FREQ set_cpu_frequency(CPUFREQ_NORMAL); #ifdef CPU_COLDFIRE coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS); #endif cpu_boost(true); #endif buffer_init(); settings_reset(); i2c_init(); power_init(); enable_irq(); #ifdef CPU_ARM enable_fiq(); #endif /* current_tick should be ticking by now */ CHART("ticking"); lcd_init(); #ifdef HAVE_REMOTE_LCD lcd_remote_init(); #endif font_init(); CHART(">show_logo"); show_logo(); CHART("<show_logo"); lang_init(core_language_builtin, language_strings, LANG_LAST_INDEX_IN_ARRAY); #ifdef DEBUG debug_init(); #else #ifdef HAVE_SERIAL serial_setup(); #endif #endif #if CONFIG_RTC rtc_init(); #endif #ifdef HAVE_RTC_RAM CHART(">settings_load(RTC)"); settings_load(SETTINGS_RTC); /* early load parts of global_settings */ CHART("<settings_load(RTC)"); #endif adc_init(); usb_init(); #if CONFIG_USBOTG == USBOTG_ISP1362 isp1362_init(); #elif CONFIG_USBOTG == USBOTG_M5636 m5636_init(); #endif backlight_init(); button_init(); powermgmt_init(); #if CONFIG_TUNER radio_init(); #endif /* Keep the order of this 3 (viewportmanager handles statusbars) * Must be done before any code uses the multi-screen API */ CHART(">gui_syncstatusbar_init"); gui_syncstatusbar_init(&statusbars); CHART("<gui_syncstatusbar_init"); CHART(">sb_skin_init"); sb_skin_init(); CHART("<sb_skin_init"); CHART(">gui_sync_wps_init"); gui_sync_wps_init(); CHART("<gui_sync_wps_init"); CHART(">viewportmanager_init"); viewportmanager_init(); CHART("<viewportmanager_init"); #if CONFIG_CHARGING && (CONFIG_CPU == SH7034) /* charger_inserted() can't be used here because power_thread() hasn't checked power_input_status() yet */ if (coldstart && (power_input_status() & POWER_INPUT_MAIN_CHARGER) && !global_settings.car_adapter_mode #ifdef ATA_POWER_PLAYERSTYLE && !ide_powered() /* relies on probing result from bootloader */ #endif ) { rc = charging_screen(); /* display a "charging" screen */ if (rc == 1) /* charger removed */ power_off(); /* "On" pressed or USB connected: proceed */ show_logo(); /* again, to provide better visual feedback */ } #endif CHART(">storage_init"); rc = storage_init(); CHART("<storage_init"); if(rc) { #ifdef HAVE_LCD_BITMAP lcd_clear_display(); lcd_putsf(0, 1, "ATA error: %d", rc); lcd_puts(0, 3, "Press ON to debug"); lcd_update(); while(!(button_get(true) & BUTTON_REL)); /*DO NOT CHANGE TO ACTION SYSTEM */ dbg_ports(); #endif panicf("ata: %d", rc); } #ifdef HAVE_EEPROM_SETTINGS CHART(">eeprom_settings_init"); eeprom_settings_init(); CHART("<eeprom_settings_init"); #endif #ifndef HAVE_USBSTACK usb_start_monitoring(); while (usb_detect() == USB_INSERTED) { #ifdef HAVE_EEPROM_SETTINGS firmware_settings.disk_clean = false; #endif /* enter USB mode early, before trying to mount */ if (button_get_w_tmo(HZ/10) == SYS_USB_CONNECTED) #if (CONFIG_STORAGE & STORAGE_MMC) if (!mmc_touched() || (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED)) #endif { gui_usb_screen_run(); mounted = true; /* mounting done @ end of USB mode */ } #ifdef HAVE_USB_POWER if (usb_powered()) /* avoid deadlock */ break; #endif } #endif if (!mounted) { CHART(">disk_mount_all"); rc = disk_mount_all(); CHART("<disk_mount_all"); if (rc<=0) { lcd_clear_display(); lcd_puts(0, 0, "No partition"); lcd_puts(0, 1, "found."); #ifdef HAVE_LCD_BITMAP lcd_puts(0, 2, "Insert USB cable"); lcd_puts(0, 3, "and fix it."); #endif lcd_update(); while(button_get(true) != SYS_USB_CONNECTED) {}; gui_usb_screen_run(); system_reboot(); } } #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \ (CONFIG_KEYPAD == IRIVER_H10_PAD) #ifdef SETTINGS_RESET /* Reset settings if holding the reset button. (Rec on Archos, A on Gigabeat) */ if ((button_status() & SETTINGS_RESET) == SETTINGS_RESET) #else /* Reset settings if the hold button is turned on */ if (button_hold()) #endif { splash(HZ*2, str(LANG_RESET_DONE_CLEAR)); settings_reset(); } else #endif { CHART(">settings_load(ALL)"); settings_load(SETTINGS_ALL); CHART("<settings_load(ALL)"); } CHART(">init_dircache(true)"); rc = init_dircache(true); CHART("<init_dircache(true)"); if (rc < 0) { #ifdef HAVE_TAGCACHE remove(TAGCACHE_STATEFILE); #endif } CHART(">settings_apply(true)"); settings_apply(true); CHART("<settings_apply(true)"); CHART(">init_dircache(false)"); init_dircache(false); CHART("<init_dircache(false)"); #ifdef HAVE_TAGCACHE CHART(">init_tagcache"); init_tagcache(); CHART("<init_tagcache"); #endif #ifdef HAVE_EEPROM_SETTINGS if (firmware_settings.initialized) { /* In case we crash. */ firmware_settings.disk_clean = false; CHART(">eeprom_settings_store"); eeprom_settings_store(); CHART("<eeprom_settings_store"); } #endif playlist_init(); tree_mem_init(); filetype_init(); scrobbler_init(); #if CONFIG_CODEC == SWCODEC tdspeed_init(); #endif /* CONFIG_CODEC == SWCODEC */ #if CONFIG_CODEC != SWCODEC /* No buffer allocation (see buffer.c) may take place after the call to audio_init() since the mpeg thread takes the rest of the buffer space */ mp3_init( global_settings.volume, global_settings.bass, global_settings.treble, global_settings.balance, global_settings.loudness, global_settings.avc, global_settings.channel_config, global_settings.stereo_width, global_settings.mdb_strength, global_settings.mdb_harmonics, global_settings.mdb_center, global_settings.mdb_shape, global_settings.mdb_enable, global_settings.superbass); /* audio_init must to know the size of voice buffer so init voice first */ talk_init(); #endif /* CONFIG_CODEC != SWCODEC */ CHART(">audio_init"); audio_init(); CHART("<audio_init"); #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR) pcm_rec_init(); #endif /* runtime database has to be initialized after audio_init() */ cpu_boost(false); #if CONFIG_CHARGING car_adapter_mode_init(); #endif #ifdef IPOD_ACCESSORY_PROTOCOL iap_setup(global_settings.serial_bitrate); #endif #ifdef HAVE_ACCESSORY_SUPPLY accessory_supply_set(global_settings.accessory_supply); #endif #ifdef HAVE_LINEOUT_POWEROFF lineout_set(global_settings.lineout_active); #endif #ifdef HAVE_HOTSWAP_STORAGE_AS_MAIN CHART("<check_bootfile(false)"); check_bootfile(false); /* remember write time and filesize */ CHART(">check_bootfile(false)"); #endif CHART("<settings_apply_skins"); settings_apply_skins(); CHART(">settings_apply_skins"); }