Pumpkin, Inc.

Pumpkin User Forums

Semaphor and delay in same task

If you can't make Salvo do what you want it to do, post it here.

Semaphor and delay in same task

Postby kigor » Tue Jul 15, 2003 10:28 am

Hi,
I have question. One if my tasks has to wait to semaphor signal to run. However, when the semaphor is signaled from isr, then the task need to wait some time (say 100 ticks) to run (time to discharge some capacitor). I think I can not put OS_Delay() after OS_WaitSem() in the same task because both have yield inside, i.e the following scenario will play:
Semaphor signaled, task become eligible, then OS_Delay will yield placing the task in waiting state. Will the task after that wait to the semaphor again? Or the scheduler will run the code from the OS_Delay down?
I need to clarify this.
Thanks
Igor
kigor
 
Posts: 3
Joined: Mon Jul 14, 2003 11:00 pm

Re: Semaphor and delay in same task

Postby aek » Tue Jul 15, 2003 10:45 am

Hi Igor.
quote:
I think I can not put OS_Delay() after OS_WaitSem() in the same task because both have yield inside
You can put as many context-switches in a task as you like, e.g.
code:
void Task (void)
{
for (;;)
{
/* wait forever until Sem is signaled */
OS_WaitSem(...);
/* Delay N ticks as cap discharges */
OS_Delay(N, ...);
/* do stuff */
foo();
/* repeat wait-delay-foo */
}
}

Just remember that with those Salvo distributions that require labels (e.g. w/PICC and PICC-18), you must use unique labesl for each OS_Xyz().

If the semaphore is signaled (again) while the task is delayed, it just means that the task will not go into the waiting state "next time" -- but all of your delays will still happen correctly, etc.

In summary, you can do exactly what you want, and it will behave correctly.

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

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: Semaphor and delay in same task

Postby kigor » Wed Jul 16, 2003 6:34 am

Thanks for the advice. After I posted the question I read again about context switching and realized it should work. I then run the code and can confirm the scheduling working properly. I have another problem though. The Salvo doing some strange things to RAM. During executing CreateTask() it modifying some of my global variables, I traced with debugger Salvo doing some stack manipulations just before the overwrite happens. Maybe I missed some configuration option to prevent this.
About my application. I made some application to try the Salvo Lite before I decide to go with bigger version. I have 2 tasks created initially and third task created within one of the first two pending some external condition. I have 2 first tasks waiting to semaphores, which are signaled from two separate ISR routines.
My platform is MSP430F123 and compiler is IAR Workbench 1.25 full.
Thanks
Igor
kigor
 
Posts: 3
Joined: Mon Jul 14, 2003 11:00 pm

Re: Semaphor and delay in same task

Postby aek » Wed Jul 16, 2003 8:25 am

Hi Igor.

Re the "strange things with global variables" ... make sure you add salvosrcmem.c as a node in your project, and make sure that you do not have any "overlap" of task or event control block pointers (OSTCBP(m) and OSECBP(n)).

Usually, this sort of problem happens because there is a mismatch between the size of tcbs and ecbs in the library's mem.c (which was compiled when the library was built), and what your application expects via the OSTASKS and OSEVENTS in your salvocfg.h. We've changed the upcoming v3.2 to avoid this problem ...

If you still can't get it to work, please .zip the whole project and send it to support@pumpkininc.com and we'll fix it.

Regards,

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

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: Semaphor and delay in same task

Postby aek » Thu Jul 17, 2003 1:57 am

Hi Igor.

I found your problem ...

My tip-off was that once I built your project (with Option changes because I have the compiler in C:IAR and you have it in C:Program FilesIAR ...) there were many warnings about OSTASKS, OSEVENTS, etc. being redefined. That's where I knew the problem was. So, I moved your four lines of

code:
#define OSEVENTS  2
#define OSEVENT_FLAGS 0
#define OSMESSAGE_QUEUES 0
#define OSTASKS 3

from your main.h to your salvocfg.h, and now it works perfectly.

Salvo's configuration options OSXyz should only be located in the project's salvocfg.h, and not in any other files. This will ensure that all of the Salvo files (which include salvocfg.h automatically) "see" the same Salvo global object structures, etc. A mismatch -- like you had in your project before this fix -- will cause precisely this kind of problem.

Note also that if you didn't specify OSTASKS, etc. at all, anywhere in your project, you also would not have had any problems, because the defaults take over.

We strongly recommend that you always resolve all Salvo-related warnings when building an application. Normally, for a successful build, you should not get any warnings from the compiler or linker that are directly related to Salvo.

Regards,

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

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: Semaphor and delay in same task

Postby kigor » Thu Jul 17, 2003 6:12 am

Hi AEK,
Thanks for reply. I added mem.c to the project, but it didn't help. I have OSTASKS on 3 and OSEVENTS on 2 (I have 2 semaphores).
I saw on your web site downloadable version
3.2-betta6, should I try with this?
Otherwise, I will send you the project.
Thanks
Igor
kigor
 
Posts: 3
Joined: Mon Jul 14, 2003 11:00 pm

Re: Semaphor and delay in same task

Postby aek » Thu Jul 17, 2003 8:43 am

Hi Igor.

Yes, please do .zip me the files.

The problem you describe can happen with Salvo LE or Pro v3.1 and earlier if you increase the numbers of tasks and events beyond the default without adding mem.c as a node in the project. But your situation is the opposite, and so I'm puzzled as to why it's happening.

I'm certain it's just a Salvo configuration problem, so do please send the files.

You can go ahead and use v3.2beta6 if you like, but it shouldn't make any difference.

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

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm


Return to Coding

Who is online

Users browsing this forum: No registered users and 1 guest

cron