Skip to content

Commit 28d935d

Browse files
committed
Add interrupt support. Add a usage example.
1 parent ee139d6 commit 28d935d

File tree

14 files changed

+389
-163
lines changed

14 files changed

+389
-163
lines changed

esp32/adainclude/a-interr.ads

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
-- --
77
-- S p e c --
88
-- --
9-
-- Copyright (C) 1992-2009, 2016-2018, Free Software Foundation, Inc. --
9+
-- Copyright (C) 1992-2009, 2016-2021, Free Software Foundation, Inc. --
1010
-- --
1111
-- This specification is derived from the Ada Reference Manual for use with --
1212
-- GNAT. The copyright notice above, and the license provisions that follow --
@@ -33,14 +33,14 @@
3333
-- --
3434
------------------------------------------------------------------------------
3535

36-
-- Modified from the GCC 4.9.1 version for the Cortex GNAT RTS
37-
-- project, for nRF51.
36+
-- Modified from the GCC 4.9.1 version for the ESP32 GNAT RTS
37+
-- project, for ESP32.
3838

3939
with System;
4040

4141
package Ada.Interrupts is
4242

43-
type Interrupt_ID is range 0 .. 25;
43+
type Interrupt_ID is range 0 .. 68;
4444
-- Has to match System.Interrupts.Interrupt_ID.
4545

4646
type Parameterless_Handler is access protected procedure;

esp32/adainclude/a-intnam.ads

Lines changed: 73 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Copyright (C) 2016-2018 Free Software Foundation, Inc.
1+
-- Copyright (C) 2016-2021 Free Software Foundation, Inc.
22

33
-- This file is part of the Cortex GNAT RTS package.
44
--
@@ -16,63 +16,81 @@
1616
-- along with this program; see the file COPYING3. If not, see
1717
-- <http://www.gnu.org/licenses/>.
1818

19-
-- For the BBC micro:bit (nRF51).
19+
-- For the ESP32. See ESP32 Technical Reference Manual, 2.3.1 Peripheral
20+
-- Interrupt Source
2021

2122
package Ada.Interrupts.Names is
2223

