commit 6a05beb1789977c2b666cb4b16cf54200b9bdd07
parent 31dc5f1b4d346fc951735235381c4bca6feed429
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Tue, 30 Jul 2024 10:17:54 +0200
detect when device has booted and wait for it
Diffstat:
7 files changed, 43 insertions(+), 10 deletions(-)
diff --git a/source/hardwareLib/i2cFlash.h b/source/hardwareLib/i2cFlash.h
@@ -29,6 +29,15 @@ namespace hwLib
bool setData(std::vector<uint8_t>& _data);
+ const auto& getAddress() const { return m_address; }
+
+ protected:
+ void onStartCondition() override;
+ void onStopCondition() override;
+ void onByteWritten() override;
+ std::optional<bool> onAck() override;
+ uint8_t onReadByte() override;
+
private:
enum class State
{
@@ -53,11 +62,6 @@ namespace hwLib
Write = 0b0000'000'0,
};
- void onStartCondition() override;
- void onStopCondition() override;
- void onByteWritten() override;
- std::optional<bool> onAck() override;
- uint8_t onReadByte() override;
void writeByte(uint8_t _byte);
void advanceAddress();
diff --git a/source/nord/n2x/n2xLib/n2xflash.cpp b/source/nord/n2x/n2xLib/n2xflash.cpp
@@ -1,11 +1,12 @@
#include "n2xflash.h"
+#include "n2xhardware.h"
#include "n2xtypes.h"
#include "synthLib/os.h"
namespace n2x
{
- Flash::Flash()
+ Flash::Flash(Hardware& _hardware) : m_hardware(_hardware)
{
const auto filename = synthLib::findROM(g_flashSize, g_flashSize);
@@ -18,4 +19,12 @@ namespace n2x
}
}
}
+
+ uint8_t Flash::onReadByte()
+ {
+ if(getAddress() == 0x31 && --m_bootCounter == 0)
+ m_hardware.notifyBootFinished();
+
+ return I2cFlash::onReadByte();
+ }
}
diff --git a/source/nord/n2x/n2xLib/n2xflash.h b/source/nord/n2x/n2xLib/n2xflash.h
@@ -4,9 +4,18 @@
namespace n2x
{
+ class Hardware;
+
class Flash : public hwLib::I2cFlash
{
public:
- Flash();
+ Flash(Hardware& _hardware);
+
+ protected:
+ uint8_t onReadByte() override;
+
+ private:
+ Hardware& m_hardware;
+ uint32_t m_bootCounter = 2;
};
}
diff --git a/source/nord/n2x/n2xLib/n2xhardware.cpp b/source/nord/n2x/n2xLib/n2xhardware.cpp
@@ -11,7 +11,7 @@ namespace n2x
static_assert(g_syncHaltDspEsaiThreshold >= g_syncEsaiFrameRate * 2, "esai DSP halt threshold must be greater than two times the sync rate");
Hardware::Hardware()
- : m_uc(m_rom)
+ : m_uc(*this, m_rom)
, m_dspA(*this, m_uc.getHdi08A(), 0)
, m_dspB(*this, m_uc.getHdi08B(), 1)
, m_samplerateInv(1.0 / g_samplerate)
@@ -27,6 +27,9 @@ namespace n2x
{
ucThreadFunc();
}));
+
+ while(!m_bootFinished)
+ processAudio(8,8);
}
Hardware::~Hardware() = default;
@@ -122,6 +125,11 @@ namespace n2x
return true;
}
+ void Hardware::notifyBootFinished()
+ {
+ m_bootFinished = true;
+ }
+
void Hardware::ensureBufferSize(const uint32_t _frames)
{
if(m_dummyInput.size() >= _frames)
diff --git a/source/nord/n2x/n2xLib/n2xhardware.h b/source/nord/n2x/n2xLib/n2xhardware.h
@@ -38,6 +38,7 @@ namespace n2x
void setButtonState(ButtonType _type, bool _pressed);
void processAudio(const synthLib::TAudioOutputs& _outputs, uint32_t _frames, uint32_t _latency);
bool sendMidi(const synthLib::SMidiEvent& _ev);
+ void notifyBootFinished();
private:
void ensureBufferSize(uint32_t _frames);
@@ -81,5 +82,7 @@ namespace n2x
uint32_t m_esaiLatency = 0;
std::mutex m_haltDSPmutex;
std::condition_variable m_haltDSPcv;
+
+ bool m_bootFinished = false;
};
}
diff --git a/source/nord/n2x/n2xLib/n2xmc.cpp b/source/nord/n2x/n2xLib/n2xmc.cpp
@@ -21,7 +21,7 @@ namespace n2x
static constexpr uint32_t g_maskResetDSP = 1 << g_bitResetDSP;
static constexpr uint32_t g_maskResetDAC = 1 << g_bitResetDAC;
- Microcontroller::Microcontroller(const Rom& _rom) : m_hdi08(m_hdi08A, m_hdi08B), m_midi(getQSM())
+ Microcontroller::Microcontroller(Hardware& _hardware, const Rom& _rom) : m_flash(_hardware), m_hdi08(m_hdi08A, m_hdi08B), m_midi(getQSM())
{
if(!_rom.isValid())
return;
diff --git a/source/nord/n2x/n2xLib/n2xmc.h b/source/nord/n2x/n2xLib/n2xmc.h
@@ -16,7 +16,7 @@ namespace n2x
class Microcontroller : public mc68k::Mc68k
{
public:
- explicit Microcontroller(const Rom& _rom);
+ explicit Microcontroller(Hardware& _hardware, const Rom& _rom);
auto& getHdi08A() { return m_hdi08A.getHdi08(); }
auto& getHdi08B() { return m_hdi08B.getHdi08(); }