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)
129 static int init_dircache(bool preinit
)
138 if (!global_settings
.dircache
)
141 # ifdef HAVE_EEPROM_SETTINGS
142 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
145 result
= dircache_load();
149 firmware_settings
.disk_clean
= false;
150 if (global_status
.dircache_size
<= 0)
152 /* This will be in default language, settings are not
153 applied yet. Not really any easy way to fix that. */
154 gui_syncsplash(0, str(LANG_DIRCACHE_BUILDING
));
158 dircache_build(global_status
.dircache_size
);
167 if (!dircache_is_enabled()
168 && !dircache_is_initializing())
170 if (global_status
.dircache_size
<= 0)
172 gui_syncsplash(0, str(LANG_DIRCACHE_BUILDING
));
175 result
= dircache_build(global_status
.dircache_size
);
180 /* Initialization of dircache failed. Manual action is
181 * necessary to enable dircache again.
183 gui_syncsplash(0, "Dircache failed, disabled. Result: %d", result
);
184 global_settings
.dircache
= false;
193 global_status
.dircache_size
= dircache_get_cache_size();
205 static void init_tagcache(void)
211 while (!tagcache_is_initialized())
213 #ifdef HAVE_LCD_CHARCELLS
216 int ret
= tagcache_get_commit_step();
220 #ifdef HAVE_LCD_BITMAP
221 gui_syncsplash(0, "%s [%d/%d]",
222 str(LANG_TAGCACHE_INIT
), ret
,
223 tagcache_get_max_commit_step());
225 lcd_double_height(false);
226 snprintf(buf
, sizeof(buf
), " DB [%d/%d]", ret
,
227 tagcache_get_max_commit_step());
247 static void init(void)
252 #ifdef HAVE_REMOTE_LCD
263 /* Must be done before any code uses the multi-screen APi */
264 screen_access_init();
265 gui_syncstatusbar_init(&statusbars
);
267 settings_load(SETTINGS_ALL
);
271 init_dircache(false);
280 #if CONFIG_CODEC != SWCODEC
281 mp3_init( global_settings
.volume
,
282 global_settings
.bass
,
283 global_settings
.treble
,
284 global_settings
.balance
,
285 global_settings
.loudness
,
287 global_settings
.channel_config
,
288 global_settings
.stereo_width
,
289 global_settings
.mdb_strength
,
290 global_settings
.mdb_harmonics
,
291 global_settings
.mdb_center
,
292 global_settings
.mdb_shape
,
293 global_settings
.mdb_enable
,
294 global_settings
.superbass
);
296 /* audio_init must to know the size of voice buffer so init voice first */
298 #endif /* CONFIG_CODEC != SWCODEC */
304 button_clear_queue(); /* Empty the keyboard buffer */
309 static void init(void)
312 bool mounted
= false;
313 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
314 /* if nobody initialized ATA before, I consider this a cold start */
315 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
323 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
324 set_cpu_frequency(CPUFREQ_NORMAL
);
326 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
339 #ifdef HAVE_REMOTE_LCD
350 #if !defined(HAVE_FMADC) && !defined(HAVE_MMC)
361 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
367 #if CONFIG_USBOTG == USBOTG_ISP1362
369 #elif CONFIG_USBOTG == USBOTG_M5636
383 /* Must be done before any code uses the multi-screen APi */
384 screen_access_init();
385 gui_syncstatusbar_init(&statusbars
);
387 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
388 if (coldstart
&& charger_inserted()
389 && !global_settings
.car_adapter_mode
390 #ifdef ATA_POWER_PLAYERSTYLE
391 && !ide_powered() /* relies on probing result from bootloader */
395 rc
= charging_screen(); /* display a "charging" screen */
396 if (rc
== 1) /* charger removed */
398 /* "On" pressed or USB connected: proceed */
399 show_logo(); /* again, to provide better visual feedback */
403 ata_idle_notify_init();
407 #ifdef HAVE_LCD_BITMAP
410 snprintf(str
, 31, "ATA error: %d", rc
);
412 lcd_puts(0, 3, "Press ON to debug");
414 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
417 panicf("ata: %d", rc
);
420 #ifdef HAVE_EEPROM_SETTINGS
421 eeprom_settings_init();
424 usb_start_monitoring();
427 #ifdef HAVE_EEPROM_SETTINGS
428 firmware_settings
.disk_clean
= false;
430 /* enter USB mode early, before trying to mount */
431 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
433 if (!mmc_touched() ||
434 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
438 mounted
= true; /* mounting done @ end of USB mode */
440 #ifdef HAVE_USB_POWER
441 if (usb_powered()) /* avoid deadlock */
448 rc
= disk_mount_all();
452 lcd_puts(0, 0, "No partition");
453 lcd_puts(0, 1, "found.");
454 #ifdef HAVE_LCD_BITMAP
455 lcd_puts(0, 2, "Insert USB cable");
456 lcd_puts(0, 3, "and fix it.");
460 while(button_get(true) != SYS_USB_CONNECTED
) {};
466 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
467 (CONFIG_KEYPAD == IRIVER_H10_PAD)
468 #ifdef SETTINGS_RESET
469 /* Reset settings if holding the reset button. (Rec on Archos,
471 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
473 /* Reset settings if the hold button is turned on */
477 gui_syncsplash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
482 settings_load(SETTINGS_ALL
);
484 if (init_dircache(true) < 0)
487 remove(TAGCACHE_STATEFILE
);
493 init_dircache(false);
498 #ifdef HAVE_EEPROM_SETTINGS
499 if (firmware_settings
.initialized
)
501 /* In case we crash. */
502 firmware_settings
.disk_clean
= false;
503 eeprom_settings_store();
513 #if CONFIG_CODEC != SWCODEC
514 /* No buffer allocation (see buffer.c) may take place after the call to
515 audio_init() since the mpeg thread takes the rest of the buffer space */
516 mp3_init( global_settings
.volume
,
517 global_settings
.bass
,
518 global_settings
.treble
,
519 global_settings
.balance
,
520 global_settings
.loudness
,
522 global_settings
.channel_config
,
523 global_settings
.stereo_width
,
524 global_settings
.mdb_strength
,
525 global_settings
.mdb_harmonics
,
526 global_settings
.mdb_center
,
527 global_settings
.mdb_shape
,
528 global_settings
.mdb_enable
,
529 global_settings
.superbass
);
531 /* audio_init must to know the size of voice buffer so init voice first */
533 #endif /* CONFIG_CODEC != SWCODEC */
537 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
541 /* runtime database has to be initialized after audio_init() */
547 static const char filename
[] = PLUGIN_DIR
"/autostart.rock";
549 fd
= open(filename
, O_RDONLY
);
550 if(fd
>= 0) /* no complaint if it doesn't exist */
553 plugin_load((char*)filename
, NULL
); /* start if it does */
556 #endif /* #ifdef AUTOROCK */
559 car_adapter_mode_init();
566 /* This is the entry point for the coprocessor
567 Anyone not running an upgraded bootloader will never reach this point,
568 so it should not be assumed that the coprocessor be usable even on
569 platforms which support it.
571 A kernel thread runs on the coprocessor which waits for other threads to be
572 added, and gracefully handles RoLo */
574 #if CONFIG_CPU == PP5002
575 /* 3G doesn't have Rolo or dual core support yet */
577 COP_CTL
= PROC_SLEEP
;
580 extern volatile unsigned char cpu_message
;
585 while(cpu_message
!= COP_REBOOT
) {
598 #if (CONFIG_LED == LED_REAL)
599 led(true); sleep(HZ
/10);
600 led(false); sleep(HZ
/10);