Skip to content

Commit

Permalink
demo: kernel 1 assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
roemvaar committed Jun 13, 2024
1 parent c538cde commit 2791f03
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Raspberry Pi 4 CI

on:
push:
Expand Down
3 changes: 1 addition & 2 deletions include/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions include/user/demo1.h
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
60 changes: 60 additions & 0 deletions src/demo1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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: <task_id>"
* 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)
{
Expand Down
25 changes: 4 additions & 21 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2791f03

Please sign in to comment.