Esempio n. 1
0
/**
 *
 * @brief Power management policy when kernel begins idling
 *
 * This routine implements the power management policy based on the time
 * until the timer expires, in system ticks.
 * Routine is invoked from the idle task with interrupts disabled
 *
 * @return N/A
 */
void _sys_power_save_idle(int32_t ticks)
{
#if defined(CONFIG_TICKLESS_IDLE)
	if ((ticks == TICKS_UNLIMITED) || ticks >= _sys_idle_threshold_ticks) {
		/*
		 * Stop generating system timer interrupts until it's time for
		 * the next scheduled microkernel timer to expire.
		 */

		_timer_idle_enter(ticks);
	}
#endif /* CONFIG_TICKLESS_IDLE */

#ifdef CONFIG_ADVANCED_IDLE
	/*
	 * Call the advanced sleep function, which checks if the system should
	 * enter a deep sleep state. If so, the function will return a non-zero
	 * value when the system resumes here after the deep sleep ends.
	 * If the time to sleep is too short to go to advanced sleep mode, the
	 * function returns zero immediately and we do normal idle processing.
	 */

	if (_AdvIdleFunc(ticks) == 0) {
		nano_cpu_set_idle(ticks);
		nano_cpu_idle();
	}
#else
	nano_cpu_set_idle(ticks);
	nano_cpu_idle();
#endif /* CONFIG_ADVANCED_IDLE */
}
Esempio n. 2
0
/**
 *
 * @brief Power saving when idle
 *
 * If _sys_power_save_flag is non-zero, this routine keeps the system in a low
 * power state whenever the kernel is idle. If it is zero, this routine will
 * fall through and _k_kernel_idle() will try the next idling mechanism.
 *
 * @return N/A
 *
 */
static void _power_save(void)
{
	if (_sys_power_save_flag) {
		for (;;) {
			irq_lock();
#ifdef CONFIG_ADVANCED_POWER_MANAGEMENT
			_sys_power_save_idle(_get_next_timer_expiry());
#else
			/*
			 * nano_cpu_idle() is invoked here directly only if APM
			 * is disabled. Otherwise the microkernel decides
			 * either to invoke it or to implement advanced idle
			 * functionality
			 */

			nano_cpu_idle();
#endif
		}

		/*
		 * Code analyzers may complain that _power_save() uses an
		 * infinite loop unless we indicate that this is intentional
		 */

		CODE_UNREACHABLE;
	}
}
/**
 * @brief Manokernel entry point.
 *
 * @details Start the kernel event data colector fiber. Then
 * do wait forever.
 * @return No return value.
 */
int main(void)
{
	int i;

#ifdef CONFIG_MICROKERNEL
	tmon_index = 0;
#endif
	kernel_event_logger_fiber_start();

	/* initialize philosopher semaphores */
	for (i = 0; i < N_PHILOSOPHERS; i++) {
		nano_sem_init(&forks[i]);
		nano_task_sem_give(&forks[i]);
	}

	/* create philosopher fibers */
	for (i = 0; i < N_PHILOSOPHERS; i++) {
		task_fiber_start(&philStack[i][0], STSIZE,
						(nano_fiber_entry_t) philEntry, 0, 0, 6, 0);
	}

	task_fiber_start(&philStack[N_PHILOSOPHERS][0], STSIZE,
		(nano_fiber_entry_t) fork_manager_entry, 0, 0, 6, 0);

	/* wait forever */
	while (1) {
		extern void nano_cpu_idle(void);
		nano_cpu_idle();
	}
}
Esempio n. 4
0
/**
 *
 * @brief Power management policy when kernel begins idling
 *
 * This routine implements the power management policy based on the time
 * until the timer expires, in system ticks.
 * Routine is invoked from the idle task with interrupts disabled
 *
 * @return N/A
 */
void _sys_power_save_idle(int32_t ticks)
{
#if defined(CONFIG_TICKLESS_IDLE)
	if ((ticks == TICKS_UNLIMITED) || ticks >= _sys_idle_threshold_ticks) {
		/*
		 * Stop generating system timer interrupts until it's time for
		 * the next scheduled microkernel timer to expire.
		 */

		_timer_idle_enter(ticks);
	}
#endif /* CONFIG_TICKLESS_IDLE */

	nano_cpu_set_idle(ticks);
#if (defined(CONFIG_SYS_POWER_LOW_POWER_STATE) || \
	defined(CONFIG_SYS_POWER_DEEP_SLEEP) || \
	defined(CONFIG_DEVICE_POWER_MANAGEMENT))
	/*
	 * Call the suspend hook function, which checks if the system should
	 * enter deep sleep, low power state or only suspend devices.
	 * If the time available is too short for any PM operation then
	 * the function returns SYS_PM_NOT_HANDLED immediately and kernel
	 * does normal idle processing. Otherwise it will return the code
	 * corresponding to the action taken.
	 *
	 * This function can just suspend devices without entering
	 * deep sleep or cpu low power state.  In this case it should return
	 * SYS_PM_DEVICE_SUSPEND_ONLY and kernel would do normal idle
	 * processing.
	 *
	 * This function is entered with interrupts disabled. If the function
	 * returns either SYS_PM_LOW_POWER_STATE or SYS_PM_DEEP_SLEEP then
	 * it should ensure interrupts are re-enabled before returning.
	 * This is because the kernel does not do its own idle processing in
	 * these cases i.e. skips nano_cpu_idle(). The kernel's idle
	 * processing re-enables interrupts which is essential for kernel's
	 * scheduling logic.
	 */
	if (!(_sys_soc_suspend(ticks) &
			(SYS_PM_DEEP_SLEEP | SYS_PM_LOW_POWER_STATE))) {
		nano_cpu_idle();
	}
#else
	nano_cpu_idle();
#endif
}
Esempio n. 5
0
int nano_cpu_idleTest(void)
{
	int  tick;   /* current tick count */
	int  i;      /* loop variable */

	/* Align to a "tick boundary". */
	tick = sys_tick_get_32();
	while (tick == sys_tick_get_32()) {
	}
	tick = sys_tick_get_32();

	for (i = 0; i < 5; i++) {     /* Repeat the test five times */
		nano_cpu_idle();
		tick++;
		if (sys_tick_get_32() != tick) {
			return TC_FAIL;
		}
	}

	return TC_PASS;
}
Esempio n. 6
0
int main(void)
{
	int i;

	PRINTF(DEMO_DESCRIPTION, "fibers", "nanokernel");

	for (i = 0; i < N_PHILOSOPHERS; i++) {
		nano_sem_init(&forks[i]);
		nano_task_sem_give(&forks[i]);
	}

	/* create philosopher fibers */
	for (i = 0; i < N_PHILOSOPHERS; i++) {
		task_fiber_start(&philStack[i][0], STSIZE,
						(nano_fiber_entry_t) philEntry, 0, 0, 6, 0);
	}

	/* wait forever */
	while (1) {
		extern void nano_cpu_idle(void);
		nano_cpu_idle();
	}
}