Skip to content

Commit

Permalink
Update switchmatrix logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiegle committed May 16, 2024
1 parent 5859cb5 commit 7ddf547
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 80 deletions.
3 changes: 3 additions & 0 deletions Source/Basestations/Basestation_v1.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> getSyncFrequencies() override;

Expand Down
174 changes: 98 additions & 76 deletions Source/Basestations/Basestation_v3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ bool Basestation_v3::open()
syncFrequencies.add(1);
syncFrequencies.add(10);

//LOGC("Initial switchmatrix status:");
//print_switchmatrix();

return true;
}

Expand All @@ -283,7 +286,6 @@ void Basestation_v3::initialize(bool signalChainIsLoading)

if (!probesInitialized)
{
//errorCode = Neuropixels::setTriggerInput(slot, Neuropixels::TRIGIN_SW);

for (auto probe : probes)
{
Expand All @@ -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();

}
Expand All @@ -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();

}

Expand All @@ -386,53 +436,25 @@ Array<int> 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()
Expand Down
6 changes: 6 additions & 0 deletions Source/Basestations/Basestation_v3.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> getSyncFrequencies() override;

Expand All @@ -144,6 +147,9 @@ class Basestation_v3 : public Basestation
void waitForThreadToExit() override;

private:

void print_switchmatrix();

std::unique_ptr<ArmBasestation> armBasestation;

Neuropixels::NP_ErrorCode errorCode;
Expand Down
5 changes: 5 additions & 0 deletions Source/Basestations/OneBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ void OneBox::setSyncAsOutput(int freqIndex)

}

void OneBox::setSyncAsPassive()
{

}

int OneBox::getProbeCount()
{
return probes.size();
Expand Down
3 changes: 3 additions & 0 deletions Source/Basestations/OneBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> getSyncFrequencies() override;

Expand Down
6 changes: 6 additions & 0 deletions Source/Basestations/SimulatedBasestation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ void SimulatedBasestation::setSyncAsOutput(int freqIndex)

}


void SimulatedBasestation::setSyncAsPassive()
{

}

int SimulatedBasestation::getProbeCount()
{
return probes.size();
Expand Down
3 changes: 3 additions & 0 deletions Source/Basestations/SimulatedBasestation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions Source/NeuropixComponents.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> getSyncFrequencies() = 0;

Expand Down
18 changes: 14 additions & 4 deletions Source/NeuropixThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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<int> NeuropixThread::getSyncFrequencies()
Expand Down Expand Up @@ -1109,8 +1120,7 @@ void NeuropixThread::updateSettings(OwnedArray<ContinuousChannel>* 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;

Expand Down

0 comments on commit 7ddf547

Please sign in to comment.