Pumpkin, Inc.

Pumpkin User Forums

Setting event flags frim within an ISR

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

Setting event flags frim within an ISR

Postby phil » Tue Apr 04, 2006 12:20 am

Andrew,

Thanks for the super-quick response. I thought it might be something like that. Is it acceptable to set up a task that could be called every, say quarter of a second (a small amount of latency is acceptable for this application). That would mean I would be polling the flag in a more controlled manner (and not so often). In the scheme you suggest it appears the flag would be tested as often as the system can, but it wouldn't be defined. This application is not too time critical, just hot insertion/removal of an SD memory card which triggers an interrupt on PORTB change pins.

THanks again for your time.

phil
 
Posts: 12
Joined: Mon Dec 12, 2005 12:00 am

Re: Setting event flags frim within an ISR

Postby aek » Tue Apr 04, 2006 12:50 am

Sure --- that's a perfectly good way to do it. We use a similar approach to detect if a USB cable has been plugged into our CubeSat Kit. See p. 42 of http://www.pumpkininc.com/content/doc/press/Pumpkin_MSP430ATC2005.pdf .

This is much more efficient, cycle-wise (as you point out) and remains event-driven, the event being the expiration of the task's delay, which is all driven from Salvo's timer.

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

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

Re: Setting event flags frim within an ISR

Postby phil » Tue Apr 04, 2006 11:29 am

Hello Andrew,

Can you advise how to set an event flag from within an ISR. The compiler is complaining (of course) about multiple call graphs because OSSetEflag() is being called from within the ISR and main.

Is there some other technique I should be using to trigger a task in the event of an interrupt.

THanks for your time

Phil

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

phil
 
Posts: 12
Joined: Mon Dec 12, 2005 12:00 am

Re: Setting event flags frim within an ISR

Postby aek » Tue Apr 04, 2006 11:49 am

This topic (uniquely for the PICC and PICC-18 compilers) is covered in the "Multiple Callgraph Issues" section of the reference manual, e.g. http://www.pumpkininc.com/content/doc/manual/rm-picc18.pdf .

The alternative is to create your own (binary sempahore) outside of Salvo and use it, e.g.

code:
void ISR(void)
{
...
if (condition)
{
flag = 1; // means that we want to signal an eFlag
}
...
}

main ()
{
...
while (1)
{
if (flag)
{
disable interrupts;
flag = 0;
enable interrupts;
OSSignalEFlag(...);
}
OSSched();
}
{


This is the suggested way to "pass signaling" up from an ISR to the mainline code, i.e. to avoid having to call OSSignalXyz() from within an ISR. It works for all Salvo distributions, not just for the PICC and PICC-18 compilers.

The advantages of this scheme include faster ISRs (and hence extremely short disabling of interrupts). The disadvantages include somewhat larger code size, time spent polling (the flag), and that events are no longer processed in exactly the order in which they occur. However, this latter disadvantage is likely to be a non-issue in most applications.

Note that for maximum efficiency, it's best to create a set of bitfields for all such flags, and combine them into a union, such that the union of all the flags can be checked in a single operation. E.g. on the MSP430 one would create a 16-bit variable in a union with 16 bit flags, and the check would look something like this:

code:
if (flags)
{
if (flag_bit0)
{
disable interrupts;
flag_bit0 = 0;
enable interrupts;
OSSignalXyz(...);
}
if (flag_bit1)
{
disable interrupts;
flag_bit1 = 0;
enable interrupts;
OSSignalXyz(...);
}
}

etc. This is a lot more efficient (but not as efficient as a purely event-driven system, where you signal from ISRs) than testing each flag every time, since on average, they'll probably all be 0 anyway ...

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

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

Re: Setting event flags frim within an ISR

Postby aek » Tue Apr 04, 2006 11:51 am

Another thing Salvo users do to "trigger a task" is to create the task and have it stop, then call OSStartTask() from within an ISR or by using the method described below.

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

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

Re: Setting event flags frim within an ISR

Postby phil » Wed Apr 05, 2006 10:04 am

Thanks again Andrew,

It's up an running. It even lists files in the root directory automatically when the card is inserted (plug n play). However, I can also get it to hang if I remove the card and insert it again very quickly - just like a real PC! Need to tighten up that code!

Cheers Phil

phil
 
Posts: 12
Joined: Mon Dec 12, 2005 12:00 am

Re: Setting event flags frim within an ISR

Postby aek » Wed Apr 05, 2006 10:17 am

quote:
I can also get it to hang if I remove the card and insert it again very quickly - just like a real PC!

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

-------
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 3 guests

cron