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"
74 #if (CONFIG_CODEC == SWCODEC)
80 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
81 #include "pcm_record.h"
85 #define SETTINGS_RESET BUTTON_REC
95 #ifdef HAVE_REMOTE_LCD
96 #include "lcd-remote.h"
99 #if CONFIG_USBOTG == USBOTG_ISP1362
103 #if CONFIG_USBOTG == USBOTG_M5636
107 #include "cuesheet.h"
109 /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */
111 const char appsversion
[]=APPSVERSION
;
113 static void init(void);
118 static void app_main(void)
125 static int init_dircache(bool preinit
)
134 if (!global_settings
.dircache
)
137 # ifdef HAVE_EEPROM_SETTINGS
138 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
141 result
= dircache_load();
145 firmware_settings
.disk_clean
= false;
146 if (global_status
.dircache_size
<= 0)
148 /* This will be in default language, settings are not
149 applied yet. Not really any easy way to fix that. */
150 gui_syncsplash(0, str(LANG_DIRCACHE_BUILDING
));
154 dircache_build(global_status
.dircache_size
);
163 if (!dircache_is_enabled()
164 && !dircache_is_initializing())
166 if (global_status
.dircache_size
<= 0)
168 gui_syncsplash(0, str(LANG_DIRCACHE_BUILDING
));
171 result
= dircache_build(global_status
.dircache_size
);
175 gui_syncsplash(0, "Failed! Result: %d", result
);
182 global_status
.dircache_size
= dircache_get_cache_size();
194 static void init_tagcache(void)
200 while (!tagcache_is_initialized())
202 #ifdef HAVE_LCD_CHARCELLS
205 int ret
= tagcache_get_commit_step();
209 #ifdef HAVE_LCD_BITMAP
210 gui_syncsplash(0, "%s [%d/%d]",
211 str(LANG_TAGCACHE_INIT
), ret
,
212 tagcache_get_max_commit_step());
214 lcd_double_height(false);
215 snprintf(buf
, sizeof(buf
), " TC [%d/%d]", ret
,
216 tagcache_get_max_commit_step());
235 static void init(void)
240 #ifdef HAVE_REMOTE_LCD
248 /* Must be done before any code uses the multi-screen APi */
249 screen_access_init();
250 gui_syncstatusbar_init(&statusbars
);
252 settings_load(SETTINGS_ALL
);
256 init_dircache(false);
265 #if CONFIG_CODEC != SWCODEC
266 mp3_init( global_settings
.volume
,
267 global_settings
.bass
,
268 global_settings
.treble
,
269 global_settings
.balance
,
270 global_settings
.loudness
,
272 global_settings
.channel_config
,
273 global_settings
.stereo_width
,
274 global_settings
.mdb_strength
,
275 global_settings
.mdb_harmonics
,
276 global_settings
.mdb_center
,
277 global_settings
.mdb_shape
,
278 global_settings
.mdb_enable
,
279 global_settings
.superbass
);
281 /* audio_init must to know the size of voice buffer so init voice first */
283 #endif /* CONFIG_CODEC != SWCODEC */
289 button_clear_queue(); /* Empty the keyboard buffer */
294 static void init(void)
297 bool mounted
= false;
298 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
299 /* if nobody initialized ATA before, I consider this a cold start */
300 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
308 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
309 set_cpu_frequency(CPUFREQ_NORMAL
);
311 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
324 #ifdef HAVE_REMOTE_LCD
329 #if !defined(TOSHIBA_GIGABEAT_F) || defined(SIMULATOR)
332 sleep(1); /* Weird. We crash w/o this tiny delay. */
339 #if !defined(HAVE_FMADC) && !defined(HAVE_MMC)
350 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
356 #if CONFIG_USBOTG == USBOTG_ISP1362
358 #elif CONFIG_USBOTG == USBOTG_M5636
372 /* Must be done before any code uses the multi-screen APi */
373 screen_access_init();
374 gui_syncstatusbar_init(&statusbars
);
376 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
377 if (coldstart
&& charger_inserted()
378 && !global_settings
.car_adapter_mode
379 #ifdef ATA_POWER_PLAYERSTYLE
380 && !ide_powered() /* relies on probing result from bootloader */
384 rc
= charging_screen(); /* display a "charging" screen */
385 if (rc
== 1) /* charger removed */
387 /* "On" pressed or USB connected: proceed */
388 show_logo(); /* again, to provide better visual feedback */
392 ata_idle_notify_init();
396 #ifdef HAVE_LCD_BITMAP
399 snprintf(str
, 31, "ATA error: %d", rc
);
401 lcd_puts(0, 3, "Press ON to debug");
403 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
406 panicf("ata: %d", rc
);
409 #ifdef HAVE_EEPROM_SETTINGS
410 eeprom_settings_init();
413 usb_start_monitoring();
416 #ifdef HAVE_EEPROM_SETTINGS
417 firmware_settings
.disk_clean
= false;
419 /* enter USB mode early, before trying to mount */
420 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
422 if (!mmc_touched() || (mmc_remove_request() == SYS_MMC_EXTRACTED
))
426 mounted
= true; /* mounting done @ end of USB mode */
428 #ifdef HAVE_USB_POWER
429 if (usb_powered()) /* avoid deadlock */
436 rc
= disk_mount_all();
440 lcd_puts(0, 0, "No partition");
441 lcd_puts(0, 1, "found.");
442 #ifdef HAVE_LCD_BITMAP
443 lcd_puts(0, 2, "Insert USB cable");
444 lcd_puts(0, 3, "and fix it.");
447 while(button_get(true) != SYS_USB_CONNECTED
) {};
453 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
454 (CONFIG_KEYPAD == IRIVER_H10_PAD) || (CONFIG_KEYPAD == GIGABEAT_PAD)
455 #ifdef SETTINGS_RESET
456 /* Reset settings if holding the rec button. */
457 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
459 /* Reset settings if the hold button is turned on */
463 gui_syncsplash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
468 settings_load(SETTINGS_ALL
);
470 if (init_dircache(true) < 0)
473 remove(TAGCACHE_STATEFILE
);
479 init_dircache(false);
484 #ifdef HAVE_EEPROM_SETTINGS
485 if (firmware_settings
.initialized
)
487 /* In case we crash. */
488 firmware_settings
.disk_clean
= false;
489 eeprom_settings_store();
499 #if CONFIG_CODEC != SWCODEC
500 /* No buffer allocation (see buffer.c) may take place after the call to
501 audio_init() since the mpeg thread takes the rest of the buffer space */
502 mp3_init( global_settings
.volume
,
503 global_settings
.bass
,
504 global_settings
.treble
,
505 global_settings
.balance
,
506 global_settings
.loudness
,
508 global_settings
.channel_config
,
509 global_settings
.stereo_width
,
510 global_settings
.mdb_strength
,
511 global_settings
.mdb_harmonics
,
512 global_settings
.mdb_center
,
513 global_settings
.mdb_shape
,
514 global_settings
.mdb_enable
,
515 global_settings
.superbass
);
517 /* audio_init must to know the size of voice buffer so init voice first */
519 #endif /* CONFIG_CODEC != SWCODEC */
523 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
527 /* runtime database has to be initialized after audio_init() */
533 static const char filename
[] = PLUGIN_DIR
"/autostart.rock";
535 fd
= open(filename
, O_RDONLY
);
536 if(fd
>= 0) /* no complaint if it doesn't exist */
539 plugin_load((char*)filename
, NULL
); /* start if it does */
542 #endif /* #ifdef AUTOROCK */
545 car_adapter_mode_init();
552 /* This is the entry point for the coprocessor
553 Anyone not running an upgraded bootloader will never reach this point,
554 so it should not be assumed that the coprocessor be usable even on
555 platforms which support it.
557 A kernel thread runs on the coprocessor which waits for other threads to be
558 added, and gracefully handles RoLo */
560 #if CONFIG_CPU == PP5002
561 /* 3G doesn't have Rolo or dual core support yet */
563 COP_CTL
= PROC_SLEEP
;
566 extern volatile unsigned char cpu_message
;
571 while(cpu_message
!= COP_REBOOT
) {
584 #if (CONFIG_LED == LED_REAL)
585 led(true); sleep(HZ
/10);
586 led(false); sleep(HZ
/10);