add chip argument, untested 22v10

This commit is contained in:
saji 2024-05-04 21:41:53 -05:00
parent 1989470bc4
commit abdaf710e6
2 changed files with 44 additions and 17 deletions

View file

@ -33,10 +33,7 @@ pub enum MappingError {
// attempt to map graph into blueprint // attempt to map graph into blueprint
/// Acquire the SOP associated with the OLMC. If it's /// Acquire the SOP associated with the OLMC. If it's
fn get_sop_for_olmc( fn get_sop_for_olmc(graph: &Graph, olmc_idx: &NodeIdx) -> Result<GalSop, MappingError> {
graph: &Graph,
olmc_idx: &NodeIdx,
) -> Result<GalSop, MappingError> {
let input = graph.get_node_port_conns(olmc_idx, "A"); let input = graph.get_node_port_conns(olmc_idx, "A");
debug!("Found connections into OLMC Input: {:?}", input); debug!("Found connections into OLMC Input: {:?}", input);
debug!("OLMC {:?}", graph.get_node(olmc_idx)); debug!("OLMC {:?}", graph.get_node(olmc_idx));
@ -56,9 +53,7 @@ fn get_sop_for_olmc(
// find the row that contains this olmc. // find the row that contains this olmc.
// we know this exists because mapping has already finished. // we know this exists because mapping has already finished.
let newsop = GalSop { let newsop = GalSop {
connections: HashMap::from([ connections: HashMap::from([("A".to_string(), vec![i.net.clone()])]),
("A".to_string(), vec![i.net.clone()]),
]),
parameters: GalSopParameters { parameters: GalSopParameters {
depth: 1, depth: 1,
width: 1, width: 1,
@ -66,8 +61,7 @@ fn get_sop_for_olmc(
}, },
}; };
Some(newsop) Some(newsop)
}
},
_ => None, _ => None,
} }
}) })
@ -117,10 +111,21 @@ fn map_remaining_olmc(
} }
} }
fn chip_to_olmc_offset(chip: &Chip) -> usize {
match chip {
Chip::GAL16V8 => 12,
Chip::GAL22V10 => 14,
_ => panic!("Invalid chip!"),
}
}
fn find_hwpin_for_net( fn find_hwpin_for_net(
graph: &Graph, graph: &Graph,
pcf: &PcfFile, pcf: &PcfFile,
olmcmap: &Vec<Option<NodeIdx>>, olmcmap: &[Option<NodeIdx>],
chip: &Chip,
net: &Net, net: &Net,
) -> Result<u32, MappingError> { ) -> Result<u32, MappingError> {
// this does a double lookup. first it finds the Input on the net, // this does a double lookup. first it finds the Input on the net,
@ -169,9 +174,12 @@ fn find_hwpin_for_net(
.iter() .iter()
.position(|node| node == inputs[0]) .position(|node| node == inputs[0])
.unwrap(); .unwrap();
let olmc_row = olmcmap.iter().position(|r| r == &Some(NodeIdx(olmc_idx))).unwrap(); let olmc_row = olmcmap
.iter()
.position(|r| r == &Some(NodeIdx(olmc_idx)))
.unwrap();
// we have the row. // we have the row.
let pin = olmc_row + 12; // TODO: fix! let pin = olmc_row + chip_to_olmc_offset(chip); // TODO: fix!
debug!("OLMC discovered on {pin}"); debug!("OLMC discovered on {pin}");
Ok(pin as u32) Ok(pin as u32)
} }
@ -182,7 +190,8 @@ fn find_hwpin_for_net(
fn make_term_from_sop( fn make_term_from_sop(
graph: &Graph, graph: &Graph,
pcf: &PcfFile, pcf: &PcfFile,
olmcmap: &Vec<Option<NodeIdx>>, olmcmap: &[Option<NodeIdx>],
chip: &Chip,
sop: GalSop, sop: GalSop,
) -> Term { ) -> Term {
let table = sop.parameters.table.as_bytes(); let table = sop.parameters.table.as_bytes();
@ -207,7 +216,7 @@ fn make_term_from_sop(
let net_for_pin = input_nets.get(idx).unwrap(); let net_for_pin = input_nets.get(idx).unwrap();
// now use the helper to find the true hardware pin // now use the helper to find the true hardware pin
let hwpin: usize = let hwpin: usize =
find_hwpin_for_net(graph, pcf, olmcmap, net_for_pin).unwrap() as usize; find_hwpin_for_net(graph, pcf, olmcmap, &chip, net_for_pin).unwrap() as usize;
// we now have our hardware pin number! // we now have our hardware pin number!
match *product { match *product {
"01" => Some(Pin { "01" => Some(Pin {
@ -353,7 +362,7 @@ pub fn graph_convert(graph: &Graph, pcf: PcfFile, chip: Chip) -> anyhow::Result<
debug!("Mapping node {node} at row {idx}"); debug!("Mapping node {node} at row {idx}");
let sop = get_sop_for_olmc(graph, node)?; let sop = get_sop_for_olmc(graph, node)?;
debug!("Got SOP {:?} attached to node", sop); debug!("Got SOP {:?} attached to node", sop);
let term = make_term_from_sop(graph, &pcf, &olmcmap, sop); let term = make_term_from_sop(graph, &pcf, &olmcmap, &chip, sop);
debug!("Got term {:?}", term); debug!("Got term {:?}", term);
let gal_olmc_node = graph.get_node(node).unwrap(); let gal_olmc_node = graph.get_node(node).unwrap();
if let Node::Olmc(o) = gal_olmc_node { if let Node::Olmc(o) = gal_olmc_node {

View file

@ -2,7 +2,7 @@ pub mod pcf;
pub mod yosys_parser; pub mod yosys_parser;
mod fitter; mod fitter;
use clap::{Parser, Subcommand, Args}; use clap::{Parser, Subcommand, ValueEnum, Args};
use galette::gal_builder::build; use galette::gal_builder::build;
use galette::writer::{make_jedec, Config}; use galette::writer::{make_jedec, Config};
use crate::pcf::parse_pcf; use crate::pcf::parse_pcf;
@ -35,6 +35,21 @@ struct ValidateArgs {
file: PathBuf, file: PathBuf,
} }
#[derive(ValueEnum, Debug, Clone)]
enum ChipType {
GAL16V8,
GAL22V10
}
impl ChipType {
fn to_galette(&self) -> Chip {
match self {
Self::GAL16V8 => Chip::GAL16V8,
Self::GAL22V10 => Chip::GAL22V10,
}
}
}
#[derive(Args)] #[derive(Args)]
struct SynthArgs { struct SynthArgs {
@ -42,6 +57,9 @@ struct SynthArgs {
netlist: PathBuf, netlist: PathBuf,
#[arg(required = true, value_hint = clap::ValueHint::DirPath)] #[arg(required = true, value_hint = clap::ValueHint::DirPath)]
constraints: PathBuf, constraints: PathBuf,
#[arg(value_enum, long, default_value_t=ChipType::GAL16V8)]
chip: ChipType
} }
@ -83,7 +101,7 @@ fn synth(s: SynthArgs) -> Result<()> {
let pcf_string = std::str::from_utf8(pcf_file)?; let pcf_string = std::str::from_utf8(pcf_file)?;
let pcf = parse_pcf(pcf_string); let pcf = parse_pcf(pcf_string);
let res = graph_convert(&g, pcf, Chip::GAL16V8)?; let res = graph_convert(&g, pcf, s.chip.to_galette())?;
let mut gal = build(&res)?; let mut gal = build(&res)?;