From 7ddf547db58b5ef6dd79441eff6fea6a2560dce5 Mon Sep 17 00:00:00 2001 From: Josh Siegle Date: Thu, 16 May 2024 15:17:17 -0700 Subject: [PATCH] Update switchmatrix logic --- Source/Basestations/Basestation_v1.h | 3 + Source/Basestations/Basestation_v3.cpp | 174 +++++++++++-------- Source/Basestations/Basestation_v3.h | 6 + Source/Basestations/OneBox.cpp | 5 + Source/Basestations/OneBox.h | 3 + Source/Basestations/SimulatedBasestation.cpp | 6 + Source/Basestations/SimulatedBasestation.h | 3 + Source/NeuropixComponents.h | 3 + Source/NeuropixThread.cpp | 18 +- 9 files changed, 141 insertions(+), 80 deletions(-) diff --git a/Source/Basestations/Basestation_v1.h b/Source/Basestations/Basestation_v1.h index 066ef17..32bf47d 100644 --- a/Source/Basestations/Basestation_v1.h +++ b/Source/Basestations/Basestation_v1.h @@ -93,6 +93,9 @@ class Basestation_v1 : public Basestation /** Set basestation SMA connector as output (and set frequency)*/ void setSyncAsOutput(int freqIndex) override; + /** Set basestation SMA connector to inherit from PXI backplane */ + void setSyncAsPassive() override { } + /** Returns an array of available frequencies when SMA is in "output" mode */ Array getSyncFrequencies() override; diff --git a/Source/Basestations/Basestation_v3.cpp b/Source/Basestations/Basestation_v3.cpp index 989daad..7af5fb1 100644 --- a/Source/Basestations/Basestation_v3.cpp +++ b/Source/Basestations/Basestation_v3.cpp @@ -275,6 +275,9 @@ bool Basestation_v3::open() syncFrequencies.add(1); syncFrequencies.add(10); + //LOGC("Initial switchmatrix status:"); + //print_switchmatrix(); + return true; } @@ -283,7 +286,6 @@ void Basestation_v3::initialize(bool signalChainIsLoading) if (!probesInitialized) { - //errorCode = Neuropixels::setTriggerInput(slot, Neuropixels::TRIGIN_SW); for (auto probe : probes) { @@ -292,16 +294,69 @@ void Basestation_v3::initialize(bool signalChainIsLoading) probesInitialized = true; } + + LOGC("Arming basestation"); - Neuropixels::arm(slot); //armBasestation->startThread(); + Neuropixels::arm(slot); LOGC("Arming complete"); } +void Basestation_v3::print_switchmatrix() +{ + bool isConnected; + + Neuropixels::switchmatrix_get(slot, Neuropixels::SM_Output_StatusBit, Neuropixels::SM_Input_PXISYNC, &isConnected); + LOGC("Slot ", slot, " connection between StatusBit and PXISYNC: ", isConnected); + Neuropixels::switchmatrix_get(slot, Neuropixels::SM_Output_StatusBit, Neuropixels::SM_Input_SMA, &isConnected); + LOGC("Slot ", slot, " connection between StatusBit and SMA: ", isConnected); + Neuropixels::switchmatrix_get(slot, Neuropixels::SM_Output_StatusBit, Neuropixels::SM_Input_SyncClk, &isConnected); + LOGC("Slot ", slot, " connection between StatusBit and SyncClk: ", isConnected); + Neuropixels::switchmatrix_get(slot, Neuropixels::SM_Output_StatusBit, Neuropixels::SM_Input_None, &isConnected); + LOGC("Slot ", slot, " connection between StatusBit and None: ", isConnected); + Neuropixels::switchmatrix_get(slot, Neuropixels::SM_Output_StatusBit, Neuropixels::SM_Input_TimeStampClk, &isConnected); + LOGC("Slot ", slot, " connection between StatusBit and TimestampClk: ", isConnected); + Neuropixels::switchmatrix_get(slot, Neuropixels::SM_Output_StatusBit, Neuropixels::SM_Input_SMA1, &isConnected); + LOGC("Slot ", slot, " connection between StatusBit and SMA1: ", isConnected); + Neuropixels::switchmatrix_get(slot, Neuropixels::SM_Output_StatusBit, Neuropixels::SM_Input_SWTrigger1, &isConnected); + LOGC("Slot ", slot, " connection between StatusBit and SWTrigger1: ", isConnected); + + Neuropixels::switchmatrix_get(slot, Neuropixels::SM_Output_PXISYNC, Neuropixels::SM_Input_PXISYNC, &isConnected); + LOGC("Slot ", slot, " connection between PXISYNC and PXISYNC: ", isConnected); + Neuropixels::switchmatrix_get(slot, Neuropixels::SM_Output_PXISYNC, Neuropixels::SM_Input_SMA, &isConnected); + LOGC("Slot ", slot, " connection between PXISYNC and SMA: ", isConnected); + Neuropixels::switchmatrix_get(slot, Neuropixels::SM_Output_PXISYNC, Neuropixels::SM_Input_SyncClk, &isConnected); + LOGC("Slot ", slot, " connection between PXISYNC and SyncClk: ", isConnected); + Neuropixels::switchmatrix_get(slot, Neuropixels::SM_Output_PXISYNC, Neuropixels::SM_Input_None, &isConnected); + LOGC("Slot ", slot, " connection between PXISYNC and None: ", isConnected); + Neuropixels::switchmatrix_get(slot, Neuropixels::SM_Output_PXISYNC, Neuropixels::SM_Input_TimeStampClk, &isConnected); + LOGC("Slot ", slot, " connection between PXISYNC and TimestampClk: ", isConnected); + Neuropixels::switchmatrix_get(slot, Neuropixels::SM_Output_PXISYNC, Neuropixels::SM_Input_SMA1, &isConnected); + LOGC("Slot ", slot, " connection between PXISYNC and SMA1: ", isConnected); + Neuropixels::switchmatrix_get(slot, Neuropixels::SM_Output_PXISYNC, Neuropixels::SM_Input_SWTrigger1, &isConnected); + LOGC("Slot ", slot, " connection between PXISYNC and SWTrigger1: ", isConnected); + + Neuropixels::switchmatrix_get(slot, Neuropixels::SM_Output_SMA, Neuropixels::SM_Input_PXISYNC, &isConnected); + LOGC("Slot ", slot, " connection between SMA and PXISYNC: ", isConnected); + Neuropixels::switchmatrix_get(slot, Neuropixels::SM_Output_SMA, Neuropixels::SM_Input_SMA, &isConnected); + LOGC("Slot ", slot, " connection between SMA and SMA: ", isConnected); + Neuropixels::switchmatrix_get(slot, Neuropixels::SM_Output_SMA, Neuropixels::SM_Input_SyncClk, &isConnected); + LOGC("Slot ", slot, " connection between SMA and SyncClk: ", isConnected); + Neuropixels::switchmatrix_get(slot, Neuropixels::SM_Output_SMA, Neuropixels::SM_Input_None, &isConnected); + LOGC("Slot ", slot, " connection between SMA and None: ", isConnected); + Neuropixels::switchmatrix_get(slot, Neuropixels::SM_Output_SMA, Neuropixels::SM_Input_TimeStampClk, &isConnected); + LOGC("Slot ", slot, " connection between SMA and TimestampClk: ", isConnected); + Neuropixels::switchmatrix_get(slot, Neuropixels::SM_Output_SMA, Neuropixels::SM_Input_SMA1, &isConnected); + LOGC("Slot ", slot, " connection between SMA and SMA1: ", isConnected); + Neuropixels::switchmatrix_get(slot, Neuropixels::SM_Output_SMA, Neuropixels::SM_Input_SWTrigger1, &isConnected); + LOGC("Slot ", slot, " connection between SMA and SWTrigger1: ", isConnected); +} + Basestation_v3::~Basestation_v3() { /* As of API 3.31, closing a v3 basestation does not turn off the SMA output */ - setSyncAsInput(); + setSyncAsPassive(); + close(); } @@ -327,54 +382,49 @@ void Basestation_v3::waitForThreadToExit() armBasestation->waitForThreadToExit(25000); } -void Basestation_v3::setSyncAsInput() +void Basestation_v3::setSyncAsPassive() { + LOGC("Setting slot ", slot, " sync as passive."); - LOGD("Setting sync as input..."); + errorCode = Neuropixels::switchmatrix_clear(slot, Neuropixels::SM_Output_StatusBit); + errorCode = Neuropixels::switchmatrix_clear(slot, Neuropixels::SM_Output_SMA); + errorCode = Neuropixels::switchmatrix_clear(slot, Neuropixels::SM_Output_PXISYNC); - errorCode = Neuropixels::switchmatrix_set(slot, Neuropixels::SM_Output_StatusBit, Neuropixels::SM_Input_PXISYNC, false); - if (errorCode != Neuropixels::SUCCESS) + errorCode = Neuropixels::switchmatrix_set(slot, Neuropixels::SM_Output_StatusBit, Neuropixels::SM_Input_PXISYNC, true); + errorCode = Neuropixels::switchmatrix_set(slot, Neuropixels::SM_Output_SMA, Neuropixels::SM_Input_PXISYNC, true); + + if (invertOutput) { - LOGC("Failed to set sync on SMA output on slot: ", slot); + for (auto probe : probes) + { + probe->invertSyncLine = true; + } } + + //print_switchmatrix(); - /*errorCode = Neuropixels::switchmatrix_set(slot, Neuropixels::SM_Output_StatusBit, Neuropixels::SM_Input_SyncClk, false); - if (errorCode != Neuropixels::SUCCESS) - { - LOGC("Failed to set sync on SMA input on slot: ", slot); - } - /* - errorCode = Neuropixels::setParameter(Neuropixels::NP_PARAM_SYNCMASTER, slot); - if (errorCode != Neuropixels::SUCCESS) - { - LOGC("Failed to set slot", slot, "as sync master!"); - return; - } +} - errorCode = Neuropixels::setParameter(Neuropixels::NP_PARAM_SYNCSOURCE, Neuropixels::SyncSource_SMA); - if (errorCode != Neuropixels::SUCCESS) - { - LOGC("Failed to set slot ", slot, "SMA as sync source!"); - } - */ - - /*errorCode = Neuropixels::switchmatrix_set(slot, Neuropixels::SM_Output_StatusBit, Neuropixels::SM_Input_PXISYNC, true); - if (errorCode != Neuropixels::SUCCESS) - { - LOGD("Failed to set sync on SMA input on slot: ", slot); - }*/ - if (invertOutput) - { - LOGD("Sync as input: don't invert sync line."); +void Basestation_v3::setSyncAsInput() +{ - for (auto probe : probes) - { - probe->invertSyncLine = false; - } + LOGC("Setting slot ", slot, " sync as input."); + + errorCode = Neuropixels::switchmatrix_clear(slot, Neuropixels::SM_Output_StatusBit); + errorCode = Neuropixels::switchmatrix_clear(slot, Neuropixels::SM_Output_SMA); + errorCode = Neuropixels::switchmatrix_clear(slot, Neuropixels::SM_Output_PXISYNC); + + errorCode = Neuropixels::switchmatrix_set(slot, Neuropixels::SM_Output_StatusBit, Neuropixels::SM_Input_SMA, true); + errorCode = Neuropixels::switchmatrix_set(slot, Neuropixels::SM_Output_PXISYNC, Neuropixels::SM_Input_SMA, true); + + if (errorCode != Neuropixels::SUCCESS) + { + LOGC("Failed to set sync on SMA output on slot: ", slot); } + //print_switchmatrix(); } @@ -386,53 +436,25 @@ Array Basestation_v3::getSyncFrequencies() void Basestation_v3::setSyncAsOutput(int freqIndex) { - /* - errorCode = Neuropixels::setParameter(Neuropixels::NP_PARAM_SYNCMASTER, slot); - if (errorCode != Neuropixels::SUCCESS) - { - LOGC("Failed to set slot ", slot, " as sync master!"); - return; - } - errorCode = Neuropixels::setParameter(Neuropixels::NP_PARAM_SYNCSOURCE, Neuropixels::SyncSource_Clock); - if (errorCode != Neuropixels::SUCCESS) - { - LOGC("Failed to set slot ", slot, " internal clock as sync source!"); - return; - } + LOGC("Setting slot ", slot, " sync as output."); - int freq = syncFrequencies[freqIndex]; + errorCode = Neuropixels::switchmatrix_clear(slot, Neuropixels::SM_Output_StatusBit); + errorCode = Neuropixels::switchmatrix_clear(slot, Neuropixels::SM_Output_SMA); + errorCode = Neuropixels::switchmatrix_clear(slot, Neuropixels::SM_Output_PXISYNC); - LOGD("Setting slot ", slot, " sync frequency to ", freq, " Hz..."); - errorCode = Neuropixels::setParameter(Neuropixels::NP_PARAM_SYNCFREQUENCY_HZ, freq); - if (errorCode != Neuropixels::SUCCESS) - { - LOGC("Failed to set slot ", slot, " sync frequency to ", freq, " Hz!"); - return; - } - */ + errorCode = Neuropixels::switchmatrix_set(slot, Neuropixels::SM_Output_StatusBit, Neuropixels::SM_Input_SyncClk, true); + errorCode = Neuropixels::switchmatrix_set(slot, Neuropixels::SM_Output_PXISYNC, Neuropixels::SM_Input_SyncClk, true); + errorCode = Neuropixels::switchmatrix_set(slot, Neuropixels::SM_Output_SMA, Neuropixels::SM_Input_SyncClk, true); - LOGD("Setting sync as output..."); + errorCode = Neuropixels::setSyncClockFrequency(slot, syncFrequencies[freqIndex]); - errorCode = Neuropixels::switchmatrix_set(slot, Neuropixels::SM_Output_PXISYNC, Neuropixels::SM_Input_SyncClk, true); if (errorCode != Neuropixels::SUCCESS) { LOGC("Failed to set sync on SMA output on slot: ", slot); } - - - - if (invertOutput) - { - LOGD("Sync as output: do invert sync line."); - - for (auto probe : probes) - { - probe->invertSyncLine = true; - } - } - + //print_switchmatrix(); } int Basestation_v3::getProbeCount() diff --git a/Source/Basestations/Basestation_v3.h b/Source/Basestations/Basestation_v3.h index 2e68c33..a27ec68 100644 --- a/Source/Basestations/Basestation_v3.h +++ b/Source/Basestations/Basestation_v3.h @@ -122,6 +122,9 @@ class Basestation_v3 : public Basestation /** Set basestation SMA connector as output (and set frequency)*/ void setSyncAsOutput(int freqIndex) override; + /** Set basestation SMA connector to inherit signal from PXI backplane */ + void setSyncAsPassive() override; + /** Returns an array of available frequencies when SMA is in "output" mode */ Array getSyncFrequencies() override; @@ -144,6 +147,9 @@ class Basestation_v3 : public Basestation void waitForThreadToExit() override; private: + + void print_switchmatrix(); + std::unique_ptr armBasestation; Neuropixels::NP_ErrorCode errorCode; diff --git a/Source/Basestations/OneBox.cpp b/Source/Basestations/OneBox.cpp index 99995b8..6e3d041 100644 --- a/Source/Basestations/OneBox.cpp +++ b/Source/Basestations/OneBox.cpp @@ -357,6 +357,11 @@ void OneBox::setSyncAsOutput(int freqIndex) } +void OneBox::setSyncAsPassive() +{ + +} + int OneBox::getProbeCount() { return probes.size(); diff --git a/Source/Basestations/OneBox.h b/Source/Basestations/OneBox.h index 5e42b39..4210f97 100644 --- a/Source/Basestations/OneBox.h +++ b/Source/Basestations/OneBox.h @@ -67,6 +67,9 @@ class OneBox : public Basestation /** Sets the SMA port to output mode */ void setSyncAsOutput(int freqIndex) override; + /** Sets the OneBox as passive input (does nothing) */ + void setSyncAsPassive() override; + /** Returns the available sync frequencies*/ Array getSyncFrequencies() override; diff --git a/Source/Basestations/SimulatedBasestation.cpp b/Source/Basestations/SimulatedBasestation.cpp index 2bad7d1..0505c32 100644 --- a/Source/Basestations/SimulatedBasestation.cpp +++ b/Source/Basestations/SimulatedBasestation.cpp @@ -208,6 +208,12 @@ void SimulatedBasestation::setSyncAsOutput(int freqIndex) } + +void SimulatedBasestation::setSyncAsPassive() +{ + +} + int SimulatedBasestation::getProbeCount() { return probes.size(); diff --git a/Source/Basestations/SimulatedBasestation.h b/Source/Basestations/SimulatedBasestation.h index be08137..36542e1 100644 --- a/Source/Basestations/SimulatedBasestation.h +++ b/Source/Basestations/SimulatedBasestation.h @@ -98,6 +98,9 @@ class SimulatedBasestation : public Basestation /** Set basestation SMA connector as output (and set frequency)*/ void setSyncAsOutput(int freqIndex) override; + /** Set basestation SMA connector to passively inherit signal from backplane */ + void setSyncAsPassive() override; + /** Starts probe data streaming */ void startAcquisition() override; diff --git a/Source/NeuropixComponents.h b/Source/NeuropixComponents.h index 0c5c511..dc36344 100644 --- a/Source/NeuropixComponents.h +++ b/Source/NeuropixComponents.h @@ -614,6 +614,9 @@ class Basestation : public NeuropixComponent /** Sets the sync channel as an "output" (and specifies the frequency index) */ virtual void setSyncAsOutput(int freqIndex) = 0; + /** Sets the sync channel to inherit from the PXI backplane */ + virtual void setSyncAsPassive() = 0; + /** Returns an array of available sync frequencies for this basestation */ virtual Array getSyncFrequencies() = 0; diff --git a/Source/NeuropixThread.cpp b/Source/NeuropixThread.cpp index 76604e4..f859368 100644 --- a/Source/NeuropixThread.cpp +++ b/Source/NeuropixThread.cpp @@ -74,7 +74,7 @@ void Initializer::run() Neuropixels::NP_ErrorCode ec = Neuropixels::getDeviceInfo(list[i].ID, &list[i]); - LOGD("Slot ID: ", slotID, "Platform ID : ", list[i].platformid); + LOGD("Slot ID: ", slotID, ", Platform ID : ", list[i].platformid); if (foundSlot && list[i].platformid == Neuropixels::NPPlatform_PXI && type == PXI) { @@ -635,13 +635,24 @@ String NeuropixThread::getApiVersion() void NeuropixThread::setMainSync(int slotIndex) { if (foundInputSource() && slotIndex > -1) + { + for (auto basestation : basestations) + basestation->setSyncAsPassive(); + basestations[slotIndex]->setSyncAsInput(); + } + } void NeuropixThread::setSyncOutput(int slotIndex) { - if (basestations.size() && slotIndex > -1) + if (foundInputSource() && slotIndex > -1) + { + for (auto basestation : basestations) + basestation->setSyncAsPassive(); + basestations[slotIndex]->setSyncAsOutput(0); + } } Array NeuropixThread::getSyncFrequencies() @@ -1109,8 +1120,7 @@ void NeuropixThread::updateSettings(OwnedArray* continuousCha float depth = float(info.probe->electrodeMetadata[selectedElectrode].ypos) + shank * 10000.0f - + float(ch % 2) - + 0.0001f * ch; // each channel must have a unique depth value + + info.probe->electrodeMetadata[selectedElectrode].column_index * 0.0001f; continuousChannels->getLast()->position.y = depth;