1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Björn Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
22 #include "ata_idle_notify.h"
32 #include "filetypes.h"
37 #include "powermgmt.h"
44 #include "mp3_playback.h"
47 #include "backlight.h"
49 #include "debug_menu.h"
71 #include "eeprom_settings.h"
72 #include "scrobbler.h"
74 #if (CONFIG_CODEC == SWCODEC)
80 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
81 #include "pcm_record.h"
85 #define SETTINGS_RESET BUTTON_REC
95 #ifdef HAVE_REMOTE_LCD
96 #include "lcd-remote.h"
99 #if CONFIG_USBOTG == USBOTG_ISP1362
103 #if CONFIG_USBOTG == USBOTG_M5636
107 #include "cuesheet.h"
109 /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */
111 const char appsversion
[]=APPSVERSION
;
113 static void init(void);
118 static void app_main(void)
125 static int init_dircache(bool preinit
)
134 if (!global_settings
.dircache
)
137 # ifdef HAVE_EEPROM_SETTINGS
138 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
141 result
= dircache_load();
145 firmware_settings
.disk_clean
= false;
146 if (global_status
.dircache_size
<= 0)
148 /* This will be in default language, settings are not
149 applied yet. Not really any easy way to fix that. */
150 gui_syncsplash(0, str(LANG_DIRCACHE_BUILDING
));
154 dircache_build(global_status
.dircache_size
);
163 if (!dircache_is_enabled()
164 && !dircache_is_initializing())
166 if (global_status
.dircache_size
<= 0)
168 gui_syncsplash(0, str(LANG_DIRCACHE_BUILDING
));
171 result
= dircache_build(global_status
.dircache_size
);
176 /* Initialization of dircache failed. Manual action is
177 * necessary to enable dircache again.
179 gui_syncsplash(0, "Dircache failed, disabled. Result: %d", result
);
180 global_settings
.dircache
= false;
189 global_status
.dircache_size
= dircache_get_cache_size();
201 static void init_tagcache(void)
207 while (!tagcache_is_initialized())
209 #ifdef HAVE_LCD_CHARCELLS
212 int ret
= tagcache_get_commit_step();
216 #ifdef HAVE_LCD_BITMAP
217 gui_syncsplash(0, "%s [%d/%d]",
218 str(LANG_TAGCACHE_INIT
), ret
,
219 tagcache_get_max_commit_step());
221 lcd_double_height(false);
222 snprintf(buf
, sizeof(buf
), " DB [%d/%d]", ret
,
223 tagcache_get_max_commit_step());
242 static void init(void)
247 #ifdef HAVE_REMOTE_LCD
255 /* Must be done before any code uses the multi-screen APi */
256 screen_access_init();
257 gui_syncstatusbar_init(&statusbars
);
259 settings_load(SETTINGS_ALL
);
263 init_dircache(false);
272 #if CONFIG_CODEC != SWCODEC
273 mp3_init( global_settings
.volume
,
274 global_settings
.bass
,
275 global_settings
.treble
,
276 global_settings
.balance
,
277 global_settings
.loudness
,
279 global_settings
.channel_config
,
280 global_settings
.stereo_width
,
281 global_settings
.mdb_strength
,
282 global_settings
.mdb_harmonics
,
283 global_settings
.mdb_center
,
284 global_settings
.mdb_shape
,
285 global_settings
.mdb_enable
,
286 global_settings
.superbass
);
288 /* audio_init must to know the size of voice buffer so init voice first */
290 #endif /* CONFIG_CODEC != SWCODEC */
296 button_clear_queue(); /* Empty the keyboard buffer */
301 static void init(void)
304 bool mounted
= false;
305 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
306 /* if nobody initialized ATA before, I consider this a cold start */
307 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
315 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
316 set_cpu_frequency(CPUFREQ_NORMAL
);
318 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
331 #ifdef HAVE_REMOTE_LCD
336 #if !defined(TOSHIBA_GIGABEAT_F) || defined(SIMULATOR)
339 sleep(1); /* Weird. We crash w/o this tiny delay. */
346 #if !defined(HAVE_FMADC) && !defined(HAVE_MMC)
357 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
363 #if CONFIG_USBOTG == USBOTG_ISP1362
365 #elif CONFIG_USBOTG == USBOTG_M5636
379 /* Must be done before any code uses the multi-screen APi */
380 screen_access_init();
381 gui_syncstatusbar_init(&statusbars
);
383 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
384 if (coldstart
&& charger_inserted()
385 && !global_settings
.car_adapter_mode
386 #ifdef ATA_POWER_PLAYERSTYLE
387 && !ide_powered() /* relies on probing result from bootloader */
391 rc
= charging_screen(); /* display a "charging" screen */
392 if (rc
== 1) /* charger removed */
394 /* "On" pressed or USB connected: proceed */
395 show_logo(); /* again, to provide better visual feedback */
399 ata_idle_notify_init();
403 #ifdef HAVE_LCD_BITMAP
406 snprintf(str
, 31, "ATA error: %d", rc
);
408 lcd_puts(0, 3, "Press ON to debug");
410 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
413 panicf("ata: %d", rc
);
416 #ifdef HAVE_EEPROM_SETTINGS
417 eeprom_settings_init();
420 usb_start_monitoring();
423 #ifdef HAVE_EEPROM_SETTINGS
424 firmware_settings
.disk_clean
= false;
426 /* enter USB mode early, before trying to mount */
427 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
429 if (!mmc_touched() || (mmc_remove_request() == SYS_MMC_EXTRACTED
))
433 mounted
= true; /* mounting done @ end of USB mode */
435 #ifdef HAVE_USB_POWER
436 if (usb_powered()) /* avoid deadlock */
443 rc
= disk_mount_all();
447 lcd_puts(0, 0, "No partition");
448 lcd_puts(0, 1, "found.");
449 #ifdef HAVE_LCD_BITMAP
450 lcd_puts(0, 2, "Insert USB cable");
451 lcd_puts(0, 3, "and fix it.");
455 while(button_get(true) != SYS_USB_CONNECTED
) {};
461 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
462 (CONFIG_KEYPAD == IRIVER_H10_PAD) || (CONFIG_KEYPAD == GIGABEAT_PAD)
463 #ifdef SETTINGS_RESET
464 /* Reset settings if holding the rec button. */
465 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
467 /* Reset settings if the hold button is turned on */
471 gui_syncsplash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
476 settings_load(SETTINGS_ALL
);
478 if (init_dircache(true) < 0)
481 remove(TAGCACHE_STATEFILE
);
487 init_dircache(false);
492 #ifdef HAVE_EEPROM_SETTINGS
493 if (firmware_settings
.initialized
)
495 /* In case we crash. */
496 firmware_settings
.disk_clean
= false;
497 eeprom_settings_store();
507 #if CONFIG_CODEC != SWCODEC
508 /* No buffer allocation (see buffer.c) may take place after the call to
509 audio_init() since the mpeg thread takes the rest of the buffer space */
510 mp3_init( global_settings
.volume
,
511 global_settings
.bass
,
512 global_settings
.treble
,
513 global_settings
.balance
,
514 global_settings
.loudness
,
516 global_settings
.channel_config
,
517 global_settings
.stereo_width
,
518 global_settings
.mdb_strength
,
519 global_settings
.mdb_harmonics
,
520 global_settings
.mdb_center
,
521 global_settings
.mdb_shape
,
522 global_settings
.mdb_enable
,
523 global_settings
.superbass
);
525 /* audio_init must to know the size of voice buffer so init voice first */
527 #endif /* CONFIG_CODEC != SWCODEC */
531 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
535 /* runtime database has to be initialized after audio_init() */
541 static const char filename
[] = PLUGIN_DIR
"/autostart.rock";
543 fd
= open(filename
, O_RDONLY
);
544 if(fd
>= 0) /* no complaint if it doesn't exist */
547 plugin_load((char*)filename
, NULL
); /* start if it does */
550 #endif /* #ifdef AUTOROCK */
553 car_adapter_mode_init();
560 /* This is the entry point for the coprocessor
561 Anyone not running an upgraded bootloader will never reach this point,
562 so it should not be assumed that the coprocessor be usable even on
563 platforms which support it.
565 A kernel thread runs on the coprocessor which waits for other threads to be
566 added, and gracefully handles RoLo */
568 #if CONFIG_CPU == PP5002
569 /* 3G doesn't have Rolo or dual core support yet */
571 COP_CTL
= PROC_SLEEP
;
574 extern volatile unsigned char cpu_message
;
579 while(cpu_message
!= COP_REBOOT
) {
592 #if (CONFIG_LED == LED_REAL)
593 led(true); sleep(HZ
/10);
594 led(false); sleep(HZ
/10);