feat: add lab-rv32i-c-interrupts card
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
#ifndef C10_COMMON_H
|
||||
#define C10_COMMON_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "hazard3_csr.h"
|
||||
#include "tb_cxxrtl_io.h"
|
||||
|
||||
#define MSTATUS_MIE UINT32_C(0x00000008)
|
||||
#define MIE_MSIE UINT32_C(0x00000008)
|
||||
#define MIP_MSIP UINT32_C(0x00000008)
|
||||
#define MACHINE_ECALL_CAUSE UINT32_C(0x0000000b)
|
||||
#define MACHINE_SOFTWARE_IRQ_CAUSE UINT32_C(0x80000003)
|
||||
|
||||
static inline void c10_global_irq_enable(bool enable)
|
||||
{
|
||||
if (enable)
|
||||
set_csr(mstatus, MSTATUS_MIE);
|
||||
else
|
||||
clear_csr(mstatus, MSTATUS_MIE);
|
||||
}
|
||||
|
||||
static inline void c10_software_irq_enable(bool enable)
|
||||
{
|
||||
if (enable)
|
||||
set_csr(mie, MIE_MSIE);
|
||||
else
|
||||
clear_csr(mie, MIE_MSIE);
|
||||
}
|
||||
|
||||
static inline void c10_disable_interrupts(void)
|
||||
{
|
||||
c10_global_irq_enable(false);
|
||||
c10_software_irq_enable(false);
|
||||
tb_clr_softirq(0);
|
||||
}
|
||||
|
||||
static inline void c10_settle(void)
|
||||
{
|
||||
for (uint32_t i = 0; i < 32u; ++i)
|
||||
__asm__ volatile("nop");
|
||||
}
|
||||
|
||||
static inline bool c10_wait_for(volatile uint32_t *value, uint32_t expected)
|
||||
{
|
||||
for (uint32_t i = 0; i < 100000u; ++i) {
|
||||
if (*value == expected)
|
||||
return true;
|
||||
__asm__ volatile("wfi");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline void c10_report(const char *label, uint32_t value)
|
||||
{
|
||||
tb_puts(label);
|
||||
tb_put_u32(value);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user