-
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.
Merge pull request #27 from stevenewald/mpu
Add MPU Support
- Loading branch information
Showing
20 changed files
with
363 additions
and
187 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* Linker script to configure memory regions. */ | ||
/* Only for gcc nrf52833 with 128kb ram and 512kb flash */ | ||
|
||
SEARCH_DIR(.) | ||
GROUP(-lgcc -lc -lnosys) | ||
|
||
MEMORY | ||
{ | ||
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x80000 | ||
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x20000 | ||
} | ||
|
||
FLASH_PAGE_SIZE = 4096; | ||
FLASH_DATA_PAGES_USED = 4; | ||
|
||
SECTIONS | ||
{ | ||
. = ALIGN(4); | ||
.svc_data : | ||
{ | ||
PROVIDE(__start_svc_data = .); | ||
KEEP(*(.svc_data)) | ||
PROVIDE(__stop_svc_data = .); | ||
} > RAM | ||
.log_dynamic_data : | ||
{ | ||
PROVIDE(__start_log_dynamic_data = .); | ||
KEEP(*(SORT(.log_dynamic_data*))) | ||
PROVIDE(__stop_log_dynamic_data = .); | ||
} > RAM | ||
.user_programs_data ALIGN(16384) : | ||
{ | ||
PROVIDE(__start_user_programs_data = .); | ||
_build/user_*.o(.data*) | ||
_build/user_*.o(.bss*) | ||
PROVIDE(__end_user_programs_data = .); | ||
ASSERT((__end_user_programs_data - __start_user_programs_data) <= 16384, "Error: .user_programs_data section exceeds 16 KB"); | ||
} > RAM | ||
} INSERT AFTER .data; | ||
|
||
SECTIONS | ||
{ | ||
.log_const_data : | ||
{ | ||
PROVIDE(__start_log_const_data = .); | ||
KEEP(*(SORT(.log_const_data*))) | ||
PROVIDE(__stop_log_const_data = .); | ||
} > FLASH | ||
/* TODO: make sure this doesnt cause duplication? */ | ||
.user_programs_code ALIGN(16384) : | ||
{ | ||
PROVIDE(__start_user_programs_code = .); | ||
_build/user_*.o(.text*) | ||
_build/user_*.o(.rodata*) | ||
KEEP(*(.user_code)) | ||
PROVIDE(__end_user_programs_code = .); | ||
ASSERT((__end_user_programs_code - __start_user_programs_code) <= 16384, "Error: .user_programs_code section exceeds 16 KB"); | ||
} > FLASH | ||
} INSERT AFTER .text | ||
|
||
SECTIONS | ||
{ | ||
__stop_ot_flash_data = (ORIGIN(FLASH) + LENGTH(FLASH) - FLASH_PAGE_SIZE); | ||
__start_ot_flash_data = (__stop_ot_flash_data - (FLASH_PAGE_SIZE * FLASH_DATA_PAGES_USED)); | ||
|
||
/* Assure that code does not overlap flash data area.*/ | ||
ASSERT((__start_ot_flash_data >= __etext + SIZEOF(.data)), "Error: Code overlaps flash data area.") | ||
} | ||
|
||
INCLUDE "nrf_common.ld" |
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,25 @@ | ||
#pragma once | ||
|
||
#include "config.hpp" | ||
|
||
namespace edge { | ||
class MpuController { | ||
MpuController() { } | ||
|
||
~MpuController() { disable_mpu(); }; | ||
|
||
void disable_mpu() const; | ||
|
||
public: | ||
void initialize_mpu() const; | ||
|
||
MpuController(const MpuController&) = delete; | ||
MpuController(MpuController&&) = delete; | ||
MpuController& operator=(const MpuController&) = delete; | ||
MpuController& operator=(MpuController&&) = delete; | ||
|
||
static MpuController& get(); | ||
|
||
void set_program_stack_start(const unsigned* stack_ptr) const; | ||
}; | ||
} // 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,44 @@ | ||
#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 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,34 @@ | ||
#pragma once | ||
|
||
#include "config.hpp" | ||
|
||
namespace edge { | ||
|
||
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
Oops, something went wrong.