mirror of
https://github.com/TomHarte/CLK.git
synced 2026-04-21 02:17:08 +00:00
Avoid synchronisation issues on inputs_.
This commit is contained in:
@@ -24,7 +24,9 @@ void uPD7002::run_for(const HalfCycles count) {
|
||||
|
||||
if(count >= conversion_time_remaining_) {
|
||||
conversion_time_remaining_ = HalfCycles(0);
|
||||
result_ = uint16_t(inputs_[channel_] * 65535.0f) & (high_precision_ ? 0xfff0 : 0xff00);
|
||||
result_ = uint16_t(
|
||||
inputs_[channel_].load(std::memory_order_relaxed) * 65535.0f) & (high_precision_ ? 0xfff0 : 0xff00
|
||||
);
|
||||
set_interrupt(true);
|
||||
return;
|
||||
}
|
||||
@@ -81,5 +83,5 @@ void uPD7002::set_interrupt(const bool value) {
|
||||
}
|
||||
|
||||
void uPD7002::set_input(const int channel, const float value) {
|
||||
inputs_[channel] = value;
|
||||
inputs_[channel].store(value, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
@@ -6,8 +6,12 @@
|
||||
// Copyright © 2025 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ClockReceiver/ClockReceiver.hpp"
|
||||
|
||||
#include <atomic>
|
||||
|
||||
namespace NEC {
|
||||
|
||||
class uPD7002 {
|
||||
@@ -21,7 +25,7 @@ public:
|
||||
|
||||
/// Defines a mean for an observer to receive notifications upon updates to the interrupt line.
|
||||
struct Delegate {
|
||||
virtual void did_change_interrupt_status(uPD7002 &) = 0;
|
||||
virtual void did_change_interrupt_status(uPD7002 &) = 0;
|
||||
};
|
||||
void set_delegate(Delegate *);
|
||||
|
||||
@@ -33,7 +37,7 @@ public:
|
||||
void set_input(int channel, float value);
|
||||
|
||||
private:
|
||||
float inputs_[4]{};
|
||||
std::atomic<float> inputs_[4]{};
|
||||
uint16_t result_ = 0;
|
||||
bool interrupt_ = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user