/*
 ******************************************************************************************
 * @file		irq.h
 * @author		GowinSemicoductor
 * @device		Gowin_PicoRV32
 * @brief		Interrupt Request.
 ******************************************************************************************
 */

#ifndef IRQ_H
#define IRQ_H

/* Includes ------------------------------------------------------------------------- */
#include <stdint.h>


/* Declarations --------------------------------------------------------------------- */
uint32_t *irq(uint32_t *regs, uint32_t irqs);
uint32_t set_timer(uint32_t timer_val)  __attribute__((optimize("O0")));
uint32_t mask_irq(uint32_t mask)  __attribute__((optimize("O0")));

#define INTNUM_TIMER 0                              /* 32-bit timer interrupt */
#define INTNUM_EBREAK 1                             /* Execute debug breakpoint instruction (ebreak) */
#define INTNUM_MISALIGNED_INSTRUCTION 2             /* Misalignment access error of memory (bus error) */
#define INTNUM_ILLEGAL_INSTRUCTION 3                /* Illegal instruction error */
#define INTNUM_DEBUG 4                              /* Debug module interrupt */
#define INTNUM_STACK 5                              /* Hardware stack protection interrupt */
#define INTNUM_WB_SPIMASTER 10                      /* Wishbone SPI Master interrupt */
#define INTNUM_WB_SPISLAVE 11                       /* Wishbone SPI Slave interrupt */
#define INTNUM_WB_I2CMASTER 12                      /* Wishbone I2C Master interrupt */
#define INTNUM_WB_UART 13                           /* Wishbone UART interrupt */
#define INTNUM_USER0 20                             /* User interrupt 0 */
#define INTNUM_USER1 21                             /* User interrupt 1 */
#define INTNUM_USER2 22                             /* User interrupt 2 */
#define INTNUM_USER3 23                             /* User interrupt 3 */
#define INTNUM_USER4 24                             /* User interrupt 4 */
#define INTNUM_USER5 25                             /* User interrupt 5 */
#define INTNUM_USER6 26                             /* User interrupt 6 */
#define INTNUM_USER7 27                             /* User interrupt 7 */
#define INTNUM_USER8 28                             /* User interrupt 8 */
#define INTNUM_USER9 29                             /* User interrupt 9 */
#define INTNUM_USER10 30                            /* User interrupt 10 */
#define INTNUM_USER11 31                            /* User interrupt 11 */

void irq_enable_one_bit(uint32_t irq_num);
void irq_disable_one_bit(uint32_t irq_num);

void enable_external_interrupt(void);
void disable_external_interrupt(void);

void enable_timer_interrupt(void);
void disable_timer_interrupt(void);

void enable_interrupt_global(void);
void disable_interrupt_global(void);

#endif