23-
POWER_CLOCK_IRQ : constant Interrupt_ID := 0;
24-
RADIO_IRQ : constant Interrupt_ID := 1;
25-
UART0_IRQ : constant Interrupt_ID := 2;
26-
SPI0_TWI0_IRQ : constant Interrupt_ID := 3;
27-
SPI1_TWI1_IRQ : constant Interrupt_ID := 4;
28-
-- unused
29-
GPIOTE_IRQ : constant Interrupt_ID := 6;
30-
ADC_IRQ : constant Interrupt_ID := 7;
31-
TIMER0_IRQ : constant Interrupt_ID := 8;
32-
TIMER1_IRQ : constant Interrupt_ID := 9;
33-
TIMER2_IRQ : constant Interrupt_ID := 10;
34-
RTC0_IRQ : constant Interrupt_ID := 11;
35-
TEMP_IRQ : constant Interrupt_ID := 12;
36-
RNG_IRQ : constant Interrupt_ID := 13;
37-
ECB_IRQ : constant Interrupt_ID := 14;
38-
CCM_AAR_IRQ : constant Interrupt_ID := 15;
39-
WDT_IRQ : constant Interrupt_ID := 16;
40-
RTC1_IRQ : constant Interrupt_ID := 17;
41-
QDEC_IRQ : constant Interrupt_ID := 18;
42-
LPCOMP_IRQ : constant Interrupt_ID := 19;
43-
SWI0_IRQ : constant Interrupt_ID := 20;
44-
SWI1_IRQ : constant Interrupt_ID := 21;
45-
SWI2_IRQ : constant Interrupt_ID := 22;
46-
SWI3_IRQ : constant Interrupt_ID := 23;
47-
SWI4_IRQ : constant Interrupt_ID := 24;
48-
SWI5_IRQ : constant Interrupt_ID := 25;
24+
MAC_INTR : constant Interrupt_ID := 0;
25+
MAC_NMI : constant Interrupt_ID := 1;
26+
BB_INT : constant Interrupt_ID := 2;
27+
BT_MAC_INT : constant Interrupt_ID := 3;
28+
BT_BB_INT : constant Interrupt_ID := 4;
29+
BT_BB_NMI : constant Interrupt_ID := 5;
30+
RWBT_IRQ : constant Interrupt_ID := 6;
31+
RWBLE_IRQ : constant Interrupt_ID := 7;
32+
RWBT_NMI : constant Interrupt_ID := 8;
33+
RWBLE_NMI : constant Interrupt_ID := 9;
34+
SLC0_INTR : constant Interrupt_ID := 10;
35+
SLC1_INTR : constant Interrupt_ID := 11;
36+
UHCI0_INTR : constant Interrupt_ID := 12;
37+
UHCI1_INTR : constant Interrupt_ID := 13;
38+
TG_T0_LEVEL_INT : constant Interrupt_ID := 14;
39+
TG_T1_LEVEL_INT : constant Interrupt_ID := 15;
40+
TG_WDT_LEVEL_INT : constant Interrupt_ID := 16;
41+
TG_LACT_LEVEL_INT : constant Interrupt_ID := 17;
42+
TG1_T0_LEVEL_INT : constant Interrupt_ID := 18;
43+
TG1_T1_LEVEL_INT : constant Interrupt_ID := 19;
44+
TG1_WDT_LEVEL_INT : constant Interrupt_ID := 20;
45+
TG1_LACT_LEVEL_INT : constant Interrupt_ID := 21;
46+
GPIO_INTERRUPT : constant Interrupt_ID := 22;
47+
GPIO_INTERRUPT_NMI : constant Interrupt_ID := 23;
48+
CPU_INTR_FROM_CPU_0 : constant Interrupt_ID := 24;
49+
CPU_INTR_FROM_CPU_1 : constant Interrupt_ID := 25;
50+
CPU_INTR_FROM_CPU_2 : constant Interrupt_ID := 26;
51+
CPU_INTR_FROM_CPU_3 : constant Interrupt_ID := 27;
52+
SPI_INTR_0 : constant Interrupt_ID := 28;
53+
SPI_INTR_1 : constant Interrupt_ID := 29;
54+
SPI_INTR_2 : constant Interrupt_ID := 30;
55+
SPI_INTR_3 : constant Interrupt_ID := 31;
4956

