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"
103 #include "usbstack.h"
106 #if CONFIG_USBOTG == USBOTG_ISP1362
110 #if CONFIG_USBOTG == USBOTG_M5636
114 #include "cuesheet.h"
116 /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */
118 const char appsversion
[]=APPSVERSION
;
120 static void init(void);
125 static void app_main(void)
133 static int init_dircache(bool preinit
)
142 if (!global_settings
.dircache
)
145 # ifdef HAVE_EEPROM_SETTINGS
146 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
149 result
= dircache_load();
153 firmware_settings
.disk_clean
= false;
154 if (global_status
.dircache_size
<= 0)
156 /* This will be in default language, settings are not
157 applied yet. Not really any easy way to fix that. */
158 gui_syncsplash(0, str(LANG_SCANNING_DISK
));
162 dircache_build(global_status
.dircache_size
);
171 if (!dircache_is_enabled()
172 && !dircache_is_initializing())
174 if (global_status
.dircache_size
<= 0)
176 gui_syncsplash(0, str(LANG_SCANNING_DISK
));
179 result
= dircache_build(global_status
.dircache_size
);
184 /* Initialization of dircache failed. Manual action is
185 * necessary to enable dircache again.
187 gui_syncsplash(0, "Dircache failed, disabled. Result: %d", result
);
188 global_settings
.dircache
= false;
197 global_status
.dircache_size
= dircache_get_cache_size();
209 static void init_tagcache(void)
215 while (!tagcache_is_initialized())
217 #ifdef HAVE_LCD_CHARCELLS
220 int ret
= tagcache_get_commit_step();
224 #if CONFIG_CODEC == SWCODEC
225 /* hwcodec can't use voice here, as the database commit
226 * uses the audio buffer. */
227 static long talked_tick
= 0;
228 if(talk_menus_enabled()
230 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
232 talked_tick
= current_tick
;
233 talk_id(LANG_TAGCACHE_INIT
, false);
234 talk_number(ret
, true);
235 talk_id(VOICE_OF
, true);
236 talk_number(tagcache_get_max_commit_step(), true);
239 #ifdef HAVE_LCD_BITMAP
240 gui_syncsplash(0, "%s [%d/%d]",
241 str(LANG_TAGCACHE_INIT
), ret
,
242 tagcache_get_max_commit_step());
244 lcd_double_height(false);
245 snprintf(buf
, sizeof(buf
), " DB [%d/%d]", ret
,
246 tagcache_get_max_commit_step());
266 static void init(void)
271 #ifdef HAVE_REMOTE_LCD
282 /* Must be done before any code uses the multi-screen APi */
283 screen_access_init();
284 gui_syncstatusbar_init(&statusbars
);
287 settings_load(SETTINGS_ALL
);
291 init_dircache(false);
300 #if CONFIG_CODEC != SWCODEC
301 mp3_init( global_settings
.volume
,
302 global_settings
.bass
,
303 global_settings
.treble
,
304 global_settings
.balance
,
305 global_settings
.loudness
,
307 global_settings
.channel_config
,
308 global_settings
.stereo_width
,
309 global_settings
.mdb_strength
,
310 global_settings
.mdb_harmonics
,
311 global_settings
.mdb_center
,
312 global_settings
.mdb_shape
,
313 global_settings
.mdb_enable
,
314 global_settings
.superbass
);
316 /* audio_init must to know the size of voice buffer so init voice first */
318 #endif /* CONFIG_CODEC != SWCODEC */
324 button_clear_queue(); /* Empty the keyboard buffer */
329 static void init(void)
332 bool mounted
= false;
333 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
334 /* if nobody initialized ATA before, I consider this a cold start */
335 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
343 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
344 set_cpu_frequency(CPUFREQ_NORMAL
);
346 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
359 #ifdef HAVE_REMOTE_LCD
370 #if !defined(HAVE_FMADC) && !defined(HAVE_MMC)
381 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
390 #if CONFIG_USBOTG == USBOTG_ISP1362
392 #elif CONFIG_USBOTG == USBOTG_M5636
406 /* Must be done before any code uses the multi-screen APi */
407 screen_access_init();
408 gui_syncstatusbar_init(&statusbars
);
410 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
411 if (coldstart
&& charger_inserted()
412 && !global_settings
.car_adapter_mode
413 #ifdef ATA_POWER_PLAYERSTYLE
414 && !ide_powered() /* relies on probing result from bootloader */
418 rc
= charging_screen(); /* display a "charging" screen */
419 if (rc
== 1) /* charger removed */
421 /* "On" pressed or USB connected: proceed */
422 show_logo(); /* again, to provide better visual feedback */
426 ata_idle_notify_init();
430 #ifdef HAVE_LCD_BITMAP
433 snprintf(str
, 31, "ATA error: %d", rc
);
435 lcd_puts(0, 3, "Press ON to debug");
437 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
440 panicf("ata: %d", rc
);
443 #ifdef HAVE_EEPROM_SETTINGS
444 eeprom_settings_init();
447 usb_start_monitoring();
448 while (usb_detect() == USB_INSERTED
)
450 #ifdef HAVE_EEPROM_SETTINGS
451 firmware_settings
.disk_clean
= false;
453 /* enter USB mode early, before trying to mount */
454 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
456 if (!mmc_touched() ||
457 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
461 mounted
= true; /* mounting done @ end of USB mode */
463 #ifdef HAVE_USB_POWER
464 if (usb_powered()) /* avoid deadlock */
471 rc
= disk_mount_all();
475 lcd_puts(0, 0, "No partition");
476 lcd_puts(0, 1, "found.");
477 #ifdef HAVE_LCD_BITMAP
478 lcd_puts(0, 2, "Insert USB cable");
479 lcd_puts(0, 3, "and fix it.");
483 while(button_get(true) != SYS_USB_CONNECTED
) {};
489 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
490 (CONFIG_KEYPAD == IRIVER_H10_PAD)
491 #ifdef SETTINGS_RESET
492 /* Reset settings if holding the reset button. (Rec on Archos,
494 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
496 /* Reset settings if the hold button is turned on */
500 gui_syncsplash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
505 settings_load(SETTINGS_ALL
);
507 if (init_dircache(true) < 0)
510 remove(TAGCACHE_STATEFILE
);
516 init_dircache(false);
521 #ifdef HAVE_EEPROM_SETTINGS
522 if (firmware_settings
.initialized
)
524 /* In case we crash. */
525 firmware_settings
.disk_clean
= false;
526 eeprom_settings_store();
536 #if CONFIG_CODEC != SWCODEC
537 /* No buffer allocation (see buffer.c) may take place after the call to
538 audio_init() since the mpeg thread takes the rest of the buffer space */
539 mp3_init( global_settings
.volume
,
540 global_settings
.bass
,
541 global_settings
.treble
,
542 global_settings
.balance
,
543 global_settings
.loudness
,
545 global_settings
.channel_config
,
546 global_settings
.stereo_width
,
547 global_settings
.mdb_strength
,
548 global_settings
.mdb_harmonics
,
549 global_settings
.mdb_center
,
550 global_settings
.mdb_shape
,
551 global_settings
.mdb_enable
,
552 global_settings
.superbass
);
554 /* audio_init must to know the size of voice buffer so init voice first */
556 #endif /* CONFIG_CODEC != SWCODEC */
560 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
564 /* runtime database has to be initialized after audio_init() */
570 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
572 fd
= open(filename
, O_RDONLY
);
573 if(fd
>= 0) /* no complaint if it doesn't exist */
576 plugin_load((char*)filename
, NULL
); /* start if it does */
579 #endif /* #ifdef AUTOROCK */
582 car_adapter_mode_init();
589 /* This is the entry point for the coprocessor
590 Anyone not running an upgraded bootloader will never reach this point,
591 so it should not be assumed that the coprocessor be usable even on
592 platforms which support it.
594 A kernel thread runs on the coprocessor which waits for other threads to be
595 added, and gracefully handles RoLo */
597 #if CONFIG_CPU == PP5002
598 /* 3G doesn't have Rolo or dual core support yet */
600 COP_CTL
= PROC_SLEEP
;
603 extern volatile unsigned char cpu_message
;
608 while(cpu_message
!= COP_REBOOT
) {
621 #if (CONFIG_LED == LED_REAL)
622 led(true); sleep(HZ
/10);
623 led(false); sleep(HZ
/10);