-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4fd36b5
commit 895dc65
Showing
16 changed files
with
167 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#pragma once | ||
#include "config.hpp" | ||
#include "util.hpp" | ||
#include "task.hpp" | ||
|
||
#include <stdio.h> | ||
|
||
#include <cstdint> | ||
|
||
static constexpr size_t QUANTUM_MILLIS = 5; | ||
|
||
namespace edge { | ||
extern "C" { | ||
void PendSV_Handler(); | ||
void SVC_Handler(); | ||
} | ||
|
||
class Scheduler { | ||
unsigned current_task_index = 0; | ||
uint8_t slices_remaining = 1; | ||
|
||
etl::vector<Task, MAX_PROCESSES> task_stack{}; | ||
|
||
public: | ||
unsigned get_current_task() const { return current_task_index; } | ||
|
||
void add_task(void (*function)(void), uint8_t priority = 1); | ||
|
||
void start_scheduler(); | ||
|
||
void change_current_task_priority(uint8_t new_priority); | ||
|
||
void yield_current_task(); | ||
|
||
private: | ||
void update_mpu_with_stack() const; | ||
void handle_first_svc_hit(); | ||
|
||
friend void PendSV_Handler(void); | ||
friend void SVC_Handler(void); | ||
}; | ||
|
||
extern Scheduler scheduler; | ||
|
||
} // namespace edge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#pragma once | ||
|
||
namespace edge { | ||
static constexpr size_t STACK_SIZE_BYTES = 2048; | ||
|
||
class Task { | ||
static constexpr size_t STACK_SIZE_IN_UNSIGNED = | ||
(STACK_SIZE_BYTES / sizeof(unsigned)) - sizeof(exception_stack_registers) | ||
- sizeof(unsigned*) - sizeof(uint8_t); | ||
|
||
public: | ||
// ===== DO NOT REARRANGE THESE ===== | ||
// Align for MPU purposes | ||
alignas(STACK_SIZE_BYTES) etl::array<unsigned, STACK_SIZE_IN_UNSIGNED> stack{}; | ||
exception_stack_registers first_stack_frame; | ||
// ================================== | ||
|
||
// needs to point to first_stack_frame | ||
unsigned* stack_ptr_loc{&first_stack_frame.R0}; | ||
|
||
// This is useful if we want to adjust the ratio of driver to process runtime | ||
uint8_t consecutive_quantums_to_run; | ||
|
||
Task( | ||
const exception_stack_registers& initial_stack_frame, uint8_t initial_priority | ||
) : | ||
first_stack_frame(initial_stack_frame), | ||
consecutive_quantums_to_run(initial_priority) | ||
{} | ||
}; | ||
|
||
static_assert(sizeof(Task) <= STACK_SIZE_BYTES); | ||
} // namespace edge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
#include "drivers/driver_enums.hpp" | ||
#include "fault_handler.hpp" | ||
#include "scheduler.hpp" | ||
#include "scheduler/scheduler.hpp" | ||
#include "util.hpp" | ||
|
||
#include <stdbool.h> | ||
#include <stdio.h> | ||
|
||
extern void task0(void); | ||
extern void ipc_part1(void); | ||
extern void ipc_part2(void); | ||
extern void exception_task(void); | ||
|
||
int main(void) | ||
{ | ||
printf("Starting EdgeOS\n"); | ||
|
||
edge::FaultHandler::get(); | ||
|
||
// edge::scheduler.add_task(exception_task); | ||
edge::scheduler.add_task(task0); | ||
// edge::scheduler.add_task(task1); | ||
edge::scheduler.add_task(exception_task); | ||
|
||
edge::scheduler.add_task(ipc_part1); | ||
edge::scheduler.add_task(ipc_part2); | ||
|
||
edge::scheduler.start_scheduler(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.