diff --git a/core/Arduino.h b/core/Arduino.h index 835d889..5f4eb63 100644 --- a/core/Arduino.h +++ b/core/Arduino.h @@ -102,10 +102,6 @@ typedef uint8_t byte; #define degrees(rad) ((rad)*RAD_TO_DEG) #define sq(x) ((x)*(x)) /* x^2 */ -/* define interrupts and noInterrupts */ -#define interrupts() -#define noInterrupts() - #ifdef F_CPU #define clockCyclesPerMicrosecond() (F_CPU / 1000000L) #define clockCyclesToMicroseconds(a) ((a) / clockCyclesPerMicrosecond()) @@ -186,6 +182,7 @@ void noTone(uint8_t _pin); #include "WCharacter.h" #include "WString.h" +#include "WInterrupts.h" #include "HardwareSerial.h" #ifdef RTDUINO_USING_USBSERIAL #include "USBSerial.h" diff --git a/core/WInterrupts.h b/core/WInterrupts.h new file mode 100644 index 0000000..bfda490 --- /dev/null +++ b/core/WInterrupts.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021-2022, RTduino Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2023-01-07 Meco Man first version + */ + +#ifndef WInterrupts_h +#define WInterrupts_h + +#include + +class rtduino_noInterrupts +{ + private: + rt_base_t rtduino_interrupt_nesting; + + public: + rtduino_noInterrupts() + { + rtduino_interrupt_nesting = rt_hw_interrupt_disable(); + } + + ~rtduino_noInterrupts() + { + rt_hw_interrupt_enable(rtduino_interrupt_nesting); + } +}; + +#define noInterrupts() rtduino_noInterrupts *rtduino_noInterrupts_obj = new rtduino_noInterrupts() +#define interrupts() delete rtduino_noInterrupts_obj + +#endif /* WInterrupts_h */