| 1 | package VIC::PIC::Gpsim; | ||||||||||||||||||||||||||||||||||||
| 2 | 34 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 3 | 34 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 4 | 34 | ▶ | use bigint; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 5 | 34 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 6 | 34 | ▶ | use Pegex::Base; # use this instead of Mo | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||
| 8 | 34 | our $VERSION = '0.29'; | |||||||||||||||||||||||||||||||||||
| 9 | 34 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||
| 11 | 34 | has type => 'gpsim'; | |||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||
| 13 | 34 | has include => 'coff.inc'; | |||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||
| 15 | 34 | has pic => undef; # refer to the PIC object | |||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||
| 17 | 34 | has node_count => 0; | |||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||
| 19 | 34 | has scope_channels => 0; | |||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||
| 21 | 34 | has stimulus_count => 0; | |||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||
| 23 | 34 | has should_autorun => 0; | |||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||
| 25 | 34 | has disable => 0; | |||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||
| 27 | sub supports_modifier { | ||||||||||||||||||||||||||||||||||||
| 28 | 12 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
supports_modifier: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 29 | 12 | my $mod = shift; | |||||||||||||||||||||||||||||||||||
| 30 | 12 | ▶ | return 1 if $mod =~ /^(?:every|wave)$/i; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 31 | 1 | 0; | |||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||
| 34 | sub init_code { | ||||||||||||||||||||||||||||||||||||
| 35 | 19 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
init_code: called CC=5 SCAR=17.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 36 | 19 | ▶ | croak "This chip is not supported" unless $self->pic->doesroles(qw(Chip CodeGen GPIO)); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 37 | 19 | my $pic = ''; | |||||||||||||||||||||||||||||||||||
| 38 | 19 | ▶ | $pic = $self->pic->type if $self->pic; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 39 | 19 | ▶ | my $freq = $self->pic->f_osc if $self->pic; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 40 | 19 | ▶ | if ($freq) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 41 | 19 | $freq = qq{\t.sim "$pic.frequency = $freq"}; | |||||||||||||||||||||||||||||||||||
| 42 | } else { | ||||||||||||||||||||||||||||||||||||
| 43 | 0 | $freq = ''; | |||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||
| 45 | 19 | return << "..."; | |||||||||||||||||||||||||||||||||||
| 46 | ;;;; generated common code for the Simulator | ||||||||||||||||||||||||||||||||||||
| 47 | \t.sim "module library libgpsim_modules" | ||||||||||||||||||||||||||||||||||||
| 48 | \t.sim "$pic.xpos = 200" | ||||||||||||||||||||||||||||||||||||
| 49 | \t.sim "$pic.ypos = 200" | ||||||||||||||||||||||||||||||||||||
| 50 | $freq | ||||||||||||||||||||||||||||||||||||
| 51 | ... | ||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||
| 54 | sub _gen_led { | ||||||||||||||||||||||||||||||||||||
| 55 | 30 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
_gen_led: called CC=6 SCAR=18.1
| |||||||||||||||||||||||||||||||||||||
| 56 | 30 | my ($id, $x, $y, $name, $port, $color) = @_; | |||||||||||||||||||||||||||||||||||
| 57 | 30 | ▶ | if (defined $color and ref $color eq 'HASH') { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $color and ref $color eq "HASH"
MC/DC50%1/2
defined $color and ref $color eq "HASH"
defined $color
ref $color eq "HASH"
Truth table66%2/3
A and B
A= defined $colorB= ref $color eq "HASH"
| |||||||||||||||||||||||||||||||||||||
| 58 | 4 | $color = $color->{string}; | |||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||
| 60 | 30 | ▶ | $color = 'red' unless defined $color; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 61 | 30 | ▶ | $color = 'red' unless $color =~ /red|orange|green|yellow|blue/i; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 62 | 30 | $color = lc $color; | |||||||||||||||||||||||||||||||||||
| 63 | 30 | ▶ | $color = substr ($color, 1) if $color =~ /^@/; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 64 | 30 | return << "..."; | |||||||||||||||||||||||||||||||||||
| 65 | \t.sim "module load led L$id" | ||||||||||||||||||||||||||||||||||||
| 66 | \t.sim "L$id.xpos = $x" | ||||||||||||||||||||||||||||||||||||
| 67 | \t.sim "L$id.ypos = $y" | ||||||||||||||||||||||||||||||||||||
| 68 | \t.sim "L$id.color = $color" | ||||||||||||||||||||||||||||||||||||
| 69 | \t.sim "node $name" | ||||||||||||||||||||||||||||||||||||
| 70 | \t.sim "attach $name $port L$id.in" | ||||||||||||||||||||||||||||||||||||
| 71 | ... | ||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||
| 75 | sub _get_gpio_info { | ||||||||||||||||||||||||||||||||||||
| 76 | 101 | ▶ | my ($self, $port) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
_get_gpio_info: called CC=3 SCAR=15.4
| |||||||||||||||||||||||||||||||||||||
| 77 | 101 | my $gpio_pin = $self->pic->get_input_pin($port); | |||||||||||||||||||||||||||||||||||
| 78 | 101 | ▶ | if ($gpio_pin) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 79 | # this is a pin | ||||||||||||||||||||||||||||||||||||
| 80 | 101 | return @{$self->pic->input_pins->{$gpio_pin}}; | |||||||||||||||||||||||||||||||||||
| 81 | } else { | ||||||||||||||||||||||||||||||||||||
| 82 | 0 | $gpio_pin = $self->pic->get_output_pin($port); | |||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ($gpio_pin) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 84 | # this is a pin | ||||||||||||||||||||||||||||||||||||
| 85 | 0 | return @{$self->pic->output_pins->{$gpio_pin}}; | |||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||
| 88 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||
| 91 | sub _get_simreg { | ||||||||||||||||||||||||||||||||||||
| 92 | 32 | ▶ | my ($self, $port) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
_get_simreg: called CC=5 SCAR=17.8
| |||||||||||||||||||||||||||||||||||||
| 93 | 32 | my $simreg = lc $port; | |||||||||||||||||||||||||||||||||||
| 94 | 32 | ▶ | if ($self->pic) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 95 | 32 | ▶ | if (exists $self->pic->registers->{$port}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 96 | # this is a port | ||||||||||||||||||||||||||||||||||||
| 97 | 1 | $simreg = lc $port; | |||||||||||||||||||||||||||||||||||
| 98 | } elsif (exists $self->pic->pins->{$port}) { | ||||||||||||||||||||||||||||||||||||
| 99 | 31 | my ($io1) = $self->_get_gpio_info($port); | |||||||||||||||||||||||||||||||||||
| 100 | 31 | ▶ | if (defined $io1) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 101 | 31 | $simreg = lc $io1; | |||||||||||||||||||||||||||||||||||
| 102 | } else { | ||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $pic = $self->pic->type; | |||||||||||||||||||||||||||||||||||
| 104 | 0 | carp "Cannot find '$port' in PIC $pic. Using '$simreg'"; | |||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||
| 106 | } else { | ||||||||||||||||||||||||||||||||||||
| 107 | 0 | my $pic = $self->pic->type; | |||||||||||||||||||||||||||||||||||
| 108 | 0 | carp "Cannot find '$port' in PIC $pic. Using '$simreg'"; | |||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||
| 111 | 32 | return $simreg; | |||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||
| 114 | sub _get_simport { | ||||||||||||||||||||||||||||||||||||
| 115 | 94 | ▶ | my ($self, $port, $pin) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
_get_simport: called CC=7 SCAR=21.8
| |||||||||||||||||||||||||||||||||||||
| 116 | 94 | my $simport = lc $port; | |||||||||||||||||||||||||||||||||||
| 117 | 94 | ▶ | if ($self->pic) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 118 | 94 | ▶ | if (exists $self->pic->registers->{$port}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 119 | # this is a port | ||||||||||||||||||||||||||||||||||||
| 120 | 25 | $simport = lc $port; | |||||||||||||||||||||||||||||||||||
| 121 | 25 | ▶ | $simport .= $pin if defined $pin; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 122 | } elsif (exists $self->pic->pins->{$port}) { | ||||||||||||||||||||||||||||||||||||
| 123 | 69 | my ($io1, $io2, $io3) = $self->_get_gpio_info($port); | |||||||||||||||||||||||||||||||||||
| 124 | 69 | ▶ | if (defined $io1 and defined $io3) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $io1 and defined $io3
MC/DC0%0/2
defined $io1 and defined $io3
defined $io1
defined $io3
Truth table33%1/3
A and B
A= defined $io1B= defined $io3
| |||||||||||||||||||||||||||||||||||||
| 125 | 69 | $simport = lc "$io1$io3"; | |||||||||||||||||||||||||||||||||||
| 126 | } else { | ||||||||||||||||||||||||||||||||||||
| 127 | 0 | my $pic = $self->pic->type; | |||||||||||||||||||||||||||||||||||
| 128 | 0 | carp "Cannot find '$port' in PIC $pic. Using '$simport'"; | |||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||
| 130 | } else { | ||||||||||||||||||||||||||||||||||||
| 131 | 0 | my $pic = $self->pic->type; | |||||||||||||||||||||||||||||||||||
| 132 | 0 | carp "Cannot find '$port' in PIC $pic. Using '$simport'"; | |||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||
| 135 | 94 | return $simport; | |||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||
| 138 | sub _get_portpin { | ||||||||||||||||||||||||||||||||||||
| 139 | 27 | ▶ | my ($self, $port) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
_get_portpin: called CC=6 SCAR=19.3
| |||||||||||||||||||||||||||||||||||||
| 140 | 27 | my $simport = lc $port; | |||||||||||||||||||||||||||||||||||
| 141 | 27 | my $simpin; | |||||||||||||||||||||||||||||||||||
| 142 | 27 | ▶ | if ($self->pic) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 143 | 27 | ▶ | if (exists $self->pic->registers->{$port}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 144 | # this is a port | ||||||||||||||||||||||||||||||||||||
| 145 | 0 | $simport = lc $port; | |||||||||||||||||||||||||||||||||||
| 146 | } elsif (exists $self->pic->pins->{$port}) { | ||||||||||||||||||||||||||||||||||||
| 147 | 1 | my ($io1, $io2, $io3) = $self->_get_gpio_info($port); | |||||||||||||||||||||||||||||||||||
| 148 | 1 | ▶ | if (defined $io1) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 149 | 1 | $simport = lc $io1; | |||||||||||||||||||||||||||||||||||
| 150 | 1 | $simpin = $io3; | |||||||||||||||||||||||||||||||||||
| 151 | } else { | ||||||||||||||||||||||||||||||||||||
| 152 | 0 | my $pic = $self->pic->type; | |||||||||||||||||||||||||||||||||||
| 153 | 0 | carp "Cannot find '$port' in PIC $pic. Using '$simport'"; | |||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||
| 155 | } else { | ||||||||||||||||||||||||||||||||||||
| 156 | 26 | return; | |||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||
| 159 | 1 | ▶ | return wantarray ? ($simport, $simpin) : $simport; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||
| 162 | sub attach_led { | ||||||||||||||||||||||||||||||||||||
| 163 | 17 | ▶ | my ($self, $port, $count, $color) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
attach_led: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 164 | 17 | ▶ | $count = 1 unless $count; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 165 | 17 | ▶ | $count = 1 if int($count) < 1; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 166 | 17 | my $code = ''; | |||||||||||||||||||||||||||||||||||
| 167 | 17 | ▶ | if ($count == 1) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 168 | 14 | my $c = $self->node_count; | |||||||||||||||||||||||||||||||||||
| 169 | 14 | my $node = lc $port . 'led'; | |||||||||||||||||||||||||||||||||||
| 170 | 14 | $self->node_count($c + 1); | |||||||||||||||||||||||||||||||||||
| 171 | 14 | ▶ | my $x = ($c >= 4) ? 400 : 100; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 172 | 14 | my $y = 50 + 50 * $c; | |||||||||||||||||||||||||||||||||||
| 173 | # use the default pin 0 here | ||||||||||||||||||||||||||||||||||||
| 174 | 14 | my $simport = $self->_get_simport($port, 0); | |||||||||||||||||||||||||||||||||||
| 175 | 14 | $code = $self->_gen_led($c, $x, $y, $node, $simport, $color); | |||||||||||||||||||||||||||||||||||
| 176 | } else { | ||||||||||||||||||||||||||||||||||||
| 177 | 3 | $count--; | |||||||||||||||||||||||||||||||||||
| 178 | 3 | ▶ | if ($self->pic) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 179 | 3 | for (0 .. $count) { | |||||||||||||||||||||||||||||||||||
| 180 | 16 | my $c = $self->node_count + $_; | |||||||||||||||||||||||||||||||||||
| 181 | 16 | ▶ | my $x = ($_ >= 4) ? 400 : 100; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 182 | 16 | my $y = 50 + 50 * $c; | |||||||||||||||||||||||||||||||||||
| 183 | 16 | my $node = lc $port . $c . 'led'; | |||||||||||||||||||||||||||||||||||
| 184 | 16 | my $simport = $self->_get_simport($port, $_); | |||||||||||||||||||||||||||||||||||
| 185 | 16 | $code .= $self->_gen_led($c, $x, $y, $node, $simport, $color); | |||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||
| 187 | 3 | $self->node_count($self->node_count + $count + 1); | |||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||
| 190 | 17 | return $code; | |||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||
| 193 | sub attach_led7seg { | ||||||||||||||||||||||||||||||||||||
| 194 | 1 | ▶ | my ($self, @pins) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
attach_led7seg: called CC=14 SCAR=31.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 195 | 1 | my $code = ''; | |||||||||||||||||||||||||||||||||||
| 196 | 1 | my @simpins = (); | |||||||||||||||||||||||||||||||||||
| 197 | 1 | my $color = 'red'; | |||||||||||||||||||||||||||||||||||
| 198 | 1 | foreach my $p (@pins) { | |||||||||||||||||||||||||||||||||||
| 199 | 2 | ▶ | if (defined $p and ref $p eq 'HASH') { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $p and ref $p eq "HASH"
MC/DC0%0/2
defined $p and ref $p eq "HASH"
defined $p
ref $p eq "HASH"
Truth table33%1/3
A and B
A= defined $pB= ref $p eq "HASH"
| |||||||||||||||||||||||||||||||||||||
| 200 | 0 | $p = $p->{string}; | |||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | next unless defined $p; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||
| 203 | 2 | ▶ | if (exists $self->pic->pins->{$p}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||
| 204 | 1 | push @simpins, $p; | |||||||||||||||||||||||||||||||||||
| 205 | } elsif (exists $self->pic->registers->{$p}) { | ||||||||||||||||||||||||||||||||||||
| 206 | # find all the output pins for the port | ||||||||||||||||||||||||||||||||||||
| 207 | 1 | foreach (sort(keys %{$self->pic->output_pins})) { | |||||||||||||||||||||||||||||||||||
| 208 | 17 | ▶ | next unless defined $self->pic->output_pins->{$_}->[0]; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 209 | 17 | ▶ | push @simpins, $_ if $self->pic->output_pins->{$_}->[0] eq $p; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||
| 211 | } elsif ($p =~ /red|orange|green|yellow|blue/i) { | ||||||||||||||||||||||||||||||||||||
| 212 | 0 | $color = $p; | |||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | $color = substr($p, 1) if $p =~ /^@/; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 214 | 0 | next; | |||||||||||||||||||||||||||||||||||
| 215 | } else { | ||||||||||||||||||||||||||||||||||||
| 216 | 0 | carp "Ignoring port $p as it doesn't exist\n"; | |||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||
| 219 | 1 | ▶ | return unless scalar @simpins; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 220 | 1 | my $id = $self->node_count; | |||||||||||||||||||||||||||||||||||
| 221 | 1 | $self->node_count($id + 1); | |||||||||||||||||||||||||||||||||||
| 222 | 1 | my $x = 500; | |||||||||||||||||||||||||||||||||||
| 223 | 1 | my $y = 50 + 50 * $id; | |||||||||||||||||||||||||||||||||||
| 224 | 1 | $code .= << "..."; | |||||||||||||||||||||||||||||||||||
| 225 | \t.sim "module load led_7segments L$id" | ||||||||||||||||||||||||||||||||||||
| 226 | \t.sim "L$id.xpos = $x" | ||||||||||||||||||||||||||||||||||||
| 227 | \t.sim "L$id.ypos = $y" | ||||||||||||||||||||||||||||||||||||
| 228 | ... | ||||||||||||||||||||||||||||||||||||
| 229 | 1 | my @nodes = qw(cc seg0 seg1 seg2 seg3 seg4 seg5 seg6); | |||||||||||||||||||||||||||||||||||
| 230 | 1 | foreach my $n (@nodes) { | |||||||||||||||||||||||||||||||||||
| 231 | 8 | my $p = shift @simpins; | |||||||||||||||||||||||||||||||||||
| 232 | 8 | my $sp = $self->_get_simport($p); | |||||||||||||||||||||||||||||||||||
| 233 | 8 | $code .= << "..."; | |||||||||||||||||||||||||||||||||||
| 234 | \t.sim "node $n" | ||||||||||||||||||||||||||||||||||||
| 235 | \t.sim "attach $n $sp L$id.$n" | ||||||||||||||||||||||||||||||||||||
| 236 | ... | ||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||
| 238 | 1 | return $code; | |||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||
| 241 | sub stop_after { | ||||||||||||||||||||||||||||||||||||
| 242 | 16 | ▶ | my ($self, $usecs) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
stop_after: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 243 | # convert $secs to cycles | ||||||||||||||||||||||||||||||||||||
| 244 | 16 | my $cycles = $usecs * 10; | |||||||||||||||||||||||||||||||||||
| 245 | 16 | my $code = << "..."; | |||||||||||||||||||||||||||||||||||
| 246 | \t.sim "break c $cycles" | ||||||||||||||||||||||||||||||||||||
| 247 | ... | ||||||||||||||||||||||||||||||||||||
| 248 | 16 | return $code; | |||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||
| 251 | sub logfile { | ||||||||||||||||||||||||||||||||||||
| 252 | 7 | ▶ | my ($self, $file) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
logfile: called CC=6 SCAR=20.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 253 | 7 | ▶ | $file = "vicsim.log" unless defined $file; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 254 | 7 | ▶ | if (ref $file eq 'HASH') { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 255 | 7 | ▶ | $file = $file->{string} || 'vicsim.log'; | ||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$file->{'string'} || 'vicsim.log'
MC/DC0%0/1
$file->{'string'} || 'vicsim.log'
$file->{'string'}
Truth table50%1/2
A
A= $file->{'string'}
| |||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||
| 257 | 7 | ▶ | $file = substr($file, 1) if $file =~ /^@/; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 258 | 7 | ▶ | return "\t.sim \"log lxt $file\"\n" if $file =~ /\.lxt/i; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 259 | 0 | return "\t.sim \"log on $file\"\n"; | |||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||
| 262 | sub log { | ||||||||||||||||||||||||||||||||||||
| 263 | 20 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
log: called CC=8 SCAR=21.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 264 | 20 | my $code = ''; | |||||||||||||||||||||||||||||||||||
| 265 | 20 | foreach my $port (@_) { | |||||||||||||||||||||||||||||||||||
| 266 | 29 | ▶ | if ($port =~ /US?ART/) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 267 | 3 | ▶ | next unless $self->pic->doesrole('USART'); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 268 | 3 | my $ipin = $self->pic->usart_pins->{async_in}; | |||||||||||||||||||||||||||||||||||
| 269 | 3 | my $opin = $self->pic->usart_pins->{async_out}; | |||||||||||||||||||||||||||||||||||
| 270 | 3 | ▶ | if (defined $ipin and defined $opin) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $ipin and defined $opin
MC/DC0%0/2
defined $ipin and defined $opin
defined $ipin
defined $opin
Truth table33%1/3
A and B
A= defined $ipinB= defined $opin
| |||||||||||||||||||||||||||||||||||||
| 271 | 3 | my $ireg = $self->_get_simreg($ipin); | |||||||||||||||||||||||||||||||||||
| 272 | 3 | my $oreg = $self->_get_simreg($opin); | |||||||||||||||||||||||||||||||||||
| 273 | 3 | $code .= $self->log($ipin); | |||||||||||||||||||||||||||||||||||
| 274 | 3 | ▶ | $code .= $self->log($opin) if $ireg ne $oreg; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||
| 276 | } else { | ||||||||||||||||||||||||||||||||||||
| 277 | 26 | my $reg = $self->_get_simreg($port); | |||||||||||||||||||||||||||||||||||
| 278 | 26 | ▶ | next unless $reg; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 279 | 26 | $code .= << "..."; | |||||||||||||||||||||||||||||||||||
| 280 | \t.sim "log r $reg" | ||||||||||||||||||||||||||||||||||||
| 281 | \t.sim "log w $reg" | ||||||||||||||||||||||||||||||||||||
| 282 | ... | ||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||
| 285 | 20 | return $code; | |||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||
| 288 | sub _set_scope { | ||||||||||||||||||||||||||||||||||||
| 289 | 33 | ▶ | my ($self, $port) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
_set_scope: called CC=8 SCAR=21.2
| |||||||||||||||||||||||||||||||||||||
| 290 | 33 | my $simport = $self->_get_simport($port); | |||||||||||||||||||||||||||||||||||
| 291 | 33 | my $chnl = $self->scope_channels; | |||||||||||||||||||||||||||||||||||
| 292 | 33 | ▶ | carp "Maximum of 8 channels can be used in the scope\n" if $chnl > 7; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 293 | 33 | ▶ | return '' if $chnl > 7; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 294 | 33 | ▶ | if (lc($simport) eq lc($port)) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 295 | 1 | my @code = (); | |||||||||||||||||||||||||||||||||||
| 296 | 1 | for (0 .. 7) { | |||||||||||||||||||||||||||||||||||
| 297 | 8 | $simport = $self->_get_simport($port, $_); | |||||||||||||||||||||||||||||||||||
| 298 | 8 | ▶ | if ($self->scope_channels < 8) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 299 | 8 | $chnl = $self->scope_channels; | |||||||||||||||||||||||||||||||||||
| 300 | 8 | push @code, "\t.sim \"scope.ch$chnl = \\\"$simport\\\"\""; | |||||||||||||||||||||||||||||||||||
| 301 | 8 | $self->scope_channels($chnl + 1); | |||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||
| 303 | 8 | ▶ | carp "Maximum of 8 channels can be used in the scope\n" if $chnl > 7; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 304 | 8 | ▶ | last if $chnl > 7; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||
| 306 | 1 | return join("\n", @code); | |||||||||||||||||||||||||||||||||||
| 307 | } else { | ||||||||||||||||||||||||||||||||||||
| 308 | 32 | $self->scope_channels($chnl + 1); | |||||||||||||||||||||||||||||||||||
| 309 | 32 | return << "..."; | |||||||||||||||||||||||||||||||||||
| 310 | \t.sim "scope.ch$chnl = \\"$simport\\"" | ||||||||||||||||||||||||||||||||||||
| 311 | ... | ||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||
| 315 | sub scope { | ||||||||||||||||||||||||||||||||||||
| 316 | 17 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
scope: called CC=6 SCAR=18.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 317 | 17 | my $code = ''; | |||||||||||||||||||||||||||||||||||
| 318 | 17 | foreach my $port (@_) { | |||||||||||||||||||||||||||||||||||
| 319 | 30 | ▶ | if ($port =~ /US?ART/) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 320 | 3 | ▶ | next unless $self->pic->doesrole('USART'); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 321 | 3 | my $ipin = $self->pic->usart_pins->{async_in}; | |||||||||||||||||||||||||||||||||||
| 322 | 3 | my $opin = $self->pic->usart_pins->{async_out}; | |||||||||||||||||||||||||||||||||||
| 323 | 3 | ▶ | $code .= $self->_set_scope($ipin) if defined $opin; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 324 | 3 | ▶ | $code .= $self->_set_scope($opin) if defined $opin; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 325 | } else { | ||||||||||||||||||||||||||||||||||||
| 326 | 27 | $code .= $self->_set_scope($port); | |||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||
| 329 | 17 | return $code; | |||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||
| 332 | ### have to change the operator back to the form acceptable by gpsim | ||||||||||||||||||||||||||||||||||||
| 333 | sub _get_operator { | ||||||||||||||||||||||||||||||||||||
| 334 | 27 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
_get_operator: called CC=7 SCAR=35.0
| |||||||||||||||||||||||||||||||||||||
| 335 | 27 | my $op = shift; | |||||||||||||||||||||||||||||||||||
| 336 | 27 | ▶ | return '==' if $op eq 'EQ'; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | return '!=' if $op eq 'NE'; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | return '>' if $op eq 'GT'; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | return '>=' if $op eq 'GE'; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | return '<' if $op eq 'LT'; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | return '<=' if $op eq 'LE'; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 342 | 0 | return undef; | |||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||
| 345 | sub sim_assert { | ||||||||||||||||||||||||||||||||||||
| 346 | 29 | ▶ | my ($self, $condition, $msg) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
sim_assert: called CC=28 SCAR=46.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 347 | 29 | my $assert_msg; | |||||||||||||||||||||||||||||||||||
| 348 | 29 | ▶ | if ($condition =~ /@@/) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 349 | 27 | my @args = split /@@/, $condition; | |||||||||||||||||||||||||||||||||||
| 350 | 27 | my $literal = qr/^\d+$/; | |||||||||||||||||||||||||||||||||||
| 351 | 27 | ▶ | if (scalar @args == 3) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 352 | 27 | my $lhs = shift @args; | |||||||||||||||||||||||||||||||||||
| 353 | 27 | my $op = shift @args; | |||||||||||||||||||||||||||||||||||
| 354 | 27 | my $rhs = shift @args; | |||||||||||||||||||||||||||||||||||
| 355 | 27 | my $op2 = $self->_get_operator($op); | |||||||||||||||||||||||||||||||||||
| 356 | 27 | ▶ | if ($lhs !~ $literal) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 357 | 27 | my ($port, $pin) = $self->_get_portpin($lhs); | |||||||||||||||||||||||||||||||||||
| 358 | 27 | ▶ | if (defined $pin) { | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 359 | 1 | my $pval = sprintf "0x%02X", (1 << $pin); | |||||||||||||||||||||||||||||||||||
| 360 | 1 | $lhs = lc "($port & $pval)"; | |||||||||||||||||||||||||||||||||||
| 361 | } elsif (defined $port) { | ||||||||||||||||||||||||||||||||||||
| 362 | 0 | $lhs = lc $port; | |||||||||||||||||||||||||||||||||||
| 363 | } else { | ||||||||||||||||||||||||||||||||||||
| 364 | # may be a variable | ||||||||||||||||||||||||||||||||||||
| 365 | 26 | $lhs = uc $lhs; | |||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||
| 367 | } else { | ||||||||||||||||||||||||||||||||||||
| 368 | 0 | $lhs = sprintf "0x%02X", $lhs; | |||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||
| 370 | 27 | ▶ | if ($rhs !~ $literal) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 371 | 0 | my ($port, $pin) = $self->_get_portpin($lhs); | |||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | if (defined $pin) { | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 373 | 0 | my $pval = sprintf "0x%02X", (1 << $pin); | |||||||||||||||||||||||||||||||||||
| 374 | 0 | $rhs = lc "($port & $pval)"; | |||||||||||||||||||||||||||||||||||
| 375 | } elsif (defined $port) { | ||||||||||||||||||||||||||||||||||||
| 376 | 0 | $rhs = lc $port; | |||||||||||||||||||||||||||||||||||
| 377 | } else { | ||||||||||||||||||||||||||||||||||||
| 378 | # may be a variable | ||||||||||||||||||||||||||||||||||||
| 379 | 0 | $rhs = uc $rhs; | |||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||
| 381 | } else { | ||||||||||||||||||||||||||||||||||||
| 382 | 27 | $rhs = sprintf "0x%02X", $rhs; | |||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||
| 384 | 27 | $condition = "$lhs $op2 $rhs"; | |||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||
| 386 | #TODO: handle more complex expressions | ||||||||||||||||||||||||||||||||||||
| 387 | 27 | ▶ | if (defined $msg and ref $msg eq 'HASH') { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $msg and ref $msg eq "HASH"
MC/DC50%1/2
defined $msg and ref $msg eq "HASH"
defined $msg
ref $msg eq "HASH"
Truth table66%2/3
A and B
A= defined $msgB= ref $msg eq "HASH"
| |||||||||||||||||||||||||||||||||||||
| 388 | 26 | $msg = $msg->{string}; | |||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||
| 390 | 27 | ▶ | $msg = "$condition is false" unless $msg; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 391 | 27 | ▶ | $msg = substr($msg, 1) if $msg =~ /^@/; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 392 | 27 | ▶ | $condition = substr($condition, 1) if $condition =~ /^@/; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 393 | 27 | $assert_msg = qq{$condition, \\\"$msg\\\"}; | |||||||||||||||||||||||||||||||||||
| 394 | } else { | ||||||||||||||||||||||||||||||||||||
| 395 | 2 | ▶ | if (defined $msg and ref $msg eq 'HASH') { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $msg and ref $msg eq "HASH"
MC/DC0%0/2
defined $msg and ref $msg eq "HASH"
defined $msg
ref $msg eq "HASH"
Truth table33%1/3
A and B
A= defined $msgB= ref $msg eq "HASH"
| |||||||||||||||||||||||||||||||||||||
| 396 | 0 | $msg = $msg->{string}; | |||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||
| 398 | 2 | ▶ | if (defined $condition and ref $condition eq 'HASH') { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $condition and ref $condition eq "HASH"
MC/DC0%0/2
defined $condition and ref $condition eq "HASH"
defined $condition
ref $condition eq "HASH"
Truth table33%1/3
A and B
A= defined $conditionB= ref $condition eq "HASH"
| |||||||||||||||||||||||||||||||||||||
| 399 | 2 | $condition = $condition->{string}; | |||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||
| 401 | 2 | ▶ | if (defined $condition and defined $msg) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%1/3
defined $condition and defined $msg
MC/DC0%0/2
defined $condition and defined $msg
defined $condition
defined $msg
Truth table33%1/3
A and B
A= defined $conditionB= defined $msg
| |||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | $msg = substr($msg, 1) if $msg =~ /^@/; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | $condition = substr($condition, 1) if $condition =~ /^@/; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 404 | 0 | $assert_msg = qq{$condition, \\\"$msg\\\"}; | |||||||||||||||||||||||||||||||||||
| 405 | ▶ | } elsif (defined $condition and not defined $msg) { | |||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $condition and not defined $msg
MC/DC0%0/2
defined $condition and not defined $msg
defined $condition
not defined $msg
Truth table33%1/3
A and not(B)
A= defined $conditionB= not defined $msg
| |||||||||||||||||||||||||||||||||||||
| 406 | 2 | ▶ | $condition = substr($condition, 1) if $condition =~ /^@/; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 407 | 2 | $assert_msg = qq{\\\"$condition\\\"}; | |||||||||||||||||||||||||||||||||||
| 408 | ▶ | } elsif (defined $msg and not defined $condition) { | |||||||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $msg and not defined $condition
MC/DC0%0/2
defined $msg and not defined $condition
defined $msg
not defined $condition
Truth table0%0/3
A and not(B)
A= defined $msgB= not defined $condition
| |||||||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | $msg = substr($msg, 1) if $msg =~ /^@/; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 410 | 0 | $assert_msg = qq{\\\"$msg\\\"}; | |||||||||||||||||||||||||||||||||||
| 411 | } else { | ||||||||||||||||||||||||||||||||||||
| 412 | 0 | $assert_msg = qq{\\\"user requested an assert\\\"}; | |||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||
| 416 | return << "..." | ||||||||||||||||||||||||||||||||||||
| 417 | \t;; break if the condition evaluates to false | ||||||||||||||||||||||||||||||||||||
| 418 | \t.assert "$assert_msg" | ||||||||||||||||||||||||||||||||||||
| 419 | \tnop ;; needed for the assert | ||||||||||||||||||||||||||||||||||||
| 420 | ... | ||||||||||||||||||||||||||||||||||||
| 421 | 29 | } | |||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||
| 423 | sub stimulate { | ||||||||||||||||||||||||||||||||||||
| 424 | 9 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
stimulate: called CC=14 SCAR=26.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 425 | 9 | my $pin = shift; | |||||||||||||||||||||||||||||||||||
| 426 | 9 | my %hh = (); | |||||||||||||||||||||||||||||||||||
| 427 | 9 | foreach my $href (@_) { | |||||||||||||||||||||||||||||||||||
| 428 | 11 | %hh = (%hh, %$href); | |||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||
| 430 | 9 | my $period = ''; | |||||||||||||||||||||||||||||||||||
| 431 | 9 | ▶ | $period = $hh{EVERY} if (defined $hh{EVERY} and length $hh{EVERY}); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $hh{"EVERY"} and length $hh{"EVERY"}
MC/DC50%1/2
defined $hh{"EVERY"} and length $hh{"EVERY"}
defined $hh{"EVERY"}
length $hh{"EVERY"}
Truth table66%2/3
A and B
A= defined $hh{"EVERY"}B= length $hh{"EVERY"}
| |||||||||||||||||||||||||||||||||||||
| 432 | 9 | ▶ | $period = qq{\t.sim "period $period"} if (defined $period and length $period); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $period and length $period
MC/DC50%1/2
defined $period and length $period
defined $period
length $period
Truth table66%2/3
A and B
A= defined $periodB= length $period
| |||||||||||||||||||||||||||||||||||||
| 433 | 9 | my $wave = ''; | |||||||||||||||||||||||||||||||||||
| 434 | 9 | my $wave_type = 'digital'; | |||||||||||||||||||||||||||||||||||
| 435 | 9 | ▶ | if (exists $hh{WAVE} and ref $hh{WAVE} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $hh{"WAVE"} and ref $hh{"WAVE"} eq "ARRAY"
MC/DC0%0/2
exists $hh{"WAVE"} and ref $hh{"WAVE"} eq "ARRAY"
exists $hh{"WAVE"}
ref $hh{"WAVE"} eq "ARRAY"
Truth table33%1/3
A and B
A= exists $hh{"WAVE"}B= ref $hh{"WAVE"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||
| 436 | 9 | my $arr = $hh{WAVE}; | |||||||||||||||||||||||||||||||||||
| 437 | 9 | ▶ | $wave = "\t.sim \"{ " . join(',', @$arr) . " }\"" if scalar @$arr; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 438 | 9 | my $ad = 0; | |||||||||||||||||||||||||||||||||||
| 439 | 9 | foreach (@$arr) { | |||||||||||||||||||||||||||||||||||
| 440 | 66 | ▶ | $ad |= 1 unless /^\d+$/; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||
| 442 | 9 | ▶ | $wave_type = 'analog' if $ad; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||
| 444 | 9 | ▶ | my $start = $hh{START} || 0; | ||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$hh{'START'} || {sign => '+', value => ['0']}
MC/DC0%0/1
$hh{'START'} || {sign => '+', value => ['0']}
$hh{'START'}
Truth table50%1/2
A
A= $hh{'START'}
| |||||||||||||||||||||||||||||||||||||
| 445 | 9 | $start = qq{\t.sim "start_cycle $start"}; | |||||||||||||||||||||||||||||||||||
| 446 | 9 | ▶ | my $init = $hh{INITIAL} || 0; | ||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$hh{'INITIAL'} || {sign => '+', value => ['0']}
MC/DC0%0/1
$hh{'INITIAL'} || {sign => '+', value => ['0']}
$hh{'INITIAL'}
Truth table50%1/2
A
A= $hh{'INITIAL'}
| |||||||||||||||||||||||||||||||||||||
| 447 | 9 | $init = qq{\t.sim "initial_state $init"}; | |||||||||||||||||||||||||||||||||||
| 448 | 9 | my $num = $self->stimulus_count; | |||||||||||||||||||||||||||||||||||
| 449 | 9 | $self->stimulus_count($num + 1); | |||||||||||||||||||||||||||||||||||
| 450 | 9 | my $node = "stim$num$pin"; | |||||||||||||||||||||||||||||||||||
| 451 | 9 | my $simpin = $self->_get_simport($pin); | |||||||||||||||||||||||||||||||||||
| 452 | return << "..." | ||||||||||||||||||||||||||||||||||||
| 453 | \t.sim \"echo creating stimulus number $num\" | ||||||||||||||||||||||||||||||||||||
| 454 | \t.sim \"stimulus asynchronous_stimulus\" | ||||||||||||||||||||||||||||||||||||
| 455 | $init | ||||||||||||||||||||||||||||||||||||
| 456 | $start | ||||||||||||||||||||||||||||||||||||
| 457 | \t.sim \"$wave_type\" | ||||||||||||||||||||||||||||||||||||
| 458 | $period | ||||||||||||||||||||||||||||||||||||
| 459 | $wave | ||||||||||||||||||||||||||||||||||||
| 460 | \t.sim \"name stim$num\" | ||||||||||||||||||||||||||||||||||||
| 461 | \t.sim \"end\" | ||||||||||||||||||||||||||||||||||||
| 462 | \t.sim \"echo done creating stimulus number $num\" | ||||||||||||||||||||||||||||||||||||
| 463 | \t.sim \"node $node\" | ||||||||||||||||||||||||||||||||||||
| 464 | \t.sim \"attach $node stim$num $simpin\" | ||||||||||||||||||||||||||||||||||||
| 465 | ... | ||||||||||||||||||||||||||||||||||||
| 466 | 9 | } | |||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||
| 468 | sub get_autorun_code { | ||||||||||||||||||||||||||||||||||||
| 469 | 12 | ▶ | return qq{\t.sim "run"\n}; | ||||||||||||||||||||||||||||||||||
|
Subroutine
get_autorun_code: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||
| 472 | sub autorun { | ||||||||||||||||||||||||||||||||||||
| 473 | 12 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
autorun: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 474 | 12 | $self->should_autorun(1); | |||||||||||||||||||||||||||||||||||
| 475 | 12 | return "\t;;;; will autorun on start\n"; | |||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||
| 478 | sub stopwatch { | ||||||||||||||||||||||||||||||||||||
| 479 | 1 | ▶ | my ($self, $rollover) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
stopwatch: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 480 | 1 | my $code = qq{\t.sim "stopwatch.enable = true"\n}; | |||||||||||||||||||||||||||||||||||
| 481 | 1 | ▶ | $code .= qq{\t.sim "stopwatch.rollover = $rollover"\n} if defined $rollover; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 482 | 1 | ▶ | $code .= qq{\t.sim "break stopwatch"\n} if defined $rollover; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 483 | 1 | return $code; | |||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||
| 486 | sub attach { | ||||||||||||||||||||||||||||||||||||
| 487 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
attach: called CC=14 SCAR=28.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 488 | 3 | ▶ | return unless @_; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 489 | 3 | my $pin = shift; | |||||||||||||||||||||||||||||||||||
| 490 | 3 | my $code = ''; | |||||||||||||||||||||||||||||||||||
| 491 | 3 | ▶ | if ($pin =~ /US?ART/) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 492 | # TX - connect to UART | ||||||||||||||||||||||||||||||||||||
| 493 | # RX - connect to UART but also send it data | ||||||||||||||||||||||||||||||||||||
| 494 | 3 | ▶ | unless ($self->pic->doesrole('USART')) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 495 | 0 | carp "PIC ", $self->pic->type, " does not do USART"; | |||||||||||||||||||||||||||||||||||
| 496 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||
| 498 | 3 | ▶ | my $baudrate = shift if @_; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 499 | 3 | ▶ | my $loopback = shift if @_; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 500 | 3 | ▶ | my $key = ($pin =~ /^UART/) ? 'uart' : 'usart'; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 501 | $baudrate = $self->pic->code_config->{$key}->{baud} unless defined | ||||||||||||||||||||||||||||||||||||
| 502 | 3 | ▶ | $baudrate; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 503 | 3 | ▶ | $baudrate = 9600 unless defined $baudrate; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 504 | 3 | my $id = $self->node_count; | |||||||||||||||||||||||||||||||||||
| 505 | 3 | $self->node_count($id + 1); | |||||||||||||||||||||||||||||||||||
| 506 | 3 | my $ipin = $self->pic->usart_pins->{async_in}; | |||||||||||||||||||||||||||||||||||
| 507 | 3 | my $rxport = $self->_get_simport($ipin); | |||||||||||||||||||||||||||||||||||
| 508 | 3 | my $opin = $self->pic->usart_pins->{async_out}; | |||||||||||||||||||||||||||||||||||
| 509 | 3 | my $txport = $self->_get_simport($opin); | |||||||||||||||||||||||||||||||||||
| 510 | 3 | ▶ | return unless (exists $self->pic->pins->{$ipin} and exists $self->pic->pins->{$opin}); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $self->pic->pins->{$ipin} and exists $self->pic->pins->{$opin}
MC/DC0%0/2
exists $self->pic->pins->{$ipin} and exists $self->pic->pins->{$opin}
exists $self->pic->pins->{$ipin}
exists $self->pic->pins->{$opin}
Truth table33%1/3
A and B
A= exists $self->pic->pins->{$ipin}B= exists $self->pic->pins->{$opin}
| |||||||||||||||||||||||||||||||||||||
| 511 | 3 | $code .= qq{\t.sim "module load usart U$id"\n}; | |||||||||||||||||||||||||||||||||||
| 512 | 3 | $code .= qq{\t.sim "node TX_U$id"\n}; | |||||||||||||||||||||||||||||||||||
| 513 | 3 | $code .= qq{\t.sim "node RX_U$id"\n}; | |||||||||||||||||||||||||||||||||||
| 514 | 3 | $code .= qq{\t.sim "attach TX_U$id $txport U$id.RXPIN"\n}; | |||||||||||||||||||||||||||||||||||
| 515 | 3 | $code .= qq{\t.sim "attach RX_U$id $rxport U$id.TXPIN"\n}; | |||||||||||||||||||||||||||||||||||
| 516 | 3 | $code .= qq{\t.sim "U$id.txbaud = $baudrate"\n}; | |||||||||||||||||||||||||||||||||||
| 517 | 3 | $code .= qq{\t.sim "U$id.rxbaud = $baudrate"\n}; | |||||||||||||||||||||||||||||||||||
| 518 | 3 | my $x = 500; | |||||||||||||||||||||||||||||||||||
| 519 | 3 | my $y = 50 + 50 * $id; | |||||||||||||||||||||||||||||||||||
| 520 | 3 | $code .= qq{\t.sim "U$id.xpos = $x"\n}; | |||||||||||||||||||||||||||||||||||
| 521 | 3 | $code .= qq{\t.sim "U$id.ypos = $y"\n}; | |||||||||||||||||||||||||||||||||||
| 522 | 3 | ▶ | if (defined $loopback) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 523 | 2 | ▶ | if (ref $loopback eq 'HASH' and $loopback->{string} =~ /loopback/i) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $loopback eq "HASH" and $loopback->{"string"} =~ /loopback/i
MC/DC0%0/2
ref $loopback eq "HASH" and $loopback->{"string"} =~ /loopback/i
ref $loopback eq "HASH"
$loopback->{"string"} =~ /loopback/i
Truth table33%1/3
A and B
A= ref $loopback eq "HASH"B= $loopback->{"string"} =~ /loopback/i
| |||||||||||||||||||||||||||||||||||||
| 524 | 2 | $code .= qq{\t.sim "U$id.loop = true"\n}; | |||||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||
| 528 | 3 | return $code; | |||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||
| 531 | 34 | 1; | |||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||
| 533 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||
| 535 | =head1 NAME | ||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||
| 537 | VIC::Receiver | ||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||
| 539 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||
| 541 | The Pegex::Receiver class for handling the grammar. | ||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||
| 543 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||
| 545 | INTERNAL CLASS. | ||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||
| 547 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||
| 549 | Vikas N Kumar <vikas@cpan.org> | ||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||
| 551 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||
| 553 | Copyright (c) 2014. Vikas N Kumar | ||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||
| 555 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||
| 556 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||
| 558 | See http://www.perl.com/perl/misc/Artistic.html | ||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||
| 560 | =cut | ||||||||||||||||||||||||||||||||||||