comp.lang.ada
 help / color / mirror / Atom feed
* Ravenscar vs selective wait
@ 2015-03-23 22:00 Simon Wright
  2015-03-24  6:48 ` Simon Wright
  0 siblings, 1 reply; 6+ messages in thread
From: Simon Wright @ 2015-03-23 22:00 UTC (permalink / raw)


Is it possible to construct an analog of the selective wait using the
Ravenscar profile?

   Turn_On_The_Lamp;
   Next := Clock + Milliseconds (500);
   select
      accept Reset do
         Next := Clock + Milliseconds (500);
      end Reset;
   or
      delay until Next;
      Turn_Off_The_Lamp;
   end select;

where the Lamp goes off 500 ms after it was turned on, but you can reset
the timer by calling the Reset entry.

Of course, Ravenscar prohibits both task entries and select statements,
so I'm looking for something else! Preferably not involving polling.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Ravenscar vs selective wait
  2015-03-23 22:00 Ravenscar vs selective wait Simon Wright
@ 2015-03-24  6:48 ` Simon Wright
  2015-03-24  7:25   ` Jeffrey Carter
  0 siblings, 1 reply; 6+ messages in thread
From: Simon Wright @ 2015-03-24  6:48 UTC (permalink / raw)


Simon Wright <simon@pushface.org> writes:

> Is it possible to construct an analog of the selective wait using the
> Ravenscar profile?
>
>    Turn_On_The_Lamp;
>    Next := Clock + Milliseconds (500);
>    select
>       accept Reset do
>          Next := Clock + Milliseconds (500);
>       end Reset;
>    or
>       delay until Next;
>       Turn_Off_The_Lamp;
>    end select;

This is rather simplified from what I want to achieve, and I can think
of an ugly solution for it.

   Turn_On_The_Lamp;
   Next := Clock + Milliseconds (500);  -- Next is a shared variable
   loop
      delay until Next;
      if Next <= Clock then
         exit;
      else
         -- something else in the program has updated Next
      end if;
   end loop;
   Turn_Off_The_Lamp;

But what if I need the next wake-up to be *earlier*?
   


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Ravenscar vs selective wait
  2015-03-24  6:48 ` Simon Wright
@ 2015-03-24  7:25   ` Jeffrey Carter
  2015-03-24  9:21     ` J-P. Rosen
  0 siblings, 1 reply; 6+ messages in thread
From: Jeffrey Carter @ 2015-03-24  7:25 UTC (permalink / raw)


On 03/23/2015 11:48 PM, Simon Wright wrote:
> Simon Wright <simon@pushface.org> writes:
> 
>> Is it possible to construct an analog of the selective wait using the
>> Ravenscar profile?
>>
>>    Turn_On_The_Lamp;
>>    Next := Clock + Milliseconds (500);
>>    select
>>       accept Reset do
>>          Next := Clock + Milliseconds (500);
>>       end Reset;
>>    or
>>       delay until Next;
>>       Turn_Off_The_Lamp;
>>    end select;
> 
> This is rather simplified from what I want to achieve, and I can think
> of an ugly solution for it.
> 
>    Turn_On_The_Lamp;
>    Next := Clock + Milliseconds (500);  -- Next is a shared variable
>    loop
>       delay until Next;
>       if Next <= Clock then
>          exit;
>       else
>          -- something else in the program has updated Next
>       end if;
>    end loop;
>    Turn_Off_The_Lamp;
> 
> But what if I need the next wake-up to be *earlier*?

Seems to me you could do what you originally asked about with 3 tasks and a PO:

Lamp task:

   Turn_On;
   Next := Clock + Interval;
   PO.Set_Expiration (Expiration_Time => Next);
   loop
      PO.Wait (Result => Wait_Result);
      case Wait_Result is
      when Reset =>
         Next := Clock + Interval;
         PO.Set_Expiration (Expiration_Time => Next);
      when Timeout =>
         Turn_Off;
         exit;
      end case;
   end loop;

