From 367e20fa0c6f15e60d943cf222d41414fffd2318 Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Fri, 21 Jan 2022 13:01:58 -0700 Subject: Added scheduling logic --- include/globals.h | 1 + include/sys/schedule.h | 2 +- src/globals.c | 1 + src/sys/schedule.c | 17 +++++++++++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/globals.h b/include/globals.h index 16845d5..cf37c06 100644 --- a/include/globals.h +++ b/include/globals.h @@ -20,6 +20,7 @@ extern unsigned long stimel; extern unsigned long stimeh; extern struct Drawer g_Drawer; extern struct Scheduler scheduler; +extern struct Thread usrloopthread; extern unsigned int gwidth, gheight, gpitch, gisrgb; extern unsigned char stacks_table[MAX_THREADS]; #endif diff --git a/include/sys/schedule.h b/include/sys/schedule.h index 90e82dd..c110533 100644 --- a/include/sys/schedule.h +++ b/include/sys/schedule.h @@ -50,7 +50,7 @@ void init_scheduler(void); // void add_thread(void* pc, void* arg, unsigned char priority); /// TODO: ENSURE IRQ/ FIQ entry switches /// to user mode then calls the SVC call -// extern void schedule(void); +extern void schedule(void); // void yield(void); // struct Thread* next_thread(void); diff --git a/src/globals.c b/src/globals.c index 99aa48f..1313bd9 100644 --- a/src/globals.c +++ b/src/globals.c @@ -19,6 +19,7 @@ __attribute__((section(".bss"))) unsigned long stimel; __attribute__((section(".bss"))) unsigned long stimeh; __attribute__((section(".bss"))) struct Drawer g_Drawer; __attribute__((section(".bss"))) struct Scheduler scheduler; +__attribute__((section(".bss"))) struct Thread usrloopthread; __attribute__((section(".bss"))) unsigned int gwidth; __attribute__((section(".bss"))) unsigned int gheight; __attribute__((section(".bss"))) unsigned int gpitch; diff --git a/src/sys/schedule.c b/src/sys/schedule.c index 0dc89e9..3aca0ff 100644 --- a/src/sys/schedule.c +++ b/src/sys/schedule.c @@ -1,5 +1,22 @@ +#include +#include + void init_scheduler(void) { // Set rthread to usrloopthread - an infinitely running thread so that the pointer will never be null + usrloopthread.pc = (void*)loop; + usrloopthread.sp = 0x0FCC; + usrloopthread.sp_base = 0x1000; + usrloopthread.mptr = 0; + usrloopthread.pid = -1; + usrloopthread.priority = -1; + usrloopthread.status = THREAD_READY; + scheduler.rthread = &usrloopthread; // Initialize Rotating Buffers } + +void loop(void) +{ + while(1) + asm volatile ("wfe"); +} -- cgit v1.2.1