Counting Semaphore! Please help me to test.

dmitrycherepanv wrote on Monday, November 19, 2007:

##############Counting semaphores.#######################

Then I start to use FreeRTOS. I thought that the first and simplest thing that
OS must have is an semaphore. And I was surprised about semaphores in
FreeRTOS. Actually there is no semaphore there is only a macroses and binary semaphores.

Also I saw that many people asked about counting semaphores. And so
I decided to look how it works and why there is only queue in OS and how
semaphores can be written.

And finally I tried to write semaphore. Here is my semaphore code for the FreeRTOS kernel.

http://dima.udmlink.ru/semaphore.zip

I hope Richard Barry will take this code to his OS kernel.

Anyway I will use It in my applications.

And that’s why I asked Richard and other people who want to have another implementation to test this code.

I used OpenWatcom1.7a compiler and WindowsXP for testing

semtest.c is working fine.

All you need is to put this file it in your freertos directory and replace headers.
Just replace
#include "semphr.h"
on 
#include "semphore.h"

Also I will be glad if you test my suggestions on memory
at heep.c

I wish to receive suggestions bugs and etc on my box

dmitrycherepanv at  users.sourceforge.net

Regards,
Dmitry.

rtel wrote on Monday, November 19, 2007:

Hi - thanks again for your contribution.

>Then I start to use FreeRTOS. I thought that the first and simplest thing that 
>OS must have is an semaphore. And I was surprised about semaphores in 
>FreeRTOS. Actually there is no semaphore there is only a macroses and binary semaphores.

One of the primary design goals for FreeRTOS.org is to keep the memory footprint to a minimum.  To this end, the queue was developed to include both the communications mechanism and the event control data (many RTOSes have these as separate data structures), providing a generic intertask communication mechanism that can be used for many purposes.  This is why both binary semaphores and mutexes are built as macros on top of the queue primitive.  Binary semaphores add no extra code to the image size, and mutexes only a tiny amount of code.

Counting semaphores are used less often in small to medium sized embedded applications.  Normally in FreeRTOS.org they are implemented by simply extending the binary semaphore implementation so that there is more than one space in the underlying queue.  Were you the person we were discussing this with on this forum a month or two back?

>
>Also I saw that many people asked about counting semaphores. And so
>I decided to look how it works and why there is only queue in OS and how
>semaphores can be written. 
>
>And finally I tried to write semaphore. Here is my semaphore code for the FreeRTOS kernel.
>
>http://dima.udmlink.ru/semaphore.zip

I have downloaded your code to take a look at your implementation.  I’m on the road at the moment so a bit out of communication so it might be a day or two.

>I used OpenWatcom1.7a compiler and WindowsXP for testing

This is a very convenient setup for testing.  I use it myself a lot.  It is great that OpenWatcom is not open source, and still being maintained.  The only thing to watch out for is that stepping the debugger from within a critical section temporarily enables interrupts, which can cause lots of problems.

>Also I will be glad if you test my suggestions on memory
>at heep.c

I will reply to your other post on this.

Thanks again and regards.

dmitrycherepanv wrote on Monday, November 19, 2007:

>It is great that OpenWatcom is not open source, and still being maintained.
OpenWatcom is not open source ???

As far as I know OpenWatcom is open source now.

I don’t know that license exacly but All new versions is maintained with opensource community.

I think it is great that it is still being maintained.
I have heard But there is problems with the leadership of the project

dmitrycherepanv wrote on Monday, November 19, 2007:

>One of the primary design goals for FreeRTOS.org is to keep the memory footprint to a minimum.

Then I looked for Operating System for my AtMega128
I found about 5 operating systems with opensourse licenses. But they are not so RealTime As FreeRTOS and not so well documented. That is why I have choosen FreeRTOS.
Some of them are not supported tasks with their own stack (only CoRoutines) and that is why they are not preemptive.
That is why they use less RAM than FreeRTOS.

Well, I can say that FreeRTOS use very little amount of RAM and ROM also.

There is no comparison between such monster Linux and FreeRTOS.

>Counting semaphores are used less often in small to medium sized embedded applications.
>Normally in FreeRTOS.org they are implemented by simply extending the binary semaphore implementation
>so that there is more than one space in the underlying queue.
>Were you the person we were discussing this with on this forum a month or two back?

I agree with you that there is less size of Code but look at my
8bit RISC ATMEGA128       128k of ROM and only 4k of RAM on board

sizeof (queue) = 9*2+5+4*2 - 31 bytes
sizeof (Semaphore) = 9

the difference is - 22 bytes

I would prefer to increase the size of freeRTOS twice with even 32k of ROM
than lost 22 bytes on every semaphore

For example I have about 10 semaphores in my project - 220 bytes
configMINIMAL_STACK_SIZE = 86 in atmega323 - 3 new tasks

Also there is Atmega chips with 512 and 1024 and 2048 bytes of RAM.
And on other low cost chips ROM is much bigger than RAM I suppose

Certainly may be there is a chips only with RAM like ancient Intel i8080 with his 64k RAM
Then I was young I played games with such computer.
A have to load games from tape recorder for 5 or 10 minutes after every reset.
That was fun. :slight_smile:
 

rtel wrote on Tuesday, November 20, 2007:

>It is great that OpenWatcom is not open source, and still being maintained.

That was meant to say:

"It is great that OpenWatcom is *now* open source".

Typo.

Regards.

bkastel1 wrote on Tuesday, November 20, 2007:

Hello Dmitry,

it is great that you have done this counting semaphore code (i just download it and will test it ASAP). I was asking about this issue a few months ago and also for event flags. I must say i used counting semaphores a lot with my previous RTOS so I was also wondering why there aren’t any here. So Richard kindly suggested how to implement them and I did and used that implementation since then. But event flags are still one feature that would be very helpfull :slight_smile:

Regards

cherepanov wrote on Tuesday, November 20, 2007:

I have found some bugs I my sources
Now I am trying to fix it.

cherepanov wrote on Tuesday, November 20, 2007:

Bugs have fixed You can use It

cherepanov wrote on Wednesday, November 28, 2007:

AS I see there is nobody who have an interest to the counting semaphores.

I have test them on Open Watcom 1.7a compiler. And it is working well.

In spite of that I am placing a new link where you can find the sources. (I have fixed some little bugs).

http://freertos.narod.ru/semaphore.zip

May be somebody will test them and use for himself and also send me a message.