comp.lang.ada
 help / color / mirror / Atom feed
* Trouble with Timers on the ARM
@ 2014-08-13  6:24 williamjthomas7777
  2014-08-13 16:53 ` Mike Silva
  0 siblings, 1 reply; 4+ messages in thread
From: williamjthomas7777 @ 2014-08-13  6:24 UTC (permalink / raw)


I'm using the latest GNAT ARM Elf download (Windows) with the STM32F4 Discovery Board.

The code ends up spinning in the last chance handler (the code generates an exception). The code runs on the Windows x86 native compiler fine.

Am I missing something special that has to be done on the ARM target or with the ARM RTS?

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

with Last_Chance_Handler;  pragma Unreferenced (Last_Chance_Handler);
with System;

with Timer_Pack;

procedure Timer_Main is
   pragma Priority (System.Priority'First);
begin
   Timer_Pack.Set_Timer;
   loop
      null;
   end loop;
end Timer_Main;

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

with Ada.Real_Time.Timing_Events; use Ada.Real_Time.Timing_Events;

package Timer_Pack is

  procedure Set_Timer;

   protected The_Timer is
     procedure The_Callback ( Event : in out Timing_Event );
   private
     State   : Boolean := False;
   end The_Timer;

end Timer_Pack;

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

with Ada.Real_Time; use Ada.Real_Time;

package body Timer_Pack is

   The_Event : Timing_Event;
   R1        : constant Integer := 500;

   procedure Set_Timer is
   begin
     Set_Handler
       (The_Event,
        Clock+Milliseconds(R1),
        The_Timer.The_Callback'Access);
   end Set_Timer;

   protected body The_Timer is

     procedure The_Callback ( Event : in out Timing_Event ) is
     begin
       State := not State;
       Set_Handler
         (Event,
          Clock+Milliseconds(R1),
          The_Timer.The_Callback'Access);
     end The_Callback;

   end The_Timer;

end Timer_Pack;

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

with System;

package Last_Chance_Handler is

   procedure Last_Chance_Handler (Msg : System.Address; Line : Integer);
   pragma Export (C, Last_Chance_Handler, "__gnat_last_chance_handler");
   pragma No_Return (Last_Chance_Handler);

end Last_Chance_Handler;

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

package body Last_Chance_Handler is

   procedure Last_Chance_Handler (Msg : System.Address; Line : Integer) is
      pragma Unreferenced (Msg, Line);
   begin
      --  No return procedure.
      pragma Warnings (Off, "*rewritten as loop");
      <<spin>> goto spin;   -- yes, a goto!
      pragma Warnings (On, "*rewritten as loop");
   end Last_Chance_Handler;

end Last_Chance_Handler;

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

* Re: Trouble with Timers on the ARM
  2014-08-13  6:24 Trouble with Timers on the ARM williamjthomas7777
@ 2014-08-13 16:53 ` Mike Silva
  2014-08-17  4:43   ` William Thomas
  0 siblings, 1 reply; 4+ messages in thread
From: Mike Silva @ 2014-08-13 16:53 UTC (permalink / raw)


I've connected an STM32F4 board to an LCD display, and modified the last chance handler to print out the offending file and line number.  Your code fails in

s-taprob.adb   line 95

which is here:
      if Caller_Priority > Object.Ceiling then
         raise Program_Error;
      end if;

Sorry, don't have the time now to dig deeper.

Mike

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

* Re: Trouble with Timers on the ARM
  2014-08-13 16:53 ` Mike Silva
@ 2014-08-17  4:43   ` William Thomas
  2014-08-17 19:51     ` Mike Silva
  0 siblings, 1 reply; 4+ messages in thread
From: William Thomas @ 2014-08-17  4:43 UTC (permalink / raw)


On Wednesday, August 13, 2014 12:53:17 PM UTC-4, Mike Silva wrote:
> I've connected an STM32F4 board to an LCD display, and modified the last chance handler to print out the offending file and line number.  Your code fails in
> 
> 
> 
> s-taprob.adb   line 95
> 
> 
> 
> which is here:
> 
>       if Caller_Priority > Object.Ceiling then
> 
>          raise Program_Error;
> 
>       end if;
> 
> 
> 
> Sorry, don't have the time now to dig deeper.
> 
> 
> 
> Mike

Thanks Mike,

I got the last chance handler to print out the Null terminated string returned at address along with the line number. Sure enough I received the same message coming from System.Tasking.Protected_Objects.

It turns out that I had to set the protected object's priority to System.Max_Interrupt_Priority in order for the timer to work properly.

I would imagine its because the Callback is being called back by something that was being executed as a result of some processor timer which I believe would have to be coming in at Max_Interrupt_Priority.

Thanks for the help.

Bill

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

* Re: Trouble with Timers on the ARM
  2014-08-17  4:43   ` William Thomas
@ 2014-08-17 19:51     ` Mike Silva
  0 siblings, 0 replies; 4+ messages in thread
From: Mike Silva @ 2014-08-17 19:51 UTC (permalink / raw)


On Saturday, August 16, 2014 9:43:53 PM UTC-7, William Thomas wrote:
> 
> Thanks Mike,
> 
> 
> 
> I got the last chance handler to print out the Null terminated string returned at address along with the line number. Sure enough I received the same message coming from System.Tasking.Protected_Objects.
> 
> 
> 
> It turns out that I had to set the protected object's priority to System.Max_Interrupt_Priority in order for the timer to work properly.
> 
> 
> 
> I would imagine its because the Callback is being called back by something that was being executed as a result of some processor timer which I believe would have to be coming in at Max_Interrupt_Priority.
> 
> 
> 
> Thanks for the help.
> 
> 
> 
> Bill

Great, Bill.  What a useful tool!

Mike

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

end of thread, other threads:[~2014-08-17 19:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-13  6:24 Trouble with Timers on the ARM williamjthomas7777
2014-08-13 16:53 ` Mike Silva
2014-08-17  4:43   ` William Thomas
2014-08-17 19:51     ` Mike Silva

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