cores/cpu/naxriscv: Add baremetal IRQ support
This commit is contained in:
parent
e03b097e8e
commit
d4c1a10817
|
@ -93,7 +93,7 @@ class NaxRiscv(CPU):
|
||||||
def gcc_flags(self):
|
def gcc_flags(self):
|
||||||
flags = f" -march={NaxRiscv.get_arch()} -mabi={NaxRiscv.get_abi()}"
|
flags = f" -march={NaxRiscv.get_arch()} -mabi={NaxRiscv.get_abi()}"
|
||||||
flags += f" -D__NaxRiscv__"
|
flags += f" -D__NaxRiscv__"
|
||||||
flags += f" -DUART_POLLING"
|
flags += f" -D__riscv_plic__"
|
||||||
return flags
|
return flags
|
||||||
|
|
||||||
# Reserved Interrupts.
|
# Reserved Interrupts.
|
||||||
|
|
|
@ -113,8 +113,10 @@ bss_loop:
|
||||||
j bss_loop
|
j bss_loop
|
||||||
bss_done:
|
bss_done:
|
||||||
|
|
||||||
li a0, 0x880 //880 enable timer + external interrupt sources (until mstatus.MIE is set, they will never trigger an interrupt)
|
call plic_init // initialize external interrupt controller
|
||||||
csrw mie,a0
|
li t0, 0x800 // external interrupt sources only (using LiteX timer);
|
||||||
|
// NOTE: must still enable mstatus.MIE!
|
||||||
|
csrw mie,t0
|
||||||
|
|
||||||
call main
|
call main
|
||||||
infinit_loop:
|
infinit_loop:
|
||||||
|
|
|
@ -9,30 +9,40 @@ extern "C" {
|
||||||
#include <generated/csr.h>
|
#include <generated/csr.h>
|
||||||
#include <generated/soc.h>
|
#include <generated/soc.h>
|
||||||
|
|
||||||
|
// NaxRiscv uses a Platform-Level Interrupt Controller (PLIC) which
|
||||||
|
// is programmed and queried via a set of MMIO registerss
|
||||||
|
|
||||||
|
#define PLIC_BASE 0xf0c00000L // Base address and per-pin priority array
|
||||||
|
#define PLIC_PENDING 0xf0c01000L // Bit field matching currently pending pins
|
||||||
|
#define PLIC_ENABLED 0xf0c02000L // Bit field corresponding to the current mask
|
||||||
|
#define PLIC_THRSHLD 0xf0e00000L // Per-pin priority must be >= this to trigger
|
||||||
|
#define PLIC_CLAIM 0xf0e00004L // Claim & completion register address
|
||||||
|
|
||||||
|
#define PLIC_EXT_IRQ_BASE 0
|
||||||
|
|
||||||
static inline unsigned int irq_getie(void)
|
static inline unsigned int irq_getie(void)
|
||||||
{
|
{
|
||||||
return 0;
|
return (csrr(mstatus) & CSR_MSTATUS_MIE) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void irq_setie(unsigned int ie)
|
static inline void irq_setie(unsigned int ie)
|
||||||
{
|
{
|
||||||
|
if(ie) csrs(mstatus,CSR_MSTATUS_MIE); else csrc(mstatus,CSR_MSTATUS_MIE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned int irq_getmask(void)
|
static inline unsigned int irq_getmask(void)
|
||||||
{
|
{
|
||||||
|
return *((unsigned int *)PLIC_ENABLED) >> PLIC_EXT_IRQ_BASE;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void irq_setmask(unsigned int mask)
|
static inline void irq_setmask(unsigned int mask)
|
||||||
{
|
{
|
||||||
|
*((unsigned int *)PLIC_ENABLED) = mask << PLIC_EXT_IRQ_BASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned int irq_pending(void)
|
static inline unsigned int irq_pending(void)
|
||||||
{
|
{
|
||||||
return 0;
|
return *((unsigned int *)PLIC_PENDING) >> PLIC_EXT_IRQ_BASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
Loading…
Reference in New Issue