From f359f46ffcb4af633d3b43a108e010058ae121e8 Mon Sep 17 00:00:00 2001 From: BlackMark Date: Sat, 28 May 2022 16:03:59 +0200 Subject: [PATCH] Disable interrupts while transmitting data --- software.hpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/software.hpp b/software.hpp index e1019f6..fb8a3e5 100644 --- a/software.hpp +++ b/software.hpp @@ -4,6 +4,8 @@ #include +#include + #include "../io/io.hpp" #include "../util/type.hpp" #include "../util/util.hpp" @@ -45,6 +47,8 @@ class Software { static word_t transfer(const word_t data) { + const auto oldInterruptState = disableInterrupts(); + auto dataIn = word_t{}; util::for_constexpr( @@ -74,6 +78,8 @@ class Software { }, util::make_index_sequence{}); + enableInterrupts(oldInterruptState); + return dataIn; } @@ -89,6 +95,18 @@ class Software { static io::Pin sm_ss; static constexpr auto DELAY_US = calcClockDelay(); + + static inline uint8_t disableInterrupts() + { + const auto oldInterruptState = SREG; + cli(); + return oldInterruptState; + } + + static inline void enableInterrupts(const uint8_t oldInterruptState) + { + SREG = oldInterruptState; + } }; } // namespace spi