Looks like it’s that time of year again: I’m ripping apart what I have in JeeH
5.3 and reconstructing it in a different way. Perhaps it’s just madness, but I
have two reasons to do this: 1) the task/thread design is too
messy and 2) the way I can add and run tests is too tedious.
Tasks vs threads
#
The first issue was unavoidable, once I figured out that tasks should not be an
add-on to a threaded system, but exactly the other way around: threads are a
special kind of task. Threads are tasks with their own stack, which can
therefore be suspended and resumed. Tasks can’t: they either run to completion
or they act on their “owning thread’s” behalf, i.e. they suspend their thread
with them, if needed. This change puts tasks first, and optionally adds
threads and context switching when needed. Then again, the reality is a bit more
complex: there is in fact always one thread, the main()
app code. It’s just
that there’s no context switching involved until at least a second thread is
created (with sys::fork()
, as before). To support this, JeeH must be given an
extra stack for interrupts, exceptions, and system calls, so that it can use
ARM’s PSP + MSP dual stack approach (as before) and use PendSV for context
switching.