50-
-- AdaCore naming
51-
POWER_CLOCK_Interrupt : constant Interrupt_ID := 0;
52-
RADIO_Interrupt : constant Interrupt_ID := 1;
53-
UART0_Interrupt : constant Interrupt_ID := 2;
54-
SPI0_TWI0_Interrupt : constant Interrupt_ID := 3;
55-
SPI1_TWI1_Interrupt : constant Interrupt_ID := 4;
56-
-- unused
57-
GPIOTE_Interrupt : constant Interrupt_ID := 6;
58-
ADC_Interrupt : constant Interrupt_ID := 7;
59-
TIMER0_Interrupt : constant Interrupt_ID := 8;
60-
TIMER1_Interrupt : constant Interrupt_ID := 9;
61-
TIMER2_Interrupt : constant Interrupt_ID := 10;
62-
RTC0_Interrupt : constant Interrupt_ID := 11;
63-
TEMP_Interrupt : constant Interrupt_ID := 12;
64-
RNG_Interrupt : constant Interrupt_ID := 13;
65-
ECB_Interrupt : constant Interrupt_ID := 14;
66-
CCM_AAR_Interrupt : constant Interrupt_ID := 15;
67-
WDT_Interrupt : constant Interrupt_ID := 16;
68-
RTC1_Interrupt : constant Interrupt_ID := 17;
69-
QDEC_Interrupt : constant Interrupt_ID := 18;
70-
LPCOMP_Interrupt : constant Interrupt_ID := 19;
71-
SWI0_Interrupt : constant Interrupt_ID := 20;
72-
SWI1_Interrupt : constant Interrupt_ID := 21;
73-
SWI2_Interrupt : constant Interrupt_ID := 22;
74-
SWI3_Interrupt : constant Interrupt_ID := 23;
75-
SWI4_Interrupt : constant Interrupt_ID := 24;
76-
SWI5_Interrupt : constant Interrupt_ID := 25;
57+
I2S0_INT : constant Interrupt_ID := 32;
58+
I2S1_INT : constant Interrupt_ID := 33;
59+
UART_INTR : constant Interrupt_ID := 34;
60+
UART1_INTR : constant Interrupt_ID := 35;
61+
UART2_INTR : constant Interrupt_ID := 36;
62+
SDIO_HOST_INTERRUPT : constant Interrupt_ID := 37;
63+
EMAC_INT : constant Interrupt_ID := 38;
64+
PWM0_INTR : constant Interrupt_ID := 39;
65+
PWM1_INTR : constant Interrupt_ID := 40;
66+
PWM2_INTR : constant Interrupt_ID := 41;
67+
PWM3_INTR : constant Interrupt_ID := 42;
68+
LEDC_INT : constant Interrupt_ID := 43;
69+
EFUSE_INT : constant Interrupt_ID := 44;
70+
CAN_INT : constant Interrupt_ID := 45;
71+
RTC_CORE_INTR : constant Interrupt_ID := 46;
72+
RMT_INTR : constant Interrupt_ID := 47;
73+
PCNT_INTR : constant Interrupt_ID := 48;
74+
I2C_EXT0_INTR : constant Interrupt_ID := 49;
75+
I2C_EXT1_INTR : constant Interrupt_ID := 50;
76+
RSA_INTR : constant Interrupt_ID := 51;
77+
SPI1_DMA_INT : constant Interrupt_ID := 52;
78+
SPI2_DMA_INT : constant Interrupt_ID := 53;
79+
SPI3_DMA_INT : constant Interrupt_ID := 54;
80+
WDG_INT : constant Interrupt_ID := 55;
81+
TIMER_INT1 : constant Interrupt_ID := 56;
82+
TIMER_INT2 : constant Interrupt_ID := 57;
83+
TG_T0_EDGE_INT : constant Interrupt_ID := 58;
84+
TG_T1_EDGE_INT : constant Interrupt_ID := 59;
85+
TG_WDT_EDGE_INT : constant Interrupt_ID := 60;
86+
TG_LACT_EDGE_INT : constant Interrupt_ID := 61;
87+
TG1_T0_EDGE_INT : constant Interrupt_ID := 62;
88+
TG1_T1_EDGE_INT : constant Interrupt_ID := 63;
89+
90+
TG1_WDT_EDGE_INT : constant Interrupt_ID := 64;
91+
TG1_LACT_EDGE_INT : constant Interrupt_ID := 65;
92+
MMU_IA_INT : constant Interrupt_ID := 66;
93+
MPU_IA_INT : constant Interrupt_ID := 67;
94+
CACHE_IA_INT : constant Interrupt_ID := 68;
7795

7896
end Ada.Interrupts.Names;

esp32/adainclude/s-interr.adb

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Copyright (C) 2016-2018 Free Software Foundation, Inc.
1+
-- Copyright (C) 2016-2021 Free Software Foundation, Inc.
22
--
33
-- This file is part of the Cortex GNAT RTS project. This file is
44
-- free software; you can redistribute it and/or modify it under
@@ -18,13 +18,70 @@
1818
-- program; see the files COPYING3 and COPYING.RUNTIME respectively.
1919
-- If not, see <http://www.gnu.org/licenses/>.
2020

21+
with Ada.Unchecked_Conversion;
22+
with Interfaces.C;
23+
2124
package body System.Interrupts is
2225

