/usr/include/gpsim/pir.h is in gpsim-dev 0.27.0-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 | /*
Copyright (C) 1998-2003 Scott Dattalo
2003 Mike Durian
2013 Roy R. Rankin
This file is part of the libgpsim library of gpsim
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, see
<http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
#ifndef PIR_H
#define PIR_H
#include "assert.h"
#include "pie.h"
class INTCON;
//---------------------------------------------------------
// PIR Peripheral Interrupt register base class for PIR1 & PIR2
class PIR : public sfr_register
{
protected:
INTCON *intcon;
PIE *pie;
sfr_register *ipr;
public:
int valid_bits;
int writable_bits;
PIR(Processor *pCpu, const char *pName, const char *pDesc,
INTCON *, PIE *, int _valid_bits);
// The PIR base class supports no PIR bits directly
virtual void clear_sspif(){}
virtual void clear_rcif(){}
virtual void clear_txif(){}
virtual void set_adif(){}
virtual void set_bclif(){}
virtual void set_ccpif(){}
virtual void set_cmif(){}
virtual void set_c1if(){fprintf(stderr, "RRR set_c1if FIX\n");}
virtual void set_c2if(){fprintf(stderr, "RRR set_c2if FIX\n");}
virtual void set_c3if(){fprintf(stderr, "RRR set_c3if FIX\n");}
virtual void set_c4if(){fprintf(stderr, "RRR set_c4if FIX\n");}
virtual void set_eccp1if(){}
virtual void set_eeif(){}
virtual void set_errif(){}
virtual void set_irxif(){}
virtual void set_lvdif(){}
virtual void set_pspif(){}
virtual void set_rcif(){}
virtual void set_rxb0if(){}
virtual void set_rxb1if(){}
virtual void set_sspif(){}
virtual void set_tmr1if(){}
virtual void set_tmr1gif(){}
virtual void set_tmr2if(){}
virtual void set_tmr3if(){}
virtual void set_txb0if(){}
virtual void set_txb1if(){}
virtual void set_txb2if(){}
virtual void set_txif(){}
virtual void set_wakif(){}
virtual void set_usbif(){}
virtual unsigned int get_txif() { return 0;}
virtual unsigned int get_rcif() { return 0;}
virtual unsigned int get_sspif() { return 0;}
/// A generic method to set an interrupt bit by mask
virtual void set(int mask)
{
put(get() | mask);
}
/// Obtain interrupt request state, as a mask of priorities if relevant
virtual int interrupt_status();
virtual void put(unsigned int new_value);
virtual void setInterrupt(unsigned int bitMask);
virtual void setPeripheralInterrupt();
void set_intcon(INTCON *);
void set_pie(PIE *);
void set_ipr(sfr_register *);
};
//---------------------------------------------------------
// InterruptSource
class InterruptSource
{
public:
InterruptSource(PIR *_pir, unsigned int bitMask);
void Trigger();
void release(); // called when source is no longer needed.
private:
PIR *m_pir;
unsigned int m_bitMask;
};
//---------------------------------------------------------
// PIR1 Peripheral Interrupt register # 1
//
// This is version 1 of the PIR1 register - as seen on the 16f62x
class PIR1v1 : public PIR
{
public:
enum {
TMR1IF = 1<<0,
TMR2IF = 1<<1,
CCP1IF = 1<<2,
SSPIF = 1<<3,
TXIF = 1<<4,
RCIF = 1<<5,
CMIF = 1<<6, // 16f62x
EEIF = 1<<7 // 16f62x
};
virtual void set_tmr1if()
{
put(get() | TMR1IF);
}
virtual void set_tmr2if()
{
put(get() | TMR2IF);
}
virtual void set_ccpif()
{
put(get() | CCP1IF);
}
virtual void set_sspif()
{
put(get() | SSPIF);
}
virtual void set_txif();
virtual void set_rcif();
virtual void set_cmif();
virtual void set_c1if(){set_cmif();}
virtual void set_c2if(){set_cmif();}
virtual void set_eeif();
virtual unsigned int get_sspif()
{
return value.get() & SSPIF;
}
void clear_sspif();
unsigned int get_txif()
{
return value.get() & TXIF;
}
void clear_txif();
unsigned int get_rcif()
{
return value.get() & RCIF;
}
virtual void clear_rcif();
PIR1v1(Processor *pCpu, const char *pName, const char *pDesc,
INTCON *, PIE *);
};
//---------------------------------------------------------
// PIR1 Peripheral Interrupt register # 1
//
// This is version 2 of the PIR1 register - as seen on the 18xxxx devices
// and devices like the 16c63a.
class PIR1v2 : public PIR
{
public:
enum {
TMR1IF = 1<<0,
TMR2IF = 1<<1,
CCP1IF = 1<<2,
SSPIF = 1<<3,
TXIF = 1<<4,
RCIF = 1<<5,
ADIF = 1<<6, // 18cxxx
PSPIF = 1<<7
};
virtual void set_tmr1if()
{
put(get() | TMR1IF);
}
virtual void set_tmr2if()
{
put(get() | TMR2IF);
}
virtual void set_ccpif()
{
put(get() | CCP1IF);
}
virtual void set_sspif();
unsigned int get_sspif()
{
return value.get() & SSPIF;
}
virtual void clear_sspif();
virtual void set_txif();
virtual void set_rcif();
virtual void set_adif()
{
put(get() | ADIF);
}
virtual void set_pspif();
virtual unsigned int get_txif()
{
return value.get() & TXIF;
}
virtual void clear_txif();
unsigned int get_rcif()
{
return value.get() & RCIF;
}
virtual void clear_rcif();
PIR1v2(Processor *pCpu, const char *pName, const char *pDesc,
INTCON *, PIE *);
};
//---------------------------------------------------------
// PIR1 Peripheral Interrupt register # 1
//
// This is version 3 of the PIR1 register - as seen on the p16f630 devices
class PIR1v3 : public PIR
{
public:
enum {
TMR1IF = 1<<0,
TMR2IF = 1<<1, //16f684
OSFIF = 1<<2, //16f684
CMIF = 1<<3,
C1IF = 1<<3, //16f684
C2IF = 1<<4, //16f684
CCP1IF = 1<<5, //16f684
ADIF = 1<<6,
EEIF = 1<<7
};
virtual void set_tmr1if();
virtual void set_tmr2if();
virtual void set_cmif();
virtual void set_adif();
virtual void set_eeif();
virtual void set_c1if();
virtual void set_c2if();
virtual void set_ccpif() { put(get() | CCP1IF); }
PIR1v3(Processor *pCpu, const char *pName, const char *pDesc,
INTCON *, PIE *);
};
//---------------------------------------------------------
// PIR2 Peripheral Interrupt register # 2
//
// This is version 1 of the PIR1 register - as seen on the 16f62x
class PIR2v1 : public PIR
{
public:
enum
{
CCP2IF = 1<<0
};
virtual void set_ccpif()
{
put(get() | CCP2IF);
}
PIR2v1(Processor *pCpu, const char *pName, const char *pDesc,
INTCON *, PIE *);
};
//---------------------------------------------------------
// PIR2 Peripheral Interrupt register # 2
//
// This is version 2 of the PIR2 register - as seen on the 18xxxx devices
// and devices like the 16c63a.
class PIR2v2 : public PIR
{
public:
enum
{
CCP2IF = 1<<0,
ECCP1IF = 1<<0, /* only on the PIC18F4xx devices */
TMR3IF = 1<<1,
LVDIF = 1<<2,
BCLIF = 1<<3,
EEIF = 1<<4,
CMIF = 1<<6 /* PIC16F87xA, PIC18F4xx devices */
};
virtual void set_eccp1if()
{
put(get() | ECCP1IF);
}
virtual void set_ccpif() /* RP - needs to define set_ccpif too! */
{
put(get() | CCP2IF);
}
virtual void set_tmr3if()
{
put(get() | TMR3IF);
}
virtual void set_lvdif()
{
put(get() | LVDIF);
}
virtual void set_bclif();
virtual void set_eeif();
virtual void set_cmif();
virtual void set_c1if(){ set_cmif();}
virtual void set_c2if(){ set_cmif();}
PIR2v2(Processor *pCpu, const char *pName, const char *pDesc,
INTCON *, PIE *);
};
//---------------------------------------------------------
// PIR2 Peripheral Interrupt register # 3
//
// This is version 2 of the PIR2 register - as seen on the 16f88x devices
class PIR2v3 : public PIR
{
public:
enum
{
CCP2IF = 1<<0,
ULPWUIF = 1<<2,
BCLIF = 1<<3,
EEIF = 1<<4,
C1IF = 1<<5,
C2IF = 1<<6,
OSFIF = 1<<7
};
virtual void set_ccpif()
{
put(get() | CCP2IF);
}
virtual void set_bclif();
virtual void set_eeif();
virtual void set_c1if();
virtual void set_c2if();
PIR2v3(Processor *pCpu, const char *pName, const char *pDesc,
INTCON *, PIE *);
};
//---------------------------------------------------------
// PIR2 Peripheral Interrupt register # 3
//
// This is version 4 of the PIR2 register - as seen on the 18F4455 devices
class PIR2v4 : public PIR
{
public:
enum
{
CCP2IF = 1<<0,
TMR3IF = 1<<1,
HLVDIF = 1<<2,
BCLIF = 1<<3,
EEIF = 1<<4,
USBIF = 1<<5,
CMIF = 1<<6,
OSCFIF = 1<<7
};
virtual void set_ccpif(){
put(get() | CCP2IF);
}
virtual void set_tmr3if() {
put(get() | TMR3IF);
}
virtual void set_hlvdif() {
put(get() | HLVDIF);
}
virtual void set_oscfif() {
put(get() | OSCFIF);
}
virtual void set_bclif();
virtual void set_eeif();
virtual void set_usbif();
virtual void set_cmif();
virtual void set_c1if(){ set_cmif(); }
virtual void set_c2if(){ set_cmif(); }
PIR2v4(Processor *pCpu, const char *pName, const char *pDesc,
INTCON *, PIE *);
};
//---------------------------------------------------------
// PIR2 Peripheral Interrupt register # 3
//
// This is version 1 of the PIR3 register - as seen on the 18F6520 devices
class PIR3v1 : public PIR
{
public:
enum
{
CCP3IF = 1<<0,
CCP4IF = 1<<1,
CCP5IF = 1<<2,
TMR4IF = 1<<3,
TXIF = 1<<4,
RCIF = 1<<5
};
virtual void set_ccpif() /* RP - needs to define set_ccpif too! */
{
put(get() | CCP3IF);
}
virtual void set_tmr2if()
{
put(get() | TMR4IF);
}
virtual void set_txif();
virtual void set_rcif();
virtual unsigned int get_txif()
{
return value.get() & TXIF;
}
virtual void clear_txif();
unsigned int get_rcif()
{
return value.get() & RCIF;
}
virtual void clear_rcif();
PIR3v1(Processor *pCpu, const char *pName, const char *pDesc,
INTCON *, PIE *);
};
//---------------------------------------------------------
// PIR2 Peripheral Interrupt register # 3
//
// This is version 2 of the PIR3 register - as seen on the 18F248 devices
// Perhaps other devices too - it contains bits for the CAN device
class PIR3v2 : public PIR
{
public:
enum
{
RXB0IF = 1<<0,
RXB1IF = 1<<1,
TXB0IF = 1<<2,
TXB1IF = 1<<3,
TXB2IF = 1<<4,
ERRIF = 1<<5,
WAKIF = 1<<6,
IRXIF = 1<<7
};
virtual void set_rxb0if()
{
put(get() | RXB0IF);
}
virtual void set_rxb1if()
{
put(get() | RXB1IF);
}
virtual void set_txb0if()
{
put(get() | TXB0IF);
}
virtual void set_txb1if()
{
put(get() | TXB1IF);
}
virtual void set_txb2if()
{
put(get() | TXB2IF);
}
virtual void set_errif()
{
put(get() | ERRIF);
}
virtual void set_wakif()
{
put(get() | WAKIF);
}
virtual void set_irxif()
{
put(get() | IRXIF);
}
PIR3v2(Processor *pCpu, const char *pName, const char *pDesc,
INTCON *, PIE *);
};
/*
* PIR_SET defines an interface to some common interrupt capabilities.
* PIR_SET is a pure virtual class - you must instantiate a more specific
* version of PIR_SET.
*
* The idea behind PIR_SET is to hide the location of the interrupt bits.
* in some cases, a bit might be in PIR1, in others it might be in PIR2.
* Instead of accessing the register directly, you go through PIR_SET
* and it will find the proper PIR register.
*/
class PIR_SET
{
public:
virtual ~PIR_SET()
{
}
virtual int interrupt_status()
{
return 0;
}
// uart stuff
virtual bool get_txif()
{
return false;
}
virtual void set_txif() {}
virtual void clear_txif() {}
virtual bool get_rcif()
{
return false;
}
virtual void set_rcif() {}
virtual void clear_rcif() {}
// ssp stuff
virtual bool get_sspif()
{
return false;
}
virtual void clear_sspif() {}
virtual void set_sspif() {}
virtual void set_bclif() {}
virtual void set_pspif() {}
virtual void set_cmif() {}
virtual void set_c1if() {}
virtual void set_c2if() {}
virtual void set_c3if() {}
virtual void set_c4if() {}
// eeprom stuff
virtual void set_eeif() {}
// CCP stuff
virtual void set_ccpif() {}
// Timer stuff
virtual void set_tmr1if() {}
virtual void set_tmr1gif() {}
virtual void set_tmr2if() {}
virtual void set_adif() {}
};
//----------------------------------------
// Supports 1 or 2 Pir version 1 registers
class PIR_SET_1 : public PIR_SET
{
public:
PIR_SET_1() { pir1 = 0; pir2 = 0; }
virtual ~PIR_SET_1()
{
}
void set_pir1(PIR *p1) { pir1 = p1; }
void set_pir2(PIR *p2) { pir2 = p2; }
virtual int interrupt_status() {
assert(pir1 != 0);
if (pir2 != 0)
return (pir1->interrupt_status() |
pir2->interrupt_status());
else
return (pir1->interrupt_status());
}
// uart stuff
virtual bool get_txif() {
assert(pir1 != 0);
return (pir1->get_txif() != 0);
}
virtual void set_txif() {
assert(pir1 != 0);
pir1->set_txif();
}
virtual void clear_txif() {
assert(pir1 != 0);
pir1->clear_txif();
}
virtual bool get_rcif() {
assert(pir1 != 0);
return (pir1->get_rcif() != 0);
}
virtual void set_rcif() {
assert(pir1 != 0);
pir1->set_rcif();
}
virtual void clear_rcif() {
assert(pir1 != 0);
pir1->clear_rcif();
}
// ssp stuff
virtual bool get_sspif() {
assert(pir1 != 0);
return (pir1->get_sspif() != 0);
}
virtual void set_sspif() {
assert(pir1 != 0);
pir1->set_sspif();
}
virtual void clear_sspif() {
assert(pir1 != 0);
pir1->clear_sspif();
}
// eeprom stuff
virtual void set_eeif() {
assert(pir1 != 0);
pir1->set_eeif();
}
// CCP stuff
virtual void set_ccpif() {
assert(pir1 != 0);
pir1->set_ccpif();
}
// Timer stuff
virtual void set_tmr1if() {
assert(pir1 != 0);
pir1->set_tmr1if();
}
virtual void set_tmr2if() {
assert(pir1 != 0);
pir1->set_tmr2if();
}
// A/D stuff - not part of base PIR_SET class
virtual void set_adif() {
assert(pir1 != 0);
pir1->set_adif();
}
// Comparator
virtual void set_cmif() {
assert(pir1 != 0);
pir1->set_cmif();
}
virtual void set_c1if() {
assert(pir1 != 0);
pir1->set_c1if();
}
virtual void set_c2if() {
assert(pir1 != 0);
pir1->set_c2if();
}
virtual void set_c3if() {
assert(pir1 != 0);
pir1->set_c3if();
}
virtual void set_c4if() {
assert(pir1 != 0);
pir1->set_c4if();
}
private:
PIR *pir1;
PIR *pir2;
};
// Supports 1, 2 or 3 version 2 Pir registers
class PIR_SET_2 : public PIR_SET
{
public:
PIR_SET_2() { pir1 = 0; pir2 = 0; pir3 = 0; }
virtual ~PIR_SET_2()
{
}
void set_pir1(PIR *p1) { pir1 = p1; }
void set_pir2(PIR *p2) { pir2 = p2; }
void set_pir3(PIR *p3) { pir3 = p3; }
virtual int interrupt_status() {
assert(pir1 != 0);
int result = pir1->interrupt_status();
if ( pir2 != 0 )
result |= pir2->interrupt_status();
if ( pir3 != 0 )
result |= pir3->interrupt_status();
return result;
}
// uart stuff
virtual bool get_txif() {
assert(pir1 != 0);
return (pir1->get_txif() != 0);
}
virtual void set_txif() {
assert(pir1 != 0);
pir1->set_txif();
}
virtual void clear_txif() {
assert(pir1 != 0);
pir1->clear_txif();
}
virtual bool get_rcif() {
assert(pir1 != 0);
return (pir1->get_rcif() != 0);
}
virtual void set_rcif() {
assert(pir1 != 0);
pir1->set_rcif();
}
virtual void clear_rcif() {
assert(pir1 != 0);
pir1->clear_rcif();
}
// ssp stuff
virtual bool get_sspif() {
assert(pir1 != 0);
return (pir1->get_sspif() != 0);
}
virtual void set_sspif() {
assert(pir1 != 0);
pir1->set_sspif();
}
virtual void clear_sspif() {
assert(pir1 != 0);
pir1->clear_sspif();
}
// eeprom stuff
virtual void set_eeif() {
assert(pir2 != 0);
pir2->set_eeif();
}
// CCP stuff
virtual void set_ccpif() {
assert(pir1 != 0);
pir1->set_ccpif();
}
// Timer stuff
virtual void set_tmr1if() {
assert(pir1 != 0);
pir1->set_tmr1if();
}
virtual void set_tmr1gif() {
assert(pir1 != 0);
pir1->set_tmr1gif();
}
virtual void set_tmr2if() {
assert(pir1 != 0);
pir1->set_tmr2if();
}
// A/D stuff - not part of base PIR_SET class
virtual void set_adif() {
assert(pir1 != 0);
pir1->set_adif();
}
// Comparator
virtual void set_cmif() {
assert(pir2 != 0);
pir2->set_cmif();
}
virtual void set_c1if() {
assert(pir2 != 0);
pir2->set_c1if();
}
virtual void set_c2if() {
assert(pir2 != 0);
pir2->set_c2if();
}
virtual void set_c3if() {
assert(pir2 != 0);
pir2->set_c3if();
}
virtual void set_c4if() {
assert(pir2 != 0);
pir2->set_c4if();
}
// I2C master
virtual void set_bclif() {
assert(pir2 != 0);
pir2->set_bclif();
}
// Parallel Slave Port
virtual void set_pspif() {
assert(pir1 != 0);
pir1->set_pspif();
}
private:
PIR *pir1;
PIR *pir2;
PIR *pir3;
};
#endif /* PIR_H */
|