Dario Nieuwenhuis 8e26f36a8e Manually maintain memory maps instead of parsing them from cubeprogdb.
First step towards fixing #301

The cubeprogdb has turned out to be a quite bad data source. It's not granular
enough (it has one entry per chip die, not per chip) so the previous code joined
the data with the C headers and cubedb to fill in the gaps, essentialy "guessing"
stuff. This has been quite error prone (see #301) and hard to make fixes to.

Instead, we're going to manually maintain memory maps in a .rs file. This way, if
something is wrong we can simply go and fix it.

This commit just migrates the existing data, even if it's wrong. (it does fix
a few very minor mistakes). Next steps is actually fixing the memory maps.
2024-04-09 03:38:33 +02:00

106 lines
2.6 KiB
Rust

mod chips;
mod dma;
mod docs;
mod gpio_af;
mod header;
mod interrupts;
mod memory;
mod rcc;
mod registers;
#[macro_export]
macro_rules! regex {
($re:literal) => {{
::ref_thread_local::ref_thread_local! {
static managed REGEX: ::regex::Regex = ::regex::Regex::new($re).unwrap();
}
<REGEX as ::ref_thread_local::RefThreadLocal<::regex::Regex>>::borrow(&REGEX)
}};
}
struct Stopwatch {
start: std::time::Instant,
section_start: Option<std::time::Instant>,
}
impl Stopwatch {
fn new() -> Self {
eprintln!("Starting timer");
let start = std::time::Instant::now();
Self {
start,
section_start: None,
}
}
fn section(&mut self, status: &str) {
let now = std::time::Instant::now();
self.print_done(now);
eprintln!(" {status}");
self.section_start = Some(now);
}
fn stop(self) {
let now = std::time::Instant::now();
self.print_done(now);
let total_elapsed = now - self.start;
eprintln!("Total time: {:.2} seconds", total_elapsed.as_secs_f32());
}
fn print_done(&self, now: std::time::Instant) {
if let Some(section_start) = self.section_start {
let elapsed = now - section_start;
eprintln!(" done in {:.2} seconds", elapsed.as_secs_f32());
}
}
}
fn main() -> anyhow::Result<()> {
pretty_env_logger::init();
let mut stopwatch = Stopwatch::new();
stopwatch.section("Parsing headers");
let headers = header::Headers::parse()?;
stopwatch.section("Parsing other stuff");
// stopwatch.section("Parsing registers");
let registers = registers::Registers::parse()?;
registers.write()?;
// stopwatch.section("Parsing interrupts");
let chip_interrupts = interrupts::ChipInterrupts::parse()?;
// stopwatch.section("Parsing RCC registers");
let peripheral_to_clock = rcc::ParsedRccs::parse(&registers)?;
// stopwatch.section("Parsing docs");
let docs = docs::Docs::parse()?;
// stopwatch.section("Parsing DMA");
let dma_channels = dma::DmaChannels::parse()?;
// stopwatch.section("Parsing GPIO AF");
let af = gpio_af::Af::parse()?;
stopwatch.section("Parsing chip groups");
let (chips, chip_groups) = chips::parse_groups()?;
stopwatch.section("Processing chips");
chips::dump_all_chips(
chip_groups,
headers,
af,
chip_interrupts,
peripheral_to_clock,
dma_channels,
chips,
docs,
)?;
stopwatch.stop();
Ok(())
}