Disable interrupts while transmitting data

This commit is contained in:
BlackMark 2022-05-28 16:03:59 +02:00
parent 999cd0e0c9
commit f359f46ffc

View File

@ -4,6 +4,8 @@
#include <stdint.h>
#include <avr/interrupt.h>
#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<Cfg::BITS>{});
enableInterrupts(oldInterruptState);
return dataIn;
}
@ -89,6 +95,18 @@ class Software {
static io::Pin<Cfg::SS_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