Skip to content

Commit f362abb

Browse files
committed
Added additional Atomic Macros
1 parent 5fdc09f commit f362abb

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

RingBuf.h

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,49 @@
11
#ifndef RINGBUG_FIFO_H
22
#define RINGBUF_FIFO_H
33

4-
#include <Arduino.h>
4+
#ifdef ARDUINO
5+
#include <Arduino.h>
6+
#else
7+
#include <stdint.h>
8+
#endif
9+
10+
#ifdef ARDUINO
11+
12+
#if defined(ARDUINO_ARCH_AVR)
13+
#include <util/atomic.h>
14+
#define RB_ATOMIC_START ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
15+
#define RB_ATOMIC_END }
16+
17+
18+
#elif defined(ARDUINO_ARCH_ESP8266)
19+
#ifndef __STRINGIFY
20+
#define __STRINGIFY(a) #a
21+
#endif
22+
23+
#ifndef xt_rsil
24+
#define xt_rsil(level) (__extension__({uint32_t state; __asm__ __volatile__("rsil %0," __STRINGIFY(level) : "=a" (state)); state;}))
25+
#endif
26+
27+
#ifndef xt_wsr_ps
28+
#define xt_wsr_ps(state) __asm__ __volatile__("wsr %0,ps; isync" :: "a" (state) : "memory")
29+
#endif
30+
31+
#define RB_ATOMIC_START do { uint32_t _savedIS = xt_rsil(15) ;
32+
#define RB_ATOMIC_END xt_wsr_ps(_savedIS) ;} while(0);
33+
34+
#else
35+
#define RB_ATOMIC_START {
36+
#define RB_ATOMIC_END }
37+
#warning “This library only fully supports AVR and ESP8266 Boards.”
38+
#warning "Operations on the buffer in ISRs are not safe!"
39+
#endif
40+
41+
#else
42+
#define RB_ATOMIC_START {
43+
#define RB_ATOMIC_END }
44+
#warning "Operations on the buffer in ISRs are not safe!"
45+
#warning "Impliment RB_ATOMIC_START and RB_ATOMIC_END macros for safe ISR operation!"
46+
#endif
547

648
template <typename Type, uint16_t MaxElements>
749

0 commit comments

Comments
 (0)