ESP8266
interrupts.h
1 #ifndef INTERRUPTS_H
2 #define INTERRUPTS_H
3 
4 #include <stddef.h>
5 #include <stdint.h>
6 extern "C" {
7 #include "c_types.h"
8 #include "ets_sys.h"
9 }
10 
11 // these auto classes wrap up xt_rsil so your code can be simplier, but can only be
12 // used in an ino or cpp files.
13 
14 // InterruptLock is used when you want to completely disable locks
15 //{
16 // {
17 // InterruptLock lock;
18 // // do work within interrupt lock here
19 // }
20 // do work outside of interrupt lock here outside its scope
21 //}
22 //
23 
25 public:
27  _state = xt_rsil(15);
28  }
29 
31  xt_wsr_ps(_state);
32  }
33 
34 protected:
35  uint32_t _state;
36 };
37 
38 // AutoInterruptLock is when you need to set a specific level, A normal use pattern is like
39 //
40 //{
41 // {
42 // AutoInterruptLock(1); // this routine will allow level 2 and above
43 // // do work within interrupt lock here
44 // }
45 // do work outside of interrupt lock here outside its scope
46 //}
47 //
48 #define AutoInterruptLock(intrLevel) \
49 class _AutoDisableIntr { \
50 public: \
51  _AutoDisableIntr() { _savedPS = xt_rsil(intrLevel); } \
52  ~_AutoDisableIntr() { xt_wsr_ps(_savedPS); } \
53 private: \
54  uint32_t _savedPS; \
55  }; \
56 _AutoDisableIntr _autoDisableIntr
57 
58 #endif //INTERRUPTS_H
~InterruptLock()
Definition: interrupts.h:30
Definition: interrupts.h:24
InterruptLock()
Definition: interrupts.h:26
uint32_t _state
Definition: interrupts.h:35