26+
type Handler_Wrapper is access procedure (Obj : System.Address)
27+
with Convention => C;
28+
29+
type Parameterless_Handler_Impl is record
30+
Object : System.Address;
31+
Wrapper : Handler_Wrapper;
32+
end record
33+
with
34+
Size => 64;
35+
36+
function To_Impl_View
37+
is new Ada.Unchecked_Conversion (Parameterless_Handler,
38+
Parameterless_Handler_Impl);
39+
40+
function esp_intr_alloc
41+
(source : Interfaces.C.int;
42+
flags : Interfaces.C.int;
43+
handler : Handler_Wrapper;
44+
arg : System.Address;
45+
ret_handle : System.Address) return Interfaces.C.int
46+
with Import, Convention => C, External_Name => "esp_intr_alloc";
47+
48+
---------------------------------
49+
-- Install_Restricted_Handlers --
50+
---------------------------------
51+
2352
procedure Install_Restricted_Handlers
2453
(Prio : Any_Priority;
25-
Handlers : New_Handler_Array) is
54+
Handlers : New_Handler_Array)
55+
is
56+
Priority : constant Interrupt_Priority :=
57+
Any_Priority'Max (Interrupt_Priority'First, Prio);
2658
begin
27-
raise Program_Error; -- Unimplemented
59+
for H of Handlers loop
60+
declare
61+
Impl : constant Parameterless_Handler_Impl :=
62+
To_Impl_View (H.Handler);
63+
Interrupt : constant Natural := Natural (H.Interrupt);
64+
65+
use type Interfaces.C.int;
66+
Error : Interfaces.C.int;
67+
ESP_OK : constant := 0;
68+
-- ESP_INTR_FLAG_SHARED : constant := 2 ** 8;
69+
Level : constant Interfaces.C.int :=
70+
2 ** (Priority - Interrupt_Priority'First + 1);
71+
begin
72+
Error := esp_intr_alloc
73+
(source => Interfaces.C.int (Interrupt),
74+
flags => Level,
75+
handler => Impl.Wrapper,
76+
arg => Impl.Object,
77+
ret_handle => System.Null_Address);
78+
79+
if Error /= ESP_OK then
80+
raise Program_Error;
81+
end if;
82+
83+
end;
84+
end loop;
2885
end Install_Restricted_Handlers;
2986

3087
procedure Install_Restricted_Handlers_Sequential is

esp32/adainclude/s-interr.ads

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Copyright (C) 2016-2018 Free Software Foundation, Inc.
1+
-- Copyright (C) 2016-2021 Free Software Foundation, Inc.
22
--
33
-- This file is part of the Cortex GNAT RTS project. This file is
44
-- free software; you can redistribute it and/or modify it under
@@ -20,8 +20,8 @@
2020
-- --
2121
------------------------------------------------------------------------------
2222

23-
-- Modified from the GCC 4.9.1 version for the Cortex GNAT RTS
24-
-- project, for micro:bit.
23+
-- Modified from the GCC 4.9.1 version for the ESP32 GNAT RTS
24+
-- project, for ESP32.
2525

2626
package System.Interrupts is
2727

@@ -30,7 +30,7 @@ package System.Interrupts is
3030
-- Used (via rtsfind) when Interrupt_Priority isn't specified for
3131
-- a PO. This can only happen if the pragma form is used.
3232

33-
type Interrupt_ID is range 0 .. 25;
33+
type Interrupt_ID is range 0 .. 68;
3434
-- Has to match Ada.Interrupts.Interrupt_ID.
3535

3636
subtype System_Interrupt_ID is Interrupt_ID;

esp32/adainclude/system.ads

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
-- --
3737
------------------------------------------------------------------------------
3838

39-
-- This file has been extensively modified for the Cortex GNAT RTS
39+
-- This file has been extensively modified for the ESP32 GNAT RTS
4040
-- project.
4141

4242
pragma Profile (Ravenscar);
@@ -47,7 +47,8 @@ pragma Restrictions (No_Finalization);
4747
-- If pragma Restrictions (No_Recursion) is required, make it a
4848
-- configuration pragma.
4949

50-
-- pragma Restrictions (No_Implicit_Dynamic_Code) not applied; it
50+
pragma Restrictions (No_Implicit_Dynamic_Code);
51+
-- ESP32 has separate code/data memory regions, so
5152
-- forbids trampolines, which are needed for 'Unrestricted_Access,
5253
-- especially for foreign-convention subprograms.
5354

@@ -111,8 +112,8 @@ package System is
111112

112113
-- These declarations correspond to FreeRTOS as originally
113114
-- configured in STM Cube (thread priorities 0 .. 7), with
114-
-- priorities 8 to 10 mapped to Cortex interrupt priorities 3
115-
-- (lowest) to 1 (highest that can be used by ISRs that call
115+
-- priorities 8 to 10 mapped to ESP32 interrupt priorities 1
116+
-- (lowest) to 3 (medium, that can be used by ISRs that call
116117
-- interrupt-safe FreeRTOS API functions).
117118

118119
Max_Priority : constant Positive := 7;

0 commit comments

Comments
 (0)