Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ add_compile_options(
option(BUILD_TESTS "Build unit tests" OFF)
option(BUILD_EXAMPLES "Build examples" OFF)

add_subdirectory(kernel)
add_subdirectory(port/cortex_m4)
add_subdirectory(hal/stm32f401)
add_subdirectory(src/kernel)
add_subdirectory(src/port/cortex_m4)
add_subdirectory(src/hal/stm32f401)

if(BUILD_TESTS)
add_subdirectory(tests)
Expand Down
4 changes: 2 additions & 2 deletions examples/blinky/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
add_executable(blinky main.c ${CMAKE_SOURCE_DIR}/startup/startup_stm32f401.c)
add_executable(blinky main.c ${CMAKE_SOURCE_DIR}/src/startup/startup_stm32f401.c)

target_link_libraries(blinky
hal_stm32f401
)

target_link_options(blinky PRIVATE
-T${CMAKE_SOURCE_DIR}/linker/stm32f401.ld
-T${CMAKE_SOURCE_DIR}/src/linker/stm32f401.ld
)

4 changes: 2 additions & 2 deletions examples/rtos_demo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
add_executable(rtos_demo main.c ${CMAKE_SOURCE_DIR}/startup/startup_stm32f401.c)
add_executable(rtos_demo main.c ${CMAKE_SOURCE_DIR}/src/startup/startup_stm32f401.c)

target_link_libraries(rtos_demo
hal_stm32f401
)

target_link_options(rtos_demo PRIVATE
-T${CMAKE_SOURCE_DIR}/linker/stm32f401.ld
-T${CMAKE_SOURCE_DIR}/src/linker/stm32f401.ld
)

3 changes: 0 additions & 3 deletions port/cortex_m4/src/port.s

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions kernel/src/task.c → src/kernel/src/task.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "task.h"
#include "port.h"
#include "fault_indicator.h"
#include "systick.h"

Task task_pool[MAX_TASKS];
uint32_t stack_pool[MAX_TASKS][TASK_STACK_SIZE];
Expand All @@ -24,7 +23,6 @@ Task *task_create(void (*function)(void), uint8_t priority, const char *name) {
Task *new_task = &task_pool[new_task_slot];
port_init_task(new_task, priority, new_task_slot, name);
port_init_task_stack(new_task, function);
systick_init();
return new_task;
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
85 changes: 85 additions & 0 deletions src/port/cortex_m4/src/port.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
.syntax unified
.text

.global PendSV_Handler
.thumb_func
PendSV_Handler:
/* MRS: move contents of
special register to a
general purpose register */
MRS R0, PSP
/* ARM assembly is beautiful,
wdym I can do R4-R11 at once,
also this is STM-DB, where
DB is decrement before each access */
STMDB R0!, {R4-R11}

/* Handle saving PSP */

/* Get pointer to current task */
LDR R1, =current_task
/* Dereference pointer */
LDR R1, [R1]
/* current_task->stack_ptr = R0 */
STR R0, [R1, #0]

/* Get Next Task*/
BL scheduler_select_next_task

/* Load new stack_ptr into PSP */
LDR R0, =current_task
/* Dereference ptr */
LDR R0, [R0]
/* Load stack ptr */
LDR R0, [R0, #0]
/* Pop Registers */
LDMIA R0!, {R4-R11}
/* Need to return from
PSP to thread mode,
0xFFFFFFFD returns
to Thread from PSP */
MSR PSP, R0

MOV LR, #0xFFFFFFFD
BX LR

/* Function to manually bootstrap task
loop on scheduler start */
.global port_start_first_task
.thumb_func
port_start_first_task:
BL scheduler_select_next_task
SVC #0

/* Need SVC exception to
get into Handler mode */
.global SVC_Handler
.thumb_func
SVC_Handler:
/* Load new stack_ptr into PSP */
LDR R0, =current_task
/* Dereference ptr */
LDR R0, [R0]
/* Load stack ptr */
LDR R0, [R0, #0]

/* Load Fake Context from stack */

/* Load all registers of fake frame*/
LDMIA R0!, {R4-R11}
/* Store updated PSP back */
MSR PSP, R0

/* Switch from Thread mode to PSP */

/* CONTROl register lets me
designate which stack to use */
MOV R1, #2
MSR CONTROL, R1
/* ISB is used to refresh & sync */
ISB

/* Return to Thread Mode */

MOV LR, #0xFFFFFFFD
BX LR
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ void (* const vector_table[])(void) = {
BusFault_Handler,
UsageFault_Handler,
0,
SVC_Handler,
DebugMon_Handler,
0,
0,
0,
SVC_Handler,
DebugMon_Handler,
0,
PendSV_Handler,
SysTick_Handler,
Expand Down
Loading