mirror of
https://github.com/embassy-rs/embassy.git
synced 2025-09-28 12:50:37 +00:00
Merge remote-tracking branch 'origin/main' into adding_eeprom
This commit is contained in:
commit
be831d0e79
@ -46,14 +46,14 @@ cortex-m = "0.7.6"
|
||||
critical-section = "1.2.0"
|
||||
|
||||
# mspm0-metapac = { version = "" }
|
||||
mspm0-metapac = { git = "https://github.com/mspm0-rs/mspm0-data-generated/", tag = "mspm0-data-66a55c7bf38a2201ff48c299843e741f2d537f0b" }
|
||||
mspm0-metapac = { git = "https://github.com/mspm0-rs/mspm0-data-generated/", tag = "mspm0-data-26a6f681eda4ef120e8cb614a1631727c848590f" }
|
||||
|
||||
[build-dependencies]
|
||||
proc-macro2 = "1.0.94"
|
||||
quote = "1.0.40"
|
||||
|
||||
# mspm0-metapac = { version = "", default-features = false, features = ["metadata"] }
|
||||
mspm0-metapac = { git = "https://github.com/mspm0-rs/mspm0-data-generated/", tag = "mspm0-data-66a55c7bf38a2201ff48c299843e741f2d537f0b", default-features = false, features = ["metadata"] }
|
||||
mspm0-metapac = { git = "https://github.com/mspm0-rs/mspm0-data-generated/", tag = "mspm0-data-26a6f681eda4ef120e8cb614a1631727c848590f", default-features = false, features = ["metadata"] }
|
||||
|
||||
[features]
|
||||
default = ["rt"]
|
||||
|
@ -1,6 +1,7 @@
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::{BTreeSet, HashMap};
|
||||
use std::io::Write;
|
||||
use std::fmt::Write;
|
||||
use std::io::Write as _;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
use std::sync::LazyLock;
|
||||
@ -16,12 +17,19 @@ mod common;
|
||||
|
||||
fn main() {
|
||||
generate_code();
|
||||
interrupt_group_linker_magic();
|
||||
}
|
||||
|
||||
fn generate_code() {
|
||||
let mut cfgs = common::CfgSet::new();
|
||||
common::set_target_cfgs(&mut cfgs);
|
||||
|
||||
#[cfg(any(feature = "rt"))]
|
||||
println!(
|
||||
"cargo:rustc-link-search={}",
|
||||
PathBuf::from(env::var_os("OUT_DIR").unwrap()).display(),
|
||||
);
|
||||
|
||||
cfgs.declare_all(&["gpio_pb", "gpio_pc", "int_group1"]);
|
||||
|
||||
let chip_name = match env::vars()
|
||||
@ -58,6 +66,7 @@ fn generate_code() {
|
||||
g.extend(generate_interrupts());
|
||||
g.extend(generate_peripheral_instances());
|
||||
g.extend(generate_pin_trait_impls());
|
||||
g.extend(generate_groups());
|
||||
|
||||
let out_dir = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
||||
let out_file = out_dir.join("_generated.rs").to_string_lossy().to_string();
|
||||
@ -123,6 +132,83 @@ fn get_chip_cfgs(chip_name: &str) -> Vec<String> {
|
||||
cfgs
|
||||
}
|
||||
|
||||
/// Interrupt groups use a weakly linked symbols and #[linkage = "extern_weak"] is nightly we need to
|
||||
/// do some linker magic to create weak linkage.
|
||||
fn interrupt_group_linker_magic() {
|
||||
let mut file = String::new();
|
||||
|
||||
for group in METADATA.interrupt_groups {
|
||||
for interrupt in group.interrupts.iter() {
|
||||
let name = interrupt.name;
|
||||
|
||||
writeln!(&mut file, "PROVIDE({name} = DefaultHandler);").unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
let out_dir = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
||||
let out_file = out_dir.join("interrupt_group.x");
|
||||
fs::write(&out_file, file).unwrap();
|
||||
}
|
||||
|
||||
fn generate_groups() -> TokenStream {
|
||||
let group_vectors = METADATA.interrupt_groups.iter().map(|group| {
|
||||
let vectors = group.interrupts.iter().map(|interrupt| {
|
||||
let fn_name = Ident::new(interrupt.name, Span::call_site());
|
||||
|
||||
quote! {
|
||||
pub(crate) fn #fn_name();
|
||||
}
|
||||
});
|
||||
|
||||
quote! { #(#vectors)* }
|
||||
});
|
||||
|
||||
let groups = METADATA.interrupt_groups.iter().map(|group| {
|
||||
let interrupt_group_name = Ident::new(group.name, Span::call_site());
|
||||
let group_enum = Ident::new(&format!("Group{}", &group.name[5..]), Span::call_site());
|
||||
let group_number = Literal::u32_unsuffixed(group.number);
|
||||
|
||||
let matches = group.interrupts.iter().map(|interrupt| {
|
||||
let variant = Ident::new(&interrupt.name, Span::call_site());
|
||||
|
||||
quote! {
|
||||
#group_enum::#variant => unsafe { group_vectors::#variant() },
|
||||
}
|
||||
});
|
||||
|
||||
quote! {
|
||||
#[cfg(feature = "rt")]
|
||||
#[crate::pac::interrupt]
|
||||
fn #interrupt_group_name() {
|
||||
use crate::pac::#group_enum;
|
||||
|
||||
let group = crate::pac::CPUSS.int_group(#group_number);
|
||||
// MUST subtract by 1 since 0 is NO_INTR
|
||||
let iidx = group.iidx().read().stat().to_bits() - 1;
|
||||
|
||||
let Ok(group) = #group_enum::try_from(iidx as u8) else {
|
||||
return;
|
||||
};
|
||||
|
||||
match group {
|
||||
#(#matches)*
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
quote! {
|
||||
#(#groups)*
|
||||
|
||||
#[cfg(feature = "rt")]
|
||||
mod group_vectors {
|
||||
extern "Rust" {
|
||||
#(#group_vectors)*
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct Singleton {
|
||||
name: String,
|
||||
|
@ -1119,24 +1119,36 @@ impl Iterator for BitIter {
|
||||
}
|
||||
}
|
||||
|
||||
// C110x has a dedicated interrupt just for GPIOA, as it does not have a GROUP1 interrupt.
|
||||
// C110x and L110x have a dedicated interrupts just for GPIOA.
|
||||
//
|
||||
// These chips do not have a GROUP1 interrupt.
|
||||
#[cfg(all(feature = "rt", any(mspm0c110x, mspm0l110x)))]
|
||||
#[interrupt]
|
||||
fn GPIOA() {
|
||||
gpioa_interrupt();
|
||||
irq_handler(pac::GPIOA, &PORTA_WAKERS);
|
||||
}
|
||||
|
||||
#[cfg(feature = "rt")]
|
||||
pub(crate) fn gpioa_interrupt() {
|
||||
// These symbols are weakly defined as DefaultHandler and are called by the interrupt group implementation.
|
||||
//
|
||||
// Defining these as no_mangle is required so that the linker will pick these over the default handler.
|
||||
|
||||
#[cfg(all(feature = "rt", not(any(mspm0c110x, mspm0l110x))))]
|
||||
#[no_mangle]
|
||||
#[allow(non_snake_case)]
|
||||
fn GPIOA() {
|
||||
irq_handler(pac::GPIOA, &PORTA_WAKERS);
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "rt", gpio_pb))]
|
||||
pub(crate) fn gpiob_interrupt() {
|
||||
#[no_mangle]
|
||||
#[allow(non_snake_case)]
|
||||
fn GPIOB() {
|
||||
irq_handler(pac::GPIOB, &PORTB_WAKERS);
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "rt", gpio_pc))]
|
||||
pub(crate) fn gpioc_interrupt() {
|
||||
#[allow(non_snake_case)]
|
||||
#[no_mangle]
|
||||
fn GPIOC() {
|
||||
irq_handler(pac::GPIOC, &PORTC_WAKERS);
|
||||
}
|
||||
|
@ -1,25 +0,0 @@
|
||||
use crate::pac;
|
||||
use crate::pac::interrupt;
|
||||
|
||||
#[cfg(feature = "rt")]
|
||||
#[interrupt]
|
||||
fn GROUP0() {
|
||||
use mspm0_metapac::Group0;
|
||||
|
||||
let group = pac::CPUSS.int_group(0);
|
||||
|
||||
// TODO: Decompose to direct u8
|
||||
let iidx = group.iidx().read().stat().to_bits();
|
||||
|
||||
let Ok(group) = pac::Group0::try_from(iidx as u8) else {
|
||||
debug!("Invalid IIDX for group 0: {}", iidx);
|
||||
return;
|
||||
};
|
||||
|
||||
match group {
|
||||
Group0::WWDT0 => todo!("implement WWDT0"),
|
||||
Group0::DEBUGSS => todo!("implement DEBUGSS"),
|
||||
Group0::FLASHCTL => todo!("implement FLASHCTL"),
|
||||
Group0::SYSCTL => todo!("implement SYSCTL"),
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
use crate::pac;
|
||||
use crate::pac::interrupt;
|
||||
|
||||
#[cfg(feature = "rt")]
|
||||
#[interrupt]
|
||||
fn GROUP0() {
|
||||
use mspm0_metapac::Group0;
|
||||
|
||||
let group = pac::CPUSS.int_group(0);
|
||||
|
||||
// Must subtract by 1 since NO_INTR is value 0
|
||||
let iidx = group.iidx().read().stat().to_bits() - 1;
|
||||
|
||||
let Ok(group) = pac::Group0::try_from(iidx as u8) else {
|
||||
debug!("Invalid IIDX for group 0: {}", iidx);
|
||||
return;
|
||||
};
|
||||
|
||||
match group {
|
||||
Group0::WWDT0 => todo!("implement WWDT0"),
|
||||
Group0::WWDT1 => todo!("implement WWDT1"),
|
||||
Group0::DEBUGSS => todo!("implement DEBUGSS"),
|
||||
Group0::FLASHCTL => todo!("implement FLASHCTL"),
|
||||
Group0::SYSCTL => todo!("implement SYSCTL"),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "rt")]
|
||||
#[interrupt]
|
||||
fn GROUP1() {
|
||||
use mspm0_metapac::Group1;
|
||||
|
||||
let group = pac::CPUSS.int_group(1);
|
||||
|
||||
// Must subtract by 1 since NO_INTR is value 0
|
||||
let iidx = group.iidx().read().stat().to_bits() - 1;
|
||||
|
||||
let Ok(group) = pac::Group1::try_from(iidx as u8) else {
|
||||
debug!("Invalid IIDX for group 1: {}", iidx);
|
||||
return;
|
||||
};
|
||||
|
||||
match group {
|
||||
Group1::GPIOA => crate::gpio::gpioa_interrupt(),
|
||||
Group1::GPIOB => crate::gpio::gpiob_interrupt(),
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
use crate::pac;
|
||||
use crate::pac::interrupt;
|
||||
|
||||
#[cfg(feature = "rt")]
|
||||
#[interrupt]
|
||||
fn GROUP0() {
|
||||
use mspm0_metapac::Group0;
|
||||
|
||||
let group = pac::CPUSS.int_group(0);
|
||||
|
||||
// Must subtract by 1 since NO_INTR is value 0
|
||||
let iidx = group.iidx().read().stat().to_bits() - 1;
|
||||
|
||||
let Ok(group) = pac::Group0::try_from(iidx as u8) else {
|
||||
debug!("Invalid IIDX for group 0: {}", iidx);
|
||||
return;
|
||||
};
|
||||
|
||||
match group {
|
||||
Group0::WWDT0 => todo!("implement WWDT0"),
|
||||
Group0::WWDT1 => todo!("implement WWDT1"),
|
||||
Group0::DEBUGSS => todo!("implement DEBUGSS"),
|
||||
Group0::FLASHCTL => todo!("implement FLASHCTL"),
|
||||
Group0::SYSCTL => todo!("implement SYSCTL"),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "rt")]
|
||||
#[interrupt]
|
||||
fn GROUP1() {
|
||||
use mspm0_metapac::Group1;
|
||||
|
||||
let group = pac::CPUSS.int_group(1);
|
||||
|
||||
// Must subtract by 1 since NO_INTR is value 0
|
||||
let iidx = group.iidx().read().stat().to_bits() - 1;
|
||||
|
||||
let Ok(group) = pac::Group1::try_from(iidx as u8) else {
|
||||
debug!("Invalid IIDX for group 1: {}", iidx);
|
||||
return;
|
||||
};
|
||||
|
||||
match group {
|
||||
Group1::GPIOA => crate::gpio::gpioa_interrupt(),
|
||||
Group1::GPIOB => crate::gpio::gpiob_interrupt(),
|
||||
Group1::COMP0 => todo!("implement COMP0"),
|
||||
Group1::COMP1 => todo!("implement COMP1"),
|
||||
Group1::COMP2 => todo!("implement COMP2"),
|
||||
Group1::TRNG => todo!("implement TRNG"),
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
use crate::pac;
|
||||
use crate::pac::interrupt;
|
||||
|
||||
#[cfg(feature = "rt")]
|
||||
#[interrupt]
|
||||
fn GROUP0() {
|
||||
use mspm0_metapac::Group0;
|
||||
|
||||
let group = pac::CPUSS.int_group(0);
|
||||
|
||||
// Must subtract by 1 since NO_INTR is value 0
|
||||
let iidx = group.iidx().read().stat().to_bits() - 1;
|
||||
|
||||
let Ok(group) = pac::Group0::try_from(iidx as u8) else {
|
||||
debug!("Invalid IIDX for group 0: {}", iidx);
|
||||
return;
|
||||
};
|
||||
|
||||
match group {
|
||||
Group0::WWDT0 => todo!("implement WWDT0"),
|
||||
Group0::WWDT1 => todo!("implement WWDT1"),
|
||||
Group0::DEBUGSS => todo!("implement DEBUGSS"),
|
||||
Group0::FLASHCTL => todo!("implement FLASHCTL"),
|
||||
Group0::SYSCTL => todo!("implement SYSCTL"),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "rt")]
|
||||
#[interrupt]
|
||||
fn GROUP1() {
|
||||
use mspm0_metapac::Group1;
|
||||
|
||||
let group = pac::CPUSS.int_group(1);
|
||||
|
||||
// Must subtract by 1 since NO_INTR is value 0
|
||||
let iidx = group.iidx().read().stat().to_bits() - 1;
|
||||
|
||||
let Ok(group) = pac::Group1::try_from(iidx as u8) else {
|
||||
debug!("Invalid IIDX for group 1: {}", iidx);
|
||||
return;
|
||||
};
|
||||
|
||||
match group {
|
||||
Group1::GPIOA => crate::gpio::gpioa_interrupt(),
|
||||
Group1::GPIOB => crate::gpio::gpiob_interrupt(),
|
||||
Group1::COMP0 => todo!("implement COMP0"),
|
||||
Group1::COMP1 => todo!("implement COMP1"),
|
||||
Group1::COMP2 => todo!("implement COMP2"),
|
||||
Group1::TRNG => todo!("implement TRNG"),
|
||||
Group1::GPIOC => crate::gpio::gpioc_interrupt(),
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
use crate::pac;
|
||||
use crate::pac::interrupt;
|
||||
|
||||
#[cfg(feature = "rt")]
|
||||
#[interrupt]
|
||||
fn GROUP0() {
|
||||
use mspm0_metapac::Group0;
|
||||
|
||||
let group = pac::CPUSS.int_group(0);
|
||||
|
||||
// Must subtract by 1 since NO_INTR is value 0
|
||||
let iidx = group.iidx().read().stat().to_bits() - 1;
|
||||
|
||||
let Ok(group) = pac::Group0::try_from(iidx as u8) else {
|
||||
debug!("Invalid IIDX for group 0: {}", iidx);
|
||||
return;
|
||||
};
|
||||
|
||||
match group {
|
||||
Group0::WWDT0 => todo!("implement WWDT0"),
|
||||
Group0::WWDT1 => todo!("implement WWDT1"),
|
||||
Group0::DEBUGSS => todo!("implement DEBUGSS"),
|
||||
Group0::FLASHCTL => todo!("implement FLASHCTL"),
|
||||
Group0::SYSCTL => todo!("implement SYSCTL"),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "rt")]
|
||||
#[interrupt]
|
||||
fn GROUP1() {
|
||||
use mspm0_metapac::Group1;
|
||||
|
||||
let group = pac::CPUSS.int_group(1);
|
||||
|
||||
// Must subtract by 1 since NO_INTR is value 0
|
||||
let iidx = group.iidx().read().stat().to_bits() - 1;
|
||||
|
||||
let Ok(group) = pac::Group1::try_from(iidx as u8) else {
|
||||
debug!("Invalid IIDX for group 1: {}", iidx);
|
||||
return;
|
||||
};
|
||||
|
||||
match group {
|
||||
Group1::GPIOA => crate::gpio::gpioa_interrupt(),
|
||||
Group1::GPIOB => crate::gpio::gpiob_interrupt(),
|
||||
Group1::TRNG => todo!("implement TRNG"),
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
use crate::pac;
|
||||
use crate::pac::interrupt;
|
||||
|
||||
#[cfg(feature = "rt")]
|
||||
#[interrupt]
|
||||
fn GROUP0() {
|
||||
use mspm0_metapac::Group0;
|
||||
|
||||
let group = pac::CPUSS.int_group(0);
|
||||
|
||||
// Must subtract by 1 since NO_INTR is value 0
|
||||
let iidx = group.iidx().read().stat().to_bits() - 1;
|
||||
|
||||
let Ok(group) = pac::Group0::try_from(iidx as u8) else {
|
||||
debug!("Invalid IIDX for group 0: {}", iidx);
|
||||
return;
|
||||
};
|
||||
|
||||
match group {
|
||||
Group0::WWDT0 => todo!("implement WWDT0"),
|
||||
Group0::WWDT1 => todo!("implement WWDT1"),
|
||||
Group0::DEBUGSS => todo!("implement DEBUGSS"),
|
||||
Group0::FLASHCTL => todo!("implement FLASHCTL"),
|
||||
Group0::SYSCTL => todo!("implement SYSCTL"),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "rt")]
|
||||
#[interrupt]
|
||||
fn GROUP1() {
|
||||
use mspm0_metapac::Group1;
|
||||
|
||||
let group = pac::CPUSS.int_group(1);
|
||||
|
||||
// Must subtract by 1 since NO_INTR is value 0
|
||||
let iidx = group.iidx().read().stat().to_bits() - 1;
|
||||
|
||||
let Ok(group) = pac::Group1::try_from(iidx as u8) else {
|
||||
debug!("Invalid IIDX for group 1: {}", iidx);
|
||||
return;
|
||||
};
|
||||
|
||||
match group {
|
||||
Group1::GPIOA => crate::gpio::gpioa_interrupt(),
|
||||
Group1::GPIOB => crate::gpio::gpiob_interrupt(),
|
||||
Group1::COMP0 => todo!("implement COMP0"),
|
||||
Group1::COMP1 => todo!("implement COMP1"),
|
||||
Group1::COMP2 => todo!("implement COMP2"),
|
||||
Group1::TRNG => todo!("implement TRNG"),
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
use crate::pac;
|
||||
use crate::pac::interrupt;
|
||||
|
||||
#[cfg(feature = "rt")]
|
||||
#[interrupt]
|
||||
fn GROUP0() {
|
||||
use mspm0_metapac::Group0;
|
||||
|
||||
let group = pac::CPUSS.int_group(0);
|
||||
|
||||
// Must subtract by 1 since NO_INTR is value 0
|
||||
let iidx = group.iidx().read().stat().to_bits() - 1;
|
||||
|
||||
let Ok(group) = pac::Group0::try_from(iidx as u8) else {
|
||||
debug!("Invalid IIDX for group 0: {}", iidx);
|
||||
return;
|
||||
};
|
||||
|
||||
match group {
|
||||
Group0::WWDT0 => todo!("implement WWDT0"),
|
||||
Group0::WWDT1 => todo!("implement WWDT1"),
|
||||
Group0::DEBUGSS => todo!("implement DEBUGSS"),
|
||||
Group0::FLASHCTL => todo!("implement FLASHCTL"),
|
||||
Group0::SYSCTL => todo!("implement SYSCTL"),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "rt")]
|
||||
#[interrupt]
|
||||
fn GROUP1() {
|
||||
use mspm0_metapac::Group1;
|
||||
|
||||
let group = pac::CPUSS.int_group(1);
|
||||
|
||||
// Must subtract by 1 since NO_INTR is value 0
|
||||
let iidx = group.iidx().read().stat().to_bits() - 1;
|
||||
|
||||
let Ok(group) = pac::Group1::try_from(iidx as u8) else {
|
||||
debug!("Invalid IIDX for group 1: {}", iidx);
|
||||
return;
|
||||
};
|
||||
|
||||
match group {
|
||||
Group1::GPIOA => crate::gpio::gpioa_interrupt(),
|
||||
Group1::GPIOB => crate::gpio::gpiob_interrupt(),
|
||||
Group1::COMP0 => todo!("implement COMP0"),
|
||||
Group1::COMP1 => todo!("implement COMP1"),
|
||||
Group1::COMP2 => todo!("implement COMP2"),
|
||||
Group1::TRNG => todo!("implement TRNG"),
|
||||
Group1::GPIOC => crate::gpio::gpioc_interrupt(),
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
use crate::pac;
|
||||
use crate::pac::interrupt;
|
||||
|
||||
#[cfg(feature = "rt")]
|
||||
#[interrupt]
|
||||
fn GROUP0() {
|
||||
use mspm0_metapac::Group0;
|
||||
|
||||
let group = pac::CPUSS.int_group(0);
|
||||
|
||||
// Must subtract by 1 since NO_INTR is value 0
|
||||
let iidx = group.iidx().read().stat().to_bits() - 1;
|
||||
|
||||
let Ok(group) = pac::Group0::try_from(iidx as u8) else {
|
||||
debug!("Invalid IIDX for group 0: {}", iidx);
|
||||
return;
|
||||
};
|
||||
|
||||
match group {
|
||||
Group0::WWDT0 => todo!("implement WWDT0"),
|
||||
Group0::DEBUGSS => todo!("implement DEBUGSS"),
|
||||
Group0::FLASHCTL => todo!("implement FLASHCTL"),
|
||||
Group0::SYSCTL => todo!("implement SYSCTL"),
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
use crate::pac;
|
||||
use crate::pac::interrupt;
|
||||
|
||||
#[cfg(feature = "rt")]
|
||||
#[interrupt]
|
||||
fn GROUP0() {
|
||||
use mspm0_metapac::Group0;
|
||||
|
||||
let group = pac::CPUSS.int_group(0);
|
||||
|
||||
// Must subtract by 1 since NO_INTR is value 0
|
||||
let iidx = group.iidx().read().stat().to_bits() - 1;
|
||||
|
||||
let Ok(group) = pac::Group0::try_from(iidx as u8) else {
|
||||
debug!("Invalid IIDX for group 0: {}", iidx);
|
||||
return;
|
||||
};
|
||||
|
||||
match group {
|
||||
Group0::WWDT0 => todo!("implement WWDT0"),
|
||||
Group0::DEBUGSS => todo!("implement DEBUGSS"),
|
||||
Group0::FLASHCTL => todo!("implement FLASHCTL"),
|
||||
Group0::SYSCTL => todo!("implement SYSCTL"),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "rt")]
|
||||
#[interrupt]
|
||||
fn GROUP1() {
|
||||
use mspm0_metapac::Group1;
|
||||
|
||||
let group = pac::CPUSS.int_group(1);
|
||||
|
||||
// Must subtract by 1 since NO_INTR is value 0
|
||||
let iidx = group.iidx().read().stat().to_bits() - 1;
|
||||
|
||||
let Ok(group) = pac::Group1::try_from(iidx as u8) else {
|
||||
debug!("Invalid IIDX for group 1: {}", iidx);
|
||||
return;
|
||||
};
|
||||
|
||||
match group {
|
||||
Group1::GPIOA => crate::gpio::gpioa_interrupt(),
|
||||
Group1::GPIOB => crate::gpio::gpiob_interrupt(),
|
||||
Group1::COMP0 => todo!("implement COMP0"),
|
||||
Group1::TRNG => todo!("implement TRNG"),
|
||||
Group1::GPIOC => crate::gpio::gpioc_interrupt(),
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
use crate::pac;
|
||||
use crate::pac::interrupt;
|
||||
|
||||
#[cfg(feature = "rt")]
|
||||
#[interrupt]
|
||||
fn GROUP0() {
|
||||
use mspm0_metapac::Group0;
|
||||
|
||||
let group = pac::CPUSS.int_group(0);
|
||||
|
||||
// Must subtract by 1 since NO_INTR is value 0
|
||||
let iidx = group.iidx().read().stat().to_bits() - 1;
|
||||
|
||||
let Ok(group) = pac::Group0::try_from(iidx as u8) else {
|
||||
debug!("Invalid IIDX for group 0: {}", iidx);
|
||||
return;
|
||||
};
|
||||
|
||||
match group {
|
||||
Group0::WWDT0 => todo!("implement WWDT0"),
|
||||
Group0::DEBUGSS => todo!("implement DEBUGSS"),
|
||||
Group0::FLASHCTL => todo!("implement FLASHCTL"),
|
||||
Group0::SYSCTL => todo!("implement SYSCTL"),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "rt")]
|
||||
#[interrupt]
|
||||
fn GROUP1() {
|
||||
use mspm0_metapac::Group1;
|
||||
|
||||
let group = pac::CPUSS.int_group(1);
|
||||
|
||||
// Must subtract by 1 since NO_INTR is value 0
|
||||
let iidx = group.iidx().read().stat().to_bits() - 1;
|
||||
|
||||
let Ok(group) = pac::Group1::try_from(iidx as u8) else {
|
||||
debug!("Invalid IIDX for group 1: {}", iidx);
|
||||
return;
|
||||
};
|
||||
|
||||
match group {
|
||||
Group1::GPIOA => crate::gpio::gpioa_interrupt(),
|
||||
Group1::COMP0 => todo!("implement COMP0"),
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
use crate::pac;
|
||||
use crate::pac::interrupt;
|
||||
|
||||
#[cfg(feature = "rt")]
|
||||
#[interrupt]
|
||||
fn GROUP0() {
|
||||
use mspm0_metapac::Group0;
|
||||
|
||||
let group = pac::CPUSS.int_group(0);
|
||||
|
||||
// Must subtract by 1 since NO_INTR is value 0
|
||||
let iidx = group.iidx().read().stat().to_bits() - 1;
|
||||
|
||||
let Ok(group) = pac::Group0::try_from(iidx as u8) else {
|
||||
debug!("Invalid IIDX for group 0: {}", iidx);
|
||||
return;
|
||||
};
|
||||
|
||||
match group {
|
||||
Group0::WWDT0 => todo!("implement WWDT0"),
|
||||
Group0::DEBUGSS => todo!("implement DEBUGSS"),
|
||||
Group0::FLASHCTL => todo!("implement FLASHCTL"),
|
||||
Group0::SYSCTL => todo!("implement SYSCTL"),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "rt")]
|
||||
#[interrupt]
|
||||
fn GROUP1() {
|
||||
use mspm0_metapac::Group1;
|
||||
|
||||
let group = pac::CPUSS.int_group(1);
|
||||
|
||||
// Must subtract by 1 since NO_INTR is value 0
|
||||
let iidx = group.iidx().read().stat().to_bits() - 1;
|
||||
|
||||
let Ok(group) = pac::Group1::try_from(iidx as u8) else {
|
||||
debug!("Invalid IIDX for group 1: {}", iidx);
|
||||
return;
|
||||
};
|
||||
|
||||
match group {
|
||||
Group1::GPIOA => crate::gpio::gpioa_interrupt(),
|
||||
Group1::GPIOB => crate::gpio::gpiob_interrupt(),
|
||||
Group1::COMP0 => todo!("implement COMP0"),
|
||||
Group1::TRNG => todo!("implement TRNG"),
|
||||
Group1::GPIOC => crate::gpio::gpioc_interrupt(),
|
||||
}
|
||||
}
|
@ -39,20 +39,6 @@ pub mod mode {
|
||||
#[cfg(feature = "_time-driver")]
|
||||
mod time_driver;
|
||||
|
||||
// Interrupt group handlers.
|
||||
#[cfg_attr(mspm0c110x, path = "int_group/c110x.rs")]
|
||||
#[cfg_attr(mspm0g110x, path = "int_group/g110x.rs")]
|
||||
#[cfg_attr(mspm0g150x, path = "int_group/g150x.rs")]
|
||||
#[cfg_attr(mspm0g350x, path = "int_group/g350x.rs")]
|
||||
#[cfg_attr(mspm0g151x, path = "int_group/g151x.rs")]
|
||||
#[cfg_attr(mspm0g351x, path = "int_group/g351x.rs")]
|
||||
#[cfg_attr(mspm0g310x, path = "int_group/g310x.rs")]
|
||||
#[cfg_attr(mspm0l110x, path = "int_group/l11xx.rs")]
|
||||
#[cfg_attr(mspm0l122x, path = "int_group/l12xx.rs")]
|
||||
#[cfg_attr(any(mspm0l130x, mspm0l134x), path = "int_group/l13xx.rs")]
|
||||
#[cfg_attr(mspm0l222x, path = "int_group/l222x.rs")]
|
||||
mod int_group;
|
||||
|
||||
pub(crate) mod _generated {
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_imports)]
|
||||
|
@ -1039,3 +1039,27 @@ pub fn init(config: config::Config) -> Peripherals {
|
||||
|
||||
peripherals
|
||||
}
|
||||
|
||||
/// Operating modes for peripherals.
|
||||
pub mod mode {
|
||||
trait SealedMode {}
|
||||
|
||||
/// Operating mode for a peripheral.
|
||||
#[allow(private_bounds)]
|
||||
pub trait Mode: SealedMode {}
|
||||
|
||||
macro_rules! impl_mode {
|
||||
($name:ident) => {
|
||||
impl SealedMode for $name {}
|
||||
impl Mode for $name {}
|
||||
};
|
||||
}
|
||||
|
||||
/// Blocking mode.
|
||||
pub struct Blocking;
|
||||
/// Async mode.
|
||||
pub struct Async;
|
||||
|
||||
impl_mode!(Blocking);
|
||||
impl_mode!(Async);
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ use embassy_hal_internal::{Peri, PeripheralType};
|
||||
use embassy_sync::waitqueue::WakerRegistration;
|
||||
|
||||
use crate::interrupt::typelevel::Interrupt;
|
||||
use crate::mode::{Async, Blocking, Mode};
|
||||
use crate::{interrupt, pac};
|
||||
|
||||
/// Interrupt handler.
|
||||
@ -55,11 +56,31 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl
|
||||
/// A wrapper around an nRF RNG peripheral.
|
||||
///
|
||||
/// It has a non-blocking API, and a blocking api through `rand`.
|
||||
pub struct Rng<'d, T: Instance> {
|
||||
pub struct Rng<'d, T: Instance, M: Mode> {
|
||||
_peri: Peri<'d, T>,
|
||||
_phantom: PhantomData<M>,
|
||||
}
|
||||
|
||||
impl<'d, T: Instance> Rng<'d, T> {
|
||||
impl<'d, T: Instance> Rng<'d, T, Blocking> {
|
||||
/// Creates a new RNG driver from the `RNG` peripheral and interrupt.
|
||||
///
|
||||
/// SAFETY: The future returned from `fill_bytes` must not have its lifetime end without running its destructor,
|
||||
/// e.g. using `mem::forget`.
|
||||
///
|
||||
/// The synchronous API is safe.
|
||||
pub fn new_blocking(rng: Peri<'d, T>) -> Self {
|
||||
let this = Self {
|
||||
_peri: rng,
|
||||
_phantom: PhantomData,
|
||||
};
|
||||
|
||||
this.stop();
|
||||
|
||||
this
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Instance> Rng<'d, T, Async> {
|
||||
/// Creates a new RNG driver from the `RNG` peripheral and interrupt.
|
||||
///
|
||||
/// SAFETY: The future returned from `fill_bytes` must not have its lifetime end without running its destructor,
|
||||
@ -70,7 +91,10 @@ impl<'d, T: Instance> Rng<'d, T> {
|
||||
rng: Peri<'d, T>,
|
||||
_irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
|
||||
) -> Self {
|
||||
let this = Self { _peri: rng };
|
||||
let this = Self {
|
||||
_peri: rng,
|
||||
_phantom: PhantomData,
|
||||
};
|
||||
|
||||
this.stop();
|
||||
this.disable_irq();
|
||||
@ -81,14 +105,6 @@ impl<'d, T: Instance> Rng<'d, T> {
|
||||
this
|
||||
}
|
||||
|
||||
fn stop(&self) {
|
||||
T::regs().tasks_stop().write_value(1)
|
||||
}
|
||||
|
||||
fn start(&self) {
|
||||
T::regs().tasks_start().write_value(1)
|
||||
}
|
||||
|
||||
fn enable_irq(&self) {
|
||||
T::regs().intenset().write(|w| w.set_valrdy(true));
|
||||
}
|
||||
@ -97,16 +113,6 @@ impl<'d, T: Instance> Rng<'d, T> {
|
||||
T::regs().intenclr().write(|w| w.set_valrdy(true));
|
||||
}
|
||||
|
||||
/// Enable or disable the RNG's bias correction.
|
||||
///
|
||||
/// Bias correction removes any bias towards a '1' or a '0' in the bits generated.
|
||||
/// However, this makes the generation of numbers slower.
|
||||
///
|
||||
/// Defaults to disabled.
|
||||
pub fn set_bias_correction(&self, enable: bool) {
|
||||
T::regs().config().write(|w| w.set_dercen(enable))
|
||||
}
|
||||
|
||||
/// Fill the buffer with random bytes.
|
||||
pub async fn fill_bytes(&mut self, dest: &mut [u8]) {
|
||||
if dest.is_empty() {
|
||||
@ -153,6 +159,26 @@ impl<'d, T: Instance> Rng<'d, T> {
|
||||
// Trigger the teardown
|
||||
drop(on_drop);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Instance, M: Mode> Rng<'d, T, M> {
|
||||
fn stop(&self) {
|
||||
T::regs().tasks_stop().write_value(1)
|
||||
}
|
||||
|
||||
fn start(&self) {
|
||||
T::regs().tasks_start().write_value(1)
|
||||
}
|
||||
|
||||
/// Enable or disable the RNG's bias correction.
|
||||
///
|
||||
/// Bias correction removes any bias towards a '1' or a '0' in the bits generated.
|
||||
/// However, this makes the generation of numbers slower.
|
||||
///
|
||||
/// Defaults to disabled.
|
||||
pub fn set_bias_correction(&self, enable: bool) {
|
||||
T::regs().config().write(|w| w.set_dercen(enable))
|
||||
}
|
||||
|
||||
/// Fill the buffer with random bytes, blocking version.
|
||||
pub fn blocking_fill_bytes(&mut self, dest: &mut [u8]) {
|
||||
@ -184,7 +210,7 @@ impl<'d, T: Instance> Rng<'d, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Instance> Drop for Rng<'d, T> {
|
||||
impl<'d, T: Instance, M: Mode> Drop for Rng<'d, T, M> {
|
||||
fn drop(&mut self) {
|
||||
self.stop();
|
||||
critical_section::with(|cs| {
|
||||
@ -195,7 +221,7 @@ impl<'d, T: Instance> Drop for Rng<'d, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Instance> rand_core_06::RngCore for Rng<'d, T> {
|
||||
impl<'d, T: Instance, M: Mode> rand_core_06::RngCore for Rng<'d, T, M> {
|
||||
fn fill_bytes(&mut self, dest: &mut [u8]) {
|
||||
self.blocking_fill_bytes(dest);
|
||||
}
|
||||
@ -211,9 +237,9 @@ impl<'d, T: Instance> rand_core_06::RngCore for Rng<'d, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Instance> rand_core_06::CryptoRng for Rng<'d, T> {}
|
||||
impl<'d, T: Instance, M: Mode> rand_core_06::CryptoRng for Rng<'d, T, M> {}
|
||||
|
||||
impl<'d, T: Instance> rand_core_09::RngCore for Rng<'d, T> {
|
||||
impl<'d, T: Instance, M: Mode> rand_core_09::RngCore for Rng<'d, T, M> {
|
||||
fn fill_bytes(&mut self, dest: &mut [u8]) {
|
||||
self.blocking_fill_bytes(dest);
|
||||
}
|
||||
@ -225,7 +251,7 @@ impl<'d, T: Instance> rand_core_09::RngCore for Rng<'d, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Instance> rand_core_09::CryptoRng for Rng<'d, T> {}
|
||||
impl<'d, T: Instance, M: Mode> rand_core_09::CryptoRng for Rng<'d, T, M> {}
|
||||
|
||||
/// Peripheral static state
|
||||
pub(crate) struct State {
|
||||
|
@ -25,7 +25,7 @@ use crate::time::Hertz;
|
||||
),
|
||||
path = "v2.rs"
|
||||
)]
|
||||
#[cfg_attr(any(rtc_v3, rtc_v3u5, rtc_v3l5), path = "v3.rs")]
|
||||
#[cfg_attr(any(rtc_v3, rtc_v3u5, rtc_v3l5, rtc_v3h7rs), path = "v3.rs")]
|
||||
mod _version;
|
||||
#[allow(unused_imports)]
|
||||
pub use _version::*;
|
||||
|
@ -32,4 +32,6 @@ fn main() {
|
||||
println!("cargo:rustc-link-arg-bins=--nmagic");
|
||||
println!("cargo:rustc-link-arg-bins=-Tlink.x");
|
||||
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
|
||||
// You must tell cargo to link interrupt groups if the rt feature is enabled.
|
||||
println!("cargo:rustc-link-arg-bins=-Tinterrupt_group.x");
|
||||
}
|
||||
|
@ -32,4 +32,6 @@ fn main() {
|
||||
println!("cargo:rustc-link-arg-bins=--nmagic");
|
||||
println!("cargo:rustc-link-arg-bins=-Tlink.x");
|
||||
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
|
||||
// You must tell cargo to link interrupt groups if the rt feature is enabled.
|
||||
println!("cargo:rustc-link-arg-bins=-Tinterrupt_group.x");
|
||||
}
|
||||
|
@ -32,4 +32,6 @@ fn main() {
|
||||
println!("cargo:rustc-link-arg-bins=--nmagic");
|
||||
println!("cargo:rustc-link-arg-bins=-Tlink.x");
|
||||
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
|
||||
// You must tell cargo to link interrupt groups if the rt feature is enabled.
|
||||
println!("cargo:rustc-link-arg-bins=-Tinterrupt_group.x");
|
||||
}
|
||||
|
@ -32,4 +32,6 @@ fn main() {
|
||||
println!("cargo:rustc-link-arg-bins=--nmagic");
|
||||
println!("cargo:rustc-link-arg-bins=-Tlink.x");
|
||||
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
|
||||
// You must tell cargo to link interrupt groups if the rt feature is enabled.
|
||||
println!("cargo:rustc-link-arg-bins=-Tinterrupt_group.x");
|
||||
}
|
||||
|
@ -32,4 +32,6 @@ fn main() {
|
||||
println!("cargo:rustc-link-arg-bins=--nmagic");
|
||||
println!("cargo:rustc-link-arg-bins=-Tlink.x");
|
||||
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
|
||||
// You must tell cargo to link interrupt groups if the rt feature is enabled.
|
||||
println!("cargo:rustc-link-arg-bins=-Tinterrupt_group.x");
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
println!("cargo:rustc-link-arg-bins=-Tlink_ram.x");
|
||||
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
|
||||
println!("cargo:rustc-link-arg-bins=-Tteleprobe.x");
|
||||
// You must tell cargo to link interrupt groups if the rt feature is enabled.
|
||||
println!("cargo:rustc-link-arg-bins=-Tinterrupt_group.x");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user