From 6839008c6aa82ef257231ed1f8087c32266d2d66 Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Thu, 24 Mar 2022 16:49:32 -0700 Subject: Added in 3 other timer compares --- kernel/cpu/irq.c | 30 ++++++++++++++++++++++++++++++ usr/main.c | 8 +++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/kernel/cpu/irq.c b/kernel/cpu/irq.c index 9490489..6e48ab1 100644 --- a/kernel/cpu/irq.c +++ b/kernel/cpu/irq.c @@ -51,6 +51,36 @@ unsigned long c_irq_handler(void) *timer_cs = SYS_TIMER_SC_M0; return 1; } + // Check if System Time Compare 1 Triggered the Interrupt + if (*(volatile unsigned long*)SYS_TIMER_CS & SYS_TIMER_SC_M1 && irqs[SYS_TIMER_1_IRQ].handler != 0) { + volatile unsigned long* timer_cs = (volatile unsigned long*)SYS_TIMER_CS; + volatile unsigned long* timer_chi = (volatile unsigned long*)SYS_TIMER_CHI; + volatile unsigned long* nexttime = (volatile unsigned long*)SYS_TIMER_C1; + add_thread(irqs[SYS_TIMER_1_IRQ].handler, 0, 1); + *nexttime = *timer_chi + *(unsigned long*)irqs[SYS_TIMER_1_IRQ].handler_info; + *timer_cs = SYS_TIMER_SC_M1; + return 1; + } + // Check if System Time Compare 2 Triggered the Interrupt + if (*(volatile unsigned long*)SYS_TIMER_CS & SYS_TIMER_SC_M2 && irqs[SYS_TIMER_2_IRQ].handler != 0) { + volatile unsigned long* timer_cs = (volatile unsigned long*)SYS_TIMER_CS; + volatile unsigned long* timer_chi = (volatile unsigned long*)SYS_TIMER_CHI; + volatile unsigned long* nexttime = (volatile unsigned long*)SYS_TIMER_C2; + add_thread(irqs[SYS_TIMER_2_IRQ].handler, 0, 1); + *nexttime = *timer_chi + *(unsigned long*)irqs[SYS_TIMER_2_IRQ].handler_info; + *timer_cs = SYS_TIMER_SC_M2; + return 1; + } + // Check if System Time Compare 3 Triggered the Interrupt + if (*(volatile unsigned long*)SYS_TIMER_CS & SYS_TIMER_SC_M3 && irqs[SYS_TIMER_3_IRQ].handler != 0) { + volatile unsigned long* timer_cs = (volatile unsigned long*)SYS_TIMER_CS; + volatile unsigned long* timer_chi = (volatile unsigned long*)SYS_TIMER_CHI; + volatile unsigned long* nexttime = (volatile unsigned long*)SYS_TIMER_C3; + add_thread(irqs[SYS_TIMER_3_IRQ].handler, 0, 1); + *nexttime = *timer_chi + *(unsigned long*)irqs[SYS_TIMER_3_IRQ].handler_info; + *timer_cs = SYS_TIMER_SC_M3; + return 1; + } } // Check if CNTV triggered the interrupt else if (source & (1 << 3)) { diff --git a/usr/main.c b/usr/main.c index 9c8a7d8..5a49f49 100644 --- a/usr/main.c +++ b/usr/main.c @@ -66,14 +66,16 @@ void loop(void) void loopt(void) { static char str[13]; - draw_string(0, 9, ulong_to_string(*(volatile unsigned long*)SYS_TIMER_CHI, str)); + draw_string(0, 14, ulong_to_string(*(volatile unsigned long*)SYS_TIMER_CHI, str)); } -static unsigned long TICK_RATE = 5000000; +static unsigned long TICK_RATE_0 = 5000000; +static unsigned long TICK_RATE_1 = 300000; static unsigned long UART_PRIORITY = 2; void main(void) { subscribe_irq(UART_IRQ, handle_data, &UART_PRIORITY); - subscribe_irq(SYS_TIMER_0_IRQ, loopt, &TICK_RATE); + subscribe_irq(SYS_TIMER_0_IRQ, loopt, &TICK_RATE_0); + subscribe_irq(SYS_TIMER_1_IRQ, loopt, &TICK_RATE_1); add_thread(loop, 0, 0); } -- cgit v1.2.1