diff --git a/sw/kernel/devices/rtc.h b/sw/kernel/devices/rtc.h index 913e7c6..6158d30 100644 --- a/sw/kernel/devices/rtc.h +++ b/sw/kernel/devices/rtc.h @@ -6,6 +6,12 @@ #define RTC_CMD_ADDR 0xeffe #define RTC_DAT_ADDR 0xefff +#define RTC_THRESHOLD 0x00 +#define RTC_INCREMENT 0x10 +#define RTC_IRQ_THRESHOLD 0x20 +#define RTC_OUTPUT 0x30 +#define RTC_CONTROL 0x30 + /* initialize RTC with default values */ void init_rtc(void); @@ -13,4 +19,7 @@ void init_rtc(void); void handle_rtc(void); +void rtc_set(uint32_t val, uint8_t idx); + + #endif \ No newline at end of file diff --git a/sw/kernel/devices/rtc.s b/sw/kernel/devices/rtc.s index 5f47134..3c34513 100644 --- a/sw/kernel/devices/rtc.s +++ b/sw/kernel/devices/rtc.s @@ -2,8 +2,11 @@ .importzp tmp1 +.import popa + .export _init_rtc .export _handle_rtc +.export _rtc_set RTC_CMD = $effe RTC_DAT = $efff @@ -86,7 +89,19 @@ IRQ_THRESHOLD_3 = $00 sta RTC_DAT rts +.endproc +; void rtc_set(uint32_t val, uint8_t idx); +.proc _rtc_set + tay ; move cmd to Y + ldx #$04 +L1: sty RTC_CMD ; store cmd+idx to CMD + jsr popa ; pop 1 byte of argument + sta RTC_DAT ; write it to data + iny ; increase index + dex + bne L1 ; repeat 4 times + rts .endproc diff --git a/sw/kernel/kernel.c b/sw/kernel/kernel.c index 035f0f1..e81a8fc 100644 --- a/sw/kernel/kernel.c +++ b/sw/kernel/kernel.c @@ -36,6 +36,9 @@ int main() { register_irq(&handle_rtc_interrupt, 0); + rtc_set(0xaaaa, RTC_THRESHOLD); + rtc_set(0xbbbb, RTC_IRQ_THRESHOLD); + asm volatile("cli"); // cputs("Initialize Serial\n");