2008-01-09 02:13:24 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* sched/os_start.c
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2014-08-07 20:35:24 +02:00
|
|
|
* Copyright (C) 2007-2014 Gregory Nutt. All rights reserved.
|
2012-03-04 00:18:34 +01:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
2008-01-09 02:13:24 +01:00
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
2007-02-18 00:21:28 +01:00
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2008-01-09 02:13:24 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-09 02:13:24 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2008-01-09 02:13:24 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-01 00:45:56 +01:00
|
|
|
#include <sys/types.h>
|
2009-12-14 22:15:18 +01:00
|
|
|
#include <stdbool.h>
|
2007-03-01 00:45:56 +01:00
|
|
|
#include <string.h>
|
2013-03-13 18:32:37 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include <debug.h>
|
2007-03-01 00:45:56 +01:00
|
|
|
|
|
|
|
#include <nuttx/arch.h>
|
|
|
|
#include <nuttx/compiler.h>
|
2012-03-21 19:01:07 +01:00
|
|
|
#include <nuttx/fs/fs.h>
|
2012-03-04 00:18:34 +01:00
|
|
|
#include <nuttx/net/net.h>
|
2007-03-01 00:45:56 +01:00
|
|
|
#include <nuttx/lib.h>
|
2011-04-05 19:33:50 +02:00
|
|
|
#include <nuttx/kmalloc.h>
|
2007-09-09 13:58:50 +02:00
|
|
|
#include <nuttx/init.h>
|
2011-04-05 19:33:50 +02:00
|
|
|
|
2007-03-01 00:45:56 +01:00
|
|
|
#include "os_internal.h"
|
2014-08-08 20:44:44 +02:00
|
|
|
#include "signal/signal.h"
|
2014-08-08 22:21:48 +02:00
|
|
|
#include "wdog/wdog.h"
|
2014-08-08 21:53:29 +02:00
|
|
|
#include "semaphore/semaphore.h"
|
2007-03-01 00:45:56 +01:00
|
|
|
#ifndef CONFIG_DISABLE_MQUEUE
|
2014-08-08 20:31:23 +02:00
|
|
|
# include "mqueue/mqueue.h"
|
2007-03-01 00:45:56 +01:00
|
|
|
#endif
|
2007-03-01 22:05:55 +01:00
|
|
|
#ifndef CONFIG_DISABLE_PTHREAD
|
2014-08-08 20:55:02 +02:00
|
|
|
# include "pthread/pthread.h"
|
2007-03-01 22:05:55 +01:00
|
|
|
#endif
|
2014-08-08 22:43:02 +02:00
|
|
|
#include "clock/clock.h"
|
2014-08-08 22:55:16 +02:00
|
|
|
#include "timer/timer.h"
|
2014-08-08 22:31:15 +02:00
|
|
|
#include "irq/irq.h"
|
2013-01-26 00:21:27 +01:00
|
|
|
#ifdef HAVE_TASK_GROUP
|
2014-08-08 22:06:42 +02:00
|
|
|
#include "group/group.h"
|
2013-01-26 00:21:27 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-09 02:13:24 +01:00
|
|
|
/****************************************************************************
|
2009-12-14 22:15:18 +01:00
|
|
|
* Pre-processor Definitions
|
2008-01-09 02:13:24 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-09 02:13:24 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Private Type Declarations
|
2008-01-09 02:13:24 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-09 02:13:24 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Global Variables
|
2008-01-09 02:13:24 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-09 02:13:24 +01:00
|
|
|
/* Task Lists ***************************************************************/
|
2012-07-14 21:30:31 +02:00
|
|
|
/* The state of a task is indicated both by the task_state field of the TCB
|
|
|
|
* and by a series of task lists. All of these tasks lists are declared
|
|
|
|
* below. Although it is not always necessary, most of these lists are
|
|
|
|
* prioritized so that common list handling logic can be used (only the
|
|
|
|
* g_readytorun, the g_pendingtasks, and the g_waitingforsemaphore lists need
|
2007-02-18 00:21:28 +01:00
|
|
|
* to be prioritized).
|
|
|
|
*/
|
|
|
|
|
2012-07-14 21:30:31 +02:00
|
|
|
/* This is the list of all tasks that are ready to run. The head of this
|
|
|
|
* list is the currently active task; the tail of this list is always the
|
|
|
|
* IDLE task.
|
2007-02-18 00:21:28 +01:00
|
|
|
*/
|
|
|
|
|
2007-03-14 19:58:21 +01:00
|
|
|
volatile dq_queue_t g_readytorun;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-07-14 21:30:31 +02:00
|
|
|
/* This is the list of all tasks that are ready-to-run, but cannot be placed
|
|
|
|
* in the g_readytorun list because: (1) They are higher priority than the
|
|
|
|
* currently active task at the head of the g_readytorun list, and (2) the
|
|
|
|
* currently active task has disabled pre-emption.
|
2007-02-18 00:21:28 +01:00
|
|
|
*/
|
|
|
|
|
2007-03-14 19:58:21 +01:00
|
|
|
volatile dq_queue_t g_pendingtasks;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* This is the list of all tasks that are blocked waiting for a semaphore */
|
|
|
|
|
2007-03-14 19:58:21 +01:00
|
|
|
volatile dq_queue_t g_waitingforsemaphore;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* This is the list of all tasks that are blocked waiting for a signal */
|
|
|
|
|
2007-03-01 00:45:56 +01:00
|
|
|
#ifndef CONFIG_DISABLE_SIGNALS
|
2007-03-14 19:58:21 +01:00
|
|
|
volatile dq_queue_t g_waitingforsignal;
|
2007-03-01 00:45:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* This is the list of all tasks that are blocked waiting for a message
|
|
|
|
* queue to become non-empty.
|
|
|
|
*/
|
|
|
|
|
2007-03-01 00:45:56 +01:00
|
|
|
#ifndef CONFIG_DISABLE_MQUEUE
|
2007-03-14 19:58:21 +01:00
|
|
|
volatile dq_queue_t g_waitingformqnotempty;
|
2007-03-01 00:45:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* This is the list of all tasks that are blocked waiting for a message
|
|
|
|
* queue to become non-full.
|
|
|
|
*/
|
|
|
|
|
2007-03-01 00:45:56 +01:00
|
|
|
#ifndef CONFIG_DISABLE_MQUEUE
|
2007-03-14 19:58:21 +01:00
|
|
|
volatile dq_queue_t g_waitingformqnotfull;
|
2007-03-01 00:45:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2010-08-14 03:56:13 +02:00
|
|
|
/* This is the list of all tasks that are blocking waiting for a page fill */
|
|
|
|
|
|
|
|
#ifdef CONFIG_PAGING
|
|
|
|
volatile dq_queue_t g_waitingforfill;
|
|
|
|
#endif
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* This the list of all tasks that have been initialized, but not yet
|
|
|
|
* activated. NOTE: This is the only list that is not prioritized.
|
|
|
|
*/
|
|
|
|
|
2007-03-14 19:58:21 +01:00
|
|
|
volatile dq_queue_t g_inactivetasks;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-03-10 16:32:33 +01:00
|
|
|
/* These are lists of dayed memory deallocations that need to be handled
|
|
|
|
* within the IDLE loop or worker thread. These deallocations get queued
|
|
|
|
* by sched_kufree and sched_kfree() if the OS needs to deallocate memory
|
|
|
|
* while it is within an interrupt handler.
|
2007-02-18 00:21:28 +01:00
|
|
|
*/
|
|
|
|
|
2013-03-10 16:32:33 +01:00
|
|
|
volatile sq_queue_t g_delayed_kufree;
|
|
|
|
|
|
|
|
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
|
|
|
|
volatile sq_queue_t g_delayed_kfree;
|
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* This is the value of the last process ID assigned to a task */
|
|
|
|
|
2007-03-14 19:58:21 +01:00
|
|
|
volatile pid_t g_lastpid;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* The following hash table is used for two things:
|
2007-03-01 22:05:55 +01:00
|
|
|
*
|
2007-02-18 00:21:28 +01:00
|
|
|
* 1. This hash table greatly speeds the determination of
|
|
|
|
* a new unique process ID for a task, and
|
|
|
|
* 2. Is used to quickly map a process ID into a TCB.
|
|
|
|
* It has the side effects of using more memory and limiting
|
2007-03-01 22:05:55 +01:00
|
|
|
*
|
|
|
|
* the number of tasks to CONFIG_MAX_TASKS.
|
2007-02-18 00:21:28 +01:00
|
|
|
*/
|
|
|
|
|
2007-03-01 22:05:55 +01:00
|
|
|
pidhash_t g_pidhash[CONFIG_MAX_TASKS];
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* This is a table of task lists. This table is indexed by
|
|
|
|
* the task state enumeration type (tstate_t) and provides
|
|
|
|
* a pointer to the associated static task list (if there
|
|
|
|
* is one) as well as a boolean indication as to if the list
|
|
|
|
* is an ordered list or not.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const tasklist_t g_tasklisttable[NUM_TASK_STATES] =
|
|
|
|
{
|
2009-12-14 22:15:18 +01:00
|
|
|
{ NULL, false }, /* TSTATE_TASK_INVALID */
|
|
|
|
{ &g_pendingtasks, true }, /* TSTATE_TASK_PENDING */
|
|
|
|
{ &g_readytorun, true }, /* TSTATE_TASK_READYTORUN */
|
|
|
|
{ &g_readytorun, true }, /* TSTATE_TASK_RUNNING */
|
|
|
|
{ &g_inactivetasks, false }, /* TSTATE_TASK_INACTIVE */
|
2010-08-17 03:37:39 +02:00
|
|
|
{ &g_waitingforsemaphore, true } /* TSTATE_WAIT_SEM */
|
2007-03-17 23:43:36 +01:00
|
|
|
#ifndef CONFIG_DISABLE_SIGNALS
|
2010-08-17 03:37:39 +02:00
|
|
|
,
|
|
|
|
{ &g_waitingforsignal, false } /* TSTATE_WAIT_SIG */
|
2007-03-01 00:45:56 +01:00
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_DISABLE_MQUEUE
|
2010-08-17 03:37:39 +02:00
|
|
|
,
|
2009-12-14 22:15:18 +01:00
|
|
|
{ &g_waitingformqnotempty, true }, /* TSTATE_WAIT_MQNOTEMPTY */
|
|
|
|
{ &g_waitingformqnotfull, true } /* TSTATE_WAIT_MQNOTFULL */
|
2007-03-01 00:45:56 +01:00
|
|
|
#endif
|
2010-08-14 03:56:13 +02:00
|
|
|
#ifdef CONFIG_PAGING
|
2010-08-17 03:37:39 +02:00
|
|
|
,
|
2010-08-14 03:56:13 +02:00
|
|
|
{ &g_waitingforfill, true } /* TSTATE_WAIT_PAGEFILL */
|
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
};
|
|
|
|
|
2008-01-09 02:13:24 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Private Variables
|
2008-01-09 02:13:24 +01:00
|
|
|
****************************************************************************/
|
2012-07-14 21:30:31 +02:00
|
|
|
/* This is the task control block for this thread of execution. This thread
|
|
|
|
* of execution is the IDLE task. NOTE: the system boots into the IDLE
|
|
|
|
* task. The IDLE task spawns the user initialization task (user_start) and
|
|
|
|
* that user init task is responsible for bringing up the rest of the system
|
2007-02-18 00:21:28 +01:00
|
|
|
*/
|
|
|
|
|
2013-02-04 22:24:00 +01:00
|
|
|
static FAR struct task_tcb_s g_idletcb;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-01 22:05:55 +01:00
|
|
|
/* This is the name of the idle task */
|
|
|
|
|
2012-03-25 23:05:02 +02:00
|
|
|
static FAR const char g_idlename[] = "Idle Task";
|
2007-03-01 22:05:55 +01:00
|
|
|
|
2008-01-09 02:13:24 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Private Function Prototypes
|
2008-01-09 02:13:24 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-09 02:13:24 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Public Functions
|
2008-01-09 02:13:24 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-09 02:13:24 +01:00
|
|
|
/****************************************************************************
|
2012-07-14 21:30:31 +02:00
|
|
|
* Name: os_start
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function is called to initialize the operating system and to spawn
|
|
|
|
* the user initization thread of execution
|
|
|
|
*
|
2008-01-09 02:13:24 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
void os_start(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2007-11-23 23:32:52 +01:00
|
|
|
slldbg("Entry\n");
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-03-12 22:53:18 +01:00
|
|
|
/* Initialize RTOS Data ***************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Initialize all task lists */
|
|
|
|
|
|
|
|
dq_init(&g_readytorun);
|
|
|
|
dq_init(&g_pendingtasks);
|
|
|
|
dq_init(&g_waitingforsemaphore);
|
2007-03-17 23:43:36 +01:00
|
|
|
#ifndef CONFIG_DISABLE_SIGNALS
|
2007-02-18 00:21:28 +01:00
|
|
|
dq_init(&g_waitingforsignal);
|
2007-03-01 00:45:56 +01:00
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_DISABLE_MQUEUE
|
2007-02-18 00:21:28 +01:00
|
|
|
dq_init(&g_waitingformqnotfull);
|
|
|
|
dq_init(&g_waitingformqnotempty);
|
2010-08-14 03:56:13 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_PAGING
|
|
|
|
dq_init(&g_waitingforfill);
|
2007-03-01 00:45:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
dq_init(&g_inactivetasks);
|
2013-03-10 16:32:33 +01:00
|
|
|
sq_init(&g_delayed_kufree);
|
|
|
|
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
|
|
|
|
sq_init(&g_delayed_kfree);
|
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Initialize the logic that determine unique process IDs. */
|
|
|
|
|
|
|
|
g_lastpid = 0;
|
2007-03-01 22:05:55 +01:00
|
|
|
for (i = 0; i < CONFIG_MAX_TASKS; i++)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
|
|
|
g_pidhash[i].tcb = NULL;
|
|
|
|
g_pidhash[i].pid = INVALID_PROCESS_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Assign the process ID of ZERO to the idle task */
|
|
|
|
|
2013-07-27 17:27:37 +02:00
|
|
|
g_pidhash[PIDHASH(0)].tcb = &g_idletcb.cmn;
|
|
|
|
g_pidhash[PIDHASH(0)].pid = 0;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-03-12 22:53:18 +01:00
|
|
|
/* Initialize the IDLE task TCB *******************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Initialize a TCB for this thread of execution. NOTE: The default
|
|
|
|
* value for most components of the g_idletcb are zero. The entire
|
|
|
|
* structure is set to zero. Then only the (potentially) non-zero
|
|
|
|
* elements are initialized. NOTE: The idle task is the only task in
|
|
|
|
* that has pid == 0 and sched_priority == 0.
|
|
|
|
*/
|
|
|
|
|
2013-02-04 22:24:00 +01:00
|
|
|
bzero((void*)&g_idletcb, sizeof(struct task_tcb_s));
|
|
|
|
g_idletcb.cmn.task_state = TSTATE_TASK_RUNNING;
|
|
|
|
g_idletcb.cmn.entry.main = (main_t)os_start;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-03-22 00:37:11 +01:00
|
|
|
/* Set the IDLE task name */
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
2013-02-04 22:24:00 +01:00
|
|
|
strncpy(g_idletcb.cmn.name, g_idlename, CONFIG_TASK_NAME_SIZE-1);
|
2013-03-22 00:37:11 +01:00
|
|
|
#endif /* CONFIG_TASK_NAME_SIZE */
|
|
|
|
|
|
|
|
/* Configure the task name in the argument list. The IDLE task does
|
|
|
|
* not really have an argument list, but this name is still useful
|
|
|
|
* for things like the NSH PS command.
|
|
|
|
*
|
|
|
|
* In the kernel mode build, the arguments are saved on the task's stack
|
|
|
|
* and there is no support that yet.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined(CONFIG_CUSTOM_STACK) || !defined(CONFIG_NUTTX_KERNEL)
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
2013-02-04 22:24:00 +01:00
|
|
|
g_idletcb.argv[0] = g_idletcb.cmn.name;
|
2007-02-18 00:21:28 +01:00
|
|
|
#else
|
2012-03-28 02:10:43 +02:00
|
|
|
g_idletcb.argv[0] = (char*)g_idlename;
|
2007-02-18 00:21:28 +01:00
|
|
|
#endif /* CONFIG_TASK_NAME_SIZE */
|
2013-03-22 00:37:11 +01:00
|
|
|
#endif /* CONFIG_CUSTOM_STACK || !CONFIG_NUTTX_KERNEL */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Then add the idle task's TCB to the head of the ready to run list */
|
|
|
|
|
2007-03-20 20:04:01 +01:00
|
|
|
dq_addfirst((FAR dq_entry_t*)&g_idletcb, (FAR dq_queue_t*)&g_readytorun);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Initialize the processor-specific portion of the TCB */
|
|
|
|
|
2013-02-04 22:24:00 +01:00
|
|
|
up_initial_state(&g_idletcb.cmn);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-03-12 22:53:18 +01:00
|
|
|
/* Initialize RTOS facilities *********************************************/
|
2012-08-26 23:35:14 +02:00
|
|
|
/* Initialize the semaphore facility(if in link). This has to be done
|
|
|
|
* very early because many subsystems depend upon fully functional
|
|
|
|
* semaphores.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
|
|
|
|
if (sem_initialize != NULL)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
sem_initialize();
|
|
|
|
}
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Initialize the memory manager */
|
|
|
|
|
|
|
|
{
|
2007-02-27 22:17:21 +01:00
|
|
|
FAR void *heap_start;
|
2007-02-18 00:21:28 +01:00
|
|
|
size_t heap_size;
|
2013-03-09 22:12:20 +01:00
|
|
|
|
|
|
|
/* Get the user-mode heap from the platform specific code and configure
|
|
|
|
* the user-mode memory allocator.
|
|
|
|
*/
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
up_allocate_heap(&heap_start, &heap_size);
|
2013-03-09 22:12:20 +01:00
|
|
|
kumm_initialize(heap_start, heap_size);
|
|
|
|
|
|
|
|
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
|
|
|
|
/* Get the kernel-mode heap from the platform specific code and configure
|
|
|
|
* the kernel-mode memory allocator.
|
|
|
|
*/
|
|
|
|
|
|
|
|
up_allocate_kheap(&heap_start, &heap_size);
|
2011-04-05 19:33:50 +02:00
|
|
|
kmm_initialize(heap_start, heap_size);
|
2007-02-18 00:21:28 +01:00
|
|
|
#endif
|
2013-03-09 22:12:20 +01:00
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-01-23 00:42:51 +01:00
|
|
|
/* Initialize tasking data structures */
|
|
|
|
|
|
|
|
#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS)
|
|
|
|
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
|
|
|
|
if (task_initialize != NULL)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
task_initialize();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Initialize the interrupt handling subsystem (if included) */
|
|
|
|
|
2007-02-21 00:51:56 +01:00
|
|
|
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
|
2007-02-18 00:21:28 +01:00
|
|
|
if (irq_initialize != NULL)
|
2007-02-21 00:51:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
|
|
|
irq_initialize();
|
|
|
|
}
|
|
|
|
|
2007-03-21 18:21:26 +01:00
|
|
|
/* Initialize the watchdog facility (if included in the link) */
|
|
|
|
|
|
|
|
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
|
|
|
|
if (wd_initialize != NULL)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
wd_initialize();
|
|
|
|
}
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Initialize the POSIX timer facility (if included in the link) */
|
|
|
|
|
2007-02-21 00:51:56 +01:00
|
|
|
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
|
2007-02-18 00:21:28 +01:00
|
|
|
if (clock_initialize != NULL)
|
2007-02-21 00:51:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
|
|
|
clock_initialize();
|
|
|
|
}
|
|
|
|
|
2007-03-21 18:21:26 +01:00
|
|
|
#ifndef CONFIG_DISABLE_POSIX_TIMERS
|
2007-02-21 00:51:56 +01:00
|
|
|
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
|
2007-03-21 18:21:26 +01:00
|
|
|
if (timer_initialize != NULL)
|
2007-02-21 00:51:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2007-03-21 18:21:26 +01:00
|
|
|
timer_initialize();
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
2007-03-21 18:21:26 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Initialize the signal facility (if in link) */
|
|
|
|
|
2007-03-01 00:45:56 +01:00
|
|
|
#ifndef CONFIG_DISABLE_SIGNALS
|
2007-02-21 00:51:56 +01:00
|
|
|
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
|
2007-02-18 00:21:28 +01:00
|
|
|
if (sig_initialize != NULL)
|
2007-02-21 00:51:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
|
|
|
sig_initialize();
|
|
|
|
}
|
2007-03-01 00:45:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Initialize the named message queue facility (if in link) */
|
|
|
|
|
2007-03-01 00:45:56 +01:00
|
|
|
#ifndef CONFIG_DISABLE_MQUEUE
|
2007-02-21 00:51:56 +01:00
|
|
|
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
|
2007-02-18 00:21:28 +01:00
|
|
|
if (mq_initialize != NULL)
|
2007-02-21 00:51:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
|
|
|
mq_initialize();
|
|
|
|
}
|
2007-03-01 00:45:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Initialize the thread-specific data facility (if in link) */
|
|
|
|
|
2007-03-01 22:05:55 +01:00
|
|
|
#ifndef CONFIG_DISABLE_PTHREAD
|
2007-02-21 00:51:56 +01:00
|
|
|
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
|
2007-02-18 00:21:28 +01:00
|
|
|
if (pthread_initialize != NULL)
|
2007-02-21 00:51:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
|
|
|
pthread_initialize();
|
|
|
|
}
|
2007-03-01 22:05:55 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Initialize the file system (needed to support device drivers) */
|
|
|
|
|
2007-03-01 22:05:55 +01:00
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
2007-02-21 00:51:56 +01:00
|
|
|
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
|
2007-02-18 00:21:28 +01:00
|
|
|
if (fs_initialize != NULL)
|
2007-02-21 00:51:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
|
|
|
fs_initialize();
|
|
|
|
}
|
2007-03-01 22:05:55 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-09-09 13:58:50 +02:00
|
|
|
/* Initialize the network system */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET
|
2014-06-28 19:35:14 +02:00
|
|
|
net_initialize();
|
2007-09-09 13:58:50 +02:00
|
|
|
#endif
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* The processor specific details of running the operating system
|
|
|
|
* will be handled here. Such things as setting up interrupt
|
|
|
|
* service routines and starting the clock are some of the things
|
|
|
|
* that are different for each processor and hardware platform.
|
|
|
|
*/
|
|
|
|
|
|
|
|
up_initialize();
|
|
|
|
|
|
|
|
/* Initialize the C libraries (if included in the link). This
|
|
|
|
* is done last because the libraries may depend on the above.
|
|
|
|
*/
|
|
|
|
|
2007-02-21 00:51:56 +01:00
|
|
|
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
|
2007-02-18 00:21:28 +01:00
|
|
|
if (lib_initialize != NULL)
|
2007-02-21 00:51:56 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
|
|
|
lib_initialize();
|
|
|
|
}
|
|
|
|
|
2013-03-12 22:53:18 +01:00
|
|
|
/* IDLE Group Initialization **********************************************/
|
|
|
|
/* Allocate the IDLE group and suppress child status. */
|
|
|
|
|
|
|
|
#ifdef HAVE_TASK_GROUP
|
2013-03-13 18:32:37 +01:00
|
|
|
DEBUGVERIFY(group_allocate(&g_idletcb));
|
2013-03-12 22:53:18 +01:00
|
|
|
#endif
|
|
|
|
|
2012-12-16 22:15:27 +01:00
|
|
|
/* Create stdout, stderr, stdin on the IDLE task. These will be
|
|
|
|
* inherited by all of the threads created by the IDLE task.
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-09-27 21:11:34 +02:00
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0
|
2013-03-13 18:32:37 +01:00
|
|
|
DEBUGVERIFY(group_setupidlefiles(&g_idletcb));
|
2013-09-27 21:11:34 +02:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-01-27 20:17:56 +01:00
|
|
|
/* Complete initialization of the IDLE group. Suppress retention
|
|
|
|
* of child status in the IDLE group.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_TASK_GROUP
|
2013-03-13 18:32:37 +01:00
|
|
|
DEBUGVERIFY(group_initialize(&g_idletcb));
|
2013-02-04 22:24:00 +01:00
|
|
|
g_idletcb.cmn.group->tg_flags = GROUP_FLAG_NOCLDWAIT;
|
2013-01-27 20:17:56 +01:00
|
|
|
#endif
|
|
|
|
|
2013-03-12 22:53:18 +01:00
|
|
|
/* Bring Up the System ****************************************************/
|
2011-03-12 18:49:47 +01:00
|
|
|
/* Create initial tasks and bring-up the system */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-03-13 18:32:37 +01:00
|
|
|
DEBUGVERIFY(os_bringup());
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-03-12 22:53:18 +01:00
|
|
|
/* The IDLE Loop **********************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
/* When control is return to this point, the system is idle. */
|
|
|
|
|
2007-11-23 23:32:52 +01:00
|
|
|
sdbg("Beginning Idle Loop\n");
|
2007-02-18 00:21:28 +01:00
|
|
|
for (;;)
|
|
|
|
{
|
2009-11-06 01:44:22 +01:00
|
|
|
/* Perform garbage collection (if it is not being done by the worker
|
|
|
|
* thread). This cleans-up memory de-allocations that were queued
|
|
|
|
* because they could not be freed in that execution context (for
|
2009-11-05 23:58:36 +01:00
|
|
|
* example, if the memory was freed from an interrupt handler).
|
2007-03-14 19:58:21 +01:00
|
|
|
*/
|
2009-11-06 01:44:22 +01:00
|
|
|
|
|
|
|
#ifndef CONFIG_SCHED_WORKQUEUE
|
|
|
|
/* We must have exclusive access to the memory manager to do this
|
|
|
|
* BUT the idle task cannot wait on a semaphore. So we only do
|
|
|
|
* the cleanup now if we can get the semaphore -- this should be
|
|
|
|
* possible because if the IDLE thread is running, no other task is!
|
|
|
|
*/
|
|
|
|
|
2011-04-05 19:33:50 +02:00
|
|
|
if (kmm_trysemaphore() == 0)
|
2009-11-06 01:44:22 +01:00
|
|
|
{
|
|
|
|
sched_garbagecollection();
|
2011-04-05 19:33:50 +02:00
|
|
|
kmm_givesemaphore();
|
2009-11-06 01:44:22 +01:00
|
|
|
}
|
2009-11-05 23:58:36 +01:00
|
|
|
#endif
|
2007-03-14 19:58:21 +01:00
|
|
|
|
|
|
|
/* Perform any processor-specific idle state operations */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
up_idle();
|
|
|
|
}
|
|
|
|
}
|