| 1 | package VIC::PIC::Functions::GPIO; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 31 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 31 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 31 | ▶ | use bigint; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 31 | our $VERSION = '0.29'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 31 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 31 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 31 | ▶ | use POSIX (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 31 | ▶ | use Scalar::Util qw(looks_like_number); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 31 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | sub get_output_pin { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 37 | ▶ | my ($self, $ipin) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_output_pin: called CC=5 SCAR=16.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 37 | ▶ | return $ipin if exists $self->output_pins->{$ipin}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # find the correct GPIO pin then matching this pin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 4 | my $pin_no = $self->pins->{$ipin}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | my $allpins = $self->pins->{$pin_no}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 4 | ▶ | unless (ref $allpins eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | carp "Invalid data for pin $pin_no"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 4 | my $opin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 4 | foreach my $iopin (@$allpins) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 4 | ▶ | next unless exists $self->output_pins->{$iopin}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # we have now found the correct iopin for the analog_pin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 4 | $opin = $iopin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 4 | return $opin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | sub get_input_pin { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 121 | ▶ | my ($self, $ipin) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_input_pin: called CC=5 SCAR=16.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 121 | ▶ | return $ipin if exists $self->input_pins->{$ipin}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # find the correct GPIO pin then matching this pin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 37 | my $pin_no = $self->pins->{$ipin}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 37 | my $allpins = $self->pins->{$pin_no}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 37 | ▶ | unless (ref $allpins eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | carp "Invalid data for pin $pin_no"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 37 | my $opin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 37 | foreach my $iopin (@$allpins) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 37 | ▶ | next unless exists $self->input_pins->{$iopin}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # we have now found the correct iopin for the analog_pin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 37 | $opin = $iopin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 37 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 37 | return $opin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | sub _gpio_select { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 37 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_gpio_select: called CC=46 SCAR=40.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 37 | my ($io, $ad, $outp) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 37 | ▶ | return unless $self->doesroles(qw(Chip GPIO)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 37 | ▶ | return unless defined $outp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 37 | ▶ | $io = 0 if $io =~ /output/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 37 | ▶ | $io = 1 if $io =~ /input/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 37 | ▶ | $ad = 0 if $ad =~ /digital/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 37 | ▶ | $ad = 1 if $ad =~ /analog/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 37 | ▶ | return unless (($io == 0 or $io == 1) and ($ad == 0 or $ad == 1)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
$io == bless( {"sign" => "+","value" => bless( [0], 'Math::BigInt::Calc' )}, 'Math::BigInt' ) || $io == bless( {"sign" => "+","value" => bless( [1], 'Math::BigInt::Calc' )}, 'Math::BigInt' ) and $ad == bless( {"sign" => "+","value" => bless( [0], 'Math::BigInt::Calc' )}, 'Math::BigInt' ) || $ad == bless( {"sign" => "+","value" => bless( [1], 'Math::BigInt::Calc' )}, 'Math::BigInt' )
$io == bless( {"sign" => "+","value" => bless( [0], 'Math::BigInt::Calc' )}, 'Math::BigInt' ) or $io == bless( {"sign" => "+","value" => bless( [1], 'Math::BigInt::Calc' )}, 'Math::BigInt' )
$ad == bless( {"sign" => "+","value" => bless( [0], 'Math::BigInt::Calc' )}, 'Math::BigInt' ) or $ad == bless( {"sign" => "+","value" => bless( [1], 'Math::BigInt::Calc' )}, 'Math::BigInt' )
MC/DC0%0/4
$io == bless( {"sign" => "+","value" => bless( [0], 'Math::BigInt::Calc' )}, 'Math::BigInt' ) || $io == bless( {"sign" => "+","value" => bless( [1], 'Math::BigInt::Calc' )}, 'Math::BigInt' ) and $ad == bless( {"sign" => "+","value" => bless( [0], 'Math::BigInt::Calc' )}, 'Math::BigInt' ) || $ad == bless( {"sign" => "+","value" => bless( [1], 'Math::BigInt::Calc' )}, 'Math::BigInt' )
$io == bless( {"sign" => "+","value" => bless( [0], 'Math::BigInt::Calc' )}, 'Math::BigInt' )
$io == bless( {"sign" => "+","value" => bless( [1], 'Math::BigInt::Calc' )}, 'Math::BigInt' )
$ad == bless( {"sign" => "+","value" => bless( [0], 'Math::BigInt::Calc' )}, 'Math::BigInt' )
$ad == bless( {"sign" => "+","value" => bless( [1], 'Math::BigInt::Calc' )}, 'Math::BigInt' )
Truth table14%1/7
A or B and C or D
A= $io == bless( {"sign" => "+","value" => bless( [0], 'Math::BigInt::Calc' )}, 'Math::BigInt' )B= $io == bless( {"sign" => "+","value" => bless( [1], 'Math::BigInt::Calc' )}, 'Math::BigInt' )C= $ad == bless( {"sign" => "+","value" => bless( [0], 'Math::BigInt::Calc' )}, 'Math::BigInt' )D= $ad == bless( {"sign" => "+","value" => bless( [1], 'Math::BigInt::Calc' )}, 'Math::BigInt' )
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | #TODO: check if banksel works for all chips | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | #if not then allow for a way to map instruction codes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | #to something else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # is this a register | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 37 | my ($trisp_code, $port_code, $an_code) = ('', '', ''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 37 | ▶ | if (exists $self->io_ports->{$outp} and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
exists $self->io_ports->{$outp} and exists $self->registers->{$outp}
MC/DC50%1/2
exists $self->io_ports->{$outp} and exists $self->registers->{$outp}
exists $self->io_ports->{$outp}
exists $self->registers->{$outp}
Truth table66%2/3
A and B
A= exists $self->io_ports->{$outp}B= exists $self->registers->{$outp}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | exists $self->registers->{$outp}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 13 | my $trisp = $self->io_ports->{$outp}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 13 | ▶ | my $flags = ($ad == 0) ? 0xFF : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 13 | ▶ | my $flagsH = ($ad == 0) ? 0xFF : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 13 | ▶ | if (exists $self->registers->{ANSEL}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # get the pins that belong to the register | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 13 | my @portpins = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 13 | ▶ | if ($io == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 12 | foreach (keys %{$self->output_pins}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 204 | ▶ | push @portpins, $_ if $self->output_pins->{$_}->[0] eq $outp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | foreach (keys %{$self->input_pins}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 18 | ▶ | push @portpins, $_ if $self->input_pins->{$_}->[0] eq $outp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 13 | foreach (@portpins) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 97 | my $pin_no = $self->pins->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 97 | ▶ | next unless defined $pin_no; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 97 | my $allpins = $self->pins->{$pin_no}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 97 | ▶ | next unless ref $allpins eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 97 | foreach my $anpin (@$allpins) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 324 | ▶ | next unless exists $self->analog_pins->{$anpin}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 72 | my ($pno, $pbit) = @{$self->analog_pins->{$anpin}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 72 | ▶ | $flags ^= 1 << $pbit if $pbit < 8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 72 | ▶ | $flagsH ^= 1 << ($pbit - 8) if $pbit >= 8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 13 | ▶ | my $iorandwf = ($ad == 0) ? 'andwf' : 'iorwf'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 13 | ▶ | if ($flags != 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 13 | $flags = sprintf "0x%02X", $flags; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 13 | $an_code .= "\tbanksel ANSEL\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 13 | $an_code .= "\tmovlw $flags\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 13 | $an_code .= "\t$iorandwf ANSEL, F\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 13 | ▶ | if (exists $self->registers->{ANSELH}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 13 | ▶ | if ($flagsH != 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 13 | $flagsH = sprintf "0x%02X", $flagsH; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 13 | $an_code .= "\tbanksel ANSELH\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 13 | $an_code .= "\tmovlw $flagsH\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 13 | $an_code .= "\t$iorandwf ANSELH, F\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 13 | ▶ | if ($io == 0) { # output | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 12 | $trisp_code = "\tbanksel $trisp\n\tclrf $trisp"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 12 | $port_code = "\tbanksel $outp\n\tclrf $outp"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } else { # input | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | $trisp_code = "\tbanksel $trisp\n\tmovlw 0xFF\n\tmovwf $trisp"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | $port_code = "\tbanksel $outp"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } elsif (exists $self->pins->{$outp}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 24 | ▶ | my $iopin = ($io == 0) ? $self->get_output_pin($outp) : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | $self->get_input_pin($outp); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 24 | ▶ | unless (defined $iopin) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | my $iostr = ($io == 0) ? 'output' : 'input'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | carp "Cannot find $outp in the list of registers or $iostr pins supporting GPIO for the chip " . $self->type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | my ($port, $trisp, $pinbit) = ($io == 0) ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 14 | @{$self->output_pins->{$iopin}} : | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 24 | ▶ | @{$self->input_pins->{$iopin}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 24 | ▶ | if (exists $self->registers->{ANSEL}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 24 | my $pin_no = $self->pins->{$iopin}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 24 | my $allpins = $self->pins->{$pin_no}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 24 | ▶ | unless (ref $allpins eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | carp "Invalid data for pin $pin_no"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 24 | foreach my $anpin (@$allpins) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 52 | ▶ | next unless exists $self->analog_pins->{$anpin}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 20 | my ($pno, $pbit) = @{$self->analog_pins->{$anpin}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 20 | my $ansel = 'ANSEL'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 20 | ▶ | if (exists $self->registers->{ANSELH}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 20 | ▶ | $ansel = ($pbit >= 8) ? 'ANSELH' : 'ANSEL'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | ##TODO: make sure that ANS$pbit exists for all header files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 20 | ▶ | my $bcfbsf = ($ad == 0) ? 'bcf' : 'bsf'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 20 | $an_code = "\tbanksel $ansel\n\t$bcfbsf $ansel, ANS$pbit"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 20 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 24 | ▶ | if ($io == 0) { # output | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 14 | $trisp_code = "\tbanksel $trisp\n\tbcf $trisp, $trisp$pinbit"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 14 | $port_code = "\tbanksel $port\n\tbcf $port, $pinbit"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } else { # input | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 10 | $trisp_code = "\tbanksel $trisp\n\tbsf $trisp, $trisp$pinbit"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 10 | $port_code = "\tbanksel $port"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | carp "Cannot find $outp in the list of registers or pins supporting GPIO"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 37 | return << "..."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | $trisp_code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | $an_code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | $port_code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | sub digital_output { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 26 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
digital_output: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 26 | return $self->_gpio_select(output => 'digital', @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | sub digital_input { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 8 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
digital_input: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 8 | return $self->_gpio_select(input => 'digital', @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | sub analog_input { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
analog_input: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 3 | return $self->_gpio_select(input => 'analog', @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | sub setup { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setup: called CC=4 SCAR=16.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 3 | my ($outp) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 3 | ▶ | if ($outp =~ /US?ART/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 3 | ▶ | if ($self->doesrole('USART') and exists $self->usart_pins->{$outp}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->doesrole("USART") and exists $self->usart_pins->{$outp}
MC/DC0%0/2
$self->doesrole("USART") and exists $self->usart_pins->{$outp}
$self->doesrole("USART")
exists $self->usart_pins->{$outp}
Truth table33%1/3
A and B
A= $self->doesrole("USART")B= exists $self->usart_pins->{$outp}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 3 | return $self->usart_setup(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | carp "The 'setup' function is not valid for $outp. Use something else."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | sub write { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 46 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=19 SCAR=36.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 46 | my ($outp, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 46 | ▶ | return unless $self->doesroles(qw(CodeGen Operations Chip GPIO)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 46 | ▶ | return unless defined $outp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 46 | ▶ | if (exists $self->io_ports->{$outp} and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
exists $self->io_ports->{$outp} and exists $self->registers->{$outp}
MC/DC50%1/2
exists $self->io_ports->{$outp} and exists $self->registers->{$outp}
exists $self->io_ports->{$outp}
exists $self->registers->{$outp}
Truth table66%2/3
A and B
A= exists $self->io_ports->{$outp}B= exists $self->registers->{$outp}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | exists $self->registers->{$outp}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 20 | my $port = $self->io_ports->{$outp}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 20 | ▶ | unless (defined $val) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | return << "..."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | \tclrf $outp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | \tcomf $outp, 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 20 | ▶ | if ($self->validate($val)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # ok we want to write the value of a pin to a port | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # that doesn't seem right so let's provide a warning | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | if ($self->pins->{$val}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | carp "$val is a pin and you're trying to write a pin to a port" . | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | " $outp. You can write a pin to a pin or a port to a port only.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # this handles the variable to port assigning | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 20 | return $self->op_assign($outp, $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } elsif (exists $self->pins->{$outp}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 19 | my $iopin = $self->get_output_pin($outp); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 19 | ▶ | unless (defined $iopin) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | carp "Cannot find $outp in the list of VALID ports, register or pins to write to"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 19 | my ($port, $trisp, $pinbit) = @{$self->output_pins->{$iopin}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 19 | ▶ | if ($val =~ /^\d+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 10 | ▶ | return "\tbanksel $port\n\tbcf $port, $pinbit\n" if "$val" eq '0'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 7 | ▶ | return "\tbanksel $port\n\tbsf $port, $pinbit\n" if "$val" eq '1'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | carp "$val cannot be applied to a pin $outp\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } elsif (exists $self->pins->{$val}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | # ok we want to short two pins, and this is not bit-banging | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # although seems like it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 4 | my $vpin = $self->get_output_pin($val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 4 | ▶ | if ($vpin) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 4 | my ($vport, $vtris, $vpinbit) = @{$self->output_pins->{$vpin}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 4 | return << "..."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | \tbtfss $vport, $vpin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | \tbcf $port, $outp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | \tbtfsc $vport, $vpin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | \tbsf $port, $outp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | carp "$val is a port or unknown pin and cannot be written to a pin $outp. ". | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | "Only a pin can be written to a pin.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } elsif ($self->is_variable($val)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 4 | $val = uc $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 4 | return << "..."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | ;;;; assigning $val to a pin => using the last bit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | \tbtfss $val, 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | \tbcf $port, $outp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | \tbtfsc $val, 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | \tbsf $port, $outp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 1 | carp "$val is a port or unknown pin and cannot be written to a pin $outp. ". | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | "Only a pin can be written to a pin.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | return $self->op_assign($port, $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } elsif (exists $self->registers->{$outp}) { # write a value to a register | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my $code = "\tbanksel $outp\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | $code .= $self->op_assign($outp, $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | return $code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 7 | ▶ | if ($self->doesrole('USART') and exists $self->usart_pins->{$outp}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->doesrole("USART") and exists $self->usart_pins->{$outp}
MC/DC0%0/2
$self->doesrole("USART") and exists $self->usart_pins->{$outp}
$self->doesrole("USART")
exists $self->usart_pins->{$outp}
Truth table33%1/3
A and B
A= $self->doesrole("USART")B= exists $self->usart_pins->{$outp}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 7 | return $self->usart_write(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | carp "Cannot find $outp in the list of ports, register or pins to write to"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | sub _macro_read_var { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 6 | ▶ | my $v = $_[1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_macro_read_var: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 6 | $v = uc $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 6 | return << "..."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | ;;;;;;; $v VARIABLES ;;;;;; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | $v\_UDATA udata | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | $v res 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | sub read { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=25 SCAR=35.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 6 | my $inp = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 6 | my $var = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 6 | my %action = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 6 | ▶ | if (scalar(@_) == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 1 | $var = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 5 | %action = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 6 | ▶ | return unless $self->doesroles(qw(CodeGen Chip GPIO)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 6 | my ($code, $funcs, $macros, $tables) = ('', {}, {}, []); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 6 | ▶ | if (defined $var) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 1 | ▶ | if (looks_like_number($var) or ref $var eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
&looks_like_number($var) or ref $var eq "HASH"
MC/DC0%0/2
&looks_like_number($var) or ref $var eq "HASH"
&looks_like_number($var)
ref $var eq "HASH"
Truth table33%1/3
A or B
A= &looks_like_number($var)B= ref $var eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | carp "Cannot read from $inp into a constant $var"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 1 | $var = uc $var; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | ## we need only 1 variable here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 5 | ▶ | if (defined $action{PARAM}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 5 | $var = $action{PARAM} . '0'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | carp "Implementation errors implementing the Action block"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 5 | $var = uc $var; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 5 | $macros->{lc("m_read_$var")} = $self->_macro_read_var($var); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 5 | ▶ | return unless (defined $action{ACTION} or defined $action{ISR}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $action{"ACTION"} or defined $action{"ISR"}
MC/DC0%0/2
defined $action{"ACTION"} or defined $action{"ISR"}
defined $action{"ACTION"}
defined $action{"ISR"}
Truth table66%2/3
A or B
A= defined $action{"ACTION"}B= defined $action{"ISR"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 5 | ▶ | return unless defined $action{END}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 6 | my $bits = $self->address_bits($var); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 6 | my ($port, $portbit); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 6 | ▶ | if (exists $self->io_ports->{$inp} and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
exists $self->io_ports->{$inp} and exists $self->registers->{$inp}
MC/DC50%1/2
exists $self->io_ports->{$inp} and exists $self->registers->{$inp}
exists $self->io_ports->{$inp}
exists $self->registers->{$inp}
Truth table66%2/3
A and B
A= exists $self->io_ports->{$inp}B= exists $self->registers->{$inp}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | exists $self->registers->{$inp}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | # this is a port like PORT[A-Z] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | # we may end up reading from all pins on a port | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 1 | $port = $inp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 1 | $code = <<"..."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | ;;; instant reading from $port into $var | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | \tbanksel $port | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | \tmovf $port, W | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | \tbanksel $var | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | \tmovwf $var | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } elsif (exists $self->pins->{$inp}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 4 | my $ipin = $self->get_input_pin($inp); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 4 | ▶ | unless (defined $ipin) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | carp "Cannot find $inp in the list of GPIO ports or pins"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 4 | my $tris; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 4 | ($port, $tris, $portbit) = @{$self->input_pins->{$inp}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 4 | $code = <<"...."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | ;;; instant reading from $inp into $var | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | \tclrw | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | \tbanksel $port | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | \tbtfsc $port, $portbit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | \taddlw 0x01 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | \tbanksel $var | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | \tmovwf $var | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | .... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 1 | ▶ | if ($self->doesrole('USART') and exists $self->usart_pins->{$inp}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->doesrole("USART") and exists $self->usart_pins->{$inp}
MC/DC0%0/2
$self->doesrole("USART") and exists $self->usart_pins->{$inp}
$self->doesrole("USART")
exists $self->usart_pins->{$inp}
Truth table33%1/3
A and B
A= $self->doesrole("USART")B= exists $self->usart_pins->{$inp}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 1 | return $self->usart_read($inp, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | carp "Cannot find $inp in the list of ports or pins to read from"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 5 | ▶ | if (%action) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 4 | ▶ | if (exists $action{ACTION}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 1 | my $action_label = $action{ACTION}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 1 | my $end_label = $action{END}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 1 | $code .= <<"..."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | ;;; invoking $action_label | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | \tgoto $action_label | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | $end_label:\n | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } elsif (exists $action{ISR}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | ## ok we can read from a port too, so let's do that as well | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 3 | ▶ | if (defined $portbit) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | # if we are a pin, then find the right pin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 2 | $inp = $self->get_input_pin($inp); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | ## reset the code here since we have to check IOC pins | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 3 | my ($ioc_bit, $ioc_reg, $ioc_flag, $ioc_enable); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 3 | ▶ | if (exists $self->ioc_pins->{$inp}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 2 | my $apin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 2 | ($apin, $ioc_bit, $ioc_reg) = @{$self->ioc_pins->{$inp}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | } elsif (exists $self->ioc_ports->{$inp}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 1 | $ioc_reg = $self->ioc_ports->{$inp}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | carp "Reading using interrupt-on-change has to be for a pin ". | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | "that supports it, $inp does not support it or is not a pin."; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 3 | $ioc_flag = $self->ioc_ports->{FLAG}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 3 | $ioc_enable = $self->ioc_ports->{ENABLE}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 3 | my $ioch = { bit => $ioc_bit, reg => $ioc_reg, flag => | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | $ioc_flag, enable => $ioc_enable }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 3 | $code = $self->isr_ioc($ioch, $inp); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 3 | ▶ | my $isr_label = 'isr_' . ((defined $ioc_bit) ? lc($ioc_bit) : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | ((defined $ioc_reg) ? lc($ioc_reg) : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | lc($inp))); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 3 | $funcs->{$isr_label} = $self->isr_ioc($ioch, $inp, $var, $port, $portbit, %action); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | carp "Unknown action requested. Probably a bug in implementation"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 5 | ▶ | return wantarray ? ($code, $funcs, $macros, $tables) : $code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 31 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||