1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Björn Stenberg
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
23 #include "gcc_extensions.h"
34 #include "filetypes.h"
39 #include "powermgmt.h"
46 #include "mp3_playback.h"
49 #include "backlight.h"
51 #include "debug_menu.h"
56 #include "core_alloc.h"
59 #include "usb_screen.h"
72 #include "eeprom_settings.h"
73 #include "scrobbler.h"
76 #include "skin_engine/skin_engine.h"
77 #include "statusbar-skinned.h"
78 #include "bootchart.h"
79 #if (CONFIG_PLATFORM & PLATFORM_ANDROID)
80 #include "notification.h"
83 #ifdef IPOD_ACCESSORY_PROTOCOL
87 #if (CONFIG_CODEC == SWCODEC)
91 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
92 #include "pcm_record.h"
96 #define SETTINGS_RESET BUTTON_REC
97 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
98 #define SETTINGS_RESET BUTTON_A
104 #if (CONFIG_STORAGE & STORAGE_MMC)
108 #ifdef HAVE_REMOTE_LCD
109 #include "lcd-remote.h"
112 #if CONFIG_USBOTG == USBOTG_ISP1362
116 #if CONFIG_USBOTG == USBOTG_M5636
120 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
121 #define MAIN_NORETURN_ATTR NORETURN_ATTR
123 /* gcc adds an implicit 'return 0;' at the end of main(), causing a warning
124 * with noreturn attribute */
125 #define MAIN_NORETURN_ATTR
128 #if (CONFIG_PLATFORM & (PLATFORM_SDL|PLATFORM_MAEMO|PLATFORM_PANDORA))
129 #include "sim_tasks.h"
130 #include "system-sdl.h"
131 #define HAVE_ARGV_MAIN
132 /* Don't use SDL_main on windows -> no more stdio redirection */
138 /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */
140 static void init(void);
141 /* main(), and various functions called by main() and init() may be
142 * be INIT_ATTR. These functions must not be called after the final call
143 * to root_menu() at the end of main()
144 * see definition of INIT_ATTR in config.h */
145 #ifdef HAVE_ARGV_MAIN
146 int main(int argc
, char *argv
[]) INIT_ATTR MAIN_NORETURN_ATTR
;
147 int main(int argc
, char *argv
[])
149 sys_handle_argv(argc
, argv
);
151 int main(void) INIT_ATTR MAIN_NORETURN_ATTR
;
160 screens
[i
].clear_display();
163 #ifdef HAVE_LCD_BITMAP
167 /* Keep the order of this 3
168 * Must be done before any code uses the multi-screen API */
170 /* All threads should be created and public queues registered by now */
171 usb_start_monitoring();
176 char filename
[MAX_PATH
];
184 if(file_exists(file
)) /* no complaint if it doesn't exist */
186 plugin_load(file
, NULL
); /* start if it does */
189 #endif /* #ifdef AUTOROCK */
191 global_status
.last_volume_change
= 0;
192 /* no calls INIT_ATTR functions after this point anymore!
193 * see definition of INIT_ATTR in config.h */
198 static int init_dircache(bool preinit
) INIT_ATTR
;
199 static int init_dircache(bool preinit
)
208 if (!global_settings
.dircache
)
211 # ifdef HAVE_EEPROM_SETTINGS
212 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
215 result
= dircache_load();
219 firmware_settings
.disk_clean
= false;
220 if (global_status
.dircache_size
<= 0)
222 /* This will be in default language, settings are not
223 applied yet. Not really any easy way to fix that. */
224 splash(0, str(LANG_SCANNING_DISK
));
228 dircache_build(global_status
.dircache_size
);
237 if (!dircache_is_enabled()
238 && !dircache_is_initializing())
240 if (global_status
.dircache_size
<= 0)
242 splash(0, str(LANG_SCANNING_DISK
));
245 result
= dircache_build(global_status
.dircache_size
);
250 /* Initialization of dircache failed. Manual action is
251 * necessary to enable dircache again.
253 splashf(0, "Dircache failed, disabled. Result: %d", result
);
254 global_settings
.dircache
= false;
262 global_status
.dircache_size
= dircache_get_cache_size();
274 static void init_tagcache(void) INIT_ATTR
;
275 static void init_tagcache(void)
278 #if CONFIG_CODEC == SWCODEC
279 long talked_tick
= 0;
283 while (!tagcache_is_initialized())
285 int ret
= tagcache_get_commit_step();
289 #if CONFIG_CODEC == SWCODEC
290 /* hwcodec can't use voice here, as the database commit
291 * uses the audio buffer. */
292 if(global_settings
.talk_menu
294 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
296 talked_tick
= current_tick
;
297 talk_id(LANG_TAGCACHE_INIT
, false);
298 talk_number(ret
, true);
299 talk_id(VOICE_OF
, true);
300 talk_number(tagcache_get_max_commit_step(), true);
303 #ifdef HAVE_LCD_BITMAP
306 splashf(0, "[%d/%d] %s", ret
, tagcache_get_max_commit_step(),
307 str(LANG_TAGCACHE_INIT
));
311 splashf(0, "%s [%d/%d]", str(LANG_TAGCACHE_INIT
), ret
,
312 tagcache_get_max_commit_step());
315 lcd_double_height(false);
316 lcd_putsf(0, 1, " DB [%d/%d]", ret
,
317 tagcache_get_max_commit_step());
334 #if (CONFIG_PLATFORM & PLATFORM_HOSTED)
336 static void init(void)
339 core_allocator_init();
346 #ifdef HAVE_REMOTE_LCD
349 #ifdef HAVE_LCD_BITMAP
351 global_status
.font_id
[i
] = FONT_SYSFIXED
;
358 #if (CONFIG_PLATFORM & (PLATFORM_SDL|PLATFORM_MAEMO|PLATFORM_PANDORA))
361 #if (CONFIG_PLATFORM & PLATFORM_ANDROID)
364 lang_init(core_language_builtin
, language_strings
,
365 LANG_LAST_INDEX_IN_ARRAY
);
369 /* Keep the order of this 3 (viewportmanager handles statusbars)
370 * Must be done before any code uses the multi-screen API */
371 gui_syncstatusbar_init(&statusbars
);
372 gui_sync_skin_init();
374 viewportmanager_init();
378 settings_load(SETTINGS_ALL
);
379 settings_apply(true);
381 init_dircache(false);
391 #if CONFIG_CODEC != SWCODEC
392 mp3_init( global_settings
.volume
,
393 global_settings
.bass
,
394 global_settings
.treble
,
395 global_settings
.balance
,
396 global_settings
.loudness
,
398 global_settings
.channel_config
,
399 global_settings
.stereo_width
,
400 global_settings
.mdb_strength
,
401 global_settings
.mdb_harmonics
,
402 global_settings
.mdb_center
,
403 global_settings
.mdb_shape
,
404 global_settings
.mdb_enable
,
405 global_settings
.superbass
);
406 #endif /* CONFIG_CODEC != SWCODEC */
412 settings_apply_skins();
417 static void init(void) INIT_ATTR
;
418 static void init(void)
421 bool mounted
= false;
422 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
423 /* if nobody initialized ATA before, I consider this a cold start */
424 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
428 core_allocator_init();
431 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
432 set_cpu_frequency(CPUFREQ_NORMAL
);
434 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
447 /* current_tick should be ticking by now */
451 #ifdef HAVE_REMOTE_LCD
454 #ifdef HAVE_LCD_BITMAP
456 global_status
.font_id
[i
] = FONT_SYSFIXED
;
465 lang_init(core_language_builtin
, language_strings
,
466 LANG_LAST_INDEX_IN_ARRAY
);
480 CHART(">settings_load(RTC)");
481 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
482 CHART("<settings_load(RTC)");
488 #if CONFIG_USBOTG == USBOTG_ISP1362
490 #elif CONFIG_USBOTG == USBOTG_M5636
504 /* Keep the order of this 3 (viewportmanager handles statusbars)
505 * Must be done before any code uses the multi-screen API */
506 CHART(">gui_syncstatusbar_init");
507 gui_syncstatusbar_init(&statusbars
);
508 CHART("<gui_syncstatusbar_init");
509 CHART(">sb_skin_init");
511 CHART("<sb_skin_init");
512 CHART(">gui_sync_wps_init");
513 gui_sync_skin_init();
514 CHART("<gui_sync_wps_init");
515 CHART(">viewportmanager_init");
516 viewportmanager_init();
517 CHART("<viewportmanager_init");
519 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
520 /* charger_inserted() can't be used here because power_thread()
521 hasn't checked power_input_status() yet */
522 if (coldstart
&& (power_input_status() & POWER_INPUT_MAIN_CHARGER
)
523 && !global_settings
.car_adapter_mode
524 #ifdef ATA_POWER_PLAYERSTYLE
525 && !ide_powered() /* relies on probing result from bootloader */
529 rc
= charging_screen(); /* display a "charging" screen */
530 if (rc
== 1) /* charger removed */
532 /* "On" pressed or USB connected: proceed */
533 show_logo(); /* again, to provide better visual feedback */
538 disk_init_subsystem();
539 CHART(">storage_init");
541 CHART("<storage_init");
544 #ifdef HAVE_LCD_BITMAP
546 lcd_putsf(0, 1, "ATA error: %d", rc
);
547 lcd_puts(0, 3, "Press ON to debug");
549 while(!(button_get(true) & BUTTON_REL
)); /* DO NOT CHANGE TO ACTION SYSTEM */
552 panicf("ata: %d", rc
);
555 #ifdef HAVE_EEPROM_SETTINGS
556 CHART(">eeprom_settings_init");
557 eeprom_settings_init();
558 CHART("<eeprom_settings_init");
561 #ifndef HAVE_USBSTACK
562 usb_start_monitoring();
563 while (usb_detect() == USB_INSERTED
)
565 #ifdef HAVE_EEPROM_SETTINGS
566 firmware_settings
.disk_clean
= false;
568 /* enter USB mode early, before trying to mount */
569 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
570 #if (CONFIG_STORAGE & STORAGE_MMC)
571 if (!mmc_touched() ||
572 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
575 gui_usb_screen_run(true);
576 mounted
= true; /* mounting done @ end of USB mode */
578 #ifdef HAVE_USB_POWER
579 if (usb_powered()) /* avoid deadlock */
587 CHART(">disk_mount_all");
588 rc
= disk_mount_all();
589 CHART("<disk_mount_all");
593 lcd_puts(0, 0, "No partition");
594 lcd_puts(0, 1, "found.");
595 #ifdef HAVE_LCD_BITMAP
596 lcd_puts(0, 2, "Insert USB cable");
597 lcd_puts(0, 3, "and fix it.");
601 while(button_get(true) != SYS_USB_CONNECTED
) {};
602 gui_usb_screen_run(true);
607 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
608 (CONFIG_KEYPAD == IRIVER_H10_PAD)
609 #ifdef SETTINGS_RESET
610 /* Reset settings if holding the reset button. (Rec on Archos,
612 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
614 /* Reset settings if the hold button is turned on */
618 splash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
624 CHART(">settings_load(ALL)");
625 settings_load(SETTINGS_ALL
);
626 CHART("<settings_load(ALL)");
629 CHART(">init_dircache(true)");
630 rc
= init_dircache(true);
631 CHART("<init_dircache(true)");
635 remove(TAGCACHE_STATEFILE
);
639 CHART(">settings_apply(true)");
640 settings_apply(true);
641 CHART("<settings_apply(true)");
642 CHART(">init_dircache(false)");
643 init_dircache(false);
644 CHART("<init_dircache(false)");
646 CHART(">init_tagcache");
648 CHART("<init_tagcache");
651 #ifdef HAVE_EEPROM_SETTINGS
652 if (firmware_settings
.initialized
)
654 /* In case we crash. */
655 firmware_settings
.disk_clean
= false;
656 CHART(">eeprom_settings_store");
657 eeprom_settings_store();
658 CHART("<eeprom_settings_store");
667 #if CONFIG_CODEC != SWCODEC
668 /* No buffer allocation (see buffer.c) may take place after the call to
669 audio_init() since the mpeg thread takes the rest of the buffer space */
670 mp3_init( global_settings
.volume
,
671 global_settings
.bass
,
672 global_settings
.treble
,
673 global_settings
.balance
,
674 global_settings
.loudness
,
676 global_settings
.channel_config
,
677 global_settings
.stereo_width
,
678 global_settings
.mdb_strength
,
679 global_settings
.mdb_harmonics
,
680 global_settings
.mdb_center
,
681 global_settings
.mdb_shape
,
682 global_settings
.mdb_enable
,
683 global_settings
.superbass
);
684 #endif /* CONFIG_CODEC != SWCODEC */
686 CHART(">audio_init");
688 CHART("<audio_init");
690 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
694 /* runtime database has to be initialized after audio_init() */
698 car_adapter_mode_init();
700 #ifdef IPOD_ACCESSORY_PROTOCOL
701 iap_setup(global_settings
.serial_bitrate
);
703 #ifdef HAVE_ACCESSORY_SUPPLY
704 accessory_supply_set(global_settings
.accessory_supply
);
706 #ifdef HAVE_LINEOUT_POWEROFF
707 lineout_set(global_settings
.lineout_active
);
709 #ifdef HAVE_HOTSWAP_STORAGE_AS_MAIN
710 CHART("<check_bootfile(false)");
711 check_bootfile(false); /* remember write time and filesize */
712 CHART(">check_bootfile(false)");
714 CHART("<settings_apply_skins");
715 settings_apply_skins();
716 CHART(">settings_apply_skins");
720 void cop_main(void) MAIN_NORETURN_ATTR
;
723 /* This is the entry point for the coprocessor
724 Anyone not running an upgraded bootloader will never reach this point,
725 so it should not be assumed that the coprocessor be usable even on
726 platforms which support it.
728 A kernel thread is initially setup on the coprocessor and immediately
729 destroyed for purposes of continuity. The cop sits idle until at least
730 one thread exists on it. */
735 /* This should never be reached */
743 #endif /* SIMULATOR */