From b791fd712e2cb61405c321ed972f4d5b1135455d Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 6 Mar 2012 16:02:17 -0300 Subject: [PATCH] m1r4/dsv/: M1rc3 BOM to BOOKSHELF conversion (may be incomplete) --- m1r4/dsv/Makefile | 25 ++++++++++++ m1r4/dsv/SUPPLEMENT | 18 +++++++++ m1r4/dsv/bomshelf | 95 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 m1r4/dsv/Makefile create mode 100644 m1r4/dsv/SUPPLEMENT create mode 100755 m1r4/dsv/bomshelf diff --git a/m1r4/dsv/Makefile b/m1r4/dsv/Makefile new file mode 100644 index 0000000..d7b2140 --- /dev/null +++ b/m1r4/dsv/Makefile @@ -0,0 +1,25 @@ +# +# Obtaining the BOM: +# +# - wget http://downloads.qi-hardware.com/hardware/milkymist_one/bom/rc3/milkymist_one_bom_rc3.ods +# - run ooffice or equivalent to save as CVS +# - edit to remove embedded newline +# + +BOM = milkymist_one_bom_rc3.csv + +.PHONY: all dsv clean spotless + +all: dsv + +dsv: BOOKSHELF + ../../../eda-tools/dsv/dsv setup BOOKSHELF + +BOOKSHELF: $(BOM) bomshelf SUPPLEMENT + ./bomshelf $< >$@ || { rm -f $@; exit 1; } + +clean: + rm -f BOOKSHELF + +spotless: + rm -rf .dsv diff --git a/m1r4/dsv/SUPPLEMENT b/m1r4/dsv/SUPPLEMENT new file mode 100644 index 0000000..0925fb3 --- /dev/null +++ b/m1r4/dsv/SUPPLEMENT @@ -0,0 +1,18 @@ +# +# Tags: +# +# C component reference +# P manufacturer part number (can be prefix or substring) +# A alias name (optional) +# D data sheet URL (optional, overrides) +# +# Exactly one of C and P must be present. +# + +# Part numbering scheme seems to have changed. +P: CC1206X7R9K472 +D: http://www.chipcera.com.cn/download/%E9%AB%98%E5%8E%8B%E5%93%811.pdf + +# On Debian/Ubuntu, may need xpdf-japanese for character mapping. +P: FBMJ3216HM600 +D: http://www.yuden.co.jp/ut/product/category/emisuppression/FBMJ3216HM600-T.pdf diff --git a/m1r4/dsv/bomshelf b/m1r4/dsv/bomshelf new file mode 100755 index 0000000..40d13c6 --- /dev/null +++ b/m1r4/dsv/bomshelf @@ -0,0 +1,95 @@ +#!/usr/bin/perl +# +# Source: +# http://downloads.qi-hardware.com/hardware/milkymist_one/bom/rc3/milkymist_one_bom_rc3.ods +# - save as CVS +# - edit to remove embedded newlines +# + +sub csv +{ + my $s = $_[0]; + my @a = (); + + while (1) { + if ($s =~ /^"/) { + die unless $s =~ /^"([^"]*)"(,\s*)?/; + push(@a, $1); + $s = $'; + return @a unless length $2; + + } elsif ($s =~ /,\s*/) { + push(@a, $`); + $s = $'; + } else { + push(@a, $s); + return @a; + } + } + +} + +while (<>) { + chop; + @f = &csv($_); + next unless $f[0] =~ /^[0-9]+$/; + die "duplicate part $f[3]" if defined $cr{$f[3]}; + $f[1] =~ s/\(DNP\)//g; + $cr{$f[3]} = $f[1]; + $url{$f[3]} = $f[4]; + $dsc{$f[3]} = $f[6]; + for (&csv($f[1])) { + warn "\"$_\" used for $r{$_} and $f[3]" if defined $r{$_}; + $r{$_} = $f[3]; + } +} + +open(F, "SUPPLEMENT") || die "open SUPPLEMENT: $!"; +while () { + chop; + next if /^\s*#/; + next if /^\s*$/; + if (/^[Cc]:\s*/) { + die "unknown component reference $'" unless defined $r{$'}; + $p = $r{$'}; + next; + } + if (/^[Pp]:\s*/) { + $p = $'; + next if defined $cr{$p}; + @a = grep { $_ =~ /^$p/ } keys %cr; + die "key $p* is ambiguous" if scalar @a > 1; + if (!@a) { + @a = grep { $_ =~ /$p/ } keys %cr; + die "key *$p* is ambiguous" if scalar @a > 1; + die "key $p matches nothing" unless @a; + } + $p = $a[0]; + next; + } + if (/^[Aa]:\s*/) { + $a{$p} .= "," if defined $a{$p}; + $a{$p} .= $'; + next; + } + if (/^[Dd]:\s*/) { + $url{$p} = $'; + next; + } + die "don't recognize \"$_\""; +} + +for (sort keys %cr) { + next if $url{$_} eq ""; + print "# $dsc{$_}\n" unless $dsc{$_} eq ""; + print "N: $_\n"; + for $a (&csv($cr{$_})) { + print "A: $a\n"; + } + if (defined $a{$_}) { + for $a (&csv($a{$_})) { + print "A: $a\n"; + } + } + print "D: $url{$_}\n\n"; +}