summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2013-06-05 17:26:38 +0900
committerNIIBE Yutaka <gniibe@fsij.org>2013-06-05 17:26:38 +0900
commit2fea34dd1c2224dad55b83700b944aa26c6cf9fc (patch)
treeb28adc353567892fd6d775e0ce1cb68ec50638d5
parent0ae3b2681fd3428baffc06cefadc40a90dcd5da4 (diff)
bug fixes for SCHED_RR
-rw-r--r--ChangeLog4
-rw-r--r--chopstx.c24
-rw-r--r--example-led/Makefile3
-rw-r--r--example-led/sample.c29
4 files changed, 48 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 3a590cf..51915cc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,10 @@
(chopstx_wakeup_usec_wait): New.
(chopstx_usec_wait): Accept wakeup to break.
(chopstx_usec_wait_internal): New.
+ (CHX_FLAGS_MAIN): New.
+ (chx_systick_init): Add chx_timer_insert for main.
+ (chx_set_timer): Don't set thread state.
+ (chopstx_usec_wait_internal): Set thread state to THREAD_WAIT_TIME.
2013-06-04 Niibe Yutaka <gniibe@fsij.org>
diff --git a/chopstx.c b/chopstx.c
index dfb655a..486adc0 100644
--- a/chopstx.c
+++ b/chopstx.c
@@ -37,6 +37,10 @@
#if !defined(CHX_PRIO_MAIN)
#define CHX_PRIO_MAIN 1
#endif
+#if !defined(CHX_FLAGS_MAIN)
+#define CHX_FLAGS_MAIN 0
+#endif
+
#define MAX_PRIO 255
/*
@@ -504,10 +508,7 @@ chx_set_timer (struct chx_thread *q, uint32_t ticks)
*SYST_RVR = 0;
}
else
- {
- q->state = THREAD_WAIT_TIME;
- q->v = ticks;
- }
+ q->v = ticks;
}
static void
@@ -675,6 +676,15 @@ chx_systick_init (void)
*SYST_RVR = 0;
*SYST_CVR = 0;
*SYST_CSR = 7;
+
+ if ((CHX_FLAGS_MAIN & CHOPSTX_SCHED_RR))
+ {
+ chx_cpu_sched_lock ();
+ chx_spin_lock (&q_timer.lock);
+ chx_timer_insert (running, PREEMPTION_USEC);
+ chx_spin_unlock (&q_timer.lock);
+ chx_cpu_sched_unlock ();
+ }
}
static uint32_t *const AIRCR = (uint32_t *const)0xE000ED0C;
@@ -698,8 +708,9 @@ chx_init (struct chx_thread *tp)
tp->mutex_list = NULL;
tp->clp = NULL;
tp->state = THREAD_RUNNING;
- tp->flag_detached = tp->flag_got_cancel
- = tp->flag_join_req = tp->flag_sched_rr = 0;
+ tp->flag_got_cancel = tp->flag_join_req = 0;
+ tp->flag_sched_rr = (CHX_FLAGS_MAIN & CHOPSTX_SCHED_RR)? 1 : 0;
+ tp->flag_detached = (CHX_FLAGS_MAIN & CHOPSTX_DETACHED)? 1 : 0;
tp->prio_orig = tp->prio = CHX_PRIO_MAIN;
tp->v = 0;
@@ -861,6 +872,7 @@ chopstx_usec_wait_internal (uint32_t *arg)
if (running->flag_sched_rr)
chx_timer_dequeue (running);
chx_spin_lock (&q_timer.lock);
+ running->state = THREAD_WAIT_TIME;
chx_timer_insert (running, usec0);
chx_spin_unlock (&q_timer.lock);
asm ("" : "=r" (usec_p) : "r" (usec_p));
diff --git a/example-led/Makefile b/example-led/Makefile
index 085d42b..f06a274 100644
--- a/example-led/Makefile
+++ b/example-led/Makefile
@@ -14,7 +14,8 @@ OBJCOPY = $(CROSS)objcopy
MCU = cortex-m3
CWARN = -Wall -Wextra -Wstrict-prototypes
-DEFS = -DFREE_STANDING
+# DEFS = -DFREE_STANDING
+DEFS = -DFREE_STANDING -DBUSY_LOOP -DCHX_FLAGS_MAIN=CHOPSTX_SCHED_RR
OPT = -O3 -Os -g
LIBS =
diff --git a/example-led/sample.c b/example-led/sample.c
index c1036d6..c89b2bc 100644
--- a/example-led/sample.c
+++ b/example-led/sample.c
@@ -10,6 +10,20 @@ static chopstx_cond_t cnd1;
static uint8_t u, v;
static uint8_t m; /* 0..100 */
+static void
+wait_for (uint32_t usec)
+{
+#if defined(BUSY_LOOP)
+ uint32_t count = usec *18;
+ uint32_t i;
+
+ for (i = 0; i < count; i++)
+ asm volatile ("" : : "r" (i) : "memory");
+#else
+ chopstx_usec_wait (usec);
+#endif
+}
+
static void *
pwm (void *arg)
{
@@ -22,9 +36,9 @@ pwm (void *arg)
while (1)
{
set_led (u&v);
- chopstx_usec_wait (m);
+ wait_for (m);
set_led (0);
- chopstx_usec_wait (100-m);
+ wait_for (100-m);
}
return NULL;
@@ -42,16 +56,21 @@ blk (void *arg)
while (1)
{
v = 0;
- chopstx_usec_wait (200*1000);
+ wait_for (200*1000);
v = 1;
- chopstx_usec_wait (200*1000);
+ wait_for (200*1000);
}
return NULL;
}
+#if defined(BUSY_LOOP)
+#define PRIO_PWM (CHOPSTX_SCHED_RR|1)
+#define PRIO_BLK (CHOPSTX_SCHED_RR|1)
+#else
#define PRIO_PWM 3
#define PRIO_BLK 2
+#endif
extern uint8_t __process1_stack_base__, __process1_stack_size__;
extern uint8_t __process2_stack_base__, __process2_stack_size__;
@@ -88,7 +107,7 @@ main (int argc, const char *argv[])
while (1)
{
u ^= 1;
- chopstx_usec_wait (200*1000*6);
+ wait_for (200*1000*6);
}
return 0;