From b0ba370bfbf6159ab90f79475ac69124553cc50f Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sat, 20 Jul 2013 09:55:09 +0200 Subject: Added multithreading test for QEMU. --- .gdbinit | 23 +++++++++++++++++++++++ .gitignore | 5 +++++ .gitmodules | 3 +++ SConstruct | 13 +++++++++++++ laks | 1 + main.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ test.py | 23 +++++++++++++++++++++++ 7 files changed, 114 insertions(+) create mode 100644 .gdbinit create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 SConstruct create mode 160000 laks create mode 100644 main.cpp create mode 100755 test.py 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 index 0000000..e14b2f0 --- /dev/null +++ b/laks @@ -0,0 +1 @@ +Subproject commit e14b2f0d2406311a6fcdaea313584995ec8adefd 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 +#include +#include +#include + +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()) -- cgit v1.2.3