PO:

   procedure Set_Expiration (Expiration_Time : in Time);
   procedure Delay_Expired;
   procedure Reset_Expiration;
   function Expiration return Time;
   entry Wait (Result : out Wait_Result_ID);

The delay task would poll function Expiration and compare it to Clock, calling
Delay_Expired when Expiration >= Clock.

Some 3rd task would call Reset_Expiration when the expiration should be extended.

With some more complication this could also allow resetting to an earlier time.

-- 
Jeff Carter
"What's the amount of the insult?"
Never Give a Sucker an Even Break
104

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Ravenscar vs selective wait
  2015-03-24  7:25   ` Jeffrey Carter
@ 2015-03-24  9:21     ` J-P. Rosen
  2015-03-24 17:16       ` Jeffrey Carter
  2015-03-24 20:12       ` Simon Wright
  0 siblings, 2 replies; 6+ messages in thread
From: J-P. Rosen @ 2015-03-24  9:21 UTC (permalink / raw)


Le 24/03/2015 08:25, Jeffrey Carter a écrit :
> Seems to me you could do what you originally asked about with 3 tasks and a PO:

I did something like that for a client of mine who is moving an
application to Ravenscar. Sorry, the code belongs to the client, so I
can't post it here.

Some hint however: I have a record containing a PO similar to what Jeff
suggests, and a Timing_Event that unblocks the PO when the delay has
expired. Similarly, the Wait entry has an out parameter to tell whether
it's been awaken by an event or by time-out.

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Ravenscar vs selective wait
  2015-03-24  9:21     ` J-P. Rosen
@ 2015-03-24 17:16       ` Jeffrey Carter
  2015-03-24 20:12       ` Simon Wright
  1 sibling, 0 replies; 6+ messages in thread
From: Jeffrey Carter @ 2015-03-24 17:16 UTC (permalink / raw)


On 03/24/2015 02:21 AM, J-P. Rosen wrote:
> 
> Some hint however: I have a record containing a PO similar to what Jeff
> suggests, and a Timing_Event that unblocks the PO when the delay has
> expired. Similarly, the Wait entry has an out parameter to tell whether
> it's been awaken by an event or by time-out.

I hadn't considered a timing event, thinking they were excluded. Now I see that
only local timing events are prohibited. A timing event would be better than a
task that polls.

-- 
Jeff Carter
"I've seen projects fail miserably for blindly
applying the Agile catechism: we're Agile, we
don't need to stop and think, we just go ahead
and code!"
Bertrand Meyer
150

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Ravenscar vs selective wait
  2015-03-24  9:21     ` J-P. Rosen
  2015-03-24 17:16       ` Jeffrey Carter
@ 2015-03-24 20:12       ` Simon Wright
  1 sibling, 0 replies; 6+ messages in thread
From: Simon Wright @ 2015-03-24 20:12 UTC (permalink / raw)


"J-P. Rosen" <rosen@adalog.fr> writes:

> Some hint however: I have a record containing a PO similar to what
> Jeff suggests, and a Timing_Event that unblocks the PO when the delay
> has expired. Similarly, the Wait entry has an out parameter to tell
> whether it's been awaken by an event or by time-out.

AdaCore's 4.9.1 implementation has a task which polls at 10 Hz
(adjustable by recompiling the RTS). The GPL 2014 arm-eabi version uses
magic deep in the System.BB (bare board) tree.

Whichever, it's clear that _something_ has to run every clock tick to
decide whether to invoke one of the timed events; and it seems best to
do it via a Timed_Event if I can get my FreeRTOS implementation to do
so.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-03-24 20:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-23 22:00 Ravenscar vs selective wait Simon Wright
2015-03-24  6:48 ` Simon Wright
2015-03-24  7:25   ` Jeffrey Carter
2015-03-24  9:21     ` J-P. Rosen
2015-03-24 17:16       ` Jeffrey Carter
2015-03-24 20:12       ` Simon Wright

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox