aboutsummaryrefslogtreecommitdiffstats
path: root/z80irq.h
blob: c221da5e12810e1242527fa8c146e0ca9cfc8e9c (plain)
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
#ifndef Z80IRQ_H
#define Z80IRQ_H

#include "compiler.h"

struct z80_irq;
typedef int (*irq_func) (struct z80_irq * irq);

struct z80_irq {
    irq_func intack;
    irq_func eoi;
    void *pvt;                  /* Available for user */
    int16_t vector;             /* Available for user if intack defined */
    uint8_t prio;               /* Priority level */
    bool handled;               /* In handler (between INTACK and EOI) */
};

#define IRQ(prio, intack, eoi, pvt) \
    { (intack), (eoi), (pvt), -1, (prio), false }

#define MAX_IRQ 32

extern atomic_uint irq_pending;
extern unsigned int irq_mask;   /* 0 = inside handler (irq->handled == true) */

static inline bool poll_irq(void)
{
    return unlikely(irq_pending & irq_mask);
}

void z80_register_irq(struct z80_irq *irq);
int z80_intack(void);
void z80_eoi(void);
static inline void z80_interrupt(struct z80_irq *irq)
{
    atomic_fetch_or(&irq_pending, 1U << irq->prio);
}

static inline void z80_clear_interrupt(struct z80_irq *irq)
{
    atomic_fetch_and(&irq_pending, ~(1U << irq->prio));
}

#endif /* Z80IRQ_H */