Pages: [1]   Go Down
Author Topic: Semaphores  (Read 795 times)
0 Members and 1 Guest are viewing this topic.
NZ
Offline Offline
Jr. Member
**
Karma: 1
Posts: 84
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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"

K
Logged

0
Offline Offline
Faraday Member
**
Karma: 19
Posts: 3420
20 LEDs are enough
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

1bit semaphores are very easy to implement. Why do you want a framework for this?
Logged

Check out my experiments http://blog.blinkenlight.net

NZ
Offline Offline
Jr. Member
**
Karma: 1
Posts: 84
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Cheers
« Last Edit: January 02, 2012, 04:11:06 am by fiddler » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46090
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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?
Logged

NZ
Offline Offline
Jr. Member
**
Karma: 1
Posts: 84
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

K
Logged

0
Offline Offline
Faraday Member
**
Karma: 19
Posts: 3420
20 LEDs are enough
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Of course you can http://en.wikipedia.org/wiki/Bit_field. How come that you know about semaphorse but not about bitfields?
Logged

Check out my experiments http://blog.blinkenlight.net

NZ
Offline Offline
Jr. Member
**
Karma: 1
Posts: 84
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Cheers
K

Logged

Pages: [1]   Go Up
Jump to: