summaryrefslogtreecommitdiff
path: root/platforms/chibios/atomic_util.h
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2023-01-28 21:07:51 +0000
committerGitHub <noreply@github.com>2023-01-28 21:07:51 +0000
commit8cc2e0e906dd8caadd8198839f57c19deea6c87e (patch)
treed0d72674a0ab074ff8a774ce66d028a6dbe96f73 /platforms/chibios/atomic_util.h
parent832479c7fbc544a3e8b305af7df9996fa3c5ba00 (diff)
Fix quantum ring_buffer for ChibiOS (#19683)
Diffstat (limited to 'platforms/chibios/atomic_util.h')
-rw-r--r--platforms/chibios/atomic_util.h17
1 files changed, 14 insertions, 3 deletions
diff --git a/platforms/chibios/atomic_util.h b/platforms/chibios/atomic_util.h
index 8975045153..234d7fd9f5 100644
--- a/platforms/chibios/atomic_util.h
+++ b/platforms/chibios/atomic_util.h
@@ -30,8 +30,19 @@ static __inline__ void __interrupt_enable__(const uint8_t *__s) {
(void)__s;
}
-#define ATOMIC_BLOCK(type) for (type, __ToDo = __interrupt_disable__(); __ToDo; __ToDo = 0)
-#define ATOMIC_FORCEON uint8_t sreg_save __attribute__((__cleanup__(__interrupt_enable__))) = 0
+static __inline__ syssts_t __interrupt_lock__(void) {
+ return chSysGetStatusAndLockX();
+}
+
+static __inline__ void __interrupt_unlock__(const syssts_t *__s) {
+ chSysRestoreStatusX(*__s);
+
+ __asm__ volatile("" ::: "memory");
+}
+
+#define ATOMIC_BLOCK(type) for (type, __ToDo = 1; __ToDo; __ToDo = 0)
+#define ATOMIC_FORCEON uint8_t status_save __attribute__((__cleanup__(__interrupt_enable__))) = __interrupt_disable__()
+#define ATOMIC_RESTORESTATE syssts_t status_save __attribute__((__cleanup__(__interrupt_unlock__))) = __interrupt_lock__()
-#define ATOMIC_BLOCK_RESTORESTATE _Static_assert(0, "ATOMIC_BLOCK_RESTORESTATE not implemented")
+#define ATOMIC_BLOCK_RESTORESTATE ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
#define ATOMIC_BLOCK_FORCEON ATOMIC_BLOCK(ATOMIC_FORCEON)