Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use settings.yaml with svd2rust for RISC-V devices #303

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions esp32c2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ bench = false
test = false

[dependencies]
critical-section = { version = "1.1.3", optional = true }
vcell = "0.1.3"
defmt = { version = "0.3.8", optional = true }
critical-section = { version = "1.2.0", optional = true }
defmt = { version = "0.3.8", optional = true }
riscv = "0.12.1"
vcell = "0.1.3"

[features]
default = []
rt = []
default = []
defmt = ["dep:defmt"]
impl-register-debug = []
defmt = ["dep:defmt"]
rt = []
20 changes: 20 additions & 0 deletions esp32c2/device.x
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
/* Core interrupt sources and trap handlers */
PROVIDE(UserSoft = DefaultHandler);
PROVIDE(_start_UserSoft_trap = _start_DefaultHandler_trap);
PROVIDE(SupervisorSoft = DefaultHandler);
PROVIDE(_start_SupervisorSoft_trap = _start_DefaultHandler_trap);
PROVIDE(MachineSoft = DefaultHandler);
PROVIDE(_start_MachineSoft_trap = _start_DefaultHandler_trap);
PROVIDE(UserTimer = DefaultHandler);
PROVIDE(_start_UserTimer_trap = _start_DefaultHandler_trap);
PROVIDE(SupervisorTimer = DefaultHandler);
PROVIDE(_start_SupervisorTimer_trap = _start_DefaultHandler_trap);
PROVIDE(MachineTimer = DefaultHandler);
PROVIDE(_start_MachineTimer_trap = _start_DefaultHandler_trap);
PROVIDE(UserExternal = DefaultHandler);
PROVIDE(_start_UserExternal_trap = _start_DefaultHandler_trap);
PROVIDE(SupervisorExternal = DefaultHandler);
PROVIDE(_start_SupervisorExternal_trap = _start_DefaultHandler_trap);
PROVIDE(MachineExternal = DefaultHandler);
PROVIDE(_start_MachineExternal_trap = _start_DefaultHandler_trap);
/* External interrupt sources */
PROVIDE(WIFI_MAC = DefaultHandler);
PROVIDE(WIFI_MAC_NMI = DefaultHandler);
PROVIDE(WIFI_PWR = DefaultHandler);
Expand Down
81 changes: 81 additions & 0 deletions esp32c2/settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
riscv_config:
core_interrupts:
- name: "UserSoft"
value: 0
description: "User Software Interrupt"
- name: "SupervisorSoft"
value: 1
description: "Supervisor Software Interrupt"
- name: "MachineSoft"
value: 3
description: "Machine Software Interrupt"
- name: "UserTimer"
value: 4
description: "User Timer Interrupt"
- name: "SupervisorTimer"
value: 5
description: "Supervisor Timer Interrupt"
- name: "MachineTimer"
value: 7
description: "Machine Timer Interrupt"
- name: "UserExternal"
value: 8
description: "User External Interrupt"
- name: "SupervisorExternal"
value: 9
description: "Supervisor External Interrupt"
- name: "MachineExternal"
value: 11
description: "Machine External Interrupt"

priorities:
- name: "P1"
value: 1
description: "Priority level 1"
- name: "P2"
value: 2
description: "Priority level 2"
- name: "P3"
value: 3
description: "Priority level 3"
- name: "P4"
value: 4
description: "Priority level 4"
- name: "P5"
value: 5
description: "Priority level 5"
- name: "P6"
value: 6
description: "Priority level 6"
- name: "P7"
value: 7
description: "Priority level 7"
- name: "P8"
value: 8
description: "Priority level 8"
- name: "P9"
value: 9
description: "Priority level 9"
- name: "P10"
value: 10
description: "Priority level 10"
- name: "P11"
value: 11
description: "Priority level 11"
- name: "P12"
value: 12
description: "Priority level 12"
- name: "P13"
value: 13
description: "Priority level 13"
- name: "P14"
value: 14
description: "Priority level 14"
- name: "P15"
value: 15
description: "Priority level 15"

