FabGL
ESP32 Display Controller and Graphics Library
PIC8259.h
1/*
2 Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - <http://www.fabgl.com>
3 Copyright (c) 2019-2022 Fabrizio Di Vittorio.
4 All rights reserved.
5
6
7* Please contact fdivitto2013@gmail.com if you need a commercial license.
8
9
10* This library and related software is available under GPL v3.
11
12 FabGL is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
16
17 FabGL is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with FabGL. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26
27#pragma once
28
29#include "fabgl.h"
30
31
32
33namespace fabgl {
34
35
36// PIC 8259 (Programmable Interrupt Controller)
37
38// Limitations:
39// - only 8086 mode
40// - only single mode
41// - don't care about input level or edge
42// - don't care about buffered mode or unbuffered mode
43// - don't support special fully nested mode
44// - priority is fixed to IR0 = highest
45// - don't support Poll command
46// - don't support Special Mask
47
48
49
50class PIC8259 {
51
52public:
53
54 void reset();
55
56 void write(int addr, uint8_t value);
57 uint8_t read(int addr);
58
59 // Device->8259: a device reports interrupt to 8259
60 bool signalInterrupt(int intnum);
61
62 // 8259->CPU: 8259 reports interrupt to CPU
63 bool pendingInterrupt() { return m_pendingInterrupt; }
64
65 // 8259->CPU: 8259 reports interrupt number to CPU
66 int pendingInterruptNum() { return m_baseVector | m_pendingIR; }
67
68 // CPU->8259: CPU acks the pending interrupt to 8259
69 void ackPendingInterrupt();
70
71
72private:
73
74 void performEOI();
75 int getHighestPriorityBitNum(uint8_t value);
76 void setPendingInterrupt();
77
78 uint8_t m_state; // all zeros = ready, bit 0 = waiting for ICW2, bit 1 = waiting for ICW3, bit 2 = waiting for ICW4
79
80 uint8_t m_baseVector; // bits 3..7 got from ICW2
81 bool m_autoEOI;
82
83 uint8_t m_IRR; // Interrupt Request Register
84 uint8_t m_ISR; // In-Service Register
85 uint8_t m_IMR; // Interrupt Mask Register
86
87 // if true port 0 reads ISR, otherwise port 0 reads IRR
88 bool m_readISR;
89
90 bool m_pendingInterrupt;
91 uint8_t m_pendingIR;
92
93};
94
95
96} // namespace fabgl
This file is the all in one include file. Application can just include this file to use FabGL library...