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"
113 #include "system-sdl.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)
132 screens
[i
].clear_display();
139 static int init_dircache(bool preinit
)
148 if (!global_settings
.dircache
)
151 # ifdef HAVE_EEPROM_SETTINGS
152 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
155 result
= dircache_load();
159 firmware_settings
.disk_clean
= false;
160 if (global_status
.dircache_size
<= 0)
162 /* This will be in default language, settings are not
163 applied yet. Not really any easy way to fix that. */
164 gui_syncsplash(0, str(LANG_SCANNING_DISK
));
168 dircache_build(global_status
.dircache_size
);
177 if (!dircache_is_enabled()
178 && !dircache_is_initializing())
180 if (global_status
.dircache_size
<= 0)
182 gui_syncsplash(0, str(LANG_SCANNING_DISK
));
185 result
= dircache_build(global_status
.dircache_size
);
190 /* Initialization of dircache failed. Manual action is
191 * necessary to enable dircache again.
193 gui_syncsplash(0, "Dircache failed, disabled. Result: %d", result
);
194 global_settings
.dircache
= false;
203 global_status
.dircache_size
= dircache_get_cache_size();
215 static void init_tagcache(void)
221 while (!tagcache_is_initialized())
223 #ifdef HAVE_LCD_CHARCELLS
226 int ret
= tagcache_get_commit_step();
230 #if CONFIG_CODEC == SWCODEC
231 /* hwcodec can't use voice here, as the database commit
232 * uses the audio buffer. */
233 static long talked_tick
= 0;
234 if(global_settings
.talk_menu
236 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
238 talked_tick
= current_tick
;
239 talk_id(LANG_TAGCACHE_INIT
, false);
240 talk_number(ret
, true);
241 talk_id(VOICE_OF
, true);
242 talk_number(tagcache_get_max_commit_step(), true);
245 #ifdef HAVE_LCD_BITMAP
246 gui_syncsplash(0, "%s [%d/%d]",
247 str(LANG_TAGCACHE_INIT
), ret
,
248 tagcache_get_max_commit_step());
250 lcd_double_height(false);
251 snprintf(buf
, sizeof(buf
), " DB [%d/%d]", ret
,
252 tagcache_get_max_commit_step());
272 static void init(void)
278 #ifdef HAVE_REMOTE_LCD
289 /* Must be done before any code uses the multi-screen APi */
290 screen_access_init();
291 gui_syncstatusbar_init(&statusbars
);
294 settings_load(SETTINGS_ALL
);
298 init_dircache(false);
307 #if CONFIG_CODEC != SWCODEC
308 mp3_init( global_settings
.volume
,
309 global_settings
.bass
,
310 global_settings
.treble
,
311 global_settings
.balance
,
312 global_settings
.loudness
,
314 global_settings
.channel_config
,
315 global_settings
.stereo_width
,
316 global_settings
.mdb_strength
,
317 global_settings
.mdb_harmonics
,
318 global_settings
.mdb_center
,
319 global_settings
.mdb_shape
,
320 global_settings
.mdb_enable
,
321 global_settings
.superbass
);
323 /* audio_init must to know the size of voice buffer so init voice first */
325 #endif /* CONFIG_CODEC != SWCODEC */
331 button_clear_queue(); /* Empty the keyboard buffer */
336 static void init(void)
339 bool mounted
= false;
340 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
341 /* if nobody initialized ATA before, I consider this a cold start */
342 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
348 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
349 set_cpu_frequency(CPUFREQ_NORMAL
);
351 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
366 set_fiq_status(FIQ_ENABLED
);
369 #ifdef HAVE_REMOTE_LCD
380 #if !defined(HAVE_FMADC) && !defined(HAVE_MMC)
389 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
395 #if CONFIG_USBOTG == USBOTG_ISP1362
397 #elif CONFIG_USBOTG == USBOTG_M5636
411 /* Must be done before any code uses the multi-screen APi */
412 screen_access_init();
413 gui_syncstatusbar_init(&statusbars
);
415 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
416 if (coldstart
&& charger_inserted()
417 && !global_settings
.car_adapter_mode
418 #ifdef ATA_POWER_PLAYERSTYLE
419 && !ide_powered() /* relies on probing result from bootloader */
423 rc
= charging_screen(); /* display a "charging" screen */
424 if (rc
== 1) /* charger removed */
426 /* "On" pressed or USB connected: proceed */
427 show_logo(); /* again, to provide better visual feedback */
431 ata_idle_notify_init();
435 #ifdef HAVE_LCD_BITMAP
438 snprintf(str
, 31, "ATA error: %d", rc
);
440 lcd_puts(0, 3, "Press ON to debug");
442 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
445 panicf("ata: %d", rc
);
448 #ifdef HAVE_EEPROM_SETTINGS
449 eeprom_settings_init();
452 usb_start_monitoring();
453 while (usb_detect() == USB_INSERTED
)
455 #ifdef HAVE_EEPROM_SETTINGS
456 firmware_settings
.disk_clean
= false;
458 /* enter USB mode early, before trying to mount */
459 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
461 if (!mmc_touched() ||
462 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
466 #ifndef HAVE_USBSTACK
467 mounted
= true; /* mounting done @ end of USB mode */
470 #ifdef HAVE_USB_POWER
471 if (usb_powered()) /* avoid deadlock */
478 rc
= disk_mount_all();
482 lcd_puts(0, 0, "No partition");
483 lcd_puts(0, 1, "found.");
484 #ifdef HAVE_LCD_BITMAP
485 lcd_puts(0, 2, "Insert USB cable");
486 lcd_puts(0, 3, "and fix it.");
490 while(button_get(true) != SYS_USB_CONNECTED
) {};
496 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
497 (CONFIG_KEYPAD == IRIVER_H10_PAD)
498 #ifdef SETTINGS_RESET
499 /* Reset settings if holding the reset button. (Rec on Archos,
501 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
503 /* Reset settings if the hold button is turned on */
507 gui_syncsplash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
512 settings_load(SETTINGS_ALL
);
514 if (init_dircache(true) < 0)
517 remove(TAGCACHE_STATEFILE
);
523 init_dircache(false);
528 #ifdef HAVE_EEPROM_SETTINGS
529 if (firmware_settings
.initialized
)
531 /* In case we crash. */
532 firmware_settings
.disk_clean
= false;
533 eeprom_settings_store();
543 #if CONFIG_CODEC != SWCODEC
544 /* No buffer allocation (see buffer.c) may take place after the call to
545 audio_init() since the mpeg thread takes the rest of the buffer space */
546 mp3_init( global_settings
.volume
,
547 global_settings
.bass
,
548 global_settings
.treble
,
549 global_settings
.balance
,
550 global_settings
.loudness
,
552 global_settings
.channel_config
,
553 global_settings
.stereo_width
,
554 global_settings
.mdb_strength
,
555 global_settings
.mdb_harmonics
,
556 global_settings
.mdb_center
,
557 global_settings
.mdb_shape
,
558 global_settings
.mdb_enable
,
559 global_settings
.superbass
);
561 /* audio_init must to know the size of voice buffer so init voice first */
563 #endif /* CONFIG_CODEC != SWCODEC */
567 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
571 /* runtime database has to be initialized after audio_init() */
577 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
579 fd
= open(filename
, O_RDONLY
);
580 if(fd
>= 0) /* no complaint if it doesn't exist */
583 plugin_load((char*)filename
, NULL
); /* start if it does */
586 #endif /* #ifdef AUTOROCK */
589 car_adapter_mode_init();
596 /* This is the entry point for the coprocessor
597 Anyone not running an upgraded bootloader will never reach this point,
598 so it should not be assumed that the coprocessor be usable even on
599 platforms which support it.
601 A kernel thread is initially setup on the coprocessor and immediately
602 destroyed for purposes of continuity. The cop sits idle until at least
603 one thread exists on it. */
605 /* 3G doesn't have Rolo or dual core support yet */
609 /* This should never be reached */
612 COP_CTL
= PROC_SLEEP
;
622 #if (CONFIG_LED == LED_REAL)
623 led(true); sleep(HZ
/10);
624 led(false); sleep(HZ
/10);