Skip to content

Commit

Permalink
Add rt-riscv and rt-xtensa features to esp-hal-common to allow …
Browse files Browse the repository at this point in the history
…enabling/disable runtime support
  • Loading branch information
jessebraham committed Jan 2, 2024
1 parent 2e2d67f commit d7bb3e2
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 24 deletions.
23 changes: 14 additions & 9 deletions esp-hal-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ embassy-sync = { version = "0.5.0", optional = true }
embassy-time = { version = "0.2.0", optional = true }

# RISC-V
esp-riscv-rt = { version = "0.6.0", optional = true, path = "../esp-riscv-rt" }
riscv = { version = "0.10.1", optional = true }
esp-riscv-rt = { version = "0.6.0", optional = true, path = "../esp-riscv-rt" }

# Xtensa
xtensa-lx = { version = "0.8.0", optional = true }
Expand All @@ -73,18 +74,22 @@ basic-toml = "0.1.7"
serde = { version = "1.0.193", features = ["derive"] }

[features]
esp32 = ["xtensa", "esp32/rt", "procmacros/esp32", "xtensa-lx/esp32", "xtensa-lx-rt/esp32"]
esp32c2 = ["riscv", "esp32c2/rt", "procmacros/esp32c2", "portable-atomic/unsafe-assume-single-core"]
esp32c3 = ["riscv", "esp32c3/rt", "procmacros/esp32c3", "portable-atomic/unsafe-assume-single-core"]
esp32c6 = ["riscv", "esp32c6/rt", "procmacros/esp32c6"]
esp32h2 = ["riscv", "esp32h2/rt", "procmacros/esp32h2"]
esp32s2 = ["xtensa", "esp32s2/rt", "procmacros/esp32s2", "xtensa-lx/esp32s2", "xtensa-lx-rt/esp32s2", "usb-otg", "portable-atomic/critical-section"]
esp32s3 = ["xtensa", "esp32s3/rt", "procmacros/esp32s3", "xtensa-lx/esp32s3", "xtensa-lx-rt/esp32s3", "usb-otg"]
esp32 = ["dep:esp32", "xtensa", "procmacros/esp32", "xtensa-lx/esp32", "xtensa-lx-rt?/esp32"]
esp32c2 = ["dep:esp32c2", "riscv", "procmacros/esp32c2", "portable-atomic/unsafe-assume-single-core"]
esp32c3 = ["dep:esp32c3", "riscv", "procmacros/esp32c3", "portable-atomic/unsafe-assume-single-core"]
esp32c6 = ["dep:esp32c6", "riscv", "procmacros/esp32c6"]
esp32h2 = ["dep:esp32h2", "riscv", "procmacros/esp32h2"]
esp32s2 = ["dep:esp32s2", "xtensa", "procmacros/esp32s2", "xtensa-lx/esp32s2", "xtensa-lx-rt?/esp32s2", "usb-otg", "portable-atomic/critical-section"]
esp32s3 = ["dep:esp32s3", "xtensa", "procmacros/esp32s3", "xtensa-lx/esp32s3", "xtensa-lx-rt?/esp32s3", "usb-otg"]

# Crystal frequency selection (ESP32 and ESP32-C2 only!)
xtal-26mhz = []
xtal-40mhz = []

# Runetime support
rt-riscv = ["esp-riscv-rt/zero-bss", "esp32c2?/rt", "esp32c3?/rt", "esp32c6?/rt", "esp32h2?/rt"]
rt-xtensa = ["dep:xtensa-lx-rt", "esp32?/rt", "esp32s2?/rt", "esp32s3?/rt"]

# Only certain chips support flip-link (ESP32-C6 and ESPS32-H2)
flip-link = ["esp-riscv-rt/fix-sp"]

Expand Down Expand Up @@ -150,7 +155,7 @@ embassy-generic-queue-64 = ["embassy-time/generic-queue-64"]
embassy-generic-queue-128 = ["embassy-time/generic-queue-128"]

# Architecture-specific features (intended for internal use)
riscv = ["critical-section/restore-state-u8", "esp-riscv-rt", "esp-riscv-rt/zero-bss"]
riscv = ["dep:riscv", "critical-section/restore-state-u8"]
xtensa = ["critical-section/restore-state-u32"]

# Initialize / clear data sections and RTC memory
Expand Down
4 changes: 2 additions & 2 deletions esp-hal-common/src/interrupt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
//! ```
#[cfg(riscv)]
pub use riscv::*;
pub use self::riscv::*;
#[cfg(xtensa)]
pub use xtensa::*;
pub use self::xtensa::*;

#[cfg(riscv)]
mod riscv;
Expand Down
12 changes: 7 additions & 5 deletions esp-hal-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
// MUST be the first module
mod fmt;

#[cfg(riscv)]
#[cfg(feature = "rt-riscv")]
pub use esp_riscv_rt::{self, entry, riscv};
pub use procmacros as macros;
#[cfg(xtensa)]
pub use xtensa_lx;
#[cfg(xtensa)]
#[cfg(feature = "rt-xtensa")]
pub use xtensa_lx_rt::{self, entry};

#[cfg(adc)]
Expand Down Expand Up @@ -104,7 +104,10 @@ pub mod hmac;
pub mod i2c;
#[cfg(any(i2s0, i2s1))]
pub mod i2s;
#[cfg(any(dport, interrupt_core0, interrupt_core1))]
#[cfg(all(
any(dport, interrupt_core0, interrupt_core1),
any(feature = "rt-riscv", feature = "rt-xtensa")
))]
pub mod interrupt;
#[cfg(ledc)]
pub mod ledc;
Expand Down Expand Up @@ -150,6 +153,7 @@ pub mod uart;
pub mod usb_serial_jtag;

