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(global_settings
.talk_menu
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 */
341 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
342 set_cpu_frequency(CPUFREQ_NORMAL
);
344 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
357 set_fiq_status(FIQ_ENABLED
);
360 #ifdef HAVE_REMOTE_LCD
371 #if !defined(HAVE_FMADC) && !defined(HAVE_MMC)
382 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
391 #if CONFIG_USBOTG == USBOTG_ISP1362
393 #elif CONFIG_USBOTG == USBOTG_M5636
407 /* Must be done before any code uses the multi-screen APi */
408 screen_access_init();
409 gui_syncstatusbar_init(&statusbars
);
411 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
412 if (coldstart
&& charger_inserted()
413 && !global_settings
.car_adapter_mode
414 #ifdef ATA_POWER_PLAYERSTYLE
415 && !ide_powered() /* relies on probing result from bootloader */
419 rc
= charging_screen(); /* display a "charging" screen */
420 if (rc
== 1) /* charger removed */
422 /* "On" pressed or USB connected: proceed */
423 show_logo(); /* again, to provide better visual feedback */
427 ata_idle_notify_init();
431 #ifdef HAVE_LCD_BITMAP
434 snprintf(str
, 31, "ATA error: %d", rc
);
436 lcd_puts(0, 3, "Press ON to debug");
438 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
441 panicf("ata: %d", rc
);
444 #ifdef HAVE_EEPROM_SETTINGS
445 eeprom_settings_init();
448 usb_start_monitoring();
449 while (usb_detect() == USB_INSERTED
)
451 #ifdef HAVE_EEPROM_SETTINGS
452 firmware_settings
.disk_clean
= false;
454 /* enter USB mode early, before trying to mount */
455 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
457 if (!mmc_touched() ||
458 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
462 mounted
= true; /* mounting done @ end of USB mode */
464 #ifdef HAVE_USB_POWER
465 if (usb_powered()) /* avoid deadlock */
472 rc
= disk_mount_all();
476 lcd_puts(0, 0, "No partition");
477 lcd_puts(0, 1, "found.");
478 #ifdef HAVE_LCD_BITMAP
479 lcd_puts(0, 2, "Insert USB cable");
480 lcd_puts(0, 3, "and fix it.");
484 while(button_get(true) != SYS_USB_CONNECTED
) {};
490 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
491 (CONFIG_KEYPAD == IRIVER_H10_PAD)
492 #ifdef SETTINGS_RESET
493 /* Reset settings if holding the reset button. (Rec on Archos,
495 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
497 /* Reset settings if the hold button is turned on */
501 gui_syncsplash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
506 settings_load(SETTINGS_ALL
);
508 if (init_dircache(true) < 0)
511 remove(TAGCACHE_STATEFILE
);
517 init_dircache(false);
522 #ifdef HAVE_EEPROM_SETTINGS
523 if (firmware_settings
.initialized
)
525 /* In case we crash. */
526 firmware_settings
.disk_clean
= false;
527 eeprom_settings_store();
537 #if CONFIG_CODEC != SWCODEC
538 /* No buffer allocation (see buffer.c) may take place after the call to
539 audio_init() since the mpeg thread takes the rest of the buffer space */
540 mp3_init( global_settings
.volume
,
541 global_settings
.bass
,
542 global_settings
.treble
,
543 global_settings
.balance
,
544 global_settings
.loudness
,
546 global_settings
.channel_config
,
547 global_settings
.stereo_width
,
548 global_settings
.mdb_strength
,
549 global_settings
.mdb_harmonics
,
550 global_settings
.mdb_center
,
551 global_settings
.mdb_shape
,
552 global_settings
.mdb_enable
,
553 global_settings
.superbass
);
555 /* audio_init must to know the size of voice buffer so init voice first */
557 #endif /* CONFIG_CODEC != SWCODEC */
561 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
565 /* runtime database has to be initialized after audio_init() */
571 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
573 fd
= open(filename
, O_RDONLY
);
574 if(fd
>= 0) /* no complaint if it doesn't exist */
577 plugin_load((char*)filename
, NULL
); /* start if it does */
580 #endif /* #ifdef AUTOROCK */
583 car_adapter_mode_init();
590 /* This is the entry point for the coprocessor
591 Anyone not running an upgraded bootloader will never reach this point,
592 so it should not be assumed that the coprocessor be usable even on
593 platforms which support it.
595 A kernel thread is initially setup on the coprocessor and immediately
596 destroyed for purposes of continuity. The cop sits idle until at least
597 one thread exists on it. */
599 /* 3G doesn't have Rolo or dual core support yet */
603 /* This should never be reached */
606 COP_CTL
= PROC_SLEEP
;
616 #if (CONFIG_LED == LED_REAL)
617 led(true); sleep(HZ
/10);
618 led(false); sleep(HZ
/10);