/**@brief Function for application main entry. */ int main(void) { #ifdef OSSW_DEBUG init_uart(); #endif spi_init(); ext_ram_init(); init_lcd_with_splash_screen(); accel_init(); // Initialize. timers_init(); rtc_timer_init(); buttons_init(); battery_init(); // Initialize the SoftDevice handler module. SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, NULL); // splash screen nrf_delay_ms(500); fs_init(); config_init(); scr_mngr_init(); vibration_init(); notifications_init(); stopwatch_init(); timer_feature_init(); mlcd_timers_init(); // Enter main loop. for (;;) { if (rtc_should_store_current_time()) { rtc_store_current_time(); } app_sched_execute(); stopwatch_process(); command_process(); watchset_process_async_operation(); scr_mngr_draw_screen(); power_manage(); } }
/** * Showtime main */ int main(int argc, char **argv) { struct timeval tv; const char *settingspath = NULL; const char *uiargs[16]; const char *argv0 = argc > 0 ? argv[0] : "showtime"; const char *forceview = NULL; int nuiargs = 0; int can_standby = 0; int can_poweroff = 0; int r; trace_level = TRACE_INFO; gettimeofday(&tv, NULL); srand(tv.tv_usec); arch_set_default_paths(argc, argv); /* We read options ourselfs since getopt() is broken on some (nintento wii) targets */ argv++; argc--; while(argc > 0) { if(!strcmp(argv[0], "-h") || !strcmp(argv[0], "--help")) { printf("HTS Showtime %s\n" "Copyright (C) 2007-2010 Andreas Öman\n" "\n" "Usage: %s [options] [<url>]\n" "\n" " Options:\n" " -h, --help - This help text.\n" " -d - Enable debug output.\n" " --ffmpeglog - Print ffmpeg log messages.\n" " --with-standby - Enable system standby.\n" " --with-poweroff - Enable system power-off.\n" " -s <path> - Non-default Showtime settings path.\n" " --ui <ui> - Use specified user interface.\n" " -L <ip:host> - Send log messages to remote <ip:host>.\n" " --syslog - Send log messages to syslog.\n" #if ENABLE_STDIN " --stdin - Listen on stdin for events.\n" #endif " -v <view> - Use specific view for <url>.\n" " --cache <path> - Set path for cache [%s].\n" #if ENABLE_SERDEV " --serdev - Probe service ports for devices.\n" #endif "\n" " URL is any URL-type supported by Showtime, " "e.g., \"file:///...\"\n" "\n", htsversion_full, argv0, showtime_cache_path); exit(0); argc--; argv++; } else if(!strcmp(argv[0], "-d")) { trace_level++; argc -= 1; argv += 1; continue; } else if(!strcmp(argv[0], "--ffmpeglog")) { ffmpeglog = 1; argc -= 1; argv += 1; continue; } else if(!strcmp(argv[0], "--syslog")) { trace_to_syslog = 1; argc -= 1; argv += 1; continue; } else if(!strcmp(argv[0], "--stdin")) { listen_on_stdin = 1; argc -= 1; argv += 1; continue; #if ENABLE_SERDEV } else if(!strcmp(argv[0], "--serdev")) { enable_serdev = 1; argc -= 1; argv += 1; continue; #endif } else if(!strcmp(argv[0], "--with-standby")) { can_standby = 1; argc -= 1; argv += 1; continue; } else if(!strcmp(argv[0], "--with-poweroff")) { can_poweroff = 1; argc -= 1; argv += 1; continue; } else if(!strcmp(argv[0], "-s") && argc > 1) { settingspath = argv[1]; argc -= 2; argv += 2; continue; } else if(!strcmp(argv[0], "--ui") && argc > 1) { if(nuiargs < 16) uiargs[nuiargs++] = argv[1]; argc -= 2; argv += 2; continue; } else if(!strcmp(argv[0], "-L") && argc > 1) { showtime_logtarget = argv[1]; argc -= 2; argv += 2; continue; } else if (!strcmp(argv[0], "-v") && argc > 1) { forceview = argv[1]; argc -= 2; argv += 2; } else if (!strcmp(argv[0], "--cache") && argc > 1) { mystrset(&showtime_cache_path, argv[1]); argc -= 2; argv += 2; #ifdef __APPLE__ /* ignore -psn argument, process serial number */ } else if(!strncmp(argv[0], "-psn", 4)) { argc -= 1; argv += 1; continue; #endif } else break; } unicode_init(); /* Initialize property tree */ prop_init(); init_global_info(); /* Initiailize logging */ trace_init(); /* Callout framework */ callout_init(); /* Notification framework */ notifications_init(); /* Architecture specific init */ arch_init(); htsmsg_store_init(); /* Try to create cache path */ if(showtime_cache_path != NULL && (r = makedirs(showtime_cache_path)) != 0) { TRACE(TRACE_ERROR, "cache", "Unable to create cache path %s -- %s", showtime_cache_path, strerror(r)); showtime_cache_path = NULL; } /* Initializte blob cache */ blobcache_init(); /* Try to create settings path */ if(showtime_settings_path != NULL && (r = makedirs(showtime_settings_path)) != 0) { TRACE(TRACE_ERROR, "settings", "Unable to create settings path %s -- %s", showtime_settings_path, strerror(r)); showtime_settings_path = NULL; } /* Initialize keyring */ keyring_init(); /* Initialize settings */ settings_init(); /* Initialize libavcodec & libavformat */ av_lockmgr_register(fflockmgr); av_log_set_callback(fflog); av_register_all(); /* Freetype keymapper */ #if ENABLE_LIBFREETYPE freetype_init(); #endif /* Global keymapper */ keymapper_init(); /* Initialize media subsystem */ media_init(); /* Service handling */ service_init(); /* Initialize backend content handlers */ backend_init(); /* Initialize navigator */ nav_init(); /* Initialize audio subsystem */ audio_init(); /* Initialize bookmarks */ bookmarks_init(); /* Initialize plugin manager and load plugins */ plugins_init(); /* Internationalization */ i18n_init(); nav_open(NAV_HOME, NULL); /* Open initial page */ if(argc > 0) nav_open(argv[0], forceview); /* Various interprocess communication stuff (D-Bus on Linux, etc) */ ipc_init(); /* Service discovery. Must be after ipc_init() (d-bus and threads, etc) */ sd_init(); /* Initialize various external APIs */ api_init(); /* HTTP server and UPNP */ #if ENABLE_HTTPSERVER http_server_init(); upnp_init(); #endif /* */ runcontrol_init(can_standby, can_poweroff); TRACE(TRACE_DEBUG, "core", "Starting UI"); /* Initialize user interfaces */ ui_start(nuiargs, uiargs, argv0); finalize(); }
extern "C" int _start(kernel_args *bootKernelArgs, int currentCPU) { if (bootKernelArgs->kernel_args_size != sizeof(kernel_args) || bootKernelArgs->version != CURRENT_KERNEL_ARGS_VERSION) { // This is something we cannot handle right now - release kernels // should always be able to handle the kernel_args of earlier // released kernels. debug_early_boot_message("Version mismatch between boot loader and " "kernel!\n"); return -1; } smp_set_num_cpus(bootKernelArgs->num_cpus); // wait for all the cpus to get here smp_cpu_rendezvous(&sCpuRendezvous, currentCPU); // the passed in kernel args are in a non-allocated range of memory if (currentCPU == 0) memcpy(&sKernelArgs, bootKernelArgs, sizeof(kernel_args)); smp_cpu_rendezvous(&sCpuRendezvous2, currentCPU); // do any pre-booting cpu config cpu_preboot_init_percpu(&sKernelArgs, currentCPU); thread_preboot_init_percpu(&sKernelArgs, currentCPU); // if we're not a boot cpu, spin here until someone wakes us up if (smp_trap_non_boot_cpus(currentCPU, &sCpuRendezvous3)) { // init platform arch_platform_init(&sKernelArgs); // setup debug output debug_init(&sKernelArgs); set_dprintf_enabled(true); dprintf("Welcome to kernel debugger output!\n"); dprintf("Haiku revision: %lu\n", get_haiku_revision()); // init modules TRACE("init CPU\n"); cpu_init(&sKernelArgs); cpu_init_percpu(&sKernelArgs, currentCPU); TRACE("init interrupts\n"); int_init(&sKernelArgs); TRACE("init VM\n"); vm_init(&sKernelArgs); // Before vm_init_post_sem() is called, we have to make sure that // the boot loader allocated region is not used anymore boot_item_init(); debug_init_post_vm(&sKernelArgs); low_resource_manager_init(); // now we can use the heap and create areas arch_platform_init_post_vm(&sKernelArgs); lock_debug_init(); TRACE("init driver_settings\n"); driver_settings_init(&sKernelArgs); debug_init_post_settings(&sKernelArgs); TRACE("init notification services\n"); notifications_init(); TRACE("init teams\n"); team_init(&sKernelArgs); TRACE("init ELF loader\n"); elf_init(&sKernelArgs); TRACE("init modules\n"); module_init(&sKernelArgs); TRACE("init semaphores\n"); haiku_sem_init(&sKernelArgs); TRACE("init interrupts post vm\n"); int_init_post_vm(&sKernelArgs); cpu_init_post_vm(&sKernelArgs); commpage_init(); TRACE("init system info\n"); system_info_init(&sKernelArgs); TRACE("init SMP\n"); smp_init(&sKernelArgs); TRACE("init timer\n"); timer_init(&sKernelArgs); TRACE("init real time clock\n"); rtc_init(&sKernelArgs); TRACE("init condition variables\n"); condition_variable_init(); // now we can create and use semaphores TRACE("init VM semaphores\n"); vm_init_post_sem(&sKernelArgs); TRACE("init generic syscall\n"); generic_syscall_init(); smp_init_post_generic_syscalls(); TRACE("init scheduler\n"); scheduler_init(); TRACE("init threads\n"); thread_init(&sKernelArgs); TRACE("init kernel daemons\n"); kernel_daemon_init(); arch_platform_init_post_thread(&sKernelArgs); TRACE("init I/O interrupts\n"); int_init_io(&sKernelArgs); TRACE("init VM threads\n"); vm_init_post_thread(&sKernelArgs); low_resource_manager_init_post_thread(); TRACE("init VFS\n"); vfs_init(&sKernelArgs); #if ENABLE_SWAP_SUPPORT TRACE("init swap support\n"); swap_init(); #endif TRACE("init POSIX semaphores\n"); realtime_sem_init(); xsi_sem_init(); xsi_msg_init(); // Start a thread to finish initializing the rest of the system. Note, // it won't be scheduled before calling scheduler_start() (on any CPU). TRACE("spawning main2 thread\n"); thread_id thread = spawn_kernel_thread(&main2, "main2", B_NORMAL_PRIORITY, NULL); resume_thread(thread); // We're ready to start the scheduler and enable interrupts on all CPUs. scheduler_enable_scheduling(); // bring up the AP cpus in a lock step fashion TRACE("waking up AP cpus\n"); sCpuRendezvous = sCpuRendezvous2 = 0; smp_wake_up_non_boot_cpus(); smp_cpu_rendezvous(&sCpuRendezvous, 0); // wait until they're booted // exit the kernel startup phase (mutexes, etc work from now on out) TRACE("exiting kernel startup\n"); gKernelStartup = false; smp_cpu_rendezvous(&sCpuRendezvous2, 0); // release the AP cpus to go enter the scheduler TRACE("starting scheduler on cpu 0 and enabling interrupts\n"); scheduler_start(); enable_interrupts(); } else { // lets make sure we're in sync with the main cpu // the boot processor has probably been sending us // tlb sync messages all along the way, but we've // been ignoring them arch_cpu_global_TLB_invalidate(); // this is run for each non boot processor after they've been set loose cpu_init_percpu(&sKernelArgs, currentCPU); smp_per_cpu_init(&sKernelArgs, currentCPU); // wait for all other AP cpus to get to this point smp_cpu_rendezvous(&sCpuRendezvous, currentCPU); smp_cpu_rendezvous(&sCpuRendezvous2, currentCPU); // welcome to the machine scheduler_start(); enable_interrupts(); } #ifdef TRACE_BOOT // We disable interrupts for this dprintf(), since otherwise dprintf() // would acquires a mutex, which is something we must not do in an idle // thread, or otherwise the scheduler would be seriously unhappy. disable_interrupts(); TRACE("main: done... begin idle loop on cpu %d\n", currentCPU); enable_interrupts(); #endif for (;;) arch_cpu_idle(); return 0; }
void showtime_init(void) { int r; hts_mutex_init(&gconf.state_mutex); hts_cond_init(&gconf.state_cond, &gconf.state_mutex); gconf.exit_code = 1; unicode_init(); /* Initialize property tree */ prop_init(); init_global_info(); /* Initiailize logging */ trace_init(); /* Callout framework */ callout_init(); /* Initialize htsmsg_store() */ htsmsg_store_init(); /* Notification framework */ notifications_init(); /* Initialize settings */ settings_init(); TRACE(TRACE_DEBUG, "core", "Loading resources from %s", showtime_dataroot()); /* Try to create cache path */ if(gconf.cache_path != NULL && (r = makedirs(gconf.cache_path)) != 0) { TRACE(TRACE_ERROR, "cache", "Unable to create cache path %s -- %s", gconf.cache_path, strerror(r)); gconf.cache_path = NULL; } /* Initialize sqlite3 */ db_init(); /* Initializte blob cache */ blobcache_init(); /* Try to create settings path */ if(gconf.persistent_path != NULL && (r = makedirs(gconf.persistent_path)) != 0) { TRACE(TRACE_ERROR, "settings", "Unable to create path for persistent storage %s -- %s", gconf.persistent_path, strerror(r)); gconf.persistent_path = NULL; } /* Metadata init */ metadata_init(); metadb_init(); kvstore_init(); /* Metadata decoration init */ decoration_init(); /* Initialize keyring */ keyring_init(); #if ENABLE_LIBAV /* Initialize libavcodec & libavformat */ av_lockmgr_register(fflockmgr); av_log_set_callback(fflog); av_register_all(); TRACE(TRACE_INFO, "libav", LIBAVFORMAT_IDENT", "LIBAVCODEC_IDENT", "LIBAVUTIL_IDENT); #endif /* Freetype */ #if ENABLE_LIBFREETYPE freetype_init(); rasterizer_ft_init(); #endif #if ENABLE_GLW glw_settings_init(); #endif fontstash_init(); /* Global keymapper */ keymapper_init(); /* Initialize media subsystem */ media_init(); /* Service handling */ service_init(); /* Initialize backend content handlers */ backend_init(); /* Initialize navigator */ nav_init(); /* Initialize audio subsystem */ audio_init(); /* Initialize plugin manager */ plugins_init(gconf.devplugin); /* Start software installer thread (plugins, upgrade, etc) */ hts_thread_create_detached("swinst", swthread, NULL, THREAD_PRIO_LOW); /* Internationalization */ i18n_init(); /* Video settings */ video_settings_init(); if(gconf.load_jsfile) js_load(gconf.load_jsfile); /* Various interprocess communication stuff (D-Bus on Linux, etc) */ init_group(INIT_GROUP_IPC); /* Service discovery. Must be after ipc_init() (d-bus and threads, etc) */ if(!gconf.disable_sd) sd_init(); /* Initialize various external APIs */ init_group(INIT_GROUP_API); /* HTTP server and UPNP */ #if ENABLE_HTTPSERVER http_server_init(); if(!gconf.disable_upnp) upnp_init(); #endif runcontrol_init(); }
void main_init(void) { char errbuf[512]; hts_mutex_init(&gconf.state_mutex); hts_cond_init(&gconf.state_cond, &gconf.state_mutex); gconf.exit_code = 1; asyncio_init_early(); init_group(INIT_GROUP_NET); unicode_init(); /* Initialize property tree */ prop_init(); init_global_info(); /* Initiailize logging */ trace_init(); /* Callout framework */ callout_init(); prop_init_late(); /* Initialize htsmsg_store() */ htsmsg_store_init(); /* Notification framework */ notifications_init(); /* Initialize settings */ settings_init(); TRACE(TRACE_DEBUG, "core", "Loading resources from %s", app_dataroot()); TRACE(TRACE_DEBUG, "core", "Cache path: %s", gconf.cache_path); /* Try to create cache path */ if(gconf.cache_path != NULL && fa_makedirs(gconf.cache_path, errbuf, sizeof(errbuf))) { TRACE(TRACE_ERROR, "core", "Unable to create cache path %s -- %s", gconf.cache_path, errbuf); gconf.cache_path = NULL; } /* Initialize sqlite3 */ #if ENABLE_SQLITE db_init(); #endif /* Initializte blob cache */ blobcache_init(); TRACE(TRACE_DEBUG, "core", "Persistent path: %s", gconf.persistent_path); /* Try to create settings path */ if(gconf.persistent_path != NULL && fa_makedirs(gconf.persistent_path, errbuf, sizeof(errbuf))) { TRACE(TRACE_ERROR, "core", "Unable to create path for persistent storage %s -- %s", gconf.persistent_path, errbuf); gconf.persistent_path = NULL; } /* Per-item key/value store */ kvstore_init(); /* Metadata init */ #if ENABLE_METADATA metadata_init(); metadb_init(); decoration_init(); #endif subtitles_init(); /* Initialize keyring */ keyring_init(); #if ENABLE_LIBAV /* Initialize libavcodec & libavformat */ av_lockmgr_register(fflockmgr); av_log_set_callback(fflog); av_register_all(); TRACE(TRACE_INFO, "libav", LIBAVFORMAT_IDENT", "LIBAVCODEC_IDENT", "LIBAVUTIL_IDENT" cpuflags:0x%x", av_get_cpu_flags()); #endif init_group(INIT_GROUP_GRAPHICS); #if ENABLE_GLW glw_settings_init(); #endif /* Global keymapper */ keymapper_init(); /* Initialize media subsystem */ media_init(); /* Service handling */ service_init(); /* Initialize backend content handlers */ backend_init(); /* Initialize navigator */ nav_init(); /* Initialize audio subsystem */ audio_init(); /* Initialize plugin manager */ plugins_init(gconf.devplugins); /* Start software installer thread (plugins, upgrade, etc) */ hts_thread_create_detached("swinst", swthread, NULL, THREAD_PRIO_BGTASK); /* Internationalization */ i18n_init(); /* Video settings */ video_settings_init(); /* Various interprocess communication stuff (D-Bus on Linux, etc) */ init_group(INIT_GROUP_IPC); /* Service discovery. Must be after ipc_init() (d-bus and threads, etc) */ if(!gconf.disable_sd) sd_init(); /* Initialize various external APIs */ init_group(INIT_GROUP_API); /* Asynchronous IO (Used by HTTP server, etc) */ asyncio_start(); runcontrol_init(); TRACE(TRACE_DEBUG, "SYSTEM", "Hashed device ID: %s", gconf.device_id); if(gconf.device_type[0]) TRACE(TRACE_DEBUG, "SYSTEM", "Device type: %s", gconf.device_type); }