Date:2012-03-06 20:02:17 (7 years 3 months ago)
Author:Werner Almesberger
Commit:b791fd712e2cb61405c321ed972f4d5b1135455d
Message:m1r4/dsv/: M1rc3 BOM to BOOKSHELF conversion (may be incomplete)

Files: m1r4/dsv/Makefile (1 diff)
m1r4/dsv/SUPPLEMENT (1 diff)
m1r4/dsv/bomshelf (1 diff)

Change Details

m1r4/dsv/Makefile
1#
2# Obtaining the BOM:
3#
4# - wget http://downloads.qi-hardware.com/hardware/milkymist_one/bom/rc3/milkymist_one_bom_rc3.ods
5# - run ooffice or equivalent to save as CVS
6# - edit to remove embedded newline
7#
8
9BOM = milkymist_one_bom_rc3.csv
10
11.PHONY: all dsv clean spotless
12
13all: dsv
14
15dsv: BOOKSHELF
16        ../../../eda-tools/dsv/dsv setup BOOKSHELF
17
18BOOKSHELF: $(BOM) bomshelf SUPPLEMENT
19        ./bomshelf $< >$@ || { rm -f $@; exit 1; }
20
21clean:
22        rm -f BOOKSHELF
23
24spotless:
25        rm -rf .dsv
m1r4/dsv/SUPPLEMENT
1#
2# Tags:
3#
4# C component reference
5# P manufacturer part number (can be prefix or substring)
6# A alias name (optional)
7# D data sheet URL (optional, overrides)
8#
9# Exactly one of C and P must be present.
10#
11
12# Part numbering scheme seems to have changed.
13P: CC1206X7R9K472
14D: http://www.chipcera.com.cn/download/%E9%AB%98%E5%8E%8B%E5%93%811.pdf
15
16# On Debian/Ubuntu, may need xpdf-japanese for character mapping.
17P: FBMJ3216HM600
18D: http://www.yuden.co.jp/ut/product/category/emisuppression/FBMJ3216HM600-T.pdf
m1r4/dsv/bomshelf
1#!/usr/bin/perl
2#
3# Source:
4# http://downloads.qi-hardware.com/hardware/milkymist_one/bom/rc3/milkymist_one_bom_rc3.ods
5# - save as CVS
6# - edit to remove embedded newlines
7#
8
9sub csv
10{
11    my $s = $_[0];
12    my @a = ();
13
14    while (1) {
15        if ($s =~ /^"/) {
16            die unless $s =~ /^"([^"]*)"(,\s*)?/;
17            push(@a, $1);
18            $s = $';
19            return @a unless length $2;
20
21        } elsif ($s =~ /,\s*/) {
22            push(@a, $`);
23            $s = $';
24        } else {
25            push(@a, $s);
26            return @a;
27        }
28    }
29
30}
31
32while (<>) {
33    chop;
34    @f = &csv($_);
35    next unless $f[0] =~ /^[0-9]+$/;
36    die "duplicate part $f[3]" if defined $cr{$f[3]};
37    $f[1] =~ s/\(DNP\)//g;
38    $cr{$f[3]} = $f[1];
39    $url{$f[3]} = $f[4];
40    $dsc{$f[3]} = $f[6];
41    for (&csv($f[1])) {
42        warn "\"$_\" used for $r{$_} and $f[3]" if defined $r{$_};
43        $r{$_} = $f[3];
44    }
45}
46
47open(F, "SUPPLEMENT") || die "open SUPPLEMENT: $!";
48while (<F>) {
49    chop;
50    next if /^\s*#/;
51    next if /^\s*$/;
52    if (/^[Cc]:\s*/) {
53        die "unknown component reference $'" unless defined $r{$'};
54        $p = $r{$'};
55        next;
56    }
57    if (/^[Pp]:\s*/) {
58        $p = $';
59        next if defined $cr{$p};
60        @a = grep { $_ =~ /^$p/ } keys %cr;
61        die "key $p* is ambiguous" if scalar @a > 1;
62        if (!@a) {
63            @a = grep { $_ =~ /$p/ } keys %cr;
64            die "key *$p* is ambiguous" if scalar @a > 1;
65            die "key $p matches nothing" unless @a;
66        }
67        $p = $a[0];
68        next;
69    }
70    if (/^[Aa]:\s*/) {
71        $a{$p} .= "," if defined $a{$p};
72        $a{$p} .= $';
73        next;
74    }
75    if (/^[Dd]:\s*/) {
76        $url{$p} = $';
77        next;
78    }
79    die "don't recognize \"$_\"";
80}
81
82for (sort keys %cr) {
83    next if $url{$_} eq "";
84    print "# $dsc{$_}\n" unless $dsc{$_} eq "";
85    print "N: $_\n";
86    for $a (&csv($cr{$_})) {
87        print "A: $a\n";
88    }
89    if (defined $a{$_}) {
90        for $a (&csv($a{$_})) {
91            print "A: $a\n";
92        }
93    }
94    print "D: $url{$_}\n\n";
95}

Archive Download the corresponding diff file

Branches:
master



interactive