diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1934c79..395aed8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: CI +name: Raspberry Pi 4 CI on: push: diff --git a/include/sched.h b/include/sched.h index 0711b88..d21b6e2 100644 --- a/include/sched.h +++ b/include/sched.h @@ -66,9 +66,8 @@ typedef struct _cpu_context unsigned long x28; // unsigned long elr_el1; // unsigned long spsr_el1; - // unsigned long sp_el0; unsigned long fp; /* fp is x29 */ - unsigned long sp; /* The task's current stack pointer */ + unsigned long sp; /* The task's current stack pointer - Once user space/kernel space are working: unsigned long sp_el0*/ unsigned long pc; /* sp is x30 */ } CPUContext_t; diff --git a/include/user/demo1.h b/include/user/demo1.h index 225c5e1..64483c3 100644 --- a/include/user/demo1.h +++ b/include/user/demo1.h @@ -1,6 +1,8 @@ #ifndef USER_DEMO1_H_ #define USER_DEMO1_H_ +void first_user_task(void); +void test_task(void); void user_task(void); void hello_name(char *array); void display_ascii_art(void); diff --git a/src/demo1.c b/src/demo1.c index d512d86..86e23c9 100644 --- a/src/demo1.c +++ b/src/demo1.c @@ -2,6 +2,66 @@ #include "peripherals/uart.h" #include "arm/utils.h" +#include "task.h" + +void first_user_task(void) +{ + /* Kernel 1 + * https://student.cs.uwaterloo.ca/~cs452/F23/assignments/k1.html + * + * The first user task should create four instances of a test task: + * Two should be at a priority lower than the priority of this task (first_user_task). + * Two should be at a priority higher than the priority of this task (first_user_task). + * The lower priority tasks should be created before the higher priority tasks. + * On return of each `create()`, busy-wait IO should be used to print "Created: " + * the terminal screen. + * After creating all tasks the first user task should call `exit()`, immediately after + * printing "FirstUserTask: exiting". + */ + + /* Two lower priority tasks */ + int ret = task_create(3, &test_task); + if (ret < 0) { + uart_printf(CONSOLE, "Error creating task: %d\r\n", ret); + return; + } + + ret = task_create(4, &test_task); + if (ret < 0) { + uart_printf(CONSOLE, "Error creating task: %d\r\n", ret); + return; + } + + /* Two higher priority tasks */ + ret = task_create(1, &test_task); + if (ret < 0) { + uart_printf(CONSOLE, "Error creating task: %d\r\n", ret); + return; + } + + ret = task_create(1, &test_task); + if (ret < 0) { + uart_printf(CONSOLE, "Error creating task: %d\r\n", ret); + return; + } + + uart_printf(CONSOLE, "FirstUserTask: exiting...\r\n"); + task_exit(); +} + +void test_task(void) +{ + TaskDescriptor_t *curr = get_current_task(); + TaskDescriptor_t *parent = curr->parent_td; + + uart_printf(CONSOLE, "TestTask - tid: %d, parent_tid: %d\r\n", curr->tid, parent->tid); + + task_yield(); + + uart_printf(CONSOLE, "TestTask - tid: %d, parent_tid: %d\r\n", curr->tid, parent->tid); + + task_exit(); +} void user_task(void) { diff --git a/src/main.c b/src/main.c index 0767d3f..fa5be10 100644 --- a/src/main.c +++ b/src/main.c @@ -50,31 +50,14 @@ int kmain(void) uart_printf(CONSOLE, "*****************************************\r\n"); uart_printf(CONSOLE, "RTOS by roemvaar (May, 2024).\r\n"); - /* Create two user tasks */ - int ret = task_create(1, &user_task); + /* Kernel 1 Assignment */ + int ret = task_create(2, &first_user_task); if (ret < 0) { - uart_printf(CONSOLE, "Error creating first task: %d\r\n", ret); - return ret; - } - - ret = task_create(3, &display_ascii_art); - if (ret < 0) { - uart_printf(CONSOLE, "Error creating second task: %d\r\n", ret); - return ret; - } - - ret = task_create(4, &display_ascii_art); - if (ret < 0) { - uart_printf(CONSOLE, "Error creating second task: %d\r\n", ret); - return ret; - } - - ret = task_create(2, &display_ascii_art); - if (ret < 0) { - uart_printf(CONSOLE, "Error creating second task: %d\r\n", ret); + uart_printf(CONSOLE, "Error creating first user task: %d\r\n", ret); return ret; } + /* Debug */ print_priority_queue(); char input;