Skip to content

Commit ee139d6

Browse files
committed
Replace main C subprogram by an Ada subprogram
declared in environment_task.adb to simplify dependency list in CMakeLists.txt. Edit README.md
1 parent b73178e commit ee139d6

File tree

10 files changed

+42
-42
lines changed

10 files changed

+42
-42
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ b__*.ad?
1212

1313
.build*
1414
obj
15+
.objs
1516
test
1617
doc
1718
cortex-gnat-rts*
@@ -22,6 +23,7 @@ gnatinspect.db
2223
gpr_query.*
2324

2425
local/
26+
examples/*/build/
2527

2628
demos-arduino-due/debounce_hardware
2729
demos-arduino-due/debounce_software

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ location of Flash, RAM; clock initialization; interrupt naming) is in
2323
The Ada source is either original or based on FSF GCC (mainly 4.9.1, some
2424
later releases too).
2525

26-
The boards supported are
26+
Any board with ESP32 should work. We have tested with
2727

2828
* Wireless Stick (Gecko Board) by Heltec
29-
* See `esp32/COPYING*` for licensing terms.
30-
* Example in `examples/`.
31-
29+
* TTGO T-Display ESP32 (Make sure to change LED pin to 2).
3230

3331
The package is based on
3432
[Cortex-GNAT-RTS](https://github.com/simonjwright/cortex-gnat-rts)
@@ -107,8 +105,9 @@ Ada code into ESP-IDF application.
107105

108106
The `hello_world` application is an ESP-IDF project.
109107
It requires `esp32-gnat-rts` component as dependency.
110-
The `hello_world.c` main subprogram just calls `main` function (created by
111-
`gnatbind`).
108+
The `app_main` subprogram called by FreeRTOS is declared in
109+
`environment_task.adb`. It creates an _environment task_ that
110+
calls `main` function (created by `gnatbind`).
112111
In turn `main` calls `Hello_Ada` procedure.
113112
The `Hello_Ada` outputs "Hello Ada!" with `puts` provided by FreeRTOS.
114113

common/gcc8/environment_task.adb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ package body Environment_Task is
6464
External_Name => "_environment_task_secondary_stack_size";
6565
pragma Weak_External (Environment_Task_Secondary_Stack_Size);
6666

67+
procedure App_Main
68+
with
69+
Export,
70+
Convention => C,
71+
External_Name => "app_main";
72+
73+
procedure App_Main is
74+
begin
75+
Create;
76+
end App_Main;
77+
6778
procedure Create is
6879
-- Will be overwritten by binder-generated code if the main
6980
-- program has pragma Priority.

esp32/README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
This is an Ada Runtime System (RTS) for the GCC Ada compiler (GNAT), targeted to the [BBC micro:bit board](http://microbit.org/).
1+
This is an Ada Runtime System (RTS) for the GCC Ada compiler (GNAT),
2+
targeted to boards based on the [ESP32](https://en.wikipedia.org/wiki/ESP32).
23

34
The RTS supports Ravenscar tasking. Package System contains the following additional restrictions:
45

56
* `pragma Restrictions (No_Exception_Propagation);`
67
* `pragma Restrictions (No_Finalization);`
78

8-
Aside from the limitations imposed by the small RAM size of the micro:bit (16K), the system clock runs at 100 Hz rather than the 1000 Hz used in the other RTSs in this family.
9-
109
The RTS is intended to support commercial binary distributions. The Ada source code has either been derived from FSF GCC (4.9.1, in some cases later) or written for this work; see the files `COPYING3` and `COPYING.RUNTIME`.
1110

1211
The RTS is based on [FreeRTOS]( http://www.freertos.org). See `COPYING.FreeRTOS`.
1312

14-
Board support (spec files only) was generated using [svd2ada](https://github.com/AdaCore/svd2ada) at commit `861c829` from the Nordic SVD. See `COPYING.Nordic`.
15-
1613
The following non-original files don't form part of a binary deliverable, so don't affect the status of the binary:
1714

1815
* `build_runtime.gpr` and `runtime.xml` originated in AdaCore's GNAT GPL 2014 arm-eabi distribution (for Linux).
19-
* The linker script `nrf51.ld` is under an MIT licence: see COPYING.MIT.
16+

examples/gpio/main/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ if(NOT CMAKE_BUILD_EARLY_EXPANSION)
1515
VERBATIM)
1616
endif()
1717

18-
idf_component_register(SRCS "blink.c"
19-
".objs/b__blink.o"
18+
idf_component_register(SRCS ".objs/b__blink.o"
2019
".objs/blink.o"
2120
".objs/esp32-gpio.o"
2221
".objs/esp32.o"

examples/gpio/main/blink.adb

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
with Ada.Real_Time;
77
with ESP32.GPIO;
88

9-
procedure blink is
9+
procedure Blink
10+
with No_Return
11+
is
1012
use type Ada.Real_Time.Time;
1113

1214
Button : constant := 0; -- Button pad
@@ -22,14 +24,15 @@ begin
2224
Direction => ESP32.GPIO.Input,
2325
Input => ESP32.GPIO.None))); -- for Get_Level
2426

25-
for J in 1 .. 10 loop
26-
-- Turl LED if button is not pressed
27-
ESP32.GPIO.Set_Level
28-
(LED, (J mod 2 = 1) and ESP32.GPIO.Get_Level (Button));
27+
loop
28+
for J in 1 .. 10 loop
29+
-- Turl LED if button is not pressed
30+
ESP32.GPIO.Set_Level
31+
(LED, (J mod 2 = 1) and ESP32.GPIO.Get_Level (Button));
2932

30-
delay until Ada.Real_Time.Clock + Ada.Real_Time.Seconds (1);
33+
delay until Ada.Real_Time.Clock + Ada.Real_Time.Seconds (1);
34+
end loop;
3135
end loop;
3236

33-
-- NOTE:
34-
-- Make sure that main subprogram doen't return in a real project!
35-
end blink;
37+
-- Make sure that main subprogram doen't return in a real project!
38+
end Blink;

examples/gpio/main/blink.c

Lines changed: 0 additions & 6 deletions
This file was deleted.

examples/hello_world/main/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ if(NOT CMAKE_BUILD_EARLY_EXPANSION)
1313
VERBATIM)
1414
endif()
1515

16-
idf_component_register(SRCS "hello_world.c"
17-
".objs/b__hello_world.o"
16+
idf_component_register(SRCS ".objs/b__hello_world.o"
1817
".objs/hello_world.o"
1918
INCLUDE_DIRS "."
2019
REQUIRES esp32-gnat-rts)

examples/hello_world/main/hello_world.adb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
with System;
77
with Ada.Real_Time;
88

9-
procedure Hello_World is
9+
procedure Hello_World
10+
with No_Return
11+
is
1012
use type Ada.Real_Time.Time;
1113

1214
procedure puts
@@ -15,10 +17,10 @@ procedure Hello_World is
1517

1618
Hello : String := "Hello from Ada!" & ASCII.NUL;
1719
begin
18-
for J in 1 .. 10 loop
19-
puts (Hello'Address);
20-
delay until Ada.Real_Time.Clock + Ada.Real_Time.Seconds (1);
21-
end loop;
20+
loop
21+
puts (Hello'Address);
22+
delay until Ada.Real_Time.Clock + Ada.Real_Time.Seconds (1);
23+
end loop;
2224

2325
-- NOTE:
2426
-- Make sure that main subprogram doen't return in a real project!

examples/hello_world/main/hello_world.c

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)