summaryrefslogtreecommitdiff
path: root/cortex_m
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2022-04-16 20:59:36 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2022-04-16 21:02:39 +0200
commitd6c95a111c0950757d75496af254e3427e3769b6 (patch)
tree049d63096e434a7dba49e018e6836faaa440ec01 /cortex_m
parentc6b1f1112a3f4a5139700ef33da62c1ebdc3a7ba (diff)
async: Add preliminary time scheduler.
Diffstat (limited to 'cortex_m')
-rw-r--r--cortex_m/critical_section.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/cortex_m/critical_section.h b/cortex_m/critical_section.h
new file mode 100644
index 0000000..6b611a8
--- /dev/null
+++ b/cortex_m/critical_section.h
@@ -0,0 +1,21 @@
+#pragma once
+
+#include <cstdint>
+
+struct critical_section {
+ uint32_t primask;
+
+ critical_section() {
+ asm volatile("mrs %0, primask" : "=r" (primask));
+
+ asm volatile("cpsid i");
+
+ asm volatile("dmb");
+ }
+
+ ~critical_section() {
+ asm volatile("dmb");
+
+ asm volatile("msr primask, %0" :: "r" (primask));
+ }
+};