Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

time facility and runtime dependencies for code in the "components" dirs

Aperta
#91 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Refactoring
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Ambito
embedded-iot

Direzione di ricerca

Inizia individuando il pacchetto HAL.Time e le astrazioni dei componenti nelle sottodirectory "components", quindi esamina come i gestori di ultima istanza specifici del runtime selezionano le implementazioni. Il lavoro è completo quando i componenti non richiedono più un Delays_Ref fornito dal client, HAL.Time espone routine di ritardo utilizzabili tra i runtime supportati e le quantità di tempo hanno unità chiare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement

Background: We want all component abstractions (the code in the "components" subdirs) to work with all runtimes. The components often require the ability to export time value declarations and execute delay statements. The ZFP runtimes do not include package Ada.Real_Time and do not support delay statements, therefore the components code cannot use them.

We can avoid the use of type Time_Span by declaring the quantities as named numbers, with a comment (or subtype of Integer) indicating what units are intended. For example:

Min_Sample_Interval : constant := 10; -- milliseconds

or

subtype Milliseconds is Natural; -- or Positive
subtype Microseconds is Natural;
...

Min_Sample_Interval : constant Milliseconds := 10;

or even derive the types so that they cannot be mixed accidentally.

Not ideal -- after all, Ada.Real_Time is included in the language to make this sort of thing unnecessary -- but acceptable.

However, that does not address the issue of delay statements.

Currently we have HAL.Time as a replacement for Ada.Real_Time:

package HAL.Time is

  type Delays is limited interface;

  type Delays_Ref is access all Delays'Class;

  procedure Delay_Microseconds (This : in out Delays;
                                Us   : Integer) is abstract;

  procedure Delay_Milliseconds (This : in out Delays;
                                Ms   : Integer) is abstract;

  procedure Delay_Seconds      (This : in out Delays;
                                S    : Integer) is abstract;

end HAL.Time;

with the intention of there being some concrete subclass implementations that do use delay statements, when a ravenscar-* runtime is in use, and other implementations that do not, when using a ZFP runtime.

Given that interface, we are using the access-to-classwide type as a discriminant in the declarations of the component abstraction types in order to make the components independent of the runtimes. For example, the Time discriminant:

type STMPE811_Device
(Port : not null I2C_Port_Ref;
I2C_Addr : I2C_Address;
Time : not null HAL.Time.Delays_Ref) is`

The problems with that approach are:

  1. It makes the client (user) code responsible for what is otherwise strictly an implementation detail. This is a very serious flaw in terms of software engineering.

  2. It "pollutes" the API with something that has nothing to do with applying the component itself.

  3. It is a rather heavy approach.

My suggestion: make HAL.Time have concrete delay routines, with the selection of the body of the package controlled by the runtime selection, something like what we do now for the last chance handlers that can use an LCD when the board supports it. Then the components code could just call the routines directly, without the client code having to do anything in that regard.

Something like this:

package HAL.Time is

  procedure Delay_Microseconds (Count : Natural);

  procedure Delay_Milliseconds (Count : Natural);

  procedure Delay_Seconds (Count : Natural);

end HAL.Time;

although we would likely declare the subtypes or derived types

subtype Milliseconds is Natural;
subtype Microseconds is Natural;
...

in that package too.

Thoughts?

Lingua principale
Ada
Stelle
286
Fork
165
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di AdaCore/Ada_Drivers_Library

Tutte le issue di AdaCore/Ada_Drivers_Library

Issue simili

Altre issue su Embedded & IoT

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.