VIC/PIC/P16F627A.pm

filter: Statementstmt 97.5% 79 / 81 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 96.5% 28 / 29 Podpod 0.0% 0 / 2 totaltotal 94.7% 108 / 114 SCAR 13.9
CC
4
Cov
96%
__ANON__
3.0
list_roles
2.0
usart_baudrates
2.0
CRAP 4.0
« VIC/PIC/Functions/Power.pm ↑ Summary VIC/PIC/P18F242.pm »
1 package VIC::PIC::P16F627A;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 our $VERSION = '0.29';
5 1 $VERSION = eval $VERSION;
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 extends 'VIC::PIC::Base';
9  
10 # role CodeGen
11 1 has type => (is => 'ro', default => 'p16f627a');
12 1 has include => (is => 'ro', default => 'p16f627a.inc');
13  
14 #role Chip
15 1 has f_osc => (is => 'ro', default => 4e6); # 4MHz internal oscillator
16 1 has pcl_size => (is => 'ro', default => 13); # program counter (PCL) size
17 1 has stack_size => (is => 'ro', default => 8); # 8 levels of 13-bit entries
18 1 has wreg_size => (is => 'ro', default => 8); # 8-bit register WREG
19 # all memory is in bytes
20 has memory => (is => 'ro', default => sub {
21 {
22 1 ▶ flash => 1024, # words
Subroutine __ANON__: called CC=1 SCAR=0.0
23 SRAM => 224,
24 EEPROM => 128,
25 }
26 1 });
27 has address => (is => 'ro', default => sub {
28 {
29 1 ▶ isr => [ 0x0004 ],
Subroutine __ANON__: called CC=1 SCAR=0.0
30 reset => [ 0x0000 ],
31 range => [ 0x0000, 0x03FF ],
32 }
33 1 });
34  
35 has pin_counts => (is => 'ro', default => sub { {
36 3 ▶ pdip => 18, ## PDIP or DIP ?
Subroutine __ANON__: called CC=1 SCAR=0.0
37 soic => 20,
38 ssop => 20,
39 qfn => 28,
40 total => 20,
41 io => 16,
42 1 }});
43  
44 has banks => (is => 'ro', default => sub {
45 {
46 2 ▶ count => 4,
Subroutine __ANON__: called CC=1 SCAR=0.0
47 size => 0x80,
48 gpr => {
49 0 => [ 0x020, 0x07F],
50 1 => [ 0x0A0, 0x0EF],
51 2 => [ 0x120, 0x14F],
52 },
53 # remapping of these addresses automatically done by chip
54 common => [0x070, 0x07F],
55 remap => [
56 [0x0F0, 0x0FF],
57 [0x170, 0x17F],
58 [0x1F0, 0x1FF],
59 ],
60 }
61 1 });
62  
63 has registers => (is => 'ro', default => sub {
64 {
65 3 ▶ INDF => [0x000, 0x080, 0x100, 0x180], # indirect addressing
Subroutine __ANON__: called CC=1 SCAR=0.0
66 TMR0 => [0x001, 0x101],
67 OPTION_REG => [0x081, 0x181],
68 PCL => [0x002, 0x082, 0x102, 0x182],
69 STATUS => [0x003, 0x083, 0x103, 0x183],
70 FSR => [0x004, 0x084, 0x104, 0x184],
71 PORTA => [0x005],
72 TRISA => [0x085],
73 PORTB => [0x006, 0x106],
74 TRISB => [0x086, 0x186],
75 PCLATH => [0x00A, 0x08A, 0x10A, 0x18A],
76 INTCON => [0x00B, 0x08B, 0x10B, 0x18B],
77 PIR1 => [0x00C],
78 PIE1 => [0x08C],
79 TMR1L => [0x00E],
80 PCON => [0x08E],
81 TMR1H => [0x00F],
82 T1CON => [0x010],
83 TMR2 => [0x011],
84 T2CON => [0x012],
85 PR2 => [0x092],
86 CCPR1L => [0x015],
87 CCPR1H => [0x016],
88 CCP1CON => [0x017],
89 RCSTA => [0x018],
90 TXSTA => [0x098],
91 TXREG => [0x019],
92 SPBRG => [0x099],
93 RCREG => [0x01A],
94 EEDATA => [0x09A],
95 EEADR => [0x09B],
96 EECON1 => [0x09C],
97 EECON2 => [0x09D], # not addressable apparently
98 CMCON => [0x01F],
99 VRCON => [0x09F],
100 }
101 1 });
102  
103 has pins => (is => 'ro', default => sub {
104 3 ▶ my $h = {
Subroutine __ANON__: called CC=3 SCAR=11.0
105 # number to pin name and pin name to number
106 1 => [qw(RA2 AN2 Vref)],
107 2 => [qw(RA3 AN3 CMP1)],
108 3 => [qw(RA4 T0CKI CMP2)],
109 4 => [qw(RA5 MCLR Vpp)],
110 5 => [qw(Vss)],
111 6 => [qw(RB0 INT)],
112 7 => [qw(RB1 RX DT)],
113 8 => [qw(RB2 TX CK)],
114 9 => [qw(RB3 CCP1)],
115 10 => [qw(RB4 PGM)],
116 11 => [qw(RB5)],
117 12 => [qw(RB6 T1OSO T1CKI PGC)],
118 13 => [qw(RB7 T1OSI PGD)],
119 14 => [qw(Vdd)],
120 15 => [qw(RA6 OSC2 CLKOUT)],
121 16 => [qw(RA7 OSC1 CLKIN)],
122 17 => [qw(RA0 AN0)],
123 18 => [qw(RA1 AN1)],
124 };
125 3 foreach my $k (keys %$h) {
126 54 my $v = $h->{$k};
127 54 foreach (@$v) {
128 132 $h->{$_} = $k;
129 }
130 }
131 3 return $h;
132 1 });
133  
134 has clock_pins => (is => 'ro', default => sub {
135 {
136 3 ▶ out => 'CLKOUT',
Subroutine __ANON__: called CC=1 SCAR=0.0
137 in => 'CLKIN',
138 }
139 1 });
140  
141 has oscillator_pins => (is => 'ro', default => sub {
142 {
143 3 ▶ 1 => 'OSC1',
Subroutine __ANON__: called CC=1 SCAR=0.0
144 2 => 'OSC2',
145 }
146 1 });
147  
148 has program_pins => (is => 'ro', default => sub {
149 {
150 3 ▶ clock => 'PGC',
Subroutine __ANON__: called CC=1 SCAR=0.0
151 data => 'PGD',
152 enable => 'PGM',
153 }
154 1 });
155  
156 has io_ports => (is => 'ro', default => sub {
157 {
158 #port => tristate,
159 3 ▶ PORTA => 'TRISA',
Subroutine __ANON__: called CC=1 SCAR=0.0
160 PORTB => 'TRISB',
161 }
162 1 });
163  
164 has input_pins => (is => 'ro', default => sub {
165 {
166 #I/O => [port, tristate, bit]
167 3 ▶ RA0 => ['PORTA', 'TRISA', 0],
Subroutine __ANON__: called CC=1 SCAR=0.0
168 RA1 => ['PORTA', 'TRISA', 1],
169 RA2 => ['PORTA', 'TRISA', 2],
170 RA3 => ['PORTA', 'TRISA', 3],
171 RA4 => ['PORTA', 'TRISA', 4],
172 RA5 => ['PORTA', 'TRISA', 5], # input only
173 RA6 => ['PORTA', 'TRISA', 6],
174 RA7 => ['PORTA', 'TRISA', 7],
175 RB0 => ['PORTB', 'TRISB', 0],
176 RB1 => ['PORTB', 'TRISB', 1],
177 RB2 => ['PORTB', 'TRISB', 2],
178 RB3 => ['PORTB', 'TRISB', 3],
179 RB4 => ['PORTB', 'TRISB', 4],
180 RB5 => ['PORTB', 'TRISB', 5],
181 RB6 => ['PORTB', 'TRISB', 6],
182 RB7 => ['PORTB', 'TRISB', 7],
183 }
184 1 });
185  
186 has output_pins => (is => 'ro', default => sub {
187 {
188 #I/O => [port, tristate, bit]
189 3 ▶ RA0 => ['PORTA', 'TRISA', 0],
Subroutine __ANON__: called CC=1 SCAR=0.0
190 RA1 => ['PORTA', 'TRISA', 1],
191 RA2 => ['PORTA', 'TRISA', 2],
192 RA3 => ['PORTA', 'TRISA', 3],
193 RA4 => ['PORTA', 'TRISA', 4],
194 RA6 => ['PORTA', 'TRISA', 6],
195 RA7 => ['PORTA', 'TRISA', 7],
196 RB0 => ['PORTB', 'TRISB', 0],
197 RB1 => ['PORTB', 'TRISB', 1],
198 RB2 => ['PORTB', 'TRISB', 2],
199 RB3 => ['PORTB', 'TRISB', 3],
200 RB4 => ['PORTB', 'TRISB', 4],
201 RB5 => ['PORTB', 'TRISB', 5],
202 RB6 => ['PORTB', 'TRISB', 6],
203 RB7 => ['PORTB', 'TRISB', 7],
204 }
205 1 });
206  
207 3 ▶has analog_pins => (is => 'ro', default => sub { {} });
Subroutine __ANON__: called CC=1 SCAR=0.0
208  
209 has timer_prescaler => (is => 'ro', default => sub {
210 {
211 3 ▶ 2 => '000',
Subroutine __ANON__: called CC=1 SCAR=0.0
212 4 => '001',
213 8 => '010',
214 16 => '011',
215 32 => '100',
216 64 => '101',
217 128 => '110',
218 256 => '111',
219 }
220 1 });
221  
222 has wdt_prescaler => (is => 'ro', default => sub {
223 {
224 3 ▶ 1 => '000',
Subroutine __ANON__: called CC=1 SCAR=0.0
225 2 => '001',
226 4 => '010',
227 8 => '011',
228 16 => '100',
229 32 => '101',
230 64 => '110',
231 128 => '111',
232 }
233 1 });
234  
235 has timer_pins => (is => 'ro', default => sub {
236 {
237 3 ▶ TMR0 => { reg => 'TMR0', freg => 'INTCON', flag => 'T0IF', enable => 'T0IE', ereg => 'INTCON' },
Subroutine __ANON__: called CC=1 SCAR=0.0
238 TMR1 => { reg => ['TMR1H', 'TMR1L'], freg => 'PIR1', ereg => 'PIE1', flag => 'TMR1IF', enable => 'TMR1IE' },
239 TMR2 => { reg => 'TMR2', freg => 'PIR1', flag => 'TMR2IF', ereg => 'PIE1', enable => 'TMR2IF' },
240 # timer 0 clock input
241 T0CKI => 3,
242 # timer 1 clock input
243 T1CKI => 12,
244 # timer oscillator input
245 T1OSI => 13,
246 # timer oscillator output
247 T1OSO => 12,
248 }
249 1 });
250  
251 has ccp_pins => (is => 'ro', default => sub {
252 {
253 3 ▶ CCP1 => 'CCP1',
Subroutine __ANON__: called CC=1 SCAR=0.0
254 }
255 1 });
256  
257 #external interrupt
258 has eint_pins => (is => 'ro', default => sub {
259 {
260 3 ▶ INT => 6,
Subroutine __ANON__: called CC=1 SCAR=0.0
261 }
262 1 });
263  
264 has ioc_pins => (is => 'ro', default => sub {
265 {
266 ## there is no special IOC register, so use nothing
267 3 ▶ RB4 => [10],
Subroutine __ANON__: called CC=1 SCAR=0.0
268 RB5 => [11],
269 RB6 => [12],
270 RB7 => [13],
271 }
272 1 });
273  
274 has ioc_ports => (is => 'ro', default => sub {
275 {
276 3 ▶ FLAG => 'RBIF',
Subroutine __ANON__: called CC=1 SCAR=0.0
277 ENABLE => 'RBIE',
278 }
279 1 });
280  
281 has usart_pins => (is => 'ro', default => sub {
282 {
283 3 ▶ async_in => 'RX',
Subroutine __ANON__: called CC=1 SCAR=0.0
284 async_out => 'TX',
285 sync_clock => 'CK',
286 sync_data => 'DT',
287 #TODO
288 rx_int => {},
289 tx_int => {},
290 # this defines the port names that the user can use
291 # validly. The port names define whether the user wants to use them in
292 # synchronous or asynchronous mode
293 UART => 'async',
294 USART => 'sync',
295 }
296 1 });
297  
298 sub usart_baudrates {
299 0 ▶ carp "Unimplemented";
Subroutine usart_baudrates: not called CC=1 SCAR=6.9
Pod undocumented
300 0 return;
301 }
302  
303 has cmp_output_pins => (is => 'ro', default => sub {
304 {
305 3 ▶ CMP1 => 'CMP1',
Subroutine __ANON__: called CC=1 SCAR=0.0
306 CMP2 => 'CMP2',
307 }
308 1 });
309  
310 has cmp_input_pins => (is => 'ro', default => sub {
311 {
312 3 ▶ AN0 => 'AN0',
Subroutine __ANON__: called CC=1 SCAR=0.0
313 AN1 => 'AN1',
314 AN2 => 'AN2',
315 AN3 => 'AN3',
316 }
317 1 });
318  
319 1 my @rolenames = qw(CodeGen Operators Chip GPIO ISR Timer Operations CCP USART Comparator);
320 1 my @roles = map (("VIC::PIC::Roles::$_", "VIC::PIC::Functions::$_"), @rolenames);
321 1 with @roles;
322  
323 sub list_roles {
324 3 ▶ my @arr = grep {!/CodeGen|Oper|Chip|ISR/} @rolenames;
Subroutine list_roles: called CC=2 SCAR=7.1
Pod undocumented
325 3 ▶ return wantarray ? @arr : [@arr];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
326 }
327  
328 1 1;
329 __END__
« VIC/PIC/Functions/Power.pm ↑ Summary VIC/PIC/P18F242.pm »