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"
117 #include "system-sdl.h"
120 /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */
122 const char appsversion
[]=APPSVERSION
;
124 static void init(void);
129 static void app_main(void)
137 static int init_dircache(bool preinit
)
146 if (!global_settings
.dircache
)
149 # ifdef HAVE_EEPROM_SETTINGS
150 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
153 result
= dircache_load();
157 firmware_settings
.disk_clean
= false;
158 if (global_status
.dircache_size
<= 0)
160 /* This will be in default language, settings are not
161 applied yet. Not really any easy way to fix that. */
162 gui_syncsplash(0, str(LANG_SCANNING_DISK
));
166 dircache_build(global_status
.dircache_size
);
175 if (!dircache_is_enabled()
176 && !dircache_is_initializing())
178 if (global_status
.dircache_size
<= 0)
180 gui_syncsplash(0, str(LANG_SCANNING_DISK
));
183 result
= dircache_build(global_status
.dircache_size
);
188 /* Initialization of dircache failed. Manual action is
189 * necessary to enable dircache again.
191 gui_syncsplash(0, "Dircache failed, disabled. Result: %d", result
);
192 global_settings
.dircache
= false;
201 global_status
.dircache_size
= dircache_get_cache_size();
213 static void init_tagcache(void)
219 while (!tagcache_is_initialized())
221 #ifdef HAVE_LCD_CHARCELLS
224 int ret
= tagcache_get_commit_step();
228 #if CONFIG_CODEC == SWCODEC
229 /* hwcodec can't use voice here, as the database commit
230 * uses the audio buffer. */
231 static long talked_tick
= 0;
232 if(global_settings
.talk_menu
234 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
236 talked_tick
= current_tick
;
237 talk_id(LANG_TAGCACHE_INIT
, false);
238 talk_number(ret
, true);
239 talk_id(VOICE_OF
, true);
240 talk_number(tagcache_get_max_commit_step(), true);
243 #ifdef HAVE_LCD_BITMAP
244 gui_syncsplash(0, "%s [%d/%d]",
245 str(LANG_TAGCACHE_INIT
), ret
,
246 tagcache_get_max_commit_step());
248 lcd_double_height(false);
249 snprintf(buf
, sizeof(buf
), " DB [%d/%d]", ret
,
250 tagcache_get_max_commit_step());
270 static void init(void)
276 #ifdef HAVE_REMOTE_LCD
287 /* Must be done before any code uses the multi-screen APi */
288 screen_access_init();
289 gui_syncstatusbar_init(&statusbars
);
292 settings_load(SETTINGS_ALL
);
296 init_dircache(false);
305 #if CONFIG_CODEC != SWCODEC
306 mp3_init( global_settings
.volume
,
307 global_settings
.bass
,
308 global_settings
.treble
,
309 global_settings
.balance
,
310 global_settings
.loudness
,
312 global_settings
.channel_config
,
313 global_settings
.stereo_width
,
314 global_settings
.mdb_strength
,
315 global_settings
.mdb_harmonics
,
316 global_settings
.mdb_center
,
317 global_settings
.mdb_shape
,
318 global_settings
.mdb_enable
,
319 global_settings
.superbass
);
321 /* audio_init must to know the size of voice buffer so init voice first */
323 #endif /* CONFIG_CODEC != SWCODEC */
329 button_clear_queue(); /* Empty the keyboard buffer */
334 static void init(void)
337 bool mounted
= false;
338 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
339 /* if nobody initialized ATA before, I consider this a cold start */
340 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
346 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
347 set_cpu_frequency(CPUFREQ_NORMAL
);
349 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
362 set_fiq_status(FIQ_ENABLED
);
365 #ifdef HAVE_REMOTE_LCD
376 #if !defined(HAVE_FMADC) && !defined(HAVE_MMC)
387 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
396 #if CONFIG_USBOTG == USBOTG_ISP1362
398 #elif CONFIG_USBOTG == USBOTG_M5636
412 /* Must be done before any code uses the multi-screen APi */
413 screen_access_init();
414 gui_syncstatusbar_init(&statusbars
);
416 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
417 if (coldstart
&& charger_inserted()
418 && !global_settings
.car_adapter_mode
419 #ifdef ATA_POWER_PLAYERSTYLE
420 && !ide_powered() /* relies on probing result from bootloader */
424 rc
= charging_screen(); /* display a "charging" screen */
425 if (rc
== 1) /* charger removed */
427 /* "On" pressed or USB connected: proceed */
428 show_logo(); /* again, to provide better visual feedback */
432 ata_idle_notify_init();
436 #ifdef HAVE_LCD_BITMAP
439 snprintf(str
, 31, "ATA error: %d", rc
);
441 lcd_puts(0, 3, "Press ON to debug");
443 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
446 panicf("ata: %d", rc
);
449 #ifdef HAVE_EEPROM_SETTINGS
450 eeprom_settings_init();
453 usb_start_monitoring();
454 while (usb_detect() == USB_INSERTED
)
456 #ifdef HAVE_EEPROM_SETTINGS
457 firmware_settings
.disk_clean
= false;
459 /* enter USB mode early, before trying to mount */
460 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
462 if (!mmc_touched() ||
463 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
467 mounted
= true; /* mounting done @ end of USB mode */
469 #ifdef HAVE_USB_POWER
470 if (usb_powered()) /* avoid deadlock */
477 rc
= disk_mount_all();
481 lcd_puts(0, 0, "No partition");
482 lcd_puts(0, 1, "found.");
483 #ifdef HAVE_LCD_BITMAP
484 lcd_puts(0, 2, "Insert USB cable");
485 lcd_puts(0, 3, "and fix it.");
489 while(button_get(true) != SYS_USB_CONNECTED
) {};
495 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
496 (CONFIG_KEYPAD == IRIVER_H10_PAD)
497 #ifdef SETTINGS_RESET
498 /* Reset settings if holding the reset button. (Rec on Archos,
500 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
502 /* Reset settings if the hold button is turned on */
506 gui_syncsplash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
511 settings_load(SETTINGS_ALL
);
513 if (init_dircache(true) < 0)
516 remove(TAGCACHE_STATEFILE
);
522 init_dircache(false);
527 #ifdef HAVE_EEPROM_SETTINGS
528 if (firmware_settings
.initialized
)
530 /* In case we crash. */
531 firmware_settings
.disk_clean
= false;
532 eeprom_settings_store();
542 #if CONFIG_CODEC != SWCODEC
543 /* No buffer allocation (see buffer.c) may take place after the call to
544 audio_init() since the mpeg thread takes the rest of the buffer space */
545 mp3_init( global_settings
.volume
,
546 global_settings
.bass
,
547 global_settings
.treble
,
548 global_settings
.balance
,
549 global_settings
.loudness
,
551 global_settings
.channel_config
,
552 global_settings
.stereo_width
,
553 global_settings
.mdb_strength
,
554 global_settings
.mdb_harmonics
,
555 global_settings
.mdb_center
,
556 global_settings
.mdb_shape
,
557 global_settings
.mdb_enable
,
558 global_settings
.superbass
);
560 /* audio_init must to know the size of voice buffer so init voice first */
562 #endif /* CONFIG_CODEC != SWCODEC */
566 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
570 /* runtime database has to be initialized after audio_init() */
576 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
578 fd
= open(filename
, O_RDONLY
);
579 if(fd
>= 0) /* no complaint if it doesn't exist */
582 plugin_load((char*)filename
, NULL
); /* start if it does */
585 #endif /* #ifdef AUTOROCK */
588 car_adapter_mode_init();
595 /* This is the entry point for the coprocessor
596 Anyone not running an upgraded bootloader will never reach this point,
597 so it should not be assumed that the coprocessor be usable even on
598 platforms which support it.
600 A kernel thread is initially setup on the coprocessor and immediately
601 destroyed for purposes of continuity. The cop sits idle until at least
602 one thread exists on it. */
604 /* 3G doesn't have Rolo or dual core support yet */
608 /* This should never be reached */
611 COP_CTL
= PROC_SLEEP
;
621 #if (CONFIG_LED == LED_REAL)
622 led(true); sleep(HZ
/10);
623 led(false); sleep(HZ
/10);