Support sleep on idle.
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
2017-11-15 NIIBE Yutaka <gniibe@fsij.org>
|
||||
|
||||
* chopstx.c (chx_init): Initialize sleep lock.
|
||||
(chopstx_conf_idle): New.
|
||||
* chopstx-cortex-m.c (idle): Support sleep.
|
||||
|
||||
* mcu/usb-stm32f103.c (usb_lld_event_handler): Fix suspend/resume.
|
||||
|
||||
2017-11-14 NIIBE Yutaka <gniibe@fsij.org>
|
||||
|
||||
@@ -232,12 +232,14 @@ chx_cpu_sched_unlock (void)
|
||||
static void __attribute__((naked, used))
|
||||
idle (void)
|
||||
{
|
||||
#if defined(USE_WFI_FOR_IDLE)
|
||||
int sleep_enabled;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
asm ("ldr %0, %1" : "=r" (sleep_enabled): "m" (chx_allow_sleep));
|
||||
if (sleep_enabled)
|
||||
asm volatile ("wfi" : : : "memory");
|
||||
#else
|
||||
for (;;);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
26
chopstx.c
26
chopstx.c
@@ -79,6 +79,10 @@ chx_fatal (uint32_t err_code)
|
||||
#include "chopstx-cortex-m.h"
|
||||
#endif
|
||||
|
||||
/* ALLOW_SLEEP for idle */
|
||||
int chx_allow_sleep;
|
||||
static struct chx_spinlock chx_enable_sleep_lock;
|
||||
|
||||
/* RUNNING: the current thread. */
|
||||
struct chx_thread *running;
|
||||
|
||||
@@ -441,6 +445,7 @@ chx_init (struct chx_thread *tp)
|
||||
{
|
||||
chx_prio_init ();
|
||||
chx_init_arch (tp);
|
||||
chx_spin_init (&chx_enable_sleep_lock);
|
||||
|
||||
q_ready.q.next = q_ready.q.prev = (struct chx_pq *)&q_ready.q;
|
||||
chx_spin_init (&q_ready.lock);
|
||||
@@ -1470,3 +1475,24 @@ chopstx_setpriority (chopstx_prio_t prio_new)
|
||||
|
||||
return prio_orig;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* chopstx_conf_idle - Configure IDLE thread
|
||||
* @enable_sleep: Enable sleep on idle or not
|
||||
*
|
||||
* If @enable_sleep is true, allow sleep for the idle thread.
|
||||
* Return previous value of @enable_sleep.
|
||||
*/
|
||||
int
|
||||
chopstx_conf_idle (int enable_sleep)
|
||||
{
|
||||
int r;
|
||||
|
||||
chx_spin_lock (&chx_enable_sleep_lock);
|
||||
r = chx_allow_sleep;
|
||||
chx_allow_sleep = enable_sleep;
|
||||
chx_spin_unlock (&chx_enable_sleep_lock);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* chopstx.h - Threads and only threads.
|
||||
*
|
||||
* Copyright (C) 2013, 2016 Flying Stone Technology
|
||||
* Copyright (C) 2013, 2016, 2017 Flying Stone Technology
|
||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
||||
*
|
||||
* This file is a part of Chopstx, a thread library for embedded.
|
||||
@@ -160,4 +160,6 @@ void chopstx_intr_wait (chopstx_intr_t *intr); /* DEPRECATED */
|
||||
|
||||
int chopstx_poll (uint32_t *usec_p, int n, struct chx_poll_head *pd_array[]);
|
||||
|
||||
int chopstx_conf_idle (int enable_sleep);
|
||||
|
||||
#define CHOPSTX_THREAD_SIZE 64
|
||||
|
||||
Reference in New Issue
Block a user