-
Notifications
You must be signed in to change notification settings - Fork 28
/
RingBufHelpers.h
53 lines (41 loc) · 1.41 KB
/
RingBufHelpers.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef EM_RINGBUF_HELPERS_CPP_H
#define EM_RINGBUF_HELPERS_CPP_H
// TODO fix this
#ifndef NULL
#define NULL (void *)(0)
#endif
#ifdef ARDUINO
#include <Arduino.h>
#else
#include <stdint.h>
#endif
#ifdef ARDUINO
#if defined(ARDUINO_ARCH_AVR)
#include <util/atomic.h>
#define RB_ATOMIC_START ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
#define RB_ATOMIC_END }
#elif defined(ARDUINO_ARCH_ESP8266)
#ifndef __STRINGIFY
#define __STRINGIFY(a) #a
#endif
#ifndef xt_rsil
#define xt_rsil(level) (__extension__({uint32_t state; __asm__ __volatile__("rsil %0," __STRINGIFY(level) : "=a" (state)); state;}))
#endif
#ifndef xt_wsr_ps
#define xt_wsr_ps(state) __asm__ __volatile__("wsr %0,ps; isync" :: "a" (state) : "memory")
#endif
#define RB_ATOMIC_START do { uint32_t _savedIS = xt_rsil(15) ;
#define RB_ATOMIC_END xt_wsr_ps(_savedIS); } while(0);
#else
#define RB_ATOMIC_START {
#define RB_ATOMIC_END }
#warning "This library only fully supports AVR and ESP8266 Boards."
#warning "Operations on the buffer in ISRs are not safe!"
#endif
#else
#define RB_ATOMIC_START {
#define RB_ATOMIC_END }
#warning "Operations on the buffer in ISRs are not safe!"
#warning "Implement RB_ATOMIC_START and RB_ATOMIC_END macros for safe ISR operation!"
#endif
#endif