Home

Awesome

STM8-Multi-Tasker

Cooperative/Preemptive Round Robin Scheduler for STM8

Stability: Not Ready In Development

Status: Broken Do Not Use Yet

Version: 0.0

A tiny scheduler to allow threading with stack based context switching to be used on the STM8 micro processor. Implemented with SDCC in mixed C and assembler. Using CMake with JetBrains CLion IDE. (TODO: Add Instructions on how to set it up to work reasonably well).

The core is written in assembler to reduce size. The SDCC compiler does not produce very efficient code for the STM8. I opted out to optimize reusable code, then I can use C for specific projects with less concern for space.

<!-- Minimal cooperative multi tasking is less than 500 bytes of code and 8 bytes of data, with additional per task data penalty of 6 bytes + task's stack size. With tick timer functionality to allow timed suspensions, less than 700 bytes of code and 16 bytes of data. It will also increase per task data use to 8 bytes + task's stack size. -->

With All features enabled, clocks in just over 1k of code, 34 bytes data + per task data use of 8 bytes + task's stack size.

Multi Threading Caveats

Any non re-entrant functions that are called with interrupts enabled will need to be protected from having one task's call interrupted and then another task making the call from another context. There are two ways of handling this:

Library Limitations

On the plus side, I was using this scheduler design on a Z80 running at a whopping 1MHz. Having a real context switcher to simplify logic and implementation was well worth the overhead.

Usage Examples

Features

Per Module Resource Requirements

ModuleFunctionality ProvidedData (bytes)Code (bytes)Per Instance Overhead (bytes)
Initializationrequired4121
QueuesCircular linked lists0131per Node or List: 4
TasksCooperative/Preemptive multi-tasking10186per Task: 6 + task stack size
TimersTimed wait, tick, millisec and seconds24378per Task: 2
SemaphoresResource lock Acquire/Release055per Semaphore: 5
EventsMulti task event synchronization060per Event: 4
MutexesMulti task lock synchronization0121per Mutex: 7
AllAll options enabled381052