harts:
- name: "H0"
value: 0
description: "Hart 0"
189 changes: 92 additions & 97 deletions esp32c2/src/interrupt.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,96 @@
#[doc = r"Enumeration of all the interrupts."]
#[doc = r" Core interrupts. These interrupts are handled by the core itself."]
# [riscv :: pac_enum (unsafe CoreInterruptNumber)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u16)]
pub enum Interrupt {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CoreInterrupt {
#[doc = "0 - User Software Interrupt"]
UserSoft = 0,
#[doc = "1 - Supervisor Software Interrupt"]
SupervisorSoft = 1,
#[doc = "3 - Machine Software Interrupt"]
MachineSoft = 3,
#[doc = "4 - User Timer Interrupt"]
UserTimer = 4,
#[doc = "5 - Supervisor Timer Interrupt"]
SupervisorTimer = 5,
#[doc = "7 - Machine Timer Interrupt"]
MachineTimer = 7,
#[doc = "8 - User External Interrupt"]
UserExternal = 8,
#[doc = "9 - Supervisor External Interrupt"]
SupervisorExternal = 9,
#[doc = "11 - Machine External Interrupt"]
MachineExternal = 11,
}
pub use riscv::interrupt::Exception;
#[doc = r" Priority levels in the device"]
# [riscv :: pac_enum (unsafe PriorityNumber)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Priority {
#[doc = "1 - Priority level 1"]
P1 = 1,
#[doc = "2 - Priority level 2"]
P2 = 2,
#[doc = "3 - Priority level 3"]
P3 = 3,
#[doc = "4 - Priority level 4"]
P4 = 4,
#[doc = "5 - Priority level 5"]
P5 = 5,
#[doc = "6 - Priority level 6"]
P6 = 6,
#[doc = "7 - Priority level 7"]
P7 = 7,
#[doc = "8 - Priority level 8"]
P8 = 8,
#[doc = "9 - Priority level 9"]
P9 = 9,
#[doc = "10 - Priority level 10"]
P10 = 10,
#[doc = "11 - Priority level 11"]
P11 = 11,
#[doc = "12 - Priority level 12"]
P12 = 12,
#[doc = "13 - Priority level 13"]
P13 = 13,
#[doc = "14 - Priority level 14"]
P14 = 14,
#[doc = "15 - Priority level 15"]
P15 = 15,
}
#[doc = r" HARTs in the device"]
# [riscv :: pac_enum (unsafe HartIdNumber)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Hart {
#[doc = "0 - Hart 0"]
H0 = 0,
}
pub use riscv::{
interrupt::{disable, enable, free, nested},
ExceptionNumber, HartIdNumber, InterruptNumber, PriorityNumber,
};
pub type Trap = riscv::interrupt::Trap<CoreInterrupt, Exception>;
#[doc = r" Retrieves the cause of a trap in the current hart."]
#[doc = r""]
#[doc = r" If the raw cause is not a valid interrupt or exception for the target, it returns an error."]
#[inline]
pub fn try_cause() -> riscv::result::Result<Trap> {
riscv::interrupt::try_cause()
}
#[doc = r" Retrieves the cause of a trap in the current hart (machine mode)."]
#[doc = r""]
#[doc = r" If the raw cause is not a valid interrupt or exception for the target, it panics."]
#[inline]
pub fn cause() -> Trap {
try_cause().unwrap()
}
#[doc = r" External interrupts. These interrupts are handled by the external peripherals."]
# [riscv :: pac_enum (unsafe ExternalInterruptNumber)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ExternalInterrupt {
#[doc = "0 - WIFI_MAC"]
WIFI_MAC = 0,
#[doc = "1 - WIFI_MAC_NMI"]
Expand Down Expand Up @@ -88,96 +176,3 @@ pub enum Interrupt {
#[doc = "41 - ETS_CORE0_PIF_PMS_SIZE"]
ETS_CORE0_PIF_PMS_SIZE = 41,
}
#[doc = r" TryFromInterruptError"]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Copy, Clone)]
pub struct TryFromInterruptError(());
impl Interrupt {
#[doc = r" Attempt to convert a given value into an `Interrupt`"]
#[inline]
pub fn try_from(value: u8) -> Result<Self, TryFromInterruptError> {
match value {
0 => Ok(Interrupt::WIFI_MAC),
1 => Ok(Interrupt::WIFI_MAC_NMI),
2 => Ok(Interrupt::WIFI_PWR),
3 => Ok(Interrupt::WIFI_BB),
4 => Ok(Interrupt::BT_MAC),
5 => Ok(Interrupt::BT_BB),
6 => Ok(Interrupt::BT_BB_NMI),
7 => Ok(Interrupt::LP_TIMER),
8 => Ok(Interrupt::COEX),
9 => Ok(Interrupt::BLE_TIMER),
10 => Ok(Interrupt::BLE_SEC),
11 => Ok(Interrupt::I2C_MST),
12 => Ok(Interrupt::APB_CTRL),
13 => Ok(Interrupt::GPIO),
14 => Ok(Interrupt::GPIO_NMI),
15 => Ok(Interrupt::SPI1),
16 => Ok(Interrupt::SPI2),
17 => Ok(Interrupt::UART0),
18 => Ok(Interrupt::UART1),
19 => Ok(Interrupt::LEDC),
20 => Ok(Interrupt::EFUSE),
21 => Ok(Interrupt::RTC_CORE),
22 => Ok(Interrupt::I2C_EXT0),
23 => Ok(Interrupt::TG0_T0_LEVEL),
24 => Ok(Interrupt::TG0_WDT_LEVEL),
25 => Ok(Interrupt::CACHE_IA),
26 => Ok(Interrupt::SYSTIMER_TARGET0),
27 => Ok(Interrupt::SYSTIMER_TARGET1),
28 => Ok(Interrupt::SYSTIMER_TARGET2),
29 => Ok(Interrupt::SPI_MEM_REJECT_CACHE),
30 => Ok(Interrupt::ICACHE_PRELOAD0),
31 => Ok(Interrupt::ICACHE_SYNC0),
32 => Ok(Interrupt::APB_ADC),
33 => Ok(Interrupt::DMA_CH0),
34 => Ok(Interrupt::SHA),
35 => Ok(Interrupt::ECC),
36 => Ok(Interrupt::FROM_CPU_INTR0),
37 => Ok(Interrupt::FROM_CPU_INTR1),
38 => Ok(Interrupt::FROM_CPU_INTR2),
39 => Ok(Interrupt::FROM_CPU_INTR3),
40 => Ok(Interrupt::ASSIST_DEBUG),
41 => Ok(Interrupt::ETS_CORE0_PIF_PMS_SIZE),
_ => Err(TryFromInterruptError(())),
}
}
}
#[cfg(feature = "rt")]
#[macro_export]
#[doc = r" Assigns a handler to an interrupt"]
#[doc = r""]
#[doc = r" This macro takes two arguments: the name of an interrupt and the path to the"]
#[doc = r" function that will be used as the handler of that interrupt. That function"]
#[doc = r" must have signature `fn()`."]
#[doc = r""]
#[doc = r" Optionally, a third argument may be used to declare interrupt local data."]
#[doc = r" The handler will have exclusive access to these *local* variables on each"]
#[doc = r" invocation. If the third argument is used then the signature of the handler"]
#[doc = r" function must be `fn(&mut $NAME::Locals)` where `$NAME` is the first argument"]
#[doc = r" passed to the macro."]
#[doc = r""]
#[doc = r" # Example"]
#[doc = r""]
#[doc = r" ``` ignore"]
#[doc = r" interrupt!(TIM2, periodic);"]
#[doc = r""]
#[doc = r" fn periodic() {"]
#[doc = r#" print!(".");"#]
#[doc = r" }"]
#[doc = r""]
#[doc = r" interrupt!(TIM3, tick, locals: {"]
#[doc = r" tick: bool = false;"]
#[doc = r" });"]
#[doc = r""]
#[doc = r" fn tick(locals: &mut TIM3::Locals) {"]
#[doc = r" locals.tick = !locals.tick;"]
#[doc = r""]
#[doc = r" if locals.tick {"]
#[doc = r#" println!("Tick");"#]
#[doc = r" } else {"]
#[doc = r#" println!("Tock");"#]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r" ```"]
macro_rules ! interrupt { ($ NAME : ident , $ path : path , locals : { $ ($ lvar : ident : $ lty : ty = $ lval : expr ;) * }) => { # [allow (non_snake_case)] mod $ NAME { pub struct Locals { $ (pub $ lvar : $ lty ,) * } } # [allow (non_snake_case)] # [no_mangle] pub extern "C" fn $ NAME () { let _ = $ crate :: interrupt :: Interrupt :: $ NAME ; static mut LOCALS : self :: $ NAME :: Locals = self :: $ NAME :: Locals { $ ($ lvar : $ lval ,) * } ; let f : fn (& mut self :: $ NAME :: Locals) = $ path ; f (unsafe { & mut LOCALS }) ; } } ; ($ NAME : ident , $ path : path) => { # [allow (non_snake_case)] # [no_mangle] pub extern "C" fn $ NAME () { let _ = $ crate :: interrupt :: Interrupt :: $ NAME ; let f : fn () = $ path ; f () ; } } }
Loading