Skip to content

Commit

Permalink
Support 'delay until Real_Time.Time_Last'.
Browse files Browse the repository at this point in the history
  * common/a-reatim.ads (FreeRTOS_Tick): New.
    (Time): Limit range to what's possible with the underlying 32-bit
      FreeRTOS clock.
    (Time_First): Revert to Time'First.
  * common/a-retide.adb (Delay_Until): Rework.

  * test-arduino-due/testbed.adb: End with delay until Time_Last.
  * test-stm32f4/testbed.adb: Likewise.
  * test-stm32f429i/testbed.adb: Likewise.
  • Loading branch information
simonjwright committed Apr 19, 2018
1 parent 1fe5e1e commit 4b25f1d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 28 deletions.
10 changes: 8 additions & 2 deletions common/a-reatim.ads
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
-- --
------------------------------------------------------------------------------

-- Modified from GCC 4.9.1, then GCC 7.1.0, for Cortex GNAT RTS.

package Ada.Real_Time with
SPARK_Mode,
Abstract_State => (Clock_Time with Synchronous,
Expand Down Expand Up @@ -149,9 +151,13 @@ private
-- Replaces Duration, which has a different representation on
-- systems with 32-bit Duration.

type Time is new Time_Base;
FreeRTOS_Tick : constant := 0.001;
-- FreeRTOSConfig.h has set configTICK_RATE_HZ to 1000

type Time is new Time_Base range 0.0 .. (2 ** 32 - 1) * FreeRTOS_Tick;
-- and configUSE_16_BIT_TICKS to 0 (so we get 32-bit clock values).

Time_First : constant Time := 0.0;
Time_First : constant Time := Time'First;

Time_Last : constant Time := Time'Last;

Expand Down
14 changes: 9 additions & 5 deletions common/a-retide.adb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2010, 2016, Free Software Foundation, Inc. --
-- Copyright (C) 1992-2010, 2016-2017, Free Software Foundation, Inc. --
-- --
-- GNARL is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
Expand All @@ -29,6 +29,8 @@
-- --
------------------------------------------------------------------------------

-- Modified from GCC 4.9.1 for Cortex GNAT RTS.

with Interfaces;

package body Ada.Real_Time.Delays is
Expand All @@ -40,12 +42,14 @@ package body Ada.Real_Time.Delays is
Convention => C,
External_Name => "vTaskDelay";
Timespan_To_Delay : constant Time_Span := T - Clock;
-- ??? need to round, see ARM
Ticks_To_Delay : constant Integer := Timespan_To_Delay / Tick;
begin
if Ticks_To_Delay > 0 then
if Timespan_To_Delay > 0.0 then
-- Need to avoid problems with ambiguity; and the version in
-- Real_Time returns Integer, whereas we actually want
-- Unsigned_32.
vTaskDelay
(Ticks_To_Delay => Interfaces.Unsigned_32 (Ticks_To_Delay));
(Interfaces.Unsigned_32
(Standard."/" (Timespan_To_Delay, Tick)));
end if;
end Delay_Until;

Expand Down
8 changes: 1 addition & 7 deletions test-arduino-due/testbed.adb
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,5 @@ begin
-- Check streams
Streams.Check (42);

declare
use type Ada.Real_Time.Time;
begin
loop
delay until Ada.Real_Time.Clock + Ada.Real_Time.Seconds (10);
end loop;
end;
delay until Ada.Real_Time.Time_Last;
end Testbed;
8 changes: 1 addition & 7 deletions test-stm32f4/testbed.adb
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,5 @@ begin
-- Check streams
Streams.Check (42);

declare
use type Ada.Real_Time.Time;
begin
loop
delay until Ada.Real_Time.Clock + Ada.Real_Time.Seconds (10);
end loop;
end;
delay until Ada.Real_Time.Time_Last;
end Testbed;
8 changes: 1 addition & 7 deletions test-stm32f429i/testbed.adb
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,5 @@ begin
-- Check streams
Streams.Check (42);

declare
use type Ada.Real_Time.Time;
begin
loop
delay until Ada.Real_Time.Clock + Ada.Real_Time.Seconds (10);
end loop;
end;
delay until Ada.Real_Time.Time_Last;
end Testbed;

0 comments on commit 4b25f1d

Please sign in to comment.