summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2013-07-20 09:55:09 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2013-07-20 09:55:09 +0200
commitb0ba370bfbf6159ab90f79475ac69124553cc50f (patch)
treecc6560bfe6a07fd58ee9b5d7ebd850f7e6b8b7a7
Added multithreading test for QEMU.qemu
-rw-r--r--.gdbinit23
-rw-r--r--.gitignore5
-rw-r--r--.gitmodules3
-rw-r--r--SConstruct13
m---------laks0
-rw-r--r--main.cpp46
-rwxr-xr-xtest.py23
7 files changed, 113 insertions, 0 deletions
diff --git a/.gdbinit b/.gdbinit
new file mode 100644
index 0000000..379d786
--- /dev/null
+++ b/.gdbinit
@@ -0,0 +1,23 @@
+define flash
+file demo.elf
+load
+end
+
+define restart
+run
+end
+
+define attach_swd
+mon swdp_scan
+attach 1
+end
+
+define attach_jtag
+mon jtag_scan
+attach 1
+end
+
+file demo.elf
+target extended-remote :1234
+
+set mem inaccessible-by-default off
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..b137a4a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+*.o
+*.a
+*.elf
+*.swp
+.sconsign.dblite
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..cd4f3c2
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "laks"]
+ path = laks
+ url = git://git.jvnv.net/laks.git
diff --git a/SConstruct b/SConstruct
new file mode 100644
index 0000000..c2d0f90
--- /dev/null
+++ b/SConstruct
@@ -0,0 +1,13 @@
+import os
+
+env = Environment(
+ ENV = os.environ,
+)
+
+SConscript('laks/build_rules')
+
+env.SelectMCU('qemu')
+
+env.Firmware('demo.elf', Glob('*.cpp'))
+
+# To execute: qemu-system-arm -machine lm3s6965evb -nographic -serial null -monitor null -semihosting -kernel demo.elf
diff --git a/laks b/laks
new file mode 160000
+Subproject e14b2f0d2406311a6fcdaea313584995ec8adef
diff --git a/main.cpp b/main.cpp
new file mode 100644
index 0000000..7fe7f73
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,46 @@
+#include <stdint.h>
+#include <os/time.h>
+#include <os/thread.h>
+#include <util/semihosting.h>
+
+void idle_main() {
+ // QEMU does not support SLEEPONEXIT yet, so we need to keep at least one thread ready at all times.
+ // By executing wfi in a loop, we force the cpu into sleep until next systick (or other interrupt), regardless of whether other threads are ready or not.
+ // This has the consequence that we sleep for up to 1ms each time we've interated through the ready queue, even if other threads are still ready.
+
+ while(1) {
+ asm volatile("wfi");
+ Thread::yield();
+ }
+}
+
+uint32_t idle_stack[1024];
+
+Thread idle_thread(idle_stack, sizeof(idle_stack), idle_main);
+
+void foo_main() {
+ while(1) {
+ semihosting_print("foo\n");
+ Thread::sleep(2000);
+ }
+}
+
+uint32_t foo_stack[1024];
+
+Thread foo_thread(foo_stack, sizeof(foo_stack), foo_main);
+
+int main() {
+ // Initialize system timer.
+ STK.LOAD = 12500000 / 1000; // 1000 Hz.
+ STK.CTRL = 0x07;
+
+ idle_thread.start();
+ foo_thread.start();
+
+ for(int i = 0; i < 5; i++) {
+ semihosting_print("main\n");
+ Thread::sleep(5000);
+ }
+
+ semihosting_exit();
+}
diff --git a/test.py b/test.py
new file mode 100755
index 0000000..481b36d
--- /dev/null
+++ b/test.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+
+import subprocess, time
+
+qemu = subprocess.Popen(
+ 'qemu-system-arm -machine lm3s6965evb -nographic -serial null -semihosting -kernel demo.elf -S'.split(),
+ stdin = subprocess.PIPE,
+ stdout = subprocess.PIPE,
+ stderr = subprocess.PIPE,
+)
+
+qemu.stdin.write('cont\n')
+
+start = time.time();
+
+while 1:
+ line = qemu.stderr.readline()
+ t = time.time()
+
+ if not line:
+ break
+
+ print '[%11.6f] %s' % (t - start, line.strip())