Draft: lab 5 failed
This commit is contained in:
@@ -11,6 +11,45 @@ timer_t *global_timer = (timer_t *)0x0;
|
||||
|
||||
MMIO_W_HELPER(_enable_timer_irq, CORE0_TIMER_IRQ_CTRL, 0x1, 1);
|
||||
|
||||
static inline
|
||||
task_t _make_timer_task(uint64_t interval_s, task_callback_func_t func,
|
||||
uint64_t param)
|
||||
{
|
||||
uint64_t cntpct_el0, cntfrq_el0;
|
||||
R_SYSREG(cntpct_el0, cntpct_el0);
|
||||
R_SYSREG(cntfrq_el0, cntfrq_el0);
|
||||
|
||||
return (task_t){
|
||||
.firing_tick = cntpct_el0 + interval_s * cntfrq_el0,
|
||||
.interval = interval_s * cntfrq_el0,
|
||||
|
||||
.func = func,
|
||||
.param = param,
|
||||
};
|
||||
}
|
||||
|
||||
static inline
|
||||
void _scheduler_timeout(uint64_t)
|
||||
{
|
||||
add_timer_task(_make_timer_task(1, _scheduler_timeout, 0x0));
|
||||
schedule();
|
||||
}
|
||||
|
||||
void timer_init()
|
||||
{
|
||||
uint64_t cntkctl_el1, cntfrq_el0;
|
||||
R_SYSREG(cntkctl_el1, cntkctl_el1);
|
||||
W_SYSREG(cntkctl_el1, cntkctl_el1 | 1);
|
||||
W_SYSREG(cntp_ctl_el0, 1);
|
||||
_enable_timer_irq(true);
|
||||
|
||||
R_SYSREG(cntfrq_el0, cntfrq_el0);
|
||||
W_SYSREG(cntp_tval_el0, cntfrq_el0 >> 1);
|
||||
|
||||
return;
|
||||
add_timer_task(_make_timer_task(1, _scheduler_timeout, 0x0));
|
||||
}
|
||||
|
||||
static inline
|
||||
uint32_t _d(timer_t *t)
|
||||
{ return t ? t->_d : 0; }
|
||||
@@ -42,8 +81,10 @@ timer_t *_merge(timer_t *a, timer_t *b)
|
||||
static inline
|
||||
timer_t *_pop(timer_t *t)
|
||||
{
|
||||
if (!t || (!t->_l && !t->_r))
|
||||
if (!t || (!t->_l && !t->_r)) {
|
||||
kfree(t);
|
||||
return (timer_t *)0x0;
|
||||
}
|
||||
return _merge(t->_l, t->_r);
|
||||
}
|
||||
|
||||
@@ -126,6 +167,9 @@ void _timer_task_wrapper(uint64_t param)
|
||||
void timer_irq_handler(void)
|
||||
{
|
||||
_enable_timer_irq(false);
|
||||
schedule();
|
||||
_enable_timer_irq(true);
|
||||
return;
|
||||
|
||||
uint64_t cntpct_el0;
|
||||
R_SYSREG(cntpct_el0, cntpct_el0);
|
||||
|
||||
Reference in New Issue
Block a user