5 #include "qm_pic_timer.h"
15 #define LVTTIMER_MODE_PERIODIC_OFFS (17)
16 #define LVTTIMER_INT_MASK_OFFS (16)
18 static void (*callback)(
void *data);
19 static void *callback_data;
22 #define PIC_TIMER (QM_LAPIC)
24 #define PIC_TIMER (QM_PIC_TIMER)
30 callback(callback_data);
37 QM_ISR_EOI(QM_IRQ_PIC_TIMER_VECTOR);
43 QM_CHECK(cfg != NULL, -EINVAL);
47 PIC_TIMER->timer_icr.reg = 0;
48 PIC_TIMER->lvttimer.reg = BIT(LVTTIMER_INT_MASK_OFFS) |
50 QM_X86_PIC_TIMER_INT_VECTOR;
57 QM_LAPIC->timer_dcr.reg = 0xB;
60 PIC_TIMER->lvttimer.reg |= cfg->
mode << LVTTIMER_MODE_PERIODIC_OFFS;
64 PIC_TIMER->lvttimer.reg &= ~BIT(LVTTIMER_INT_MASK_OFFS);
71 PIC_TIMER->timer_icr.reg = count;
78 QM_CHECK(count != NULL, -EINVAL);
80 *count = PIC_TIMER->timer_ccr.reg;
85 #if (ENABLE_RESTORE_CONTEXT)
88 QM_CHECK(ctx != NULL, -EINVAL);
90 ctx->
timer_icr = PIC_TIMER->timer_ccr.reg;
91 ctx->
timer_dcr = PIC_TIMER->timer_dcr.reg;
92 ctx->
lvttimer = PIC_TIMER->lvttimer.reg;
99 QM_CHECK(ctx != NULL, -EINVAL);
102 PIC_TIMER->timer_icr.reg = ctx->
timer_icr;
103 PIC_TIMER->timer_dcr.reg = ctx->
timer_dcr;
104 PIC_TIMER->lvttimer.reg = ctx->
lvttimer;
void(* callback)(void *data)
User callback.
uint32_t timer_icr
Initial Count Register.
int qm_pic_timer_set(const uint32_t count)
Set the current count value of the PIC timer.
int qm_pic_timer_restore_context(const qm_pic_timer_context_t *const ctx)
Restore PIC Timer peripheral's context.
bool int_en
Interrupt enable.
uint32_t timer_dcr
Divide Configuration Register.
QM_ISR_DECLARE(qm_pic_timer_0_isr)
ISR for PIC Timer interrupt.
int qm_pic_timer_get(uint32_t *const count)
Get the current count value of the PIC timer.
qm_pic_timer_mode_t mode
Operation mode.
int qm_pic_timer_set_config(const qm_pic_timer_config_t *const cfg)
Set the PIC timer configuration.
uint32_t lvttimer
Timer Entry in Local Vector Table.
PIC timer configuration type.
int qm_pic_timer_save_context(qm_pic_timer_context_t *const ctx)
Save PIC Timer peripheral's context.
void * callback_data
Callback user data.