Page 1 of 2

2x OSSignalBinSem in Salvo Lite and AVR Studio

PostPosted: Wed Jan 02, 2008 5:25 am
by aek
Looks fine -- did you set OSEVENTS in salvocfg.h to 2?

------------------


Re: 2x OSSignalBinSem in Salvo Lite and AVR Studio

PostPosted: Wed Jan 02, 2008 11:43 am
by MaxMax1
Hello,
My Problem is that in task3 two BinSem are signaled by switches which should wake up task1 or task2. But nothing works. In the AVRStudio Debugger, the program goes from the beginning to OSSched(); and then it resets. With one BinSem it is ok, but not with a second. Also Delays and Yields are working. So the setup should be ok. In the manual is written that Liteversion supports 5 semaphores?!
I use:
AVRStudio Version4.13 Build528
with AVRGCC Plugin
GCC 4.1.2 from WinAVR-20070525

Please see my code:

salvocfg.h

code:

#if defined(MAKE_WITH_FREE_LIB)
/* */
/* Salvo Lite build */
/* */
#define OSUSE_LIBRARY TRUE
#define OSLIBRARY_TYPE OSF
#define OSLIBRARY_CONFIG OSA
#define OSEVENTS 2
#define OSEVENT_FLAGS 0
#define OSMESSAGE_QUEUES 0
#define OSTASKS 3


main.c

code:

#include "main.h"
#include "salvo.h"


/* use #defines for legibility. */
#define TASK1_P OSTCBP(1)
#define TASK2_P OSTCBP(2)
#define TASK3_P OSTCBP(3)
#define BINSEM1_P OSECBP(1)
#define BINSEM2_P OSECBP(2)


/* use _OSLabel() to create context-switching labels. */
_OSLabel(Task1a)
_OSLabel(Task2a)
_OSLabel(Task3a)


void Task1( void )
{

for (; ;) {


OS_WaitBinSem(BINSEM1_P, OSNO_TIMEOUT, Task1a);

PORT ^= 0x02;
UDR='1';
OS_Yield();

}

}

void Task2( void )
{
for (; ;)
{

OS_WaitBinSem(BINSEM2_P, OSNO_TIMEOUT, Task2a);

PORT ^= 0x04;
UDR='2';
OS_Yield();
}
}


void Task3( void )
{
for (; ;) {


PORT ^= 0x08;
UDR='3';

if(PINA&(1<<0))
OSSignalBinSem(BINSEM1_P);

if(PINA&(1<<1))
OSSignalBinSem(BINSEM2_P);

OS_Delay(10, Task3a);
}
}

int main( void )
{


InitPORT();
DDRA=0x00;
PORTA=0xFF;

// Init();
TCCR1B = 0x00; // Stop Timer1
TCNT1H = 0x00; // Clear Timer1
OCR1AH = 0x00; // Set Compare A to 39
OCR1AL = 0x26; // ((4MHz/1024)/39) = 10ms (9.984ms) timer
TIMSK = 0x10; // Compare A Interrupt enable
TCCR1B = 0x0D; // Start Timer1 with clk/1024

UBRR=25;
UCSRA=0x00;
UCSRB=0x08;
/* initialize Salvo. */
OSInit();

/* create the three tasks */
OSCreateTask(Task1, TASK1_P, 2);
OSCreateTask(Task2, TASK2_P, 2);
OSCreateTask(Task3, TASK3_P, 2);

/* initialize binary semaphore to 0. */
OSCreateBinSem(BINSEM1_P, 0);
OSCreateBinSem(BINSEM2_P, 0);
/* enable interrupts. */
OSEi();

/* start multitasking. */
for (; ;)
{
OSSched();
}
}



[This message has been edited by MaxMax1 (edited January 02, 2008).]

[This message has been edited by aek (edited January 03, 2008).]


Re: 2x OSSignalBinSem in Salvo Lite and AVR Studio

PostPosted: Thu Jan 03, 2008 1:20 am
by MaxMax1
Yes, OSEVENTS is 2.
(I posted the salvocfg.h and then the main.c)
When I define a second binsem with OSECBP is (2) the problem begins. When I set both OSECBPs to (1), (which makes no sense) the code works, but not in the way it should work (means no reset,runs anyhow). I also tried to signal from different tasks, no change. I use the ATmega163 with Salvo Lite 3.2.4 for AVR. Perhaps I forgot any important thing.
Max

Re: 2x OSSignalBinSem in Salvo Lite and AVR Studio

PostPosted: Thu Jan 03, 2008 5:04 am
by aek
Ah, sorry, I missed that.

1) Remove the OS_Yield() calls. They're unnecessary and will confuse you re the runtime behavior of the system.

2) We have found that the AVR simulator does not always work properly ... see e.g. http://www.pumpkininc.com/ubb/Forum22/HTML/000018.html.

------------------


Re: 2x OSSignalBinSem in Salvo Lite and AVR Studio

PostPosted: Thu Jan 03, 2008 5:08 am
by aek
In AVRStudio, when you watch OSecbArea[], do you see two array elements or only one? You should see two ...

A common error is that the salvocfg.h you think you are using is not in fact the one used by the project (due to incorrectly defined include paths). A quick way to test that is to add an #error Hello! directive to your salvocfg.h and rebuild -- it should result in a Hello! error when building.

------------------


Re: 2x OSSignalBinSem in Salvo Lite and AVR Studio

PostPosted: Thu Jan 03, 2008 5:13 am
by aek
One last thing -- have you verified that OSTimer() is being called regularly? Because I don't see your ISR to call OSTimer(), and without it Task3() will never return from the OS_Delay() call ...

------------------


Re: 2x OSSignalBinSem in Salvo Lite and AVR Studio

PostPosted: Thu Jan 03, 2008 8:04 am
by MaxMax1
1. The salvocfg.h is the right one
2. The timer comes regularly, because its working with one binsem
3. OSecbArea has no values [...]; OStypeEcb[0];SRAM 0x76
I made a testarray x with for chars - and its ok.

I also tested it on my AVR board, with Porttoggling and UART output. So its not only a problem with AVRStudio debugger/Simulator.


Re: 2x OSSignalBinSem in Salvo Lite and AVR Studio

PostPosted: Thu Jan 03, 2008 10:20 am
by aek
Just so that I understand -- are you saying that just "cleaning" the project made it work, or that you started over with a clean install of WinAVR and then it worked?

I ask because last week or so I had some problems with the latest WinAVR and the latest AVR Studio on the mega2560, and eventually after a couple of restarts, etc. everything suddenly worked OK (but before that I had problems launching the simulator).

------------------


Re: 2x OSSignalBinSem in Salvo Lite and AVR Studio

PostPosted: Thu Jan 03, 2008 10:55 am
by aek
For a successful build with OSEVENTS = 2, OSecbArea[] should have two members, OSecbArea[0] & OSecbArea[1], with some valid fields once OSCreateBinSem() has been called.

Just like OStcbArea[0], [1] & [2] for your application.

So if it doesn't have those, I would suggest focusing on why those members don't exist.

------------------


Re: 2x OSSignalBinSem in Salvo Lite and AVR Studio

PostPosted: Thu Jan 03, 2008 12:51 pm
by MaxMax1
Hi,
Now it works.
I made the whole project with WINAVR Tools > no success. Then I made a "clean", started AVR Studio and it was ok.
Thanks for help, I will take care of this phenomenon.
Max