Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

A silly really small co-operative kernel for atmel avr arduino :-)

Status
Not open for further replies.

voidptr

Member
so ... one of my friend needed a little help with concurrency so last weekend I chopped out one silly little co-operative kernel for his arduino applications (works fine on 328p and atmega2560 )...

I built many of those little kernels for different cpu over the years (there is also many os outthere too).

they are usually simple ( not time sliced ) and they work fine with ucontroller and few cooperative tasks.

this silly one is as much thin you can go, only simple tasks( with their own stack) and semaphore (with P and V) , all in C, and using for context switching setjump() and longjump().

my current bot used a more extended version of this one, but this code can give to some people a good starting point...

so there is 3 files attached:

osp.h - prototype file
osp.c - c code
zosavr.ino a silly test for testing the kernel.

the test is basically 3 tasks

taskIdle will emulate the arduino main function.

task0 ans task1 will synchronize themself with semaphores and blink the pin13 led ...

of course in the real word, the led should be a ressource and it should be gated be semaphore... but this is just a demo so ...

enjoy :)
 

Attachments

  • zosavr.ino
    1.4 KB · Views: 494
  • osp.h
    225 bytes · Views: 512
  • osp.c
    2.1 KB · Views: 566
You should comment your code if you are sharing it for others to use. Only comment I found was "Magic stuff here!" :)

I have also written a multitasking kernel.. properly commented. Attached.
 

Attachments

  • E2.c
    3.1 KB · Views: 566
  • avrrtos.h
    6.7 KB · Views: 649
  • avrrtos.c
    8.7 KB · Views: 595
Last edited:
I can't figure out how your silly co-operative kernel differs from finite state machine? There is no system clock.. there is no scheduling.. what is there? I know that you wrote that for arduino, so it makes sense that it is "silly".

**broken link removed**
 
I can't figure out how your silly co-operative kernel differs from finite state machine? There is no system clock.. there is no scheduling.. what is there? I know that you wrote that for arduino, so it makes sense that it is "silly".

well...
all task has their own stack...
no need for a system clock , it is a co-operative scheduling approach, a task yield the cpu when it want, and because it has it own stack, yield or a semaphore P can happen wherever you want ...
there IS scheduling, simple silly round robin, context switching is done with setjump and longjump ...

remember the first MAC OS aka The Finder ?

sometime we dont need to bother our self with time slice kernel and interrupt protection etc etc ...
(I also wrote few of them :eek:) )

try it you will see :p
 
Last edited:
You should comment your code if you are sharing it for others to use. Only comment I found was "Magic stuff here!" :)

I have also written a multitasking kernel.. properly commented. Attached.

I will add at least 1 kernel function
taskYield() or taskPreempt()

in this way, a task can yield itself when it has no more job to do, and not spinning like hell consuming it timeslice doing nothing :eek:)

semaphore object and P and V operation can be also very handy :)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top