From b6ca3a4df6ca34cd40f09d4b97e54679eb95840a Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Wed, 30 Mar 2022 16:51:36 -0700 Subject: Timer execute once --- include/cpu/irq.h | 1 + kernel/cpu/irq.c | 8 ++++++++ usr/main.c | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/include/cpu/irq.h b/include/cpu/irq.h index e244cc9..0fb7fbb 100644 --- a/include/cpu/irq.h +++ b/include/cpu/irq.h @@ -24,6 +24,7 @@ struct SysTimerInfo { unsigned long tick_rate; unsigned long priority; void* arg; + unsigned long oneshot; }; struct GPIOInfo { diff --git a/kernel/cpu/irq.c b/kernel/cpu/irq.c index f718b7e..2990881 100644 --- a/kernel/cpu/irq.c +++ b/kernel/cpu/irq.c @@ -61,6 +61,8 @@ unsigned long c_irq_handler(void) *nexttime = *timer_chi + stinfo->tick_rate; *timer_cs = SYS_TIMER_SC_M0; scheduled = 1; + if (stinfo->oneshot) + store32(SYS_TIMER_SC_M0, IRQ_DISABLE1); } // 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) { @@ -72,6 +74,8 @@ unsigned long c_irq_handler(void) *nexttime = *timer_chi + stinfo->tick_rate; *timer_cs = SYS_TIMER_SC_M1; scheduled = 1; + if (stinfo->oneshot) + store32(SYS_TIMER_SC_M1, IRQ_DISABLE1); } // 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) { @@ -83,6 +87,8 @@ unsigned long c_irq_handler(void) *nexttime = *timer_chi + stinfo->tick_rate; *timer_cs = SYS_TIMER_SC_M2; scheduled = 1; + if (stinfo->oneshot) + store32(SYS_TIMER_SC_M2, IRQ_DISABLE1); } // 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) { @@ -94,6 +100,8 @@ unsigned long c_irq_handler(void) *nexttime = *timer_chi + stinfo->tick_rate; *timer_cs = SYS_TIMER_SC_M3; scheduled = 1; + if (stinfo->oneshot) + store32(SYS_TIMER_SC_M3, IRQ_DISABLE1); } } // Check if CNTV triggered the interrupt diff --git a/usr/main.c b/usr/main.c index 0308d4b..5d5348a 100644 --- a/usr/main.c +++ b/usr/main.c @@ -14,24 +14,28 @@ static struct SysTimerInfo stime_0 = { .tick_rate = 5000000, .priority = 0, .arg = 0, + .oneshot = 0, }; static struct SysTimerInfo stime_1 = { .tick_rate = 700000, .priority = 0, .arg = 0, + .oneshot = 0, }; static struct SysTimerInfo stime_2 = { .tick_rate = 300000, .priority = 0, .arg = 0, + .oneshot = 0, }; static struct SysTimerInfo stime_3 = { .tick_rate = 10, .priority = 0, .arg = 0, + .oneshot = 0, }; static struct UartInfo UART_INFO = { -- cgit v1.2.1