int nx_start(void) { pid_t server; /* Start the server kernel thread */ gvdbg("Starting server task\n"); server = KERNEL_THREAD("NX Server", CONFIG_NXSTART_SERVERPRIO, CONFIG_NXSTART_SERVERSTACK, nx_server, NULL); if (server < 0) { int errcode = errno; DEBUGASSERT(errcode > 0); gdbg("ERROR: Failed to create nx_server kernel thread: %d\n", errcode); return -errcode; } /* Wait a bit to make sure that the server get started. NOTE that this * operation cannot be done from the IDLE thread! */ usleep(50*1000); return OK; }
int up_wdginitialize(void) { #if (defined(CONFIG_SAM34_WDT) && !defined(CONFIG_WDT_DISABLE_ON_RESET)) int fd; int ret; /* Initialize tha register the watchdog timer device */ wdgvdbg("Initializing Watchdog driver...\n"); sam_wdtinitialize(CONFIG_WATCHDOG_DEVPATH); /* Open the watchdog device */ wdgvdbg("Opening.\n"); fd = open(CONFIG_WATCHDOG_DEVPATH, O_RDONLY); if (fd < 0) { wdgdbg("open %s failed: %d\n", CONFIG_WATCHDOG_DEVPATH, errno); goto errout; } /* Set the watchdog timeout */ wdgvdbg("Timeout = %d.\n", CONFIG_WDT_TIMEOUT); ret = ioctl(fd, WDIOC_SETTIMEOUT, (unsigned long)CONFIG_WDT_TIMEOUT); if (ret < 0) { wdgdbg("ioctl(WDIOC_SETTIMEOUT) failed: %d\n", errno); goto errout_with_dev; } /* Set the watchdog minimum time */ wdgvdbg("MinTime = %d.\n", CONFIG_WDT_MINTIME); ret = ioctl(fd, WDIOC_MINTIME, (unsigned long)CONFIG_WDT_MINTIME); if (ret < 0) { wdgdbg("ioctl(WDIOC_MINTIME) failed: %d\n", errno); goto errout_with_dev; } /* Start Kicker task */ #if defined(CONFIG_WDT_THREAD) sched_lock(); int taskid = KERNEL_THREAD(CONFIG_WDT_THREAD_NAME, CONFIG_WDT_THREAD_PRIORITY, CONFIG_WDT_THREAD_STACKSIZE, (main_t)wdog_daemon, (FAR char * const *)NULL); ASSERT(taskid > 0); sched_unlock(); #endif return OK; errout_with_dev: close(fd); errout: return ERROR; #else return -ENODEV; #endif }
int os_bringup(void) { int taskid; /* Setup up the initial environment for the idle task. At present, this * may consist of only the initial PATH variable. The PATH variable is * (probably) not used by the IDLE task. However, the environment * containing the PATH variable will be inherited by all of the threads * created by the IDLE task. */ #if !defined(CONFIG_DISABLE_ENVIRON) && defined(CONFIG_PATH_INITIAL) (void)setenv("PATH", CONFIG_PATH_INITIAL, 1); #endif /* Start the page fill worker kernel thread that will resolve page faults. * This should always be the first thread started because it may have to * resolve page faults in other threads */ #ifdef CONFIG_PAGING svdbg("Starting paging thread\n"); g_pgworker = KERNEL_THREAD("pgfill", CONFIG_PAGING_DEFPRIO, CONFIG_PAGING_STACKSIZE, (main_t)pg_worker, (FAR char * const *)NULL); DEBUGASSERT(g_pgworker > 0); #endif /* Start the worker thread that will serve as the device driver "bottom- * half" and will perform misc garbage clean-up. */ #ifdef CONFIG_SCHED_WORKQUEUE #ifdef CONFIG_SCHED_HPWORK #ifdef CONFIG_SCHED_LPWORK svdbg("Starting high-priority kernel worker thread\n"); #else svdbg("Starting kernel worker thread\n"); #endif g_work[HPWORK].pid = KERNEL_THREAD(HPWORKNAME, CONFIG_SCHED_WORKPRIORITY, CONFIG_SCHED_WORKSTACKSIZE, (main_t)work_hpthread, (FAR char * const *)NULL); DEBUGASSERT(g_work[HPWORK].pid > 0); /* Start a lower priority worker thread for other, non-critical continuation * tasks */ #ifdef CONFIG_SCHED_LPWORK svdbg("Starting low-priority kernel worker thread\n"); g_work[LPWORK].pid = KERNEL_THREAD(LPWORKNAME, CONFIG_SCHED_LPWORKPRIORITY, CONFIG_SCHED_LPWORKSTACKSIZE, (main_t)work_lpthread, (FAR char * const *)NULL); DEBUGASSERT(g_work[LPWORK].pid > 0); #endif /* CONFIG_SCHED_LPWORK */ #endif /* CONFIG_SCHED_HPWORK */ #if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_SCHED_USRWORK) /* Start the user-space work queue */ DEBUGASSERT(USERSPACE->work_usrstart != NULL); taskid = USERSPACE->work_usrstart(); DEBUGASSERT(taskid > 0); #endif #endif /* CONFIG_SCHED_WORKQUEUE */ /* Once the operating system has been initialized, the system must be * started by spawning the user init thread of execution. This is the * first user-mode thead. */ svdbg("Starting init thread\n"); /* Perform any last-minute, board-specific initialization, if so * configured. */ #ifdef CONFIG_BOARD_INITIALIZE board_initialize(); #endif /* Start the default application. In a flat build, this is entrypoint * is given by the definitions, CONFIG_USER_ENTRYPOINT. In the kernel * build, however, we must get the address of the entrypoint from the * header at the beginning of the user-space blob. */ #ifdef CONFIG_NUTTX_KERNEL DEBUGASSERT(USERSPACE->us_entrypoint != NULL); taskid = TASK_CREATE("init", SCHED_PRIORITY_DEFAULT, CONFIG_USERMAIN_STACKSIZE, USERSPACE->us_entrypoint, (FAR char * const *)NULL); #else taskid = TASK_CREATE("init", SCHED_PRIORITY_DEFAULT, CONFIG_USERMAIN_STACKSIZE, (main_t)CONFIG_USER_ENTRYPOINT, (FAR char * const *)NULL); #endif ASSERT(taskid > 0); /* We an save a few bytes by discarding the IDLE thread's environment. */ #if !defined(CONFIG_DISABLE_ENVIRON) && defined(CONFIG_PATH_INITIAL) (void)clearenv(); #endif return OK; }
int os_bringup(void) { int init_taskid; /* Setup up the initial environment for the idle task. At present, this * may consist of only the initial PATH variable. The PATH variable is * (probably) not used by the IDLE task. However, the environment * containing the PATH variable will be inherited by all of the threads * created by the IDLE task. */ #if !defined(CONFIG_DISABLE_ENVIRON) && defined(CONFIG_PATH_INITIAL) (void)setenv("PATH", CONFIG_PATH_INITIAL, 1); #endif /* Start the page fill worker kernel thread that will resolve page faults. * This should always be the first thread started because it may have to * resolve page faults in other threads */ #ifdef CONFIG_PAGING svdbg("Starting paging thread\n"); g_pgworker = KERNEL_THREAD("pgfill", CONFIG_PAGING_DEFPRIO, CONFIG_PAGING_STACKSIZE, (main_t)pg_worker, (const char **)NULL); ASSERT(g_pgworker != ERROR); #endif /* Start the worker thread that will serve as the device driver "bottom- * half" and will perform misc garbage clean-up. */ #ifdef CONFIG_SCHED_WORKQUEUE svdbg("Starting worker thread\n"); g_work[HPWORK].pid = KERNEL_THREAD("work0", CONFIG_SCHED_WORKPRIORITY, CONFIG_SCHED_WORKSTACKSIZE, (main_t)work_hpthread, (const char **)NULL); ASSERT(g_work[HPWORK].pid != ERROR); /* Start a lower priority worker thread for other, non-critical continuation * tasks */ #ifdef CONFIG_SCHED_LPWORK svdbg("Starting worker thread\n"); g_work[LPWORK].pid = KERNEL_THREAD("work1", CONFIG_SCHED_LPWORKPRIORITY, CONFIG_SCHED_LPWORKSTACKSIZE, (main_t)work_lpthread, (const char **)NULL); ASSERT(g_work[LPWORK].pid != ERROR); #endif #endif /* Once the operating system has been initialized, the system must be * started by spawning the user init thread of execution. This is the * first user-mode thead. */ svdbg("Starting init thread\n"); /* Start the default application at CONFIG_USER_ENTRYPOINT() */ init_taskid = TASK_CREATE("init", SCHED_PRIORITY_DEFAULT, CONFIG_USERMAIN_STACKSIZE, (main_t)CONFIG_USER_ENTRYPOINT, (const char **)NULL); ASSERT(init_taskid != ERROR); /* We an save a few bytes by discarding the IDLE thread's environment. */ #if !defined(CONFIG_DISABLE_ENVIRON) && defined(CONFIG_PATH_INITIAL) (void)clearenv(); #endif return OK; }