VIC/PIC/Functions/ISR.pm

filter: Statementstmt 89.3% 92 / 103 Branchbran 59.2% 32 / 54 Conditioncond 40.0% 6 / 15 MC/DCmcdc 10.0% 1 / 10 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 5 totaltotal 71.5% 141 / 197 SCAR 39.3
CC
34
Cov
76%
isr_ioc
17.4
isr_timer
17.3
isr_var
4.2
CRAP 50.8
« VIC/PIC/Functions/Operations.pm ↑ Summary VIC/PIC/Functions/CodeGen.pm »
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.29';
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 sub isr_var {
11 5 ▶ my $self = shift;
Subroutine isr_var: called CC=4 SCAR=14.5
Pod undocumented
12 5 ▶ return unless $self->doesroles(qw(Chip ISR));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->doesroles("Chip", "ISR") 0 5 5
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
BranchTrueFalseTotal
if (ref $cb_start eq "ARRAY") 0 5 5
16 0 ($cb_start, $cb_end) = @$cb_start;
17 }
18 5 ▶ $cb_start = 0x70 unless $cb_start;
Branch: 1 branch
BranchTrueFalseTotal
unless $cb_start 0 5 5
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 sub isr_entry {
29 5 ▶ my $self = shift;
Subroutine isr_entry: called CC=4 SCAR=14.5
Pod undocumented
30 5 ▶ return unless $self->doesroles(qw(Chip ISR));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->doesroles("Chip", "ISR") 0 5 5
31 5 ▶ unless (exists $self->registers->{STATUS}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->registers->{"STATUS"}) 0 5 5
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 sub isr_exit {
55 5 ▶ my $self = shift;
Subroutine isr_exit: called CC=3 SCAR=12.7
Pod undocumented
56 5 ▶ return unless $self->doesroles(qw(Chip ISR));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->doesroles("Chip", "ISR") 0 5 5
57 5 ▶ unless (exists $self->registers->{STATUS}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->registers->{"STATUS"}) 0 5 5
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 sub isr_timer {
72 2 ▶ my $self = shift;
Subroutine isr_timer: called CC=12 SCAR=28.5
Pod undocumented
73 2 ▶ return unless $self->doesroles(qw(Chip ISR));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->doesroles("Chip", "ISR") 0 2 2
74 2 my $th = shift;
75 2 ▶ return unless (defined $th and ref $th eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless defined $th and ref $th eq "HASH" 0 2 2
Condition33%1/3
defined $th and ref $th eq "HASH"
!ll&&!rl&&r
002
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless (exists $self->registers->{$freg} and exists $self->registers->{$ereg}) 0 2 2
Condition33%1/3
exists $self->registers->{$freg} and exists $self->registers->{$ereg}
!ll&&!rl&&r
002
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}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
ref $th->{'reg'} eq 'ARRAY' ? : 0 2 2
85 2 my %isr = @_;
86 2 ▶ if (%isr) {
Branch: 1 branch
BranchTrueFalseTotal
if (%isr) { } 1 1 2
87 1 my $action_label = $isr{ISR};
88 1 my $end_label = $isr{END};
89 1 ▶ return unless $action_label;
Branch: 1 branch
BranchTrueFalseTotal
unless $action_label 0 1 1
90 1 ▶ return unless $end_label;
Branch: 1 branch
BranchTrueFalseTotal
unless $end_label 0 1 1
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
BranchTrueFalseTotal
if ($freg eq 'INTCON' and $ereg eq 'INTCON') { } 1 0 1
Condition33%1/3
$freg eq "INTCON" and $ereg eq "INTCON"
!ll&&!rl&&r
001
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"
ABresult
0X0
100
111
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 sub isr_ioc {
127 6 ▶ my $self = shift;
Subroutine isr_ioc: called CC=15 SCAR=28.5
Pod undocumented
128 6 ▶ return unless $self->doesroles(qw(Chip ISR));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->doesroles("Chip", "ISR") 0 6 6
129 6 ▶ unless (exists $self->registers->{INTCON}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->registers->{"INTCON"}) 0 6 6
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
BranchTrueFalseTotal
unless defined $ioch and ref $ioch eq "HASH" 0 6 6
Condition33%1/3
defined $ioch and ref $ioch eq "HASH"
!ll&&!rl&&r
006
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"
ABresult
0X0
100
111
136 6 ▶ return unless defined $ipin;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ipin 0 6 6
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
BranchTrueFalseTotal
if (@_) { } 3 3 6
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
BranchTrueFalseTotal
unless $action_label 0 3 3
146 3 ▶ return unless $end_label;
Branch: 1 branch
BranchTrueFalseTotal
unless $end_label 0 3 3
147 3 my $isr_label;
148 3 ▶ if (defined $ioc_bit) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $ioc_bit) { } 2 1 3
elsif (defined $ioc_reg) { } 1 0 1
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
BranchTrueFalseTotal
if (defined $portbit) { } 2 1 3
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
BranchTrueFalseTotal
if (defined $ioc_bit and defined $ioc_reg) { } 2 1 3
elsif (defined $ioc_reg) { } 1 0 1
Condition66%2/3
defined $ioc_bit and defined $ioc_reg
!ll&&!rl&&r
102
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
ABresult
0X0
100
111
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__
« VIC/PIC/Functions/Operations.pm ↑ Summary VIC/PIC/Functions/CodeGen.pm »