/// State of the CPU saved when entering exception or interrupt
#[cfg(any(feature = "rt-riscv", feature = "rt-xtensa"))]
pub mod trapframe {
#[cfg(riscv)]
pub use esp_riscv_rt::TrapFrame;
Expand Down Expand Up @@ -278,8 +282,6 @@ mod critical_section_impl {

#[cfg(riscv)]
mod riscv {
use esp_riscv_rt::riscv;

#[cfg(multi_core)]
// The restore state is a u8 that is casted from a bool, so it has a value of
// 0x00 or 0x01 before we add the reentry flag to it.
Expand Down
4 changes: 3 additions & 1 deletion esp-hal-common/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub use crate::dma::{
DmaTransfer as _esp_hal_dma_DmaTransfer,
DmaTransferRxTx as _esp_hal_dma_DmaTransferRxTx,
};
#[cfg(any(feature = "rt-riscv", feature = "rt-xtensa"))]
pub use crate::entry;
#[cfg(gpio)]
pub use crate::gpio::{
InputPin as _esp_hal_gpio_InputPin,
Expand All @@ -59,4 +61,4 @@ pub use crate::timer::{
};
#[cfg(any(uart0, uart1, uart2))]
pub use crate::uart::{Instance as _esp_hal_uart_Instance, UartPins as _esp_hal_uart_UartPins};
pub use crate::{clock::Clock as _esp_hal_clock_Clock, entry, macros::*};
pub use crate::{clock::Clock as _esp_hal_clock_Clock, macros::*};
2 changes: 1 addition & 1 deletion esp32-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ debug = ["esp-hal-common/debug"]
defmt = ["esp-hal-common/defmt", "esp-println/defmt"]
eh1 = ["esp-hal-common/eh1"]
log = ["esp-hal-common/log", "esp-println/log"]
rt = []
rt = ["esp-hal-common/rt-xtensa"]
ufmt = ["esp-hal-common/ufmt"]
vectored = ["esp-hal-common/vectored"]
xtal-26mhz = ["esp-hal-common/xtal-26mhz"]
Expand Down
2 changes: 1 addition & 1 deletion esp32c2-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ direct-vectoring = ["esp-hal-common/direct-vectoring"]
eh1 = ["esp-hal-common/eh1"]
interrupt-preemption = ["esp-hal-common/interrupt-preemption"]
log = ["esp-hal-common/log", "esp-println/log"]
rt = []
rt = ["esp-hal-common/rt-riscv"]
ufmt = ["esp-hal-common/ufmt"]
vectored = ["esp-hal-common/vectored"]
xtal-26mhz = ["esp-hal-common/xtal-26mhz"]
Expand Down
2 changes: 1 addition & 1 deletion esp32c3-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ direct-vectoring = ["esp-hal-common/direct-vectoring"]
eh1 = ["esp-hal-common/eh1"]
interrupt-preemption = ["esp-hal-common/interrupt-preemption"]
log = ["esp-hal-common/log", "esp-println/log"]
rt = []
rt = ["esp-hal-common/rt-riscv"]
ufmt = ["esp-hal-common/ufmt"]
vectored = ["esp-hal-common/vectored"]

Expand Down
2 changes: 1 addition & 1 deletion esp32c6-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ direct-vectoring = ["esp-hal-common/direct-vectoring"]
eh1 = ["esp-hal-common/eh1"]
interrupt-preemption = ["esp-hal-common/interrupt-preemption"]
log = ["esp-hal-common/log", "esp-println/log"]
rt = []
rt = ["esp-hal-common/rt-riscv"]
ufmt = ["esp-hal-common/ufmt"]
vectored = ["esp-hal-common/vectored"]
flip-link = ["esp-hal-common/flip-link"]
Expand Down
2 changes: 1 addition & 1 deletion esp32h2-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ direct-vectoring = ["esp-hal-common/direct-vectoring"]
eh1 = ["esp-hal-common/eh1"]
interrupt-preemption = ["esp-hal-common/interrupt-preemption"]
log = ["esp-hal-common/log", "esp-println/log"]
rt = []
rt = ["esp-hal-common/rt-riscv"]
ufmt = ["esp-hal-common/ufmt"]
vectored = ["esp-hal-common/vectored"]
flip-link = ["esp-hal-common/flip-link"]
Expand Down
2 changes: 1 addition & 1 deletion esp32s2-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ debug = ["esp-hal-common/debug"]
defmt = ["esp-hal-common/defmt", "esp-println/defmt"]
eh1 = ["esp-hal-common/eh1"]
log = ["esp-hal-common/log", "esp-println/log"]
rt = []
rt = ["esp-hal-common/rt-xtensa"]
ufmt = ["esp-hal-common/ufmt"]
vectored = ["esp-hal-common/vectored"]

Expand Down
2 changes: 1 addition & 1 deletion esp32s3-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ debug = ["esp-hal-common/debug"]
defmt = ["esp-hal-common/defmt", "esp-println/defmt"]
eh1 = ["esp-hal-common/eh1"]
log = ["esp-hal-common/log", "esp-println/log"]
rt = []
rt = ["esp-hal-common/rt-xtensa"]
ufmt = ["esp-hal-common/ufmt"]
vectored = ["esp-hal-common/vectored"]

Expand Down

0 comments on commit d7bb3e2

Please sign in to comment.