forked from samkusin/clemens_iigs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clem_timer.c
28 lines (24 loc) · 797 Bytes
/
clem_timer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "clem_device.h"
#include "clem_mmio_defs.h"
void clem_timer_reset(struct ClemensDeviceTimer* timer) {
timer->flags = 0;
}
void clem_timer_sync(
struct ClemensDeviceTimer* timer,
uint32_t delta_us
) {
timer->irq_1sec_us += delta_us;
timer->irq_qtrsec_us += delta_us;
while (timer->irq_1sec_us >= CLEM_MEGA2_TIMER_1SEC_US) {
timer->irq_1sec_us -= CLEM_MEGA2_TIMER_1SEC_US;
if (timer->flags & CLEM_MMIO_TIMER_1SEC_ENABLED) {
timer->irq_line |= CLEM_IRQ_TIMER_RTC_1SEC;
}
}
while (timer->irq_qtrsec_us >= CLEM_MEGA2_TIMER_QSEC_US) {
timer->irq_qtrsec_us -= CLEM_MEGA2_TIMER_QSEC_US;
if (timer->flags & CLEM_MMIO_TIMER_QSEC_ENABLED) {
timer->irq_line |= CLEM_IRQ_TIMER_QSEC;
}
}
}