Hi
I’ve developed the SCoop library for the Arduino platform some years ago here:
https://forum.arduino.cc/index.php?topic=137801.0
and I was missing an easy Cooperative scheduler to execute multiple cpp tasks on XMOS.
The intend is for me to manage some sort of front-panel and I/O within the USB application, in an Arduino style.
Here is a xc demo application using XCScheduler.cpp library file providing a Cooperative scheduler solution, in addition and compatible with the XCore multitasking inherent capability of the XMOS architecture; it uses Setjump/longjump and is 80% based on the original code ad smart approach of from Mikael Patel here: https://github.com/mikaelpatel/Arduino-Scheduler
All credits to him for this very smart approach.
A main.xc program declares 2 tasks in a par statement for 2 cores.
One core is just printing a message every 5 seconds using a blocking delay function;
The other core is
- initializing the XCScheduler with a certain amount of stack space for all the cpp tasks
- launching the initialization of multiple tasks written in cpp
- allocating a specific stack space for each of them
- orchestrating and monitoring a simple context switch between the task with a round robin approach.
- This is done as a default branch of a select statement.
Each cpp task is blocking and just yielding to the other tasks when cpu is not needed.
A sleepMs function provides a simple delay(ms) with embedded yield call.
A stronger and clean library will most probably be provided on my github in a next post here but wanted to share this interesting outcome as of now, hope it worth your reading.
Remark:
- A #pragma stackfunction is needed and the amount of memory reserved should be greater than the sum of all stack task (2500 words in this demo)
- With this implementation spread between xc and cpp, there is no any linker error due to stack information missing or due to name-mangling. All seems ok
- The xcore task1 can just yield or execute a loop() in the cpp code, depending if we want a circularly or sequential approach. The second one gives the possibility to measure the time of a complete circularly cycle, which is of 2us in this example. Any firm blocking timer within a task will increase the time for a cycle.
- the demo uses only printf to the stdio rerouted with xscope so need a xtag
Don’t forget to change the platform .xn file to suit your dev board. This app is running on a DXIO board bought at diyinhk.com
a Cooperative Scheduler Arduino style
-
- Experienced Member
- Posts: 94
- Joined: Mon Jan 08, 2018 4:14 pm
a Cooperative Scheduler Arduino style
You do not have the required permissions to view the files attached to this post.
-
- Experienced Member
- Posts: 94
- Joined: Mon Jan 08, 2018 4:14 pm
Hi,
there was 19 downloads as of october 8th, any feedback or suggestions ?
cheers
there was 19 downloads as of october 8th, any feedback or suggestions ?
cheers
-
- Experienced Member
- Posts: 94
- Joined: Mon Jan 08, 2018 4:14 pm
Hi,
the scheduler is hosted on my xmos GitHub project but havent had time to make examples, your welcome to fork and propose merge
https://github.com/fabriceo/XMOS
the scheduler is hosted on my xmos GitHub project but havent had time to make examples, your welcome to fork and propose merge
https://github.com/fabriceo/XMOS