Skip to content

Commit 26a6f68

Browse files
committed
metapac: generate interrupt groups
1 parent 66a55c7 commit 26a6f68

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

mspm0-metapac-gen/res/metadata.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub struct Metadata {
77
pub pins: &'static [Pin],
88
// pub nvic_priority_bits: Option<u8>,
99
pub interrupts: &'static [Interrupt],
10+
pub interrupt_groups: &'static [InterruptGroup],
1011
pub dma_channels: &'static [DmaChannel],
1112
}
1213

@@ -36,6 +37,19 @@ pub struct Interrupt {
3637
pub number: u32,
3738
}
3839

40+
#[derive(Debug, Eq, PartialEq, Clone)]
41+
pub struct InterruptGroup {
42+
pub name: &'static str,
43+
pub number: u32,
44+
pub interrupts: &'static [GroupInterrupt],
45+
}
46+
47+
#[derive(Debug, Eq, PartialEq, Clone)]
48+
pub struct GroupInterrupt {
49+
pub name: &'static str,
50+
pub number: u32,
51+
}
52+
3953
#[derive(Debug, Eq, PartialEq, Clone)]
4054
pub struct DmaChannel {
4155
/// The number of the dma channel.

mspm0-metapac-gen/src/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,13 @@ fn generate_chip_metadata(
112112
"
113113
pub(crate) static PERIPHERALS: &[Peripheral] = {};
114114
pub(crate) static INTERRUPTS: &[Interrupt] = {};
115+
pub(crate) static INTERRUPT_GROUPS: &[InterruptGroup] = {};
115116
pub(crate) static DMA_CHANNELS: &[DmaChannel] = {};
116117
pub(crate) static PINS: &[Pin] = {};
117118
",
118119
metadata::peripherals(chip, package),
119120
metadata::interrupts(chip),
121+
metadata::interrupt_groups(chip),
120122
metadata::dma_channels(chip),
121123
metadata::pins(chip, package),
122124
)
@@ -147,6 +149,7 @@ fn generate_chip_metadata(
147149
peripherals: PERIPHERALS,
148150
pins: PINS,
149151
interrupts: INTERRUPTS,
152+
interrupt_groups: INTERRUPT_GROUPS,
150153
dma_channels: DMA_CHANNELS,
151154
}};
152155
",
@@ -158,7 +161,10 @@ fn generate_chip_metadata(
158161
rustfmt(path);
159162
}
160163

161-
fn generate_all_chips<'a>(out_dir: &Path, chips: impl Iterator<Item = &'a Chip>) -> anyhow::Result<()> {
164+
fn generate_all_chips<'a>(
165+
out_dir: &Path,
166+
chips: impl Iterator<Item = &'a Chip>,
167+
) -> anyhow::Result<()> {
162168
let mut list = Vec::new();
163169

164170
for chip in chips {

mspm0-metapac-gen/src/metadata.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,49 @@ pub fn interrupts(chip: &Chip) -> TokenStream {
9999
}
100100
}
101101

102+
pub fn interrupt_groups(chip: &Chip) -> TokenStream {
103+
let mut groups = Vec::new();
104+
105+
for (_, interrupt) in chip.interrupts.iter() {
106+
// Skip interrupts handled by cortex-m
107+
if interrupt.num < 0 {
108+
continue;
109+
}
110+
111+
if interrupt.group.is_empty() {
112+
continue;
113+
}
114+
115+
let mut entries = Vec::new();
116+
117+
for (index, interrupt) in interrupt.group.iter() {
118+
let number = Literal::u32_unsuffixed(*index);
119+
120+
entries.push(quote! {
121+
GroupInterrupt {
122+
name: #interrupt,
123+
number: #number
124+
}
125+
});
126+
}
127+
128+
let name = &interrupt.name;
129+
let number = Literal::u32_unsuffixed(interrupt.num as u32);
130+
131+
groups.push(quote! {
132+
InterruptGroup {
133+
name: #name,
134+
number: #number,
135+
interrupts: &[#(#entries),*]
136+
}
137+
});
138+
}
139+
140+
quote! {
141+
&[#(#groups),*]
142+
}
143+
}
144+
102145
fn skip_peripheral(ty: PeripheralType) -> bool {
103146
matches!(ty, PeripheralType::Unknown | PeripheralType::Sysctl)
104147
}

0 commit comments

Comments
 (0)