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_SCANNING_DISK
));
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_SCANNING_DISK
));
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 static long talked_tick
= 0;
221 if(talk_menus_enabled()
223 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
225 talked_tick
= current_tick
;
226 talk_id(LANG_TAGCACHE_INIT
, false);
227 talk_number(ret
, true);
228 talk_id(VOICE_OF
, true);
229 talk_number(tagcache_get_max_commit_step(), true);
231 #ifdef HAVE_LCD_BITMAP
232 gui_syncsplash(0, "%s [%d/%d]",
233 str(LANG_TAGCACHE_INIT
), ret
,
234 tagcache_get_max_commit_step());
236 lcd_double_height(false);
237 snprintf(buf
, sizeof(buf
), " DB [%d/%d]", ret
,
238 tagcache_get_max_commit_step());
258 static void init(void)
263 #ifdef HAVE_REMOTE_LCD
274 /* Must be done before any code uses the multi-screen APi */
275 screen_access_init();
276 gui_syncstatusbar_init(&statusbars
);
278 settings_load(SETTINGS_ALL
);
282 init_dircache(false);
291 #if CONFIG_CODEC != SWCODEC
292 mp3_init( global_settings
.volume
,
293 global_settings
.bass
,
294 global_settings
.treble
,
295 global_settings
.balance
,
296 global_settings
.loudness
,
298 global_settings
.channel_config
,
299 global_settings
.stereo_width
,
300 global_settings
.mdb_strength
,
301 global_settings
.mdb_harmonics
,
302 global_settings
.mdb_center
,
303 global_settings
.mdb_shape
,
304 global_settings
.mdb_enable
,
305 global_settings
.superbass
);
307 /* audio_init must to know the size of voice buffer so init voice first */
309 #endif /* CONFIG_CODEC != SWCODEC */
315 button_clear_queue(); /* Empty the keyboard buffer */
320 static void init(void)
323 bool mounted
= false;
324 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
325 /* if nobody initialized ATA before, I consider this a cold start */
326 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
334 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
335 set_cpu_frequency(CPUFREQ_NORMAL
);
337 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
350 #ifdef HAVE_REMOTE_LCD
361 #if !defined(HAVE_FMADC) && !defined(HAVE_MMC)
372 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
378 #if CONFIG_USBOTG == USBOTG_ISP1362
380 #elif CONFIG_USBOTG == USBOTG_M5636
394 /* Must be done before any code uses the multi-screen APi */
395 screen_access_init();
396 gui_syncstatusbar_init(&statusbars
);
398 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
399 if (coldstart
&& charger_inserted()
400 && !global_settings
.car_adapter_mode
401 #ifdef ATA_POWER_PLAYERSTYLE
402 && !ide_powered() /* relies on probing result from bootloader */
406 rc
= charging_screen(); /* display a "charging" screen */
407 if (rc
== 1) /* charger removed */
409 /* "On" pressed or USB connected: proceed */
410 show_logo(); /* again, to provide better visual feedback */
414 ata_idle_notify_init();
418 #ifdef HAVE_LCD_BITMAP
421 snprintf(str
, 31, "ATA error: %d", rc
);
423 lcd_puts(0, 3, "Press ON to debug");
425 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
428 panicf("ata: %d", rc
);
431 #ifdef HAVE_EEPROM_SETTINGS
432 eeprom_settings_init();
435 usb_start_monitoring();
438 #ifdef HAVE_EEPROM_SETTINGS
439 firmware_settings
.disk_clean
= false;
441 /* enter USB mode early, before trying to mount */
442 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
444 if (!mmc_touched() ||
445 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
449 mounted
= true; /* mounting done @ end of USB mode */
451 #ifdef HAVE_USB_POWER
452 if (usb_powered()) /* avoid deadlock */
459 rc
= disk_mount_all();
463 lcd_puts(0, 0, "No partition");
464 lcd_puts(0, 1, "found.");
465 #ifdef HAVE_LCD_BITMAP
466 lcd_puts(0, 2, "Insert USB cable");
467 lcd_puts(0, 3, "and fix it.");
471 while(button_get(true) != SYS_USB_CONNECTED
) {};
477 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
478 (CONFIG_KEYPAD == IRIVER_H10_PAD)
479 #ifdef SETTINGS_RESET
480 /* Reset settings if holding the reset button. (Rec on Archos,
482 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
484 /* Reset settings if the hold button is turned on */
488 gui_syncsplash(HZ
*2, ID2P(LANG_RESET_DONE_CLEAR
));
493 settings_load(SETTINGS_ALL
);
495 if (init_dircache(true) < 0)
498 remove(TAGCACHE_STATEFILE
);
504 init_dircache(false);
509 #ifdef HAVE_EEPROM_SETTINGS
510 if (firmware_settings
.initialized
)
512 /* In case we crash. */
513 firmware_settings
.disk_clean
= false;
514 eeprom_settings_store();
524 #if CONFIG_CODEC != SWCODEC
525 /* No buffer allocation (see buffer.c) may take place after the call to
526 audio_init() since the mpeg thread takes the rest of the buffer space */
527 mp3_init( global_settings
.volume
,
528 global_settings
.bass
,
529 global_settings
.treble
,
530 global_settings
.balance
,
531 global_settings
.loudness
,
533 global_settings
.channel_config
,
534 global_settings
.stereo_width
,
535 global_settings
.mdb_strength
,
536 global_settings
.mdb_harmonics
,
537 global_settings
.mdb_center
,
538 global_settings
.mdb_shape
,
539 global_settings
.mdb_enable
,
540 global_settings
.superbass
);
542 /* audio_init must to know the size of voice buffer so init voice first */
544 #endif /* CONFIG_CODEC != SWCODEC */
548 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
552 /* runtime database has to be initialized after audio_init() */
558 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
560 fd
= open(filename
, O_RDONLY
);
561 if(fd
>= 0) /* no complaint if it doesn't exist */
564 plugin_load((char*)filename
, NULL
); /* start if it does */
567 #endif /* #ifdef AUTOROCK */
570 car_adapter_mode_init();
577 /* This is the entry point for the coprocessor
578 Anyone not running an upgraded bootloader will never reach this point,
579 so it should not be assumed that the coprocessor be usable even on
580 platforms which support it.
582 A kernel thread runs on the coprocessor which waits for other threads to be
583 added, and gracefully handles RoLo */
585 #if CONFIG_CPU == PP5002
586 /* 3G doesn't have Rolo or dual core support yet */
588 COP_CTL
= PROC_SLEEP
;
591 extern volatile unsigned char cpu_message
;
596 while(cpu_message
!= COP_REBOOT
) {
609 #if (CONFIG_LED == LED_REAL)
610 led(true); sleep(HZ
/10);
611 led(false); sleep(HZ
/10);