From 059f08cb73ef2b1631f2c89f8c524e27888f6ba5 Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Sun, 2 Jan 2022 15:53:57 -0800 Subject: Expanded upon memory library --- src/sys/schedule.c | 2 ++ src/sys/schedule.flat.c | 32 +++++++++++++++++++++++++++++ src/sys/schedule.h | 1 + src/sys/schedule.ll.c | 13 ++++++++++++ src/sys/schedule.q.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 102 insertions(+) create mode 100644 src/sys/schedule.flat.c create mode 100644 src/sys/schedule.ll.c create mode 100644 src/sys/schedule.q.c (limited to 'src/sys') diff --git a/src/sys/schedule.c b/src/sys/schedule.c index f920b0e..8cf2780 100644 --- a/src/sys/schedule.c +++ b/src/sys/schedule.c @@ -2,6 +2,7 @@ #include "../lib/ll.h" #include "../lib/q.h" +#ifdef IGNORE #ifdef FLAT static struct Task* task_list[256]; @@ -79,3 +80,4 @@ void execute_task(void) } } #endif +#endif diff --git a/src/sys/schedule.flat.c b/src/sys/schedule.flat.c new file mode 100644 index 0000000..6eb0d14 --- /dev/null +++ b/src/sys/schedule.flat.c @@ -0,0 +1,32 @@ +#ifdef FLAT + +#include "../sys/schedule.h" +static struct Task* task_list[256]; + +static struct Scheduler scheduler = { + .tasks = task_list, +}; + +static unsigned int ntask_i = 0; + +void add_task(struct Task* t) +{ + scheduler.tasks[ntask_i] = t; + ntask_i += 1; + if (ntask_i > 256) { + ntask_i = 0; + } +} + +unsigned int get_task_length(void) +{ + return ntask_i; +} + +void execute_task(void) +{ + if (scheduler.tasks[ntask_i-1] != 0) + scheduler.tasks[ntask_i-1]->task(); +} + +#endif diff --git a/src/sys/schedule.h b/src/sys/schedule.h index 04dad6a..2fd6acd 100644 --- a/src/sys/schedule.h +++ b/src/sys/schedule.h @@ -22,6 +22,7 @@ struct Scheduler { }; #endif +void add_fxn(void (*task)(void), unsigned char priority); void add_task(struct Task*); unsigned int get_task_length(void); void execute_task(void); diff --git a/src/sys/schedule.ll.c b/src/sys/schedule.ll.c new file mode 100644 index 0000000..d9ab954 --- /dev/null +++ b/src/sys/schedule.ll.c @@ -0,0 +1,13 @@ +#ifdef LL + +#include "../sys/schedule.h" +#include "../lib/ll.h" +static struct LL bl = { + .prev = 0, + .next = 0, +}; +static struct Scheduler scheduler = { + .tasks = &bl, +}; + +#endif diff --git a/src/sys/schedule.q.c b/src/sys/schedule.q.c new file mode 100644 index 0000000..818ba66 --- /dev/null +++ b/src/sys/schedule.q.c @@ -0,0 +1,54 @@ +#if !(defined(LL) || defined(FLAT)) +#include "../sys/schedule.h" +#include "../lib/q.h" +#include "../lib/mem.h" + +static struct Q_base bq = { + .next = 0, + .last = 0, +}; +static struct Scheduler scheduler = { + .tasks = &bq, +}; + +void add_fxn(void (*task)(void), unsigned char priority) +{ + struct Task* t = (struct Task*)malloc(sizeof(struct Task)); + t->priority = priority; + t->task = task; + add_task(t); +} + +void add_task(struct Task* t) +{ + pushq(scheduler.tasks, t); +} + +unsigned int get_task_length(void) +{ + unsigned int length = 0; + if (scheduler.tasks->last == 0) + return length; + else if (scheduler.tasks->next == scheduler.tasks->last) + return 1; + else { + struct Q* q = scheduler.tasks->next; + length += 1; + while (q->next != 0) { + q = q->next; + length += 1; + } + return length; + } +} + +void execute_task(void) +{ + if (scheduler.tasks->last != 0) { + struct Task* tsk = (struct Task*)scheduler.tasks->next->data; + (tsk->task)(); + popq(scheduler.tasks); + } +} + +#endif -- cgit v1.2.1