| 1 | # | ||
| 2 | # This file is part of the Perlilog project. | ||
| 3 | # | ||
| 4 | # Copyright (C) 2003, Eli Billauer | ||
| 5 | # | ||
| 6 | # This program is free software; you can redistribute it and/or modify | ||
| 7 | # it under the terms of the GNU General Public License as published by | ||
| 8 | # the Free Software Foundation; either version 2 of the License, or | ||
| 9 | # (at your option) any later version. | ||
| 10 | # | ||
| 11 | # This program is distributed in the hope that it will be useful, | ||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | # GNU General Public License for more details. | ||
| 15 | # | ||
| 16 | # You should have received a copy of the GNU General Public License | ||
| 17 | # along with this program; if not, write to the Free Software | ||
| 18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | # | ||
| 20 | # A copy of the license can be found in a file named "licence.txt", at the | ||
| 21 | # root directory of this project. | ||
| 22 | # | ||
| 23 | |||
| 24 | sub attempt { | ||
| 25 | my $this = shift; | ||
| 26 | |||
| 27 | # One master, one slave? | ||
| 28 | return undef if | ||
| 29 | ( | ||
| 30 | ((grep {ref eq 'wbm'} @_) != 1) || | ||
| 31 | ((grep {ref eq 'wbs'} @_) != 1) | ||
| 32 | ); | ||
| 33 | |||
| 34 | my @extras = grep {ref eq 'vars'} @_; | ||
| 35 | |||
| 36 | return "There are ports other than 'wbm', wbs' and 'vars' in the bundle" | ||
| 37 | if (grep {(ref ne 'wbm') && (ref ne 'wbs') && (ref ne 'vars')} @_ ); | ||
| 38 | |||
| 39 | # Now we make sure that none of the "vars" weren't meant to be | ||
| 40 | # mapped on the bus themselves. | ||
| 41 | |||
| 42 | foreach (@extras) { | ||
| 43 | my %l = $_->get('labels'); | ||
| 44 | return undef | ||
| 45 | if (grep /^(r|w|rw|wr)\d+$/, keys %l); | ||
| 46 | } | ||
| 47 | |||
| 48 | my $self = $this->new(nick => 'Wishbone_simple_connection'); | ||
| 49 | return $self; | ||
| 50 | } | ||
| 51 | |||
| 52 | sub generate { | ||
| 53 | my $self = shift; | ||
| 54 | |||
| 55 | my %pairs = (cyc_o => 'cyc_i', | ||
| 56 | stb_o => 'stb_i', | ||
| 57 | ack_i => 'ack_o', | ||
| 58 | we_o => 'we_i', | ||
| 59 | adr_o => 'adr_i', | ||
| 60 | dat_o => 'dat_i', | ||
| 61 | dat_i => 'dat_o'); | ||
| 62 | |||
| 63 | # Get the ports to connect... | ||
| 64 | my @ports = $self->get('perlilog-ports-to-connect'); | ||
| 65 | my ($wbs) = grep {ref eq 'wbs'} @ports; | ||
| 66 | my ($wbm) = grep {ref eq 'wbm'} @ports; | ||
| 67 | my @extras = grep {ref eq 'vars'} @ports; | ||
| 68 | |||
| 69 | # Now we assure the excusiveness of the connection | ||
| 70 | my $prevconn; | ||
| 71 | |||
| 72 | $prevconn = $wbs->get('wishbone-connection-marker'); | ||
| 73 | wrong("Attempt to connect ".$wbs->who." to ".$wbm->who. | ||
| 74 | " when already connected to ".$self->safewho($prevconn)."\n") | ||
| 75 | if (defined $prevconn); | ||
| 76 | |||
| 77 | $prevconn = $wbm->get('wishbone-connection-marker'); | ||
| 78 | wrong("Attempt to connect ".$wbm->who." to ".$wbs->who. | ||
| 79 | " when already connected to ".$self->safewho($prevconn)."\n") | ||
| 80 | if (defined $prevconn); | ||
| 81 | |||
| 82 | $wbs->const('wishbone-connection-marker', $wbm); | ||
| 83 | $wbm->const('wishbone-connection-marker', $wbs); | ||
| 84 | |||
| 85 | # Translate variable names to ID's | ||
| 86 | my %hs=$self->labelID($wbs); | ||
| 87 | my %hm=$self->labelID($wbm); | ||
| 88 | |||
| 89 | my %he = (); | ||
| 90 | my $port; | ||
| 91 | foreach $port (reverse @extras) { | ||
| 92 | my %h = $self->labelID($port); | ||
| 93 | foreach (keys %h) { $he{$_} = $h{$_}; } | ||
| 94 | } | ||
| 95 | |||
| 96 | foreach (qw(rst_i clk_i), sort keys %pairs) { | ||
| 97 | wrong("Missing label \'$_\' in ".$wbm->who()."\n") | ||
| 98 | unless (defined $hm{$_}); | ||
| 99 | } | ||
| 100 | |||
| 101 | foreach (qw(rst_i clk_i), sort values %pairs) { | ||
| 102 | wrong("Missing label \'$_\' in ".$wbs->who()."\n") | ||
| 103 | unless (defined $hs{$_}); | ||
| 104 | } | ||
| 105 | |||
| 106 | # Now we make variable attachments. First clock and reset, if | ||
| 107 | # they were given by some 'vars' port | ||
| 108 | |||
| 109 | if (defined $he{'rst'}) { | ||
| 110 | $self->attach($hm{'rst_i'}, $he{'rst'}); | ||
| 111 | $self->attach($hs{'rst_i'}, $he{'rst'}); | ||
| 112 | } | ||
| 113 | |||
| 114 | if (defined $he{'clk'}) { | ||
| 115 | $self->attach($hm{'clk_i'}, $he{'clk'}); | ||
| 116 | $self->attach($hs{'clk_i'}, $he{'clk'}); | ||
| 117 | } | ||
| 118 | |||
| 119 | # And now we attach the master-slave signals | ||
| 120 | |||
| 121 | foreach (sort keys %pairs) { | ||
| 122 | $self->attach($hm{$_}, $hs{$pairs{$_}}); | ||
| 123 | } | ||
| 124 | } |