libElysianVMU 1.6.0
Full-featured, accurate, cross-platform library emulating the Dreamcast's Visual Memory Unit
Loading...
Searching...
No Matches
evmu_pic.h
Go to the documentation of this file.
1/*! \file
2 * \brief EvmuPic programmable interrupt controller peripheral
3 * \ingroup peripherals
4 *
5 * This file models the programmable interrupt controller of the VMU.
6 *
7 * \todo
8 * - shouldn't update be private?
9 *
10 * \author 2023 Falco Girgis
11 * \copyright MIT License
12 */
13
14#ifndef EVMU_PIC_H
15#define EVMU_PIC_H
16
17#include <stdint.h>
18#include "../types/evmu_peripheral.h"
19#include <gimbal/meta/signals/gimbal_signal.h>
20
21/*! \name Type System
22 * \brief Type UUID and cast operators
23 * @{
24 */
25#define EVMU_PIC_TYPE (GBL_TYPEID(EvmuPic)) //!< Type UUID for EvmuPic
26#define EVMU_PIC(self) (GBL_CAST(EvmuPic, self)) //!< Function-style GblInstance cast
27#define EVMU_PIC_CLASS(klass) (GBL_CLASS_CAST(EvmuPic, klass)) //!< Function-style GblClass cast
28#define EVMU_PIC_GET_CLASS(self) (GBL_CLASSOF(EvmuPic, self)) //!< Get EvmuPicClass from GblInstance
29//! @}
30
31#define EVMU_PIC_NAME "pic" //!< EvmuPic GblObject name
32
33/*! \defgroup isrs Interrupt Service Routines
34 * \brief Entry addresses for each interrupt
35 * @{
36 */
37#define EVMU_ISR_ADDR_RESET 0x00 //!< Reset ISR address
38#define EVMU_ISR_ADDR_EXT_INT0 0x03 //!< INT0 interrupt (external) ISR address
39#define EVMU_ISR_ADDR_EXT_INT1 0x0b //!< INT1 interrupt (external) ISR address
40#define EVMU_ISR_ADDR_EXT_INT2_T0L 0x13 //!< INT2 interrupt (external) or T0L overflow ISR address
41#define EVMU_ISR_ADDR_EXT_INT3_TBASE 0x1b //!< INT3 interrupt (external) or Base Timer overflow ISR address
42#define EVMU_ISR_ADDR_T0H 0x23 //!< T0H overflow ISR address
43#define EVMU_ISR_ADDR_T1 0x2b //!< T1H or T1L overflow ISR address
44#define EVMU_ISR_ADDR_SIO0 0x33 //!< SIO0 ISR address
45#define EVMU_ISR_ADDR_SIO1 0x3b //!< SI01 ISR address
46#define EVMU_ISR_ADDR_RFB 0x43 //!< RFB interrupt (VMU<->VMU receive/detect) ISR address
47#define EVMU_ISR_ADDR_P3 0x4b //!< P3 interrupt ISR address
48#define EVMU_ISR_ADDR_11 0x4f //!< ISR 11 Address (undocumented/unused?)
49#define EVMU_ISR_ADDR_12 0x52 //!< ISR 12 Address (undocumented/unused?)
50#define EVMU_ISR_ADDR_13 0x55 //!< ISR 13 Address (undocumented/unused?)
51#define EVMU_ISR_ADDR_14 0x5a //!< ISR 14 Address (undocumented/unused?)
52#define EVMU_ISR_ADDR_15 0x5d //!< ISR 15 Address (undocumented/unused?)
53//! @}
54
55#define GBL_SELF_TYPE EvmuPic
56
57GBL_DECLS_BEGIN
58
59GBL_FORWARD_DECLARE_STRUCT(EvmuPic);
60
61//! Enumeration of all the different IRQ types
62GBL_DECLARE_ENUM(EVMU_IRQ) {
63 EVMU_IRQ_RESET, //!< Reset
66 EVMU_IRQ_EXT_INT2_T0L, //!< INT2 or T0L overflow
67 EVMU_IRQ_EXT_INT3_TBASE, //!< INT3 or TBase overflow
68 EVMU_IRQ_T0H, //!< TOH Overflow
69 EVMU_IRQ_T1, //!< T1H or T1L overflow
70 EVMU_IRQ_SIO0, //!< SIO0
71 EVMU_IRQ_SIO1, //!< SI01
72 EVMU_IRQ_RFB, //!< Maple
73 EVMU_IRQ_P3, //!< Port 3
74 EVMU_IRQ_11, //!< ISR 11 (?)
75 EVMU_IRQ_12, //!< ISR 12 (?)
76 EVMU_IRQ_13, //!< ISR 13 (?)
77 EVMU_IRQ_14, //!< ISR 14 (?)
78 EVMU_IRQ_15, //!< ISR 15 (?)
79 EVMU_IRQ_COUNT //!< Number of ISRs (16)
80};
81
82//! All available interrupt priority levels
83GBL_DECLARE_ENUM(EVMU_IRQ_PRIORITY) {
87 EVMU_IRQ_PRIORITY_COUNT, //!< Number of levels
88 EVMU_IRQ_PRIORITY_NONE //!< No level (not valid)
89};
90
91//! Mask of EVMU_IRQ values shifted and OR'd into a single mask
92typedef uint16_t EvmuIrqMask;
93
94/*! \struct EvmuPicClass
95 * \extends EvmuPeripheralClass
96 * \brief GblClass structure for EvmuPic
97 *
98 * Provides overridable virtual methods for polling for
99 * interrupts as well as for accepting single interrupts.
100 *
101 * \sa EvmuPic
102 */
103GBL_CLASS_DERIVE(EvmuPic, EvmuPeripheral)
104 //! Activates any pending IRQs if there's a slot available
105 EVMU_RESULT (*pFnPoll) (GBL_SELF);
106 //! Called whenever a single IRQ has been activated/accepted
107 EVMU_RESULT (*pFnAccept)(GBL_SELF, EVMU_IRQ irq);
108GBL_CLASS_END
109
110/*! \struct EvmuPic
111 * \extends EvmuPeripheral
112 * \ingroup peripherals
113 * \brief GblInstance structure for EvmuPic
114 *
115 * Contains no public members.
116 *
117 * \sa EvmuPicClass
118 */
119GBL_INSTANCE_DERIVE_EMPTY (EvmuPic, EvmuPeripheral)
120
121//! \cond
122GBL_PROPERTIES(EvmuPic,
123 (irqEnabledMask, GBL_GENERIC, (READ), GBL_UINT16_TYPE),
124 (irqPendingMask, GBL_GENERIC, (READ), GBL_UINT16_TYPE),
125 (irqActiveMask, GBL_GENERIC, (READ), GBL_UINT16_TYPE),
126 (irqActiveTop, GBL_GENERIC, (READ), GBL_ENUM_TYPE),
127 (irqActiveTopPriority, GBL_GENERIC, (READ), GBL_UINT8_TYPE),
128 (irqActiveDepth, GBL_GENERIC, (READ), GBL_UINT8_TYPE),
129 (processInstruction, GBL_GENERIC, (READ), GBL_BOOL_TYPE)
130)
131
132GBL_SIGNALS(EvmuPic,
133 (irqChanged, (GBL_INSTANCE, pReceiver), (GBL_FLAGS, irqsActive))
134)
135//! \endcond
136
137//! Returns the GblType UUID associated with EvmuPic
138EVMU_EXPORT GblType EvmuPic_type (void) GBL_NOEXCEPT;
139//! Static method returning the corresponding ISR address for a given interrupt routine
141
142/*! \name Interrupt Queries
143 * \brief Methods for querying interrupt information
144 * \relatesalso EvmuPic
145 * @{
146 */
147//! Returns the interrupt priority level currently configured for the routine given by \p irq
149//! Returns a mask of all of the IRQs which are enabled for the priority level given by \p priority
151//! Returns a mask of all the active interrupt routines, at any priority level or depth
153//! Returns the depth of the current active interrupt routine (or 0 if there isn't one)
154EVMU_EXPORT size_t EvmuPic_irqsActiveDepth (GBL_CSELF) GBL_NOEXCEPT;
155//! @}
156
157/*! \name Interrupt Processing
158 * \brief Methods for processing interrupts
159 * \relatesalso EvmuPic
160 * @{
161 */
162//! Raises an interrupt request for the given \p irq
163EVMU_EXPORT void EvmuPic_raiseIrq (GBL_SELF, EVMU_IRQ irq) GBL_NOEXCEPT;
164//! Checks whether any pending IRQs can be serviced, activating them if so
165EVMU_EXPORT GblBool EvmuPic_update (GBL_SELF) GBL_NOEXCEPT;
166//! @}
167
168GBL_DECLS_END
169
170#undef GBL_SELF_TYPE
171
172#endif // EVMU_PIC_H
#define EVMU_EXPORT
Define used for adding attributes to export public symbols.
Definition evmu_api.h:18
#define EVMU_INLINE
Define used for inlining a funcion within a C header file.
Definition evmu_api.h:20
uint16_t EvmuIrqMask
Mask of EVMU_IRQ values shifted and OR'd into a single mask.
Definition evmu_pic.h:92
EVMU_IRQ
Definition evmu_pic.h:62
@ EVMU_IRQ_EXT_INT1
INT1.
Definition evmu_pic.h:65
@ EVMU_IRQ_EXT_INT2_T0L
INT2 or T0L overflow.
Definition evmu_pic.h:66
@ EVMU_IRQ_T1
T1H or T1L overflow.
Definition evmu_pic.h:69
@ EVMU_IRQ_EXT_INT0
INT0.
Definition evmu_pic.h:64
@ EVMU_IRQ_P3
Port 3.
Definition evmu_pic.h:73
@ EVMU_IRQ_13
ISR 13 (?)
Definition evmu_pic.h:76
@ EVMU_IRQ_T0H
TOH Overflow.
Definition evmu_pic.h:68
@ EVMU_IRQ_15
ISR 15 (?)
Definition evmu_pic.h:78
@ EVMU_IRQ_SIO0
SIO0.
Definition evmu_pic.h:70
@ EVMU_IRQ_RFB
Maple.
Definition evmu_pic.h:72
@ EVMU_IRQ_RESET
Reset.
Definition evmu_pic.h:63
@ EVMU_IRQ_14
ISR 14 (?)
Definition evmu_pic.h:77
@ EVMU_IRQ_SIO1
SI01.
Definition evmu_pic.h:71
@ EVMU_IRQ_COUNT
Number of ISRs (16)
Definition evmu_pic.h:79
@ EVMU_IRQ_EXT_INT3_TBASE
INT3 or TBase overflow.
Definition evmu_pic.h:67
@ EVMU_IRQ_11
ISR 11 (?)
Definition evmu_pic.h:74
@ EVMU_IRQ_12
ISR 12 (?)
Definition evmu_pic.h:75
GblType EvmuPic_type(void)
Returns the GblType UUID associated with EvmuPic.
static EvmuAddress EvmuPic_isrAddress(EVMU_IRQ irq)
Static method returning the corresponding ISR address for a given interrupt routine.
EVMU_IRQ_PRIORITY
Definition evmu_pic.h:83
@ EVMU_IRQ_PRIORITY_LOW
Low.
Definition evmu_pic.h:84
@ EVMU_IRQ_PRIORITY_COUNT
Number of levels.
Definition evmu_pic.h:87
@ EVMU_IRQ_PRIORITY_HIGHEST
Highest.
Definition evmu_pic.h:86
@ EVMU_IRQ_PRIORITY_HIGH
High.
Definition evmu_pic.h:85
@ EVMU_IRQ_PRIORITY_NONE
No level (not valid)
Definition evmu_pic.h:88
uint32_t EvmuAddress
Represents a generic absolute address.
#define GBL_ENUM_TYPE
#define GBL_UINT16_TYPE
#define GBL_BOOL_TYPE
#define GBL_UINT8_TYPE
#define GBL_PROPERTIES(object,...)
uint8_t GblBool
uintptr_t GblType
GblInstance structure for EvmuPic.
Definition evmu_pic.h:119
size_t EvmuPic_irqsActiveDepth(const EvmuPic *pSelf)
Returns the depth of the current active interrupt routine (or 0 if there isn't one)
GblBool EvmuPic_update(EvmuPic *pSelf)
Checks whether any pending IRQs can be serviced, activating them if so.
EvmuIrqMask EvmuPic_irqsEnabledByPriority(const EvmuPic *pSelf, EVMU_IRQ_PRIORITY priority)
Returns a mask of all of the IRQs which are enabled for the priority level given by priority.
void EvmuPic_raiseIrq(EvmuPic *pSelf, EVMU_IRQ irq)
Raises an interrupt request for the given irq.
EvmuIrqMask EvmuPic_irqsActive(const EvmuPic *pSelf)
Returns a mask of all the active interrupt routines, at any priority level or depth.
EVMU_IRQ_PRIORITY EvmuPic_irqPriority(const EvmuPic *pSelf, EVMU_IRQ irq)
Returns the interrupt priority level currently configured for the routine given by irq.
#define GBL_CLASS_CAST(cType, klass)
#define GBL_CLASSOF(cType, self)
#define GBL_CAST(cType, self)