Skip to content

Commit 62a0eea

Browse files
committed
temp12
1 parent af117fa commit 62a0eea

15 files changed

Lines changed: 439 additions & 281 deletions

kernel/cortex_m4.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#pragma once
2+
3+
#include <stddef.h>
4+
5+
// Interrupt control and state register
6+
static volatile size_t *const cm4_icsr = (volatile size_t *)0xE000ED04U;
7+
8+
static const size_t cm4_icsr_pendsvset_mask = 1U << 28U;
9+
10+
// Floating point context control register
11+
static volatile size_t *const fpcsr = (volatile size_t *)0xE000EF34U;
12+
13+
static const size_t fpcsr_aspen_mask = 1U << 31U;
14+
static const size_t fpcsr_lspen_mask = 1U << 30U;
15+
16+
// Return to thread mode, use PSP, no FP context
17+
static const size_t cm4_exc_return_thread_psp_nofp = 0xFFFFFFFDU;
18+
19+
static const size_t cm4_epsr_thumb_mask = 1U << 24U;
20+
21+
static void cm4_enable_irq(void) {
22+
__asm volatile("cpsie i");
23+
}
24+
25+
// Equivalent to writing 0 to PRIMASK, which raises the execution priority to
26+
// 0, effectively disabling all interrupts. Note that Hardfault, NMI, and
27+
// Reset exceptions still have higher priority.
28+
static void cm4_disable_irq(void) {
29+
__asm volatile("cpsid i");
30+
}

kernel/dll.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#pragma once
2+
3+
#include "rtos.h"
4+
5+
#include <stdbool.h>
6+
#include <stddef.h>
7+
8+
static bool dll_is_empty(const rtos_dll_t *dll) {
9+
return dll->head == NULL;
10+
}
11+
12+
static rtos_task_t *dll_pop_front(rtos_dll_t *dll) {
13+
assert(dll->head != NULL);
14+
rtos_task_t *const popped = dll->head;
15+
if (popped->next == NULL) {
16+
dll->tail = NULL;
17+
} else {
18+
popped->next->prev = NULL;
19+
}
20+
dll->head = popped->next;
21+
popped->prev = NULL;
22+
popped->next = NULL;
23+
return popped;
24+
}
25+
26+
static void dll_push_front(rtos_dll_t *dll, rtos_task_t *task) {
27+
if (dll->head == NULL) {
28+
dll->head = task;
29+
dll->tail = task;
30+
task->prev = NULL;
31+
task->next = NULL;
32+
} else {
33+
dll->head->prev = task;
34+
task->next = dll->head;
35+
dll->head = task;
36+
task->prev = NULL;
37+
}
38+
}
39+
40+
static void dll_push_back(rtos_dll_t *dll, rtos_task_t *task) {
41+
if (dll->head == NULL) {
42+
dll->head = task;
43+
dll->tail = task;
44+
task->prev = NULL;
45+
task->next = NULL;
46+
} else {
47+
dll->tail->next = task;
48+
task->prev = dll->tail;
49+
task->next = NULL;
50+
dll->tail = task;
51+
}
52+
}
53+
54+
static void dll_insert_ascending(rtos_dll_t *dll, rtos_task_t *task) {
55+
rtos_task_t *ptr = dll->head;
56+
while (ptr != NULL && ptr->wake_time < task->wake_time) {
57+
ptr = ptr->next;
58+
}
59+
if (ptr == NULL) {
60+
dll_push_back(dll, task);
61+
} else {
62+
if (ptr->prev == NULL) {
63+
dll->head = task;
64+
} else {
65+
ptr->prev->next = task;
66+
}
67+
task->prev = ptr->prev;
68+
task->next = ptr;
69+
ptr->prev = task;
70+
}
71+
}

0 commit comments

Comments
 (0)