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"
75 #if (CONFIG_CODEC == SWCODEC)
81 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
82 #include "pcm_record.h"
86 #define SETTINGS_RESET BUTTON_REC
87 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
88 #define SETTINGS_RESET BUTTON_A
98 #ifdef HAVE_REMOTE_LCD
99 #include "lcd-remote.h"
102 #if CONFIG_USBOTG == USBOTG_ISP1362
106 #if CONFIG_USBOTG == USBOTG_M5636
110 #include "cuesheet.h"
112 /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */
114 const char appsversion
[]=APPSVERSION
;
116 static void init(void);
121 static void app_main(void)
128 static int init_dircache(bool preinit
)
137 if (!global_settings
.dircache
)
140 # ifdef HAVE_EEPROM_SETTINGS
141 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
144 result
= dircache_load();
148 firmware_settings
.disk_clean
= false;
149 if (global_status
.dircache_size
<= 0)
151 /* This will be in default language, settings are not
152 applied yet. Not really any easy way to fix that. */
153 gui_syncsplash(0, str(LANG_DIRCACHE_BUILDING
));
157 dircache_build(global_status
.dircache_size
);
166 if (!dircache_is_enabled()
167 && !dircache_is_initializing())
169 if (global_status
.dircache_size
<= 0)
171 gui_syncsplash(0, str(LANG_DIRCACHE_BUILDING
));
174 result
= dircache_build(global_status
.dircache_size
);
179 /* Initialization of dircache failed. Manual action is
180 * necessary to enable dircache again.
182 gui_syncsplash(0, "Dircache failed, disabled. Result: %d", result
);
183 global_settings
.dircache
= false;
192 global_status
.dircache_size
= dircache_get_cache_size();
204 static void init_tagcache(void)
210 while (!tagcache_is_initialized())
212 #ifdef HAVE_LCD_CHARCELLS
215 int ret
= tagcache_get_commit_step();
219 #ifdef HAVE_LCD_BITMAP
220 gui_syncsplash(0, "%s [%d/%d]",
221 str(LANG_TAGCACHE_INIT
), ret
,
222 tagcache_get_max_commit_step());
224 lcd_double_height(false);
225 snprintf(buf
, sizeof(buf
), " DB [%d/%d]", ret
,
226 tagcache_get_max_commit_step());
246 static void init(void)
251 #ifdef HAVE_REMOTE_LCD
262 /* Must be done before any code uses the multi-screen APi */
263 screen_access_init();
264 gui_syncstatusbar_init(&statusbars
);
266 settings_load(SETTINGS_ALL
);
270 init_dircache(false);
279 #if CONFIG_CODEC != SWCODEC
280 mp3_init( global_settings
.volume
,
281 global_settings
.bass
,
282 global_settings
.treble
,
283 global_settings
.balance
,
284 global_settings
.loudness
,
286 global_settings
.channel_config
,
287 global_settings
.stereo_width
,
288 global_settings
.mdb_strength
,
289 global_settings
.mdb_harmonics
,
290 global_settings
.mdb_center
,
291 global_settings
.mdb_shape
,
292 global_settings
.mdb_enable
,
293 global_settings
.superbass
);
295 /* audio_init must to know the size of voice buffer so init voice first */
297 #endif /* CONFIG_CODEC != SWCODEC */
303 button_clear_queue(); /* Empty the keyboard buffer */
308 static void init(void)
311 bool mounted
= false;
312 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
313 /* if nobody initialized ATA before, I consider this a cold start */
314 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
322 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
323 set_cpu_frequency(CPUFREQ_NORMAL
);
325 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
338 #ifdef HAVE_REMOTE_LCD
349 #if !defined(HAVE_FMADC) && !defined(HAVE_MMC)
360 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
366 #if CONFIG_USBOTG == USBOTG_ISP1362
368 #elif CONFIG_USBOTG == USBOTG_M5636
382 /* Must be done before any code uses the multi-screen APi */
383 screen_access_init();
384 gui_syncstatusbar_init(&statusbars
);
386 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
387 if (coldstart
&& charger_inserted()
388 && !global_settings
.car_adapter_mode
389 #ifdef ATA_POWER_PLAYERSTYLE
390 && !ide_powered() /* relies on probing result from bootloader */
394 rc
= charging_screen(); /* display a "charging" screen */
395 if (rc
== 1) /* charger removed */
397 /* "On" pressed or USB connected: proceed */
398 show_logo(); /* again, to provide better visual feedback */
402 ata_idle_notify_init();
406 #ifdef HAVE_LCD_BITMAP
409 snprintf(str
, 31, "ATA error: %d", rc
);
411 lcd_puts(0, 3, "Press ON to debug");
413 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
416 panicf("ata: %d", rc
);
419 #ifdef HAVE_EEPROM_SETTINGS
420 eeprom_settings_init();
423 usb_start_monitoring();
426 #ifdef HAVE_EEPROM_SETTINGS
427 firmware_settings
.disk_clean
= false;
429 /* enter USB mode early, before trying to mount */
430 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
432 if (!mmc_touched() || (mmc_remove_request() == SYS_MMC_EXTRACTED
))
436 mounted
= true; /* mounting done @ end of USB mode */
438 #ifdef HAVE_USB_POWER
439 if (usb_powered()) /* avoid deadlock */
446 rc
= disk_mount_all();
450 lcd_puts(0, 0, "No partition");
451 lcd_puts(0, 1, "found.");
452 #ifdef HAVE_LCD_BITMAP
453 lcd_puts(0, 2, "Insert USB cable");
454 lcd_puts(0, 3, "and fix it.");
458 while(button_get(true) != SYS_USB_CONNECTED
) {};
464 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
465 (CONFIG_KEYPAD == IRIVER_H10_PAD)
466 #ifdef SETTINGS_RESET
467 /* Reset settings if holding the reset button. (Rec on Archos,
469 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
471 /* Reset settings if the hold button is turned on */
475 gui_syncsplash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
480 settings_load(SETTINGS_ALL
);
482 if (init_dircache(true) < 0)
485 remove(TAGCACHE_STATEFILE
);
491 init_dircache(false);
496 #ifdef HAVE_EEPROM_SETTINGS
497 if (firmware_settings
.initialized
)
499 /* In case we crash. */
500 firmware_settings
.disk_clean
= false;
501 eeprom_settings_store();
511 #if CONFIG_CODEC != SWCODEC
512 /* No buffer allocation (see buffer.c) may take place after the call to
513 audio_init() since the mpeg thread takes the rest of the buffer space */
514 mp3_init( global_settings
.volume
,
515 global_settings
.bass
,
516 global_settings
.treble
,
517 global_settings
.balance
,
518 global_settings
.loudness
,
520 global_settings
.channel_config
,
521 global_settings
.stereo_width
,
522 global_settings
.mdb_strength
,
523 global_settings
.mdb_harmonics
,
524 global_settings
.mdb_center
,
525 global_settings
.mdb_shape
,
526 global_settings
.mdb_enable
,
527 global_settings
.superbass
);
529 /* audio_init must to know the size of voice buffer so init voice first */
531 #endif /* CONFIG_CODEC != SWCODEC */
535 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
539 /* runtime database has to be initialized after audio_init() */
545 static const char filename
[] = PLUGIN_DIR
"/autostart.rock";
547 fd
= open(filename
, O_RDONLY
);
548 if(fd
>= 0) /* no complaint if it doesn't exist */
551 plugin_load((char*)filename
, NULL
); /* start if it does */
554 #endif /* #ifdef AUTOROCK */
557 car_adapter_mode_init();
564 /* This is the entry point for the coprocessor
565 Anyone not running an upgraded bootloader will never reach this point,
566 so it should not be assumed that the coprocessor be usable even on
567 platforms which support it.
569 A kernel thread runs on the coprocessor which waits for other threads to be
570 added, and gracefully handles RoLo */
572 #if CONFIG_CPU == PP5002
573 /* 3G doesn't have Rolo or dual core support yet */
575 COP_CTL
= PROC_SLEEP
;
578 extern volatile unsigned char cpu_message
;
583 while(cpu_message
!= COP_REBOOT
) {
596 #if (CONFIG_LED == LED_REAL)
597 led(true); sleep(HZ
/10);
598 led(false); sleep(HZ
/10);