Generate dma-related macro tables.

This commit is contained in:
Bob McWhirter 2021-06-22 14:53:19 -04:00
parent d49adc98be
commit 1732551db4
2 changed files with 58 additions and 11 deletions

@ -1 +1 @@
Subproject commit eb76ee900ac67b51497196572250323e82666b4c Subproject commit 9856b11172ae27ffa60d339ac271d2d06c190756

View File

@ -27,6 +27,7 @@ pub struct Core {
pub name: String, pub name: String,
pub peripherals: HashMap<String, Peripheral>, pub peripherals: HashMap<String, Peripheral>,
pub interrupts: HashMap<String, u32>, pub interrupts: HashMap<String, u32>,
pub dma_channels: HashMap<String, DmaChannel>,
} }
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)] #[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
@ -46,6 +47,10 @@ pub struct Peripheral {
pub clock: Option<String>, pub clock: Option<String>,
#[serde(default)] #[serde(default)]
pub pins: Vec<Pin>, pub pins: Vec<Pin>,
#[serde(default)]
pub dma_channels: HashMap<String, Vec<String>>,
#[serde(default)]
pub dma_requests: HashMap<String, u32>,
} }
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)] #[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
@ -55,6 +60,12 @@ pub struct Pin {
pub af: Option<String>, pub af: Option<String>,
} }
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
pub struct DmaChannel {
pub dma: String,
pub channel: u32,
}
struct BlockInfo { struct BlockInfo {
/// usart_v1/USART -> usart /// usart_v1/USART -> usart
module: String, module: String,
@ -123,7 +134,7 @@ macro_rules! {} {{
", ",
name, name name, name
) )
.unwrap(); .unwrap();
for row in data { for row in data {
write!(out, " __{}_inner!(({}));\n", name, row.join(",")).unwrap(); write!(out, " __{}_inner!(({}));\n", name, row.join(",")).unwrap();
@ -134,7 +145,7 @@ macro_rules! {} {{
" }}; " }};
}}" }}"
) )
.unwrap(); .unwrap();
} }
pub struct Options { pub struct Options {
@ -220,6 +231,9 @@ pub fn gen(options: Options) {
let mut peripherals_table: Vec<Vec<String>> = Vec::new(); let mut peripherals_table: Vec<Vec<String>> = Vec::new();
let mut peripheral_pins_table: Vec<Vec<String>> = Vec::new(); let mut peripheral_pins_table: Vec<Vec<String>> = Vec::new();
let mut peripheral_rcc_table: Vec<Vec<String>> = Vec::new(); let mut peripheral_rcc_table: Vec<Vec<String>> = Vec::new();
let mut dma_channels_table: Vec<Vec<String>> = Vec::new();
let mut dma_requests_table: Vec<Vec<String>> = Vec::new();
let mut peripheral_dma_channels_table: Vec<Vec<String>> = Vec::new();
let dma_base = core let dma_base = core
.peripherals .peripherals
@ -231,6 +245,14 @@ pub fn gen(options: Options) {
let gpio_base = core.peripherals.get(&"GPIOA".to_string()).unwrap().address; let gpio_base = core.peripherals.get(&"GPIOA".to_string()).unwrap().address;
let gpio_stride = 0x400; let gpio_stride = 0x400;
for (id, channel_info) in &core.dma_channels {
let mut row = Vec::new();
row.push(id.clone());
row.push(channel_info.dma.clone() );
row.push(channel_info.channel.to_string());
dma_channels_table.push(row);
}
for (name, p) in &core.peripherals { for (name, p) in &core.peripherals {
let mut ir_peri = ir::Peripheral { let mut ir_peri = ir::Peripheral {
name: name.clone(), name: name.clone(),
@ -257,13 +279,35 @@ pub fn gen(options: Options) {
peripheral_pins_table.push(row); peripheral_pins_table.push(row);
} }
for dma_request in &p.dma_requests {
let mut row = Vec::new();
row.push(name.clone());
row.push(dma_request.0.clone());
row.push(dma_request.1.to_string());
dma_requests_table.push(row);
}
for (event, dma_channels) in &p.dma_channels {
for channel in dma_channels.iter() {
let mut row = Vec::new();
row.push(name.clone());
row.push( bi.module.clone() );
row.push( bi.block.clone() );
row.push(event.clone());
row.push( channel.clone() );
row.push( core.dma_channels[channel].dma.clone() );
row.push( core.dma_channels[channel].channel.to_string() );
peripheral_dma_channels_table.push(row);
}
}
let mut peripheral_row = Vec::new(); let mut peripheral_row = Vec::new();
peripheral_row.push(bi.module.clone()); peripheral_row.push(bi.module.clone());
peripheral_row.push(name.clone()); peripheral_row.push(name.clone());
peripherals_table.push(peripheral_row); peripherals_table.push(peripheral_row);
if let Some(old_version) = if let Some(old_version) =
peripheral_versions.insert(bi.module.clone(), bi.version.clone()) peripheral_versions.insert(bi.module.clone(), bi.version.clone())
{ {
if old_version != bi.version { if old_version != bi.version {
panic!( panic!(
@ -402,7 +446,10 @@ pub fn gen(options: Options) {
make_table(&mut extra, "peripherals", &peripherals_table); make_table(&mut extra, "peripherals", &peripherals_table);
make_table(&mut extra, "peripheral_versions", &peripheral_version_table); make_table(&mut extra, "peripheral_versions", &peripheral_version_table);
make_table(&mut extra, "peripheral_pins", &peripheral_pins_table); make_table(&mut extra, "peripheral_pins", &peripheral_pins_table);
make_table(&mut extra, "peripheral_dma_channels", &peripheral_dma_channels_table);
make_table(&mut extra, "peripheral_rcc", &peripheral_rcc_table); make_table(&mut extra, "peripheral_rcc", &peripheral_rcc_table);
make_table(&mut extra, "dma_channels", &dma_channels_table);
make_table(&mut extra, "dma_requests", &dma_requests_table);
for (module, version) in peripheral_versions { for (module, version) in peripheral_versions {
all_peripheral_versions.insert((module.clone(), version.clone())); all_peripheral_versions.insert((module.clone(), version.clone()));
@ -411,7 +458,7 @@ pub fn gen(options: Options) {
"#[path=\"../../peripherals/{}_{}.rs\"] pub mod {};\n", "#[path=\"../../peripherals/{}_{}.rs\"] pub mod {};\n",
module, version, module module, version, module
) )
.unwrap(); .unwrap();
} }
// Cleanups! // Cleanups!
@ -449,7 +496,7 @@ pub fn gen(options: Options) {
"PROVIDE({} = DefaultHandler);\n", "PROVIDE({} = DefaultHandler);\n",
name.to_ascii_uppercase() name.to_ascii_uppercase()
) )
.unwrap(); .unwrap();
} }
File::create(chip_dir.join("device.x")) File::create(chip_dir.join("device.x"))
@ -477,7 +524,7 @@ pub fn gen(options: Options) {
transform::NameKind::Enum => format!("vals::{}", s), transform::NameKind::Enum => format!("vals::{}", s),
_ => s.to_string(), _ => s.to_string(),
}) })
.unwrap(); .unwrap();
transform::sort::Sort {}.run(&mut ir).unwrap(); transform::sort::Sort {}.run(&mut ir).unwrap();
transform::Sanitize {}.run(&mut ir).unwrap(); transform::Sanitize {}.run(&mut ir).unwrap();
@ -488,7 +535,7 @@ pub fn gen(options: Options) {
.join("src/peripherals") .join("src/peripherals")
.join(format!("{}_{}.rs", module, version)), .join(format!("{}_{}.rs", module, version)),
) )
.unwrap(); .unwrap();
let data = items.to_string().replace("] ", "]\n"); let data = items.to_string().replace("] ", "]\n");
// Remove inner attributes like #![no_std] // Remove inner attributes like #![no_std]
@ -511,14 +558,14 @@ pub fn gen(options: Options) {
"#[cfg_attr(feature=\"{}_{}\", path = \"chips/{}_{}/pac.rs\")]", "#[cfg_attr(feature=\"{}_{}\", path = \"chips/{}_{}/pac.rs\")]",
x, c, x, c x, c, x, c
) )
.unwrap(); .unwrap();
} else { } else {
write!( write!(
&mut paths, &mut paths,
"#[cfg_attr(feature=\"{}\", path = \"chips/{}/pac.rs\")]", "#[cfg_attr(feature=\"{}\", path = \"chips/{}/pac.rs\")]",
x, x x, x
) )
.unwrap(); .unwrap();
} }
} }
let mut contents: Vec<u8> = Vec::new(); let mut contents: Vec<u8> = Vec::new();
@ -541,7 +588,7 @@ pub fn gen(options: Options) {
out_dir.join("src").join("common.rs"), out_dir.join("src").join("common.rs"),
generate::COMMON_MODULE, generate::COMMON_MODULE,
) )
.unwrap(); .unwrap();
// Generate Cargo.toml // Generate Cargo.toml
const BUILDDEP_BEGIN: &[u8] = b"# BEGIN BUILD DEPENDENCIES"; const BUILDDEP_BEGIN: &[u8] = b"# BEGIN BUILD DEPENDENCIES";