#ifndef IRQ_H
#define IRQ_H

#include "picorv32.h"

typedef void (*irqhandler_t)(unsigned int vector);
extern irqhandler_t __irq_handler_table[];

#define IRQHANDLER(x) \
  void irqhandler_ ##x (unsigned int); \
  void irqhandler_ ##x (unsigned int vector __attribute__((unused)))

static inline unsigned int mask_irq(unsigned int vector)
{
    const unsigned int mask = 1U << vector;
    return p_maskirq(mask, ~mask);
}
static inline unsigned int unmask_irq(unsigned int vector)
{
    const unsigned int mask = 1U << vector;
    return p_maskirq(0, ~mask);
}
static inline unsigned int irqmask(void)
{
    return p_maskirq(0, ~0);
}

#endif /* IRQ_H */
