2008-06-01 15:18:51 +02:00
|
|
|
/****************************************************************************
|
2014-08-07 19:39:16 +02:00
|
|
|
* arch/sim/src/up_idle.c
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2016-02-11 19:16:19 +01:00
|
|
|
* Copyright (C) 2007-2009, 2011-2012, 2014, 2016 Gregory Nutt. All rights reserved.
|
2012-01-22 17:42:49 +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.
|
2007-08-27 01:18:13 +02: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-06-01 15:18:51 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-06-01 15:18:51 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2008-06-01 15:18:51 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2009-12-16 15:52:56 +01:00
|
|
|
|
2016-02-11 21:10:19 +01:00
|
|
|
#include <pthread.h>
|
2008-11-30 19:51:40 +01:00
|
|
|
#include <time.h>
|
2011-09-04 21:24:27 +02:00
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <nuttx/arch.h>
|
2016-02-20 21:56:25 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
# include <nuttx/power/pm.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
# include <nuttx/spinlock.h>
|
|
|
|
#endif
|
2011-09-04 21:24:27 +02:00
|
|
|
|
2014-09-30 22:41:23 +02:00
|
|
|
#include "up_internal.h"
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-03-27 19:18:54 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#define PM_IDLE_DOMAIN 0 /* Revisit */
|
|
|
|
|
2008-06-01 15:18:51 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Private Data
|
2008-06-01 15:18:51 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-11-30 19:51:40 +01:00
|
|
|
#ifdef CONFIG_SIM_X11FB
|
|
|
|
static int g_x11refresh = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(CONFIG_SIM_WALLTIME) || defined(CONFIG_SIM_X11FB)
|
|
|
|
extern int up_hostusleep(unsigned int usec);
|
|
|
|
#ifdef CONFIG_SIM_X11FB
|
|
|
|
extern void up_x11update(void);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2008-06-01 15:18:51 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-06-01 15:18:51 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Name: up_idle
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* up_idle() is the logic that will be executed when their
|
|
|
|
* is no other ready-to-run task. This is processor idle
|
|
|
|
* time and will continue until some interrupt occurs to
|
|
|
|
* cause a context switch from the idle task.
|
|
|
|
*
|
|
|
|
* Processing in this state may be processor-specific. e.g.,
|
|
|
|
* this is where power management operations might be
|
|
|
|
* performed.
|
|
|
|
*
|
2008-06-01 15:18:51 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
void up_idle(void)
|
|
|
|
{
|
2016-02-11 19:16:19 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* In the SMP configuration, only one CPU should do these operations. It
|
|
|
|
* should not matter which, however.
|
|
|
|
*/
|
|
|
|
|
2016-11-26 15:47:03 +01:00
|
|
|
static volatile spinlock_t lock SP_SECTION = SP_UNLOCKED;
|
2016-02-11 19:16:19 +01:00
|
|
|
|
|
|
|
/* The one that gets the lock is the one that executes the IDLE operations */
|
|
|
|
|
|
|
|
if (up_testset(&lock) != SP_UNLOCKED)
|
|
|
|
{
|
2016-02-12 15:13:44 +01:00
|
|
|
/* We didn't get it... Give other pthreads/CPUs a shot and try again
|
|
|
|
* later.
|
|
|
|
*/
|
2016-02-11 19:16:19 +01:00
|
|
|
|
2016-02-12 15:13:44 +01:00
|
|
|
pthread_yield();
|
2016-02-11 19:16:19 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-08-07 02:29:29 +02:00
|
|
|
#ifdef CONFIG_SCHED_TICKLESS
|
|
|
|
/* Driver the simulated interval timer */
|
|
|
|
|
|
|
|
up_timer_update();
|
|
|
|
#else
|
2007-03-08 00:34:48 +01:00
|
|
|
/* If the system is idle, then process "fake" timer interrupts.
|
|
|
|
* Hopefully, something will wake up.
|
2007-02-18 00:21:28 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
sched_process_timer();
|
2014-08-07 02:29:29 +02:00
|
|
|
#endif
|
2007-08-27 01:18:13 +02:00
|
|
|
|
2014-10-01 22:59:51 +02:00
|
|
|
#if defined(CONFIG_DEV_CONSOLE) && !defined(CONFIG_SIM_UART_DATAPOST)
|
|
|
|
/* Handle UART data availability */
|
|
|
|
|
|
|
|
if (g_uart_data_available)
|
|
|
|
{
|
|
|
|
g_uart_data_available = 0;
|
|
|
|
simuart_post();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-04-03 01:46:22 +02:00
|
|
|
#if defined(CONFIG_NET_ETHERNET) && defined(CONFIG_SIM_NETDEV)
|
2014-10-01 22:59:51 +02:00
|
|
|
/* Run the network if enabled */
|
|
|
|
|
2014-07-04 01:53:16 +02:00
|
|
|
netdriver_loop();
|
2008-11-30 19:51:40 +01:00
|
|
|
#endif
|
|
|
|
|
2014-10-01 22:59:51 +02:00
|
|
|
#ifdef CONFIG_PM
|
2011-09-04 21:24:27 +02:00
|
|
|
/* Fake some power management stuff for testing purposes */
|
|
|
|
|
|
|
|
{
|
|
|
|
static enum pm_state_e state = PM_NORMAL;
|
|
|
|
enum pm_state_e newstate;
|
|
|
|
|
2016-03-27 21:01:32 +02:00
|
|
|
newstate = pm_checkstate(PM_IDLE_DOMAIN);
|
2011-09-04 21:24:27 +02:00
|
|
|
if (newstate != state)
|
|
|
|
{
|
2016-03-27 19:18:54 +02:00
|
|
|
if (pm_changestate(PM_IDLE_DOMAIN, newstate) == OK)
|
2011-09-04 21:24:27 +02:00
|
|
|
{
|
|
|
|
state = newstate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-10-01 22:59:51 +02:00
|
|
|
#if defined(CONFIG_SIM_WALLTIME) || defined(CONFIG_SIM_X11FB)
|
2008-11-30 19:51:40 +01:00
|
|
|
/* Wait a bit so that the sched_process_timer() is called close to the
|
|
|
|
* correct rate.
|
|
|
|
*/
|
|
|
|
|
|
|
|
(void)up_hostusleep(1000000 / CLK_TCK);
|
2011-09-29 23:13:49 +02:00
|
|
|
|
|
|
|
/* Handle X11-related events */
|
|
|
|
|
2008-11-30 19:51:40 +01:00
|
|
|
#ifdef CONFIG_SIM_X11FB
|
2011-10-06 18:31:13 +02:00
|
|
|
if (g_x11initialized)
|
2011-09-29 23:13:49 +02:00
|
|
|
{
|
2014-12-14 17:19:07 +01:00
|
|
|
#if defined(CONFIG_SIM_TOUCHSCREEN) || defined(CONFIG_SIM_AJOYSTICK)
|
2012-02-08 01:05:36 +01:00
|
|
|
/* Drive the X11 event loop */
|
2011-10-06 18:31:13 +02:00
|
|
|
|
|
|
|
if (g_eventloop)
|
|
|
|
{
|
|
|
|
up_x11events();
|
|
|
|
}
|
2011-09-29 23:13:49 +02:00
|
|
|
#endif
|
|
|
|
|
2011-10-06 18:31:13 +02:00
|
|
|
/* Update the display periodically */
|
2011-09-29 23:13:49 +02:00
|
|
|
|
2011-10-06 18:31:13 +02:00
|
|
|
g_x11refresh += 1000000 / CLK_TCK;
|
|
|
|
if (g_x11refresh > 500000)
|
|
|
|
{
|
|
|
|
up_x11update();
|
|
|
|
}
|
2008-11-30 19:51:40 +01:00
|
|
|
}
|
|
|
|
#endif
|
2007-08-27 01:18:13 +02:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-11 19:16:19 +01:00
|
|
|
#ifdef CONFIG_SMP
|
2016-02-11 21:10:19 +01:00
|
|
|
/* Release the spinlock */
|
2016-02-11 19:16:19 +01:00
|
|
|
|
|
|
|
lock = SP_UNLOCKED;
|
2016-02-11 21:10:19 +01:00
|
|
|
|
|
|
|
/* Give other pthreads/CPUs a shot */
|
|
|
|
|
2016-02-12 15:13:44 +01:00
|
|
|
pthread_yield();
|
2016-02-11 19:16:19 +01:00
|
|
|
#endif
|
|
|
|
}
|