| 1 | package VIC::PIC::Functions::ISR; | ||||||||||||||||||||||||||||||||
| 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 | our $VERSION = '0.32'; | |||||||||||||||||||||||||||||||
| 5 | 31 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||||||||
| 6 | 31 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 31 | ▶ | use POSIX (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 31 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | sub isr_var { | ||||||||||||||||||||||||||||||
|
Subroutine
isr_var: called CC=4 SCAR=14.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 11 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||
| 12 | 5 | ▶ | return unless $self->doesroles(qw(Chip ISR)); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 13 | 5 | my @common = @{$self->banks->{common}}; | |||||||||||||||||||||||||||||||
| 14 | 5 | my ($cb_start, $cb_end) = @common; | |||||||||||||||||||||||||||||||
| 15 | 5 | ▶ | if (ref $cb_start eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 16 | 0 | ($cb_start, $cb_end) = @$cb_start; | |||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||
| 18 | 5 | ▶ | $cb_start = 0x70 unless $cb_start; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 19 | 5 | $cb_start = sprintf "0x%02X", $cb_start; | |||||||||||||||||||||||||||||||
| 20 | 5 | return << "..."; | |||||||||||||||||||||||||||||||
| 21 | cblock $cb_start ;; unbanked RAM that is common across all banks | ||||||||||||||||||||||||||||||||
| 22 | ISR_STATUS | ||||||||||||||||||||||||||||||||
| 23 | ISR_W | ||||||||||||||||||||||||||||||||
| 24 | endc | ||||||||||||||||||||||||||||||||
| 25 | ... | ||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | 5 | ▶ | sub isr_entry { | ||||||||||||||||||||||||||||||
|
Subroutine
isr_entry: called CC=4 SCAR=14.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 29 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||
| 30 | 5 | ▶ | return unless $self->doesroles(qw(Chip ISR)); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 31 | 5 | ▶ | unless (exists $self->registers->{STATUS}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 32 | 0 | carp $self->type, " has no register named STATUS"; | |||||||||||||||||||||||||||||||
| 33 | 0 | return; | |||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||
| 35 | #TODO: high/low address ? | ||||||||||||||||||||||||||||||||
| 36 | 5 | my $isr_addr = $self->address->{isr}->[0]; | |||||||||||||||||||||||||||||||
| 37 | 5 | my $reset_addr = $self->address->{reset}->[0]; | |||||||||||||||||||||||||||||||
| 38 | 5 | my $count = $isr_addr - $reset_addr - 1; | |||||||||||||||||||||||||||||||
| 39 | 5 | my $nops = ''; | |||||||||||||||||||||||||||||||
| 40 | 5 | for my $i (1 .. $count) { | |||||||||||||||||||||||||||||||
| 41 | 15 | $nops .= "\tnop\n"; | |||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||
| 43 | 5 | return << "..."; | |||||||||||||||||||||||||||||||
| 44 | $nops | ||||||||||||||||||||||||||||||||
| 45 | \torg $isr_addr | ||||||||||||||||||||||||||||||||
| 46 | ISR: | ||||||||||||||||||||||||||||||||
| 47 | _isr_entry: | ||||||||||||||||||||||||||||||||
| 48 | \tmovwf ISR_W | ||||||||||||||||||||||||||||||||
| 49 | \tmovf STATUS, W | ||||||||||||||||||||||||||||||||
| 50 | \tmovwf ISR_STATUS | ||||||||||||||||||||||||||||||||
| 51 | ... | ||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | 5 | ▶ | sub isr_exit { | ||||||||||||||||||||||||||||||
|
Subroutine
isr_exit: called CC=3 SCAR=12.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 55 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||
| 56 | 5 | ▶ | return unless $self->doesroles(qw(Chip ISR)); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 57 | 5 | ▶ | unless (exists $self->registers->{STATUS}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 58 | 0 | carp $self->type, " has no register named STATUS"; | |||||||||||||||||||||||||||||||
| 59 | 0 | return; | |||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||
| 61 | 5 | return << "..."; | |||||||||||||||||||||||||||||||
| 62 | _isr_exit: | ||||||||||||||||||||||||||||||||
| 63 | \tmovf ISR_STATUS, W | ||||||||||||||||||||||||||||||||
| 64 | \tmovwf STATUS | ||||||||||||||||||||||||||||||||
| 65 | \tswapf ISR_W, F | ||||||||||||||||||||||||||||||||
| 66 | \tswapf ISR_W, W | ||||||||||||||||||||||||||||||||
| 67 | \tretfie | ||||||||||||||||||||||||||||||||
| 68 | ... | ||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | 2 | ▶ | sub isr_timer { | ||||||||||||||||||||||||||||||
|
Subroutine
isr_timer: called CC=12 SCAR=28.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 72 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||
| 73 | 2 | ▶ | return unless $self->doesroles(qw(Chip ISR)); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 74 | 2 | my $th = shift; | |||||||||||||||||||||||||||||||
| 75 | 2 | ▶ | return unless (defined $th and ref $th eq 'HASH'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $th and ref $th eq "HASH"
MC/DC0%0/2
defined $th and ref $th eq "HASH"
defined $th
ref $th eq "HASH"
Truth table33%1/3
A and B
A= defined $thB= ref $th eq "HASH"
| |||||||||||||||||||||||||||||||||
| 76 | 2 | my $freg = $th->{freg}; | |||||||||||||||||||||||||||||||
| 77 | 2 | my $ereg = $th->{ereg}; | |||||||||||||||||||||||||||||||
| 78 | 2 | ▶ | unless (exists $self->registers->{$freg} and exists $self->registers->{$ereg}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $self->registers->{$freg} and exists $self->registers->{$ereg}
MC/DC0%0/2
exists $self->registers->{$freg} and exists $self->registers->{$ereg}
exists $self->registers->{$freg}
exists $self->registers->{$ereg}
Truth table33%1/3
A and B
A= exists $self->registers->{$freg}B= exists $self->registers->{$ereg}
| |||||||||||||||||||||||||||||||||
| 79 | 0 | carp $self->type, " has no register named $freg or $ereg"; | |||||||||||||||||||||||||||||||
| 80 | 0 | return; | |||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||
| 82 | 2 | my $tflag = $th->{flag}; | |||||||||||||||||||||||||||||||
| 83 | 2 | my $tenable = $th->{enable}; | |||||||||||||||||||||||||||||||
| 84 | 2 | ▶ | my $treg = (ref $th->{reg} eq 'ARRAY') ? $th->{reg}->[0] : $th->{reg}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 85 | 2 | my %isr = @_; | |||||||||||||||||||||||||||||||
| 86 | 2 | ▶ | if (%isr) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 87 | 1 | my $action_label = $isr{ISR}; | |||||||||||||||||||||||||||||||
| 88 | 1 | my $end_label = $isr{END}; | |||||||||||||||||||||||||||||||
| 89 | 1 | ▶ | return unless $action_label; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 90 | 1 | ▶ | return unless $end_label; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 91 | 1 | my $isr_label = '_isr_' . lc($treg); | |||||||||||||||||||||||||||||||
| 92 | return << "..." | ||||||||||||||||||||||||||||||||
| 93 | $isr_label: | ||||||||||||||||||||||||||||||||
| 94 | \tbtfss $freg, $tflag | ||||||||||||||||||||||||||||||||
| 95 | \tgoto $end_label | ||||||||||||||||||||||||||||||||
| 96 | \tbcf $freg, $tflag | ||||||||||||||||||||||||||||||||
| 97 | \tgoto $action_label | ||||||||||||||||||||||||||||||||
| 98 | $end_label: | ||||||||||||||||||||||||||||||||
| 99 | ... | ||||||||||||||||||||||||||||||||
| 100 | 1 | } else { | |||||||||||||||||||||||||||||||
| 101 | 1 | ▶ | if ($freg eq 'INTCON' and $ereg eq 'INTCON') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$freg eq "INTCON" and $ereg eq "INTCON"
MC/DC0%0/2
$freg eq "INTCON" and $ereg eq "INTCON"
$freg eq "INTCON"
$ereg eq "INTCON"
Truth table33%1/3
A and B
A= $freg eq "INTCON"B= $ereg eq "INTCON"
| |||||||||||||||||||||||||||||||||
| 102 | 1 | return << "..."; | |||||||||||||||||||||||||||||||
| 103 | ;; enable interrupt servicing for $treg | ||||||||||||||||||||||||||||||||
| 104 | \tbanksel $freg | ||||||||||||||||||||||||||||||||
| 105 | \tbsf INTCON, GIE | ||||||||||||||||||||||||||||||||
| 106 | \tbcf $freg, $tflag | ||||||||||||||||||||||||||||||||
| 107 | \tbsf $ereg, $tenable | ||||||||||||||||||||||||||||||||
| 108 | ;; end of interrupt servicing | ||||||||||||||||||||||||||||||||
| 109 | ... | ||||||||||||||||||||||||||||||||
| 110 | } else { | ||||||||||||||||||||||||||||||||
| 111 | 0 | return << "..."; | |||||||||||||||||||||||||||||||
| 112 | ;; enable interrupt servicing for $treg | ||||||||||||||||||||||||||||||||
| 113 | \tbanksel INTCON | ||||||||||||||||||||||||||||||||
| 114 | \tbsf INTCON, GIE | ||||||||||||||||||||||||||||||||
| 115 | \tbanksel $freg | ||||||||||||||||||||||||||||||||
| 116 | \tbcf $freg, $tflag | ||||||||||||||||||||||||||||||||
| 117 | \tbanksel $ereg | ||||||||||||||||||||||||||||||||
| 118 | \tbsf $ereg, $tenable | ||||||||||||||||||||||||||||||||
| 119 | ;; end of interrupt servicing | ||||||||||||||||||||||||||||||||
| 120 | ... | ||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | 6 | ▶ | sub isr_ioc { | ||||||||||||||||||||||||||||||
|
Subroutine
isr_ioc: called CC=15 SCAR=28.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 127 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||
| 128 | 6 | ▶ | return unless $self->doesroles(qw(Chip ISR)); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 129 | 6 | ▶ | unless (exists $self->registers->{INTCON}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 130 | 0 | carp $self->type, " has no register named INTCON"; | |||||||||||||||||||||||||||||||
| 131 | 0 | return; | |||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||
| 133 | 6 | my $ioch = shift; | |||||||||||||||||||||||||||||||
| 134 | 6 | my $ipin = shift; | |||||||||||||||||||||||||||||||
| 135 | 6 | ▶ | return unless (defined $ioch and ref $ioch eq 'HASH'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $ioch and ref $ioch eq "HASH"
MC/DC0%0/2
defined $ioch and ref $ioch eq "HASH"
defined $ioch
ref $ioch eq "HASH"
Truth table33%1/3
A and B
A= defined $iochB= ref $ioch eq "HASH"
| |||||||||||||||||||||||||||||||||
| 136 | 6 | ▶ | return unless defined $ipin; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 137 | 6 | my $ioc_reg = $ioch->{reg}; | |||||||||||||||||||||||||||||||
| 138 | 6 | my $ioc_bit = $ioch->{bit}; | |||||||||||||||||||||||||||||||
| 139 | 6 | my $ioc_flag = $ioch->{flag}; | |||||||||||||||||||||||||||||||
| 140 | 6 | my $ioc_enable = $ioch->{enable}; | |||||||||||||||||||||||||||||||
| 141 | 6 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 142 | 3 | my ($var, $port, $portbit, %isr) = @_; | |||||||||||||||||||||||||||||||
| 143 | 3 | my $action_label = $isr{ISR}; | |||||||||||||||||||||||||||||||
| 144 | 3 | my $end_label = $isr{END}; | |||||||||||||||||||||||||||||||
| 145 | 3 | ▶ | return unless $action_label; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 146 | 3 | ▶ | return unless $end_label; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 147 | 3 | my $isr_label; | |||||||||||||||||||||||||||||||
| 148 | 3 | ▶ | if (defined $ioc_bit) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 149 | 2 | $isr_label = '_isr_' . lc($ioc_bit); | |||||||||||||||||||||||||||||||
| 150 | } elsif (defined $ioc_reg) { | ||||||||||||||||||||||||||||||||
| 151 | 1 | $isr_label = '_isr_' .lc($ioc_reg); | |||||||||||||||||||||||||||||||
| 152 | } else { | ||||||||||||||||||||||||||||||||
| 153 | 0 | $isr_label = '_isr_' . lc($ipin); | |||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||
| 155 | 3 | my $code_ioc = ''; | |||||||||||||||||||||||||||||||
| 156 | 3 | ▶ | if (defined $portbit) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 157 | 2 | $code_ioc = "\tbtfsc $port, $portbit\n\taddlw 0x01"; | |||||||||||||||||||||||||||||||
| 158 | } else { | ||||||||||||||||||||||||||||||||
| 159 | 1 | $code_ioc = "\tmovf $port, W"; | |||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||
| 161 | return << "..." | ||||||||||||||||||||||||||||||||
| 162 | $isr_label: | ||||||||||||||||||||||||||||||||
| 163 | \tbtfss INTCON, $ioc_flag | ||||||||||||||||||||||||||||||||
| 164 | \tgoto $end_label | ||||||||||||||||||||||||||||||||
| 165 | \tbcf INTCON, $ioc_flag | ||||||||||||||||||||||||||||||||
| 166 | \tbanksel $port | ||||||||||||||||||||||||||||||||
| 167 | $code_ioc | ||||||||||||||||||||||||||||||||
| 168 | \tbanksel $var | ||||||||||||||||||||||||||||||||
| 169 | \tmovwf $var | ||||||||||||||||||||||||||||||||
| 170 | \tgoto $action_label | ||||||||||||||||||||||||||||||||
| 171 | $end_label: | ||||||||||||||||||||||||||||||||
| 172 | ... | ||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||
| 174 | 3 | } else { | |||||||||||||||||||||||||||||||
| 175 | 3 | my $code_en = ''; | |||||||||||||||||||||||||||||||
| 176 | 3 | ▶ | if (defined $ioc_bit and defined $ioc_reg) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
defined $ioc_bit and defined $ioc_reg
MC/DC50%1/2
defined $ioc_bit and defined $ioc_reg
defined $ioc_bit
defined $ioc_reg
Truth table66%2/3
A and B
A= defined $ioc_bitB= defined $ioc_reg
| |||||||||||||||||||||||||||||||||
| 177 | 2 | $code_en = "\tbanksel $ioc_reg\n\tbsf $ioc_reg, $ioc_bit"; | |||||||||||||||||||||||||||||||
| 178 | } elsif (defined $ioc_reg) { | ||||||||||||||||||||||||||||||||
| 179 | 1 | $code_en = "\tbanksel $ioc_reg\n\tclrf $ioc_reg\n\tcomf $ioc_reg, F"; | |||||||||||||||||||||||||||||||
| 180 | } else { | ||||||||||||||||||||||||||||||||
| 181 | # if ioc_reg/ioc_bit is not defined just move on | ||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||
| 183 | 3 | return << "..."; | |||||||||||||||||||||||||||||||
| 184 | ;; enable interrupt-on-change setup for $ipin | ||||||||||||||||||||||||||||||||
| 185 | \tbanksel INTCON | ||||||||||||||||||||||||||||||||
| 186 | \tbcf INTCON, $ioc_flag | ||||||||||||||||||||||||||||||||
| 187 | \tbsf INTCON, GIE | ||||||||||||||||||||||||||||||||
| 188 | \tbsf INTCON, $ioc_enable | ||||||||||||||||||||||||||||||||
| 189 | $code_en | ||||||||||||||||||||||||||||||||
| 190 | ;; end of interrupt-on-change setup | ||||||||||||||||||||||||||||||||
| 191 | ... | ||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||
| 196 | 31 | 1; | |||||||||||||||||||||||||||||||
| 197 | __END__ | ||||||||||||||||||||||||||||||||