Feat: lab 3 w/o adv 2
This commit is contained in:
@@ -1,58 +1,45 @@
|
||||
#include <interrupt.h>
|
||||
#include <uart.h>
|
||||
#include <timer.h>
|
||||
#include <utils.h>
|
||||
#include <logger.h>
|
||||
#include <errcode.h>
|
||||
|
||||
#define CORE0_TIMER_IRQ_CTRL ((volatile uint32_t *)0x40000040)
|
||||
#define CORE0_IRQ_SOURCE ((volatile uint32_t *)0x40000060)
|
||||
|
||||
static inline
|
||||
void _enable_interrupt(void)
|
||||
{ W_SYSREG_IMM(DAIFClr, 0xf); }
|
||||
|
||||
static inline
|
||||
void _disable_interrupt(void)
|
||||
{ W_SYSREG_IMM(DAIFSet, 0xf); }
|
||||
|
||||
MMIO_W_HELPER(_enable_timer_irq, CORE0_TIMER_IRQ_CTRL, 0x1, 1);
|
||||
|
||||
MMIO_R_HELPER(_irq_source_timer, CORE0_IRQ_SOURCE, 0x1, 1);
|
||||
MMIO_R_HELPER(_irq_source_uart, CORE0_IRQ_SOURCE, 0x1, 8);
|
||||
|
||||
void init_interrupt(void)
|
||||
{
|
||||
uint64_t cntfrq_el0;
|
||||
W_SYSREG(cntp_ctl_el0, 1);
|
||||
R_SYSREG(cntfrq_el0, cntfrq_el0);
|
||||
W_SYSREG(cntp_tval_el0, cntfrq_el0);
|
||||
|
||||
*CORE0_TIMER_IRQ_CTRL = 0x2;
|
||||
}
|
||||
|
||||
static inline
|
||||
void _uart_irq_handler(void)
|
||||
{
|
||||
DEBUG_EXCEP("uart irq");
|
||||
}
|
||||
|
||||
static inline
|
||||
void _timer_irq_handler(void)
|
||||
{
|
||||
LOG("timer irq");
|
||||
|
||||
uint64_t cntpct_el0;
|
||||
R_SYSREG(cntpct_el0, cntpct_el0);
|
||||
DEBUG_EXCEP(cntpct_el0);
|
||||
|
||||
uint64_t cntfrq_el0;
|
||||
R_SYSREG(cntfrq_el0, cntfrq_el0);
|
||||
W_SYSREG(cntp_tval_el0, cntfrq_el0);
|
||||
_enable_timer_irq(true);
|
||||
_enable_interrupt();
|
||||
}
|
||||
|
||||
void irq_handler(void)
|
||||
{
|
||||
LOG("irq caught");
|
||||
uint64_t irq_source = *CORE0_IRQ_SOURCE;
|
||||
DEBUG_EXCEP(irq_source);
|
||||
// uint64_t core0_irq_source = *CORE0_IRQ_SOURCE;
|
||||
// DEBUG_EXCEP(core0_irq_source);
|
||||
|
||||
*CORE0_TIMER_IRQ_CTRL = 0x0;
|
||||
if (irq_source & GPU_INT)
|
||||
_uart_irq_handler();
|
||||
if (irq_source & CNTPNSIRQ_INT)
|
||||
_timer_irq_handler();
|
||||
if (_irq_source_timer())
|
||||
timer_irq_handler();
|
||||
|
||||
*CORE0_TIMER_IRQ_CTRL = 0x2;
|
||||
}
|
||||
|
||||
void enable_interrupt(void)
|
||||
{
|
||||
asm volatile("msr DAIFClr, 0xf");
|
||||
}
|
||||
|
||||
void disable_interrupt(void)
|
||||
{
|
||||
asm volatile("msr DAIFSet, 0xf");
|
||||
if (_irq_source_uart())
|
||||
uart_irq_handler();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user