aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJakob Odersky <jodersky@gmail.com>2014-03-30 22:38:35 +0200
committerJakob Odersky <jodersky@gmail.com>2014-03-30 22:38:35 +0200
commitf93ab955074e213ad6f2bf60522cc86952d57d83 (patch)
tree65af07c02d6f0541f31cddef9cd564189395952b /test
parent2500120f64db83fc682f38a83f7f9e03ed8a5123 (diff)
downloadmux-f93ab955074e213ad6f2bf60522cc86952d57d83.tar.gz
mux-f93ab955074e213ad6f2bf60522cc86952d57d83.tar.bz2
mux-f93ab955074e213ad6f2bf60522cc86952d57d83.zip
major update
Diffstat (limited to 'test')
-rw-r--r--test/locks/main.c55
-rw-r--r--test/scheduler/main.c59
2 files changed, 114 insertions, 0 deletions
diff --git a/test/locks/main.c b/test/locks/main.c
new file mode 100644
index 0000000..526d75f
--- /dev/null
+++ b/test/locks/main.c
@@ -0,0 +1,55 @@
+#include <stddef.h>
+#include <stdio.h>
+#include <avr/pgmspace.h>
+#include <avr/interrupt.h>
+#include "task/task.h"
+#include "task/sched.h"
+#include "bug/panic.h"
+#include "bug/debug.h"
+#include "task/lock.h"
+#include "time/clock.h"
+#include "mcu/task/context.h"
+#include "tshield/tshield.h"
+
+#define WAIT_CYCLES(cycles) for (volatile unsigned long i = 0; i < cycles; ++i) {}
+
+spin_lock_t on_lock = SPIN_LOCK_UNLOCKED;
+volatile char on = 0;
+
+void read(char id) {
+ while(1) {
+ spin_lock(&on_lock);
+ debug_led(0,on);
+ spin_unlock(&on_lock);
+ }
+}
+
+void write( char id) {
+ while(1) {
+ spin_lock(&on_lock);
+ on = !on;
+ WAIT_CYCLES(30000);
+ spin_unlock(&on_lock);
+ }
+}
+
+
+DECLARE_TASK(task1, DEFAULT_STACK_SIZE, read, 1);
+DECLARE_TASK(task2, DEFAULT_STACK_SIZE, write, 2);
+
+
+int main(int argc, char *argv[]) {
+ cli();
+ tshield_init();
+
+
+ spawn(&task1);
+ spawn(&task2);
+
+ sei();
+ clock_init(10, schedule);
+ clock_start();
+ sched_init();
+ panic(); //should never reach here
+ while(1){}
+}
diff --git a/test/scheduler/main.c b/test/scheduler/main.c
new file mode 100644
index 0000000..79ca41b
--- /dev/null
+++ b/test/scheduler/main.c
@@ -0,0 +1,59 @@
+#include <stddef.h>
+#include <stdio.h>
+#include <avr/pgmspace.h>
+#include <avr/interrupt.h>
+#include "task/task.h"
+#include "task/sched.h"
+#include "bug/panic.h"
+#include "bug/debug.h"
+#include "mcu/task/context.h"
+#include "tshield/tshield.h"
+
+#define WAIT_CYCLES(cycles) for (volatile unsigned long i = 0; i < cycles; ++i) {}
+
+struct list_head frozen = LIST_HEAD_INIT(frozen);
+
+void freeze() __attribute__ ( ( naked ) );
+void freeze() {
+ context_save();
+ sleep_queue(&frozen);
+ schedule();
+ context_restore();
+}
+
+void blink( char id) {
+ while(1) {
+ debug_led(id - 1,1);
+ WAIT_CYCLES((long) 30000);
+ debug_led(id - 1,0);
+ WAIT_CYCLES((long) 30000);
+ }
+}
+
+
+DECLARE_TASK(task1, DEFAULT_STACK_SIZE, blink, 1);
+DECLARE_TASK(task2, DEFAULT_STACK_SIZE, blink, 2);
+DECLARE_TASK(task3, DEFAULT_STACK_SIZE, blink, 3);
+DECLARE_TASK(task4, DEFAULT_STACK_SIZE, blink, 4);
+
+
+int main(int argc, char *argv[]) {
+ cli();
+ tshield_init();
+
+
+
+ spawn(&task1);
+ spawn(&task2);
+ spawn(&task3);
+ spawn(&task4);
+
+ sei();
+ clock_init(10, schedule);
+ clock_start();
+ sched_init();
+
+
+ panic(); //should never reach here
+ while(1){}
+}