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)
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)
272 #ifdef HAVE_REMOTE_LCD
283 /* Must be done before any code uses the multi-screen APi */
284 screen_access_init();
285 gui_syncstatusbar_init(&statusbars
);
288 settings_load(SETTINGS_ALL
);
292 init_dircache(false);
301 #if CONFIG_CODEC != SWCODEC
302 mp3_init( global_settings
.volume
,
303 global_settings
.bass
,
304 global_settings
.treble
,
305 global_settings
.balance
,
306 global_settings
.loudness
,
308 global_settings
.channel_config
,
309 global_settings
.stereo_width
,
310 global_settings
.mdb_strength
,
311 global_settings
.mdb_harmonics
,
312 global_settings
.mdb_center
,
313 global_settings
.mdb_shape
,
314 global_settings
.mdb_enable
,
315 global_settings
.superbass
);
317 /* audio_init must to know the size of voice buffer so init voice first */
319 #endif /* CONFIG_CODEC != SWCODEC */
325 button_clear_queue(); /* Empty the keyboard buffer */
330 static void init(void)
333 bool mounted
= false;
334 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
335 /* if nobody initialized ATA before, I consider this a cold start */
336 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
342 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
343 set_cpu_frequency(CPUFREQ_NORMAL
);
345 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
358 set_fiq_status(FIQ_ENABLED
);
361 #ifdef HAVE_REMOTE_LCD
372 #if !defined(HAVE_FMADC) && !defined(HAVE_MMC)
383 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
389 #if CONFIG_USBOTG == USBOTG_ISP1362
391 #elif CONFIG_USBOTG == USBOTG_M5636
405 /* Must be done before any code uses the multi-screen APi */
406 screen_access_init();
407 gui_syncstatusbar_init(&statusbars
);
409 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
410 if (coldstart
&& charger_inserted()
411 && !global_settings
.car_adapter_mode
412 #ifdef ATA_POWER_PLAYERSTYLE
413 && !ide_powered() /* relies on probing result from bootloader */
417 rc
= charging_screen(); /* display a "charging" screen */
418 if (rc
== 1) /* charger removed */
420 /* "On" pressed or USB connected: proceed */
421 show_logo(); /* again, to provide better visual feedback */
425 ata_idle_notify_init();
429 #ifdef HAVE_LCD_BITMAP
432 snprintf(str
, 31, "ATA error: %d", rc
);
434 lcd_puts(0, 3, "Press ON to debug");
436 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
439 panicf("ata: %d", rc
);
442 #ifdef HAVE_EEPROM_SETTINGS
443 eeprom_settings_init();
446 usb_start_monitoring();
447 while (usb_detect() == USB_INSERTED
)
449 #ifdef HAVE_EEPROM_SETTINGS
450 firmware_settings
.disk_clean
= false;
452 /* enter USB mode early, before trying to mount */
453 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
455 if (!mmc_touched() ||
456 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
460 mounted
= true; /* mounting done @ end of USB mode */
462 #ifdef HAVE_USB_POWER
463 if (usb_powered()) /* avoid deadlock */
470 rc
= disk_mount_all();
474 lcd_puts(0, 0, "No partition");
475 lcd_puts(0, 1, "found.");
476 #ifdef HAVE_LCD_BITMAP
477 lcd_puts(0, 2, "Insert USB cable");
478 lcd_puts(0, 3, "and fix it.");
482 while(button_get(true) != SYS_USB_CONNECTED
) {};
488 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
489 (CONFIG_KEYPAD == IRIVER_H10_PAD)
490 #ifdef SETTINGS_RESET
491 /* Reset settings if holding the reset button. (Rec on Archos,
493 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
495 /* Reset settings if the hold button is turned on */
499 gui_syncsplash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
504 settings_load(SETTINGS_ALL
);
506 if (init_dircache(true) < 0)
509 remove(TAGCACHE_STATEFILE
);
515 init_dircache(false);
520 #ifdef HAVE_EEPROM_SETTINGS
521 if (firmware_settings
.initialized
)
523 /* In case we crash. */
524 firmware_settings
.disk_clean
= false;
525 eeprom_settings_store();
535 #if CONFIG_CODEC != SWCODEC
536 /* No buffer allocation (see buffer.c) may take place after the call to
537 audio_init() since the mpeg thread takes the rest of the buffer space */
538 mp3_init( global_settings
.volume
,
539 global_settings
.bass
,
540 global_settings
.treble
,
541 global_settings
.balance
,
542 global_settings
.loudness
,
544 global_settings
.channel_config
,
545 global_settings
.stereo_width
,
546 global_settings
.mdb_strength
,
547 global_settings
.mdb_harmonics
,
548 global_settings
.mdb_center
,
549 global_settings
.mdb_shape
,
550 global_settings
.mdb_enable
,
551 global_settings
.superbass
);
553 /* audio_init must to know the size of voice buffer so init voice first */
555 #endif /* CONFIG_CODEC != SWCODEC */
559 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
563 /* runtime database has to be initialized after audio_init() */
569 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
571 fd
= open(filename
, O_RDONLY
);
572 if(fd
>= 0) /* no complaint if it doesn't exist */
575 plugin_load((char*)filename
, NULL
); /* start if it does */
578 #endif /* #ifdef AUTOROCK */
581 car_adapter_mode_init();
588 /* This is the entry point for the coprocessor
589 Anyone not running an upgraded bootloader will never reach this point,
590 so it should not be assumed that the coprocessor be usable even on
591 platforms which support it.
593 A kernel thread is initially setup on the coprocessor and immediately
594 destroyed for purposes of continuity. The cop sits idle until at least
595 one thread exists on it. */
597 /* 3G doesn't have Rolo or dual core support yet */
601 /* This should never be reached */
604 COP_CTL
= PROC_SLEEP
;
614 #if (CONFIG_LED == LED_REAL)
615 led(true); sleep(HZ
/10);
616 led(false); sleep(HZ
/10);