VIC/PIC/P18F242.pm

filter: Statementstmt 100% 83 / 83 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 96.7% 30 / 31 Podpod 0.0% 0 / 2 totaltotal 96.6% 114 / 118 CC 4 SCAR 2.1
CC
4
Cov
99%
__ANON__
3.0
list_roles
2.0
BEGIN
1.0
CRAP 1.2
« VIC/PIC/P16F677.pm ↑ Summary VIC/PIC/P18F13K50.pm »
1 package VIC::PIC::P18F242;
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.32';
5 1 $VERSION = eval $VERSION;
6 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 extends 'VIC::PIC::Base';
8  
9 # role CodeGen
10 1 has type => (is => 'ro', default => 'p18f242');
11 1 has include => (is => 'ro', default => 'p18f242.inc');
12  
13 #role Chip
14 1 has f_osc => (is => 'ro', default => 4e6); # 4MHz internal oscillator
15 1 has pcl_size => (is => 'ro', default => 21); # program counter (PCL) size
16 1 has stack_size => (is => 'ro', default => 31); # 31 levels of 21-bit entries
17 1 has wreg_size => (is => 'ro', default => 8); # 8-bit register WREG
18 # all memory is in bytes
19 2 ▶has memory => (is => 'ro', default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
20 {
21 2 flash => 8192, # words
22 SRAM => 768,
23 EEPROM => 256,
24 }
25 1 });
26 2 ▶has address => (is => 'ro', default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
27 {
28 # high # low
29 2 isr => [ 0x0008, 0x0018 ],
30 reset => [ 0x0000 ],
31 range => [ 0x0000, 0x3FFF ],
32 }
33 1 });
34  
35 2 ▶has pin_counts => (is => 'ro', default => sub { {
Subroutine __ANON__: called CC=1 SCAR=0.0
36 2 pdip => 28, ## PDIP or DIP ?
37 soic => 28,
38 total => 28,
39 io => 22,
40 1 }});
41  
42 2 ▶has banks => (is => 'ro', default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
43 {
44 2 count => 16,
45 size => 0x100,
46 gpr => {
47 0 => [ 0x000, 0x0FF],
48 1 => [ 0x100, 0x1FF],
49 2 => [ 0x200, 0x2FF],
50 },
51 # remapping of these addresses automatically done by chip
52 common => [ [0x000, 0x07F], [0xF80, 0xFFF] ],
53 remap => [],
54 }
55 1 });
56  
57 2 ▶has registers => (is => 'ro', default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
58 {
59 2 TOSU => [0xFFF],
60 TOSH => [0xFFE],
61 TOSL => [0xFFD],
62 STKPTR => [0xFFC],
63 PCLATU => [0xFFB],
64 PCLATH => [0xFFA],
65 PCL => [0xFF9],
66 TBLPTRU => [0xFF8],
67 TBLPTRH => [0xFF7],
68 TBLPTRL => [0xFF6],
69 TABLAT => [0xFF5],
70 PRODH => [0xFF4],
71 PRODL => [0xFF3],
72 INTCON => [0xFF2],
73 INTCON2 => [0xFF1],
74 INTCON3 => [0xFF0],
75 INDF0 => [0xFEF],
76 POSTINC0 => [0xFEE],
77 POSTDEC0 => [0xFED],
78 PREINC0 => [0xFEC],
79 PLUSW0 => [0xFEB],
80 FSR0H => [0xFEA],
81 FSR0L => [0xFE9],
82 WREG => [0xFE8],
83 INDF1 => [0xFE7],
84 POSTINC1 => [0xFE6],
85 POSTDEC1 => [0xFE5],
86 PREINC1 => [0xFE4],
87 PLUSW1 => [0xFE3],
88 FSR1H => [0xFE2],
89 FSR1L => [0xFE1],
90 BSR => [0xFE0],
91 INDF2 => [0xFDF],
92 POSTINC2 => [0xFDE],
93 POSTDEC2 => [0xFDD],
94 PREINC2 => [0xFDC],
95 PLUSW2 => [0xFDB],
96 FSR2H => [0xFDA],
97 FSR2L => [0xFD9],
98 STATUS => [0xFD8],
99 TMR0H => [0xFD7],
100 TMR0L => [0xFD6],
101 T0CON => [0xFD5],
102 OSCCON => [0xFD3],
103 LVDCON => [0xFD2],
104 WDTCON => [0xFD1],
105 RCON => [0xFD0],
106 TMR1H => [0xFCF],
107 TMR1L => [0xFCE],
108 T1CON => [0xFCD],
109 TMR2 => [0xFCC],
110 PR2 => [0xFCB],
111 T2CON => [0xFCA],
112 SSPBUF => [0xFC9],
113 SSPADD => [0xFC8],
114 SSPSTAT => [0xFC7],
115 SSPCON1 => [0xFC6],
116 SSPCON2 => [0xFC5],
117 ADRESH => [0xFC4],
118 ADRESL => [0xFC3],
119 ADCON0 => [0xFC2],
120 ADCON1 => [0xFC1],
121 CCPR1H => [0xFBF],
122 CCPR1L => [0xFBE],
123 CCP1CON => [0xFBD],
124 CCPR2H => [0xFBC],
125 CCPR2L => [0xFBB],
126 CCP2CON => [0xFBA],
127 TMR3H => [0xFB3],
128 TMR3L => [0xFB2],
129 T3CON => [0xFB1],
130 SPBRG => [0xFAF],
131 RCREG => [0xFAE],
132 TXREG => [0xFAD],
133 TXSTA => [0xFAC],
134 RCSTA => [0xFAB],
135 EEADR => [0xFA9],
136 EEDATA => [0xFA8],
137 EECON2 => [0xFA7],
138 EECON1 => [0xFA6],
139 IPR2 => [0xFA2],
140 PIR2 => [0xFA1],
141 PIE2 => [0xFA0],
142 IPR1 => [0xF9F],
143 PIR1 => [0xF9E],
144 PIE1 => [0xF9D],
145 TRISC => [0xF94],
146 TRISB => [0xF93],
147 TRISA => [0xF92],
148 LATC => [0xF8B],
149 LATB => [0xF8A],
150 LATA => [0xF89],
151 PORTC => [0xF82],
152 PORTB => [0xF81],
153 PORTA => [0xF80],
154 }
155 1 });
156  
157 2 ▶has pins => (is => 'ro', default => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
158 2 my $h =
159 {
160 1 => [qw(MCLR Vpp)],
161 2 => [qw(RA0 AN0)],
162 3 => [qw(RA1 AN1)],
163 4 => [qw(RA2 AN2 Vref-)],
164 5 => [qw(RA3 AN3 Vref+)],
165 6 => [qw(RA4 T0CKI)],
166 7 => [qw(RA5 AN4 SS LVDIN)],
167 8 => [qw(Vss)],
168 9 => [qw(OSC1 CLKI)],
169 10 => [qw(OSC2 CLKO RA6)],
170 11 => [qw(RC0 T1OSO T1CKI)],
171 12 => [qw(RC1 T1OSI CCP2)],
172 13 => [qw(RC2 CCP1)],
173 14 => [qw(RC3 SCK SCL)],
174 15 => [qw(RC4 SDI SDA)],
175 16 => [qw(RC5 SDO)],
176 17 => [qw(RC6 TX CK)],
177 18 => [qw(RC7 RX DT)],
178 19 => [qw(Vss)],
179 20 => [qw(Vdd)],
180 21 => [qw(RB0 INT0)],
181 22 => [qw(RB1 INT1)],
182 23 => [qw(RB2 INT2)],
183 24 => [qw(RB3 CCP2)],
184 25 => [qw(RB4)],
185 26 => [qw(RB5 PGM)],
186 27 => [qw(RB6 PGC)],
187 28 => [qw(RB7 PGD)],
188 };
189 2 foreach my $k (keys %$h) {
190 56 my $v = $h->{$k};
191 56 foreach (@$v) {
192 126 $h->{$_} = $k;
193 }
194 }
195 2 return $h;
196 1 });
197  
198 4 ▶has clock_pins => (is => 'ro', default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
199 {
200 4 out => 'CLKO',
201 in => 'CLKI',
202 }
203 1 });
204  
205 4 ▶has oscillator_pins => (is => 'ro', default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
206 {
207 4 in => 'OSC1',
208 out => 'OSC2',
209 }
210 1 });
211  
212 4 ▶has program_pins => (is => 'ro', default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
213 {
214 4 clock => 'PGC',
215 data => 'PGD',
216 enable => 'PGM',
217 }
218 1 });
219  
220 2 ▶has io_ports => (is => 'ro', default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
221 {
222 #port => tristate,
223 2 PORTA => 'TRISA',
224 PORTB => 'TRISB',
225 PORTC => 'TRISC',
226 }
227 1 });
228  
229 2 ▶has input_pins => (is => 'ro', default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
230 {
231 #I/O => [port, tristate, bit]
232 2 RA0 => ['PORTA', 'TRISA', 0],
233 RA1 => ['PORTA', 'TRISA', 1],
234 RA2 => ['PORTA', 'TRISA', 2],
235 RA3 => ['PORTA', 'TRISA', 3], # input only
236 RA4 => ['PORTA', 'TRISA', 4],
237 RA5 => ['PORTA', 'TRISA', 5],
238 RB0 => ['PORTB', 'TRISB', 0],
239 RB1 => ['PORTB', 'TRISB', 1],
240 RB2 => ['PORTB', 'TRISB', 2],
241 RB3 => ['PORTB', 'TRISB', 3],
242 RB4 => ['PORTB', 'TRISB', 4],
243 RB5 => ['PORTB', 'TRISB', 5],
244 RB6 => ['PORTB', 'TRISB', 6],
245 RB7 => ['PORTB', 'TRISB', 7],
246 RC0 => ['PORTC', 'TRISC', 0],
247 RC1 => ['PORTC', 'TRISC', 1],
248 RC2 => ['PORTC', 'TRISC', 2],
249 RC3 => ['PORTC', 'TRISC', 3],
250 RC4 => ['PORTC', 'TRISC', 4],
251 RC5 => ['PORTC', 'TRISC', 5],
252 RC6 => ['PORTC', 'TRISC', 6],
253 RC7 => ['PORTC', 'TRISC', 7],
254 }
255 1 });
256  
257 2 ▶has output_pins => (is => 'ro', default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
258 {
259 #I/O => [port, tristate, bit]
260 2 RA0 => ['PORTA', 'TRISA', 0],
261 RA1 => ['PORTA', 'TRISA', 1],
262 RA2 => ['PORTA', 'TRISA', 2],
263 RA3 => ['PORTA', 'TRISA', 3], # input only
264 RA4 => ['PORTA', 'TRISA', 4],
265 RA5 => ['PORTA', 'TRISA', 5],
266 RB0 => ['PORTB', 'TRISB', 0],
267 RB1 => ['PORTB', 'TRISB', 1],
268 RB2 => ['PORTB', 'TRISB', 2],
269 RB3 => ['PORTB', 'TRISB', 3],
270 RB4 => ['PORTB', 'TRISB', 4],
271 RB5 => ['PORTB', 'TRISB', 5],
272 RB6 => ['PORTB', 'TRISB', 6],
273 RB7 => ['PORTB', 'TRISB', 7],
274 RC0 => ['PORTC', 'TRISC', 0],
275 RC1 => ['PORTC', 'TRISC', 1],
276 RC2 => ['PORTC', 'TRISC', 2],
277 RC3 => ['PORTC', 'TRISC', 3],
278 RC4 => ['PORTC', 'TRISC', 4],
279 RC5 => ['PORTC', 'TRISC', 5],
280 RC6 => ['PORTC', 'TRISC', 6],
281 RC7 => ['PORTC', 'TRISC', 7],
282 }
283 1 });
284  
285 2 ▶has analog_pins => (is => 'ro', default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
286 {
287 # use ANSEL for pins AN0-AN7 and ANSELH for AN8-AN11
288 #pin => number, bit
289 2 AN0 => [2, 0],
290 AN1 => [3, 1],
291 AN2 => [4, 2],
292 AN3 => [5, 3],
293 AN4 => [7, 4],
294 }
295 1 });
296  
297 1 has adc_channels => (is => 'ro', default => 5);
298 4 ▶has adcs_bits => (is => 'ro', default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
299 {
300 4 2 => '000',
301 4 => '100',
302 8 => '001',
303 16 => '101',
304 32 => '010',
305 64 => '110',
306 internal => '111',
307 }
308 1 });
309 2 ▶has adc_chs_bits => (is => 'ro', default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
310 {
311 #pin => chsbits
312 2 AN0 => '0000',
313 AN1 => '0001',
314 AN2 => '0010',
315 AN3 => '0011',
316 AN4 => '0100',
317 }
318 1 });
319  
320 4 ▶has timer_prescaler => (is => 'ro', default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
321 {
322 4 2 => '000',
323 4 => '001',
324 8 => '010',
325 16 => '011',
326 32 => '100',
327 64 => '101',
328 128 => '110',
329 256 => '111',
330 }
331 1 });
332  
333 4 ▶has wdt_prescaler => (is => 'ro', default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
334 {
335 4 1 => '000',
336 2 => '001',
337 4 => '010',
338 8 => '011',
339 16 => '100',
340 32 => '101',
341 64 => '110',
342 128 => '111',
343 }
344 1 });
345  
346 2 ▶has timer_pins => (is => 'ro', default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
347 {
348 2 TMR0 => { reg => 'TMR0', freg => 'INTCON', flag => 'TMR0IF', enable => 'TMR0IE', ereg => 'INTCON' },
349 TMR1 => { reg => ['TMR1H', 'TMR1L'], freg => 'PIR1', ereg => 'PIE1', flag => 'TMR1IF', enable => 'TMR1E' },
350 TMR2 => { reg => 'TMR2', freg => 'PIR1', flag => 'TMR2IF', enable => 'TMR2IE', ereg => 'PIE1' },
351 TMR3 => { reg => ['TMR3H', 'TMR3L'], freg => 'PIR2', ereg => 'PIE2', flag => 'TMR3IF', enable => 'TMR3E' },
352 T0CKI => 6,
353 T1OSO => 11,
354 T1CKI => 11,
355 T1OSI => 12,
356 }
357 1 });
358  
359 2 ▶has ccp_pins => (is => 'ro', default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
360 {
361 # multiple pins for multiplexing
362 2 CCP2 => [12, 24],
363 CCP1 => 13,
364 }
365 1 });
366  
367 #external interrupt
368 2 ▶has eint_pins => (is => 'ro', default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
369 {
370 2 INT0 => 21,
371 INT1 => 22,
372 INT2 => 23,
373 }
374 1 });
375  
376 2 ▶has ioc_pins => (is => 'ro', default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
377 {
378 2 RB4 => [25],
379 RB5 => [26],
380 RB6 => [27],
381 RB7 => [28],
382 }
383 1 });
384  
385 2 ▶has ioc_ports => (is => 'ro', default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
386 {
387 2 FLAG => 'RBIF',
388 ENABLE => 'RBIE',
389 }
390 1 });
391  
392 4 ▶has usart_pins => (is => 'ro', default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
393 {
394 4 async_in => 'RX',
395 async_out => 'TX',
396 sync_clock => 'CK',
397 sync_data => 'DT',
398 #TODO
399 rx_int => {},
400 tx_int => {},
401 # this defines the port names that the user can use
402 # validly. The port names define whether the user wants to use them in
403 # synchronous or asynchronous mode
404 UART => 'async',
405 USART => 'sync',
406 }
407 1 });
408  
409 0 ▶sub usart_baudrates {}
Subroutine usart_baudrates: not called CC=1 SCAR=0.0
Pod undocumented
410  
411 2 ▶has selector_pins => (is => 'ro', default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
412 {
413 2 'spi_or_i2c' => 'SS',
414 }
415 1 });
416  
417 4 ▶has spi_pins => (is => 'ro', default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
418 {
419 4 data_out => 'SDO',
420 data_in => 'SDI',
421 clock => 'SCK',
422 }
423 1 });
424  
425 4 ▶has i2c_pins => (is => 'ro', default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
426 {
427 4 data => 'SDA',
428 clock => 'SCL',
429 }
430 1 });
431  
432 1 my @rolenames = qw(CodeGen Operators Chip GPIO ADC ISR Timer Operations CCP
433 USART SPI I2C);
434 1 my @roles = map (("VIC::PIC::Roles::$_", "VIC::PIC::Functions::$_"), @rolenames);
435 1 with @roles;
436  
437 2 ▶sub list_roles {
Subroutine list_roles: called CC=2 SCAR=7.1
Pod undocumented
438 2 my @arr = grep {!/CodeGen|Oper|Chip|ISR/} @rolenames;
439 2 ▶ return wantarray ? @arr : [@arr];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 2 2
440 }
441  
442 1 1;
443  
444 =encoding utf8
445  
446 =head1 NAME
447  
448 VIC::PIC::P18F242
449  
450 =head1 SYNOPSIS
451  
452 A class that describes the code to be generated for each specific
453 microcontroller that maps the VIC syntax back into assembly. This is the
454 back-end to VIC's front-end.
455  
456 =head1 DESCRIPTION
457  
458 INTERNAL CLASS.
459  
460 =head1 AUTHOR
461  
462 Vikas N Kumar <vikas@cpan.org>
463  
464 =head1 COPYRIGHT
465  
466 Copyright (c) 2014. Vikas N Kumar
467  
468 This program is free software; you can redistribute it and/or modify it
469 under the same terms as Perl itself.
470  
471 See http://www.perl.com/perl/misc/Artistic.html
472  
473 =cut
« VIC/PIC/P16F677.pm ↑ Summary VIC/PIC/P18F13K50.pm »