aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Cunningham <cc@localhost>2022-03-24 17:14:32 -0700
committerChristian Cunningham <cc@localhost>2022-03-24 17:14:32 -0700
commit78493b1d441ef888910cf958a16f260bc3c1a7bd (patch)
tree3df0bd30040af43b5e4072eb3730fafe8a952167
parentc5f8eb6c35f6b3ca14c2a0e916fa835ed85cdfd6 (diff)
Subscriibe w/ More Info
-rw-r--r--include/cpu/irq.h10
-rw-r--r--kernel/cpu/irq.c23
-rw-r--r--usr/main.c25
3 files changed, 43 insertions, 15 deletions
diff --git a/include/cpu/irq.h b/include/cpu/irq.h
index 11740ad..28e060b 100644
--- a/include/cpu/irq.h
+++ b/include/cpu/irq.h
@@ -14,6 +14,16 @@ struct IrqEntry {
void* handler_info;
};
+struct UartInfo {
+ unsigned long priority;
+};
+
+struct SysTimerInfo {
+ unsigned long tick_rate;
+ unsigned long priority;
+ void* arg;
+};
+
static inline void enableirq(void)
{
asm volatile("cpsie i");
diff --git a/kernel/cpu/irq.c b/kernel/cpu/irq.c
index e7ab8c0..0bc8221 100644
--- a/kernel/cpu/irq.c
+++ b/kernel/cpu/irq.c
@@ -36,7 +36,8 @@ unsigned long c_irq_handler(void)
#endif
// Add task to handle the data
if (irqs[UART_IRQ].handler != 0) {
- add_thread(irqs[UART_IRQ].handler, (void*)data, *(unsigned long*)irqs[UART_IRQ].handler_info);
+ struct UartInfo* uart_info = irqs[UART_IRQ].handler_info;
+ add_thread(irqs[UART_IRQ].handler, (void*)data, uart_info->priority);
return 1;
}
}
@@ -46,8 +47,9 @@ unsigned long c_irq_handler(void)
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_C0;
- add_thread(irqs[SYS_TIMER_0_IRQ].handler, 0, 1);
- *nexttime = *timer_chi + *(unsigned long*)irqs[SYS_TIMER_0_IRQ].handler_info;
+ struct SysTimerInfo* stinfo = irqs[SYS_TIMER_0_IRQ].handler_info;
+ add_thread(irqs[SYS_TIMER_0_IRQ].handler, stinfo->arg, stinfo->priority);
+ *nexttime = *timer_chi + stinfo->tick_rate;
*timer_cs = SYS_TIMER_SC_M0;
return 1;
}
@@ -56,8 +58,9 @@ unsigned long c_irq_handler(void)
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;
+ struct SysTimerInfo* stinfo = irqs[SYS_TIMER_1_IRQ].handler_info;
+ add_thread(irqs[SYS_TIMER_1_IRQ].handler, stinfo->arg, stinfo->priority);
+ *nexttime = *timer_chi + stinfo->tick_rate;
*timer_cs = SYS_TIMER_SC_M1;
return 1;
}
@@ -66,8 +69,9 @@ unsigned long c_irq_handler(void)
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;
+ struct SysTimerInfo* stinfo = irqs[SYS_TIMER_2_IRQ].handler_info;
+ add_thread(irqs[SYS_TIMER_2_IRQ].handler, stinfo->arg, stinfo->priority);
+ *nexttime = *timer_chi + stinfo->tick_rate;
*timer_cs = SYS_TIMER_SC_M2;
return 1;
}
@@ -76,8 +80,9 @@ unsigned long c_irq_handler(void)
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;
+ struct SysTimerInfo* stinfo = irqs[SYS_TIMER_3_IRQ].handler_info;
+ add_thread(irqs[SYS_TIMER_3_IRQ].handler, stinfo->arg, stinfo->priority);
+ *nexttime = *timer_chi + stinfo->tick_rate;
*timer_cs = SYS_TIMER_SC_M3;
return 1;
}
diff --git a/usr/main.c b/usr/main.c
index 1743c33..b6cfee3 100644
--- a/usr/main.c
+++ b/usr/main.c
@@ -75,13 +75,26 @@ void loopt(void)
unsubscribe_irq(SYS_TIMER_0_IRQ);
}
-static unsigned long TICK_RATE_0 = 5000000;
-static unsigned long TICK_RATE_1 = 300000;
-static unsigned long UART_PRIORITY = 2;
+static struct SysTimerInfo stime_0 = {
+ .tick_rate = 5000000,
+ .priority = 0,
+ .arg = 0,
+};
+
+static struct SysTimerInfo stime_1 = {
+ .tick_rate = 300000,
+ .priority = 0,
+ .arg = 0,
+};
+
+static struct UartInfo UART_INFO = {
+ .priority = 2,
+};
+
void main(void)
{
- subscribe_irq(UART_IRQ, handle_data, &UART_PRIORITY);
- subscribe_irq(SYS_TIMER_0_IRQ, loopt, &TICK_RATE_0);
- subscribe_irq(SYS_TIMER_1_IRQ, loopt, &TICK_RATE_1);
+ subscribe_irq(UART_IRQ, handle_data, &UART_INFO);
+ subscribe_irq(SYS_TIMER_0_IRQ, loopt, &stime_0);
+ subscribe_irq(SYS_TIMER_1_IRQ, loopt, &stime_1);
add_thread(loop, 0, 0);
}