summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--platforms/atomic_util.h10
-rw-r--r--platforms/chibios/atomic_util.h17
-rw-r--r--quantum/ring_buffer.h2
3 files changed, 22 insertions, 7 deletions
diff --git a/platforms/atomic_util.h b/platforms/atomic_util.h
index 2c95302a13..21286d72eb 100644
--- a/platforms/atomic_util.h
+++ b/platforms/atomic_util.h
@@ -24,9 +24,13 @@
24# define ATOMIC_BLOCK _Static_assert(0, "ATOMIC_BLOCK not implemented") 24# define ATOMIC_BLOCK _Static_assert(0, "ATOMIC_BLOCK not implemented")
25# define ATOMIC_BLOCK_RESTORESTATE _Static_assert(0, "ATOMIC_BLOCK_RESTORESTATE not implemented") 25# define ATOMIC_BLOCK_RESTORESTATE _Static_assert(0, "ATOMIC_BLOCK_RESTORESTATE not implemented")
26# define ATOMIC_BLOCK_FORCEON _Static_assert(0, "ATOMIC_BLOCK_FORCEON not implemented") 26# define ATOMIC_BLOCK_FORCEON _Static_assert(0, "ATOMIC_BLOCK_FORCEON not implemented")
27# define ATOMIC_FORCEON _Static_assert(0, "ATOMIC_FORCEON not implemented")
28# define ATOMIC_RESTORESTATE _Static_assert(0, "ATOMIC_RESTORESTATE not implemented")
27# endif 29# endif
28#else /* do nothing atomic macro */ 30#else /* do nothing atomic macro */
29# define ATOMIC_BLOCK for (uint8_t __ToDo = 1; __ToDo; __ToDo = 0) 31# define ATOMIC_BLOCK(t) for (uint8_t __ToDo = 1; __ToDo; __ToDo = 0)
30# define ATOMIC_BLOCK_RESTORESTATE ATOMIC_BLOCK 32# define ATOMIC_FORCEON
31# define ATOMIC_BLOCK_FORCEON ATOMIC_BLOCK 33# define ATOMIC_RESTORESTATE
34# define ATOMIC_BLOCK_RESTORESTATE ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
35# define ATOMIC_BLOCK_FORCEON ATOMIC_BLOCK(ATOMIC_FORCEON)
32#endif 36#endif
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) {
30 (void)__s; 30 (void)__s;
31} 31}
32 32
33#define ATOMIC_BLOCK(type) for (type, __ToDo = __interrupt_disable__(); __ToDo; __ToDo = 0) 33static __inline__ syssts_t __interrupt_lock__(void) {
34#define ATOMIC_FORCEON uint8_t sreg_save __attribute__((__cleanup__(__interrupt_enable__))) = 0 34 return chSysGetStatusAndLockX();
35}
36
37static __inline__ void __interrupt_unlock__(const syssts_t *__s) {
38 chSysRestoreStatusX(*__s);
39
40 __asm__ volatile("" ::: "memory");
41}
42
43#define ATOMIC_BLOCK(type) for (type, __ToDo = 1; __ToDo; __ToDo = 0)
44#define ATOMIC_FORCEON uint8_t status_save __attribute__((__cleanup__(__interrupt_enable__))) = __interrupt_disable__()
45#define ATOMIC_RESTORESTATE syssts_t status_save __attribute__((__cleanup__(__interrupt_unlock__))) = __interrupt_lock__()
35 46
36#define ATOMIC_BLOCK_RESTORESTATE _Static_assert(0, "ATOMIC_BLOCK_RESTORESTATE not implemented") 47#define ATOMIC_BLOCK_RESTORESTATE ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
37#define ATOMIC_BLOCK_FORCEON ATOMIC_BLOCK(ATOMIC_FORCEON) 48#define ATOMIC_BLOCK_FORCEON ATOMIC_BLOCK(ATOMIC_FORCEON)
diff --git a/quantum/ring_buffer.h b/quantum/ring_buffer.h
index 85419de11b..54b2bfffd1 100644
--- a/quantum/ring_buffer.h
+++ b/quantum/ring_buffer.h
@@ -1,8 +1,8 @@
1#pragma once 1#pragma once
2 2
3#include <util/atomic.h>
4#include <stdint.h> 3#include <stdint.h>
5#include <stdbool.h> 4#include <stdbool.h>
5#include "atomic_util.h"
6 6
7#ifndef RBUF_SIZE 7#ifndef RBUF_SIZE
8# define RBUF_SIZE 32 8# define RBUF_SIZE 32