Go Down

Topic: Semaphores (Read 1 time) previous topic - next topic


I want to use 1 bit semaphores for communicating between tasks.
I have searched the site but everything points to semaphores using quite advanced RTOS, which I don't need.

Is there not some sort of framework for using semaphores in Arduino ?

I use Protothread as my cooperative "operating system"


Udo Klein

1bit semaphores are very easy to implement. Why do you want a framework for this?
Check out my experiments http://blog.blinkenlight.net


Jan 02, 2012, 10:08 am Last Edit: Jan 02, 2012, 10:11 am by fiddler Reason: 1
I'm obviously missing something here :-), not first time.

So, how would I normally declare a bunch of semaphore ?
Can I use an unsigned int, ie 32bit, and declare semaphores from 0 to 31 using labels ?

I see its quite easy to set and clear them using bit() or bitset() etc



Can I use an unsigned int, ie 32bit, and declare semaphores from 0 to 31 using labels ?

An unsigned int is 16 bits. Why do you need labels?
The art of getting good answers lies in asking good questions.


Oops, yes they are. Unsigned long then.

Couple of reason.
I find it much easier to remember names and the code is usually easier to read when using labels.

Also by using 32bits, it fits my inputs very nicely as i have 32 inputs per channel and 3 channels.

This makes comparisons and bitwise stuff easier.


Udo Klein

Of course you can http://en.wikipedia.org/wiki/Bit_field. How come that you know about semaphorse but not about bitfields?
Check out my experiments http://blog.blinkenlight.net


I have been using Splat controller for quite a while. www.splatco.com.au
They have a very simple cooperative OS with semaphores.

Quite a bit of free downloadable material their site.

Anyway, this is my first C program, so there is quite a bit of syntax learning to be had.

I'm using Protothread as my "OS" as it appears to be nice and simple (AND completely in C) and I'm just doing a bunch of tasks doing different things to get my head around C.
As I have an Duemilanove (8bit) and Chipkit Max32 (Pic32 bit) board, I can have the same program running on both.  :-)

Task1 is just the blinking LED, task2 is button press with LED on using bit(), task3 is a star delta motor starter, task4 to task8 to be decided.
Trying to use all the Protothread timing functions to understand them.


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131