Skip to content

Commit 91a878b

Browse files
committed
Added additional atomic macros
1 parent 3e419dd commit 91a878b

1 file changed

Lines changed: 31 additions & 16 deletions

File tree

RingBuf.h

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,47 @@
1515
#endif
1616
#endif
1717

18-
#if defined(ARDUINO_ARCH_AVR)
19-
#include <util/atomic.h>
20-
#define RB_ATOMIC_START ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
21-
#define RB_ATOMIC_END }
2218

19+
#ifdef ARDUINO
2320

24-
#elif defined(ARDUINO_ARCH_ESP8266)
25-
#ifndef __STRINGIFY
26-
#define __STRINGIFY(a) #a
27-
#endif
21+
#if defined(ARDUINO_ARCH_AVR)
22+
#include <util/atomic.h>
23+
#define RB_ATOMIC_START ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
24+
#define RB_ATOMIC_END }
2825

29-
#ifndef xt_rsil
30-
#define xt_rsil(level) (__extension__({uint32_t state; __asm__ __volatile__("rsil %0," __STRINGIFY(level) : "=a" (state)); state;}))
31-
#endif
3226

33-
#ifndef xt_wsr_ps
34-
#define xt_wsr_ps(state) __asm__ __volatile__("wsr %0,ps; isync" :: "a" (state) : "memory")
27+
#elif defined(ARDUINO_ARCH_ESP8266)
28+
#ifndef __STRINGIFY
29+
#define __STRINGIFY(a) #a
30+
#endif
31+
32+
#ifndef xt_rsil
33+
#define xt_rsil(level) (__extension__({uint32_t state; __asm__ __volatile__("rsil %0," __STRINGIFY(level) : "=a" (state)); state;}))
34+
#endif
35+
36+
#ifndef xt_wsr_ps
37+
#define xt_wsr_ps(state) __asm__ __volatile__("wsr %0,ps; isync" :: "a" (state) : "memory")
38+
#endif
39+
40+
#define RB_ATOMIC_START do { uint32_t _savedIS = xt_rsil(15) ;
41+
#define RB_ATOMIC_END xt_wsr_ps(_savedIS) ;} while(0);
42+
43+
#else
44+
#define RB_ATOMIC_START {
45+
#define RB_ATOMIC_END }
46+
#warning “This library only fully supports AVR and ESP8266 Boards.”
47+
#warning "Operations on the buffer in ISRs are not safe!"
3548
#endif
3649

37-
#define RB_ATOMIC_START do { uint32_t _savedIS = xt_rsil(15) ;
38-
#define RB_ATOMIC_END xt_wsr_ps(_savedIS) ;} while(0);
3950
#else
40-
#error “This library only supports AVR and ESP8266 Boards.”
51+
#define RB_ATOMIC_START {
52+
#define RB_ATOMIC_END }
53+
#warning "Operations on the buffer in ISRs are not safe!"
54+
#warning "Impliment RB_ATOMIC_START and RB_ATOMIC_END macros for safe ISR operation!"
4155
#endif
4256

4357

58+
4459
typedef struct RingBuf RingBuf;
4560

4661
typedef struct RingBuf

0 commit comments

Comments
 (0)