void Si4703_Breakout::setChannel(int channel) { //Freq(MHz) = 0.200(in USA) * Channel + 87.5MHz //97.3 = 0.2 * Chan + 87.5 //9.8 / 0.2 = 49 int newChannel = channel * 10; //973 * 10 = 9730 newChannel -= 8750; //9730 - 8750 = 980 newChannel /= 10; //980 / 10 = 98 //These steps come from AN230 page 20 rev 0.5 readRegisters(); si4703_registers[CHANNEL] &= 0xFE00; //Clear out the channel bits si4703_registers[CHANNEL] |= newChannel; //Mask in the new channel si4703_registers[CHANNEL] |= (1<<TUNE); //Set the TUNE bit to start updateRegisters(); //delay(60); //Wait 60ms - you can use or skip this delay //Poll to see if STC is set while(1) { readRegisters(); if( (si4703_registers[STATUSRSSI] & (1<<STC)) != 0) break; //Tuning complete! } readRegisters(); si4703_registers[CHANNEL] &= ~(1<<TUNE); //Clear the tune after a tune has completed updateRegisters(); //Wait for the si4703 to clear the STC as well while(1) { readRegisters(); if( (si4703_registers[STATUSRSSI] & (1<<STC)) == 0) break; //Tuning complete! } }
void Si4703_Breakout::powerOn(){ //To get the Si4703 inito 2-wire mode, SEN needs to be high and SDIO needs to be low after a reset //The breakout board has SEN pulled high, but also has SDIO pulled high. Therefore, after a normal power up //The Si4703 will be in an unknown state. RST must be controlled pinMode(_resetPin, OUTPUT); pinMode(_sdioPin, OUTPUT); //SDIO is connected to A4 for I2C digitalWrite(_sdioPin, LOW); //A low SDIO indicates a 2-wire interface digitalWrite(_resetPin, LOW); //Put Si4703 into reset delay(1); //Some delays while we allow pins to settle digitalWrite(_resetPin, HIGH); //Bring Si4703 out of reset with SDIO set to low and SEN pulled high with on-board resistor delay(1); //Allow Si4703 to come out of reset Wire.begin(); //Now that the unit is reset and I2C inteface mode, we need to begin I2C readRegisters(); //Read the current register set //si4703_registers[0x07] = 0xBC04; //Enable the oscillator, from AN230 page 9, rev 0.5 (DOES NOT WORK, wtf Silicon Labs datasheet?) si4703_registers[0x07] = 0x8100; //Enable the oscillator, from AN230 page 9, rev 0.61 (works) updateRegisters(); //Update delay(500); //Wait for clock to settle - from AN230 page 9 readRegisters(); //Read the current register set si4703_registers[POWERCFG] = 0x4001; //Enable the IC // si4703_registers[POWERCFG] |= (1<<SMUTE) | (1<<DMUTE); //Disable Mute, disable softmute si4703_registers[SYSCONFIG1] |= (1 << RDS); //Enable RDS si4703_registers[SYSCONFIG1] |= (1 << DE); //50kHz Europe setup si4703_registers[SYSCONFIG2] |= (1 << SPACE0); //100kHz channel spacing for Europe si4703_registers[SYSCONFIG2] &= 0xFFF0; //Clear volume bits si4703_registers[SYSCONFIG2] |= 0x0001; //Set volume to lowest updateRegisters(); //Update delay(110); //Max powerup time, from datasheet page 13 }
static bool getExceptionLocation(PDReader* reader, uint64_t* address, CPUState* cpuState) { uint32_t event; bool foundException = false; while ((event = PDRead_getEvent(reader)) != 0) { switch (event) { case PDEventType_setRegisters: { if (cpuState) updateRegisters(cpuState, reader); break; } case PDEventType_setExceptionLocation: { assert_true(PDRead_findU64(reader, address, "address", 0) & PDReadStatus_ok); foundException = true; break; } } } return foundException; }
void RegistersManager::architectureParsedSlot(Architecture arch) { qCDebug(DEBUGGERGDB) << " Current controller: " << m_registerController << "Current arch " << m_currentArchitecture; if (m_registerController || m_currentArchitecture != undefined) { return; } switch (arch) { case x86: m_registerController.reset(new RegisterController_x86(m_debugSession)) ; qCDebug(DEBUGGERGDB) << "Found x86 architecture"; break; case x86_64: m_registerController.reset(new RegisterController_x86_64(m_debugSession)); qCDebug(DEBUGGERGDB) << "Found x86_64 architecture"; break; case arm: m_registerController.reset(new RegisterController_Arm(m_debugSession)); qCDebug(DEBUGGERGDB) << "Found Arm architecture"; break; default: m_registerController.reset(); qWarning() << "Unsupported architecture. Registers won't be available."; break; } m_currentArchitecture = arch; setController(m_registerController.data()); if (m_registerController) { updateRegisters(); } }
void Si4703_Breakout::setVolume(int volume){ readRegisters(); //Read the current register set if (volume < 0) volume = 0; if (volume > 15) volume = 15; si4703_registers[SYSCONFIG2] &= 0xFFF0; //Clear volume bits si4703_registers[SYSCONFIG2] |= volume; //Set new volume updateRegisters(); //Update }
double RHD2000Thread::setLowerBandwidth(double lower) { desiredLowerBandwidth = lower; updateRegisters(); return actualLowerBandwidth; }
void Si4703_Breakout::setChannel(int channel) { //Freq(MHz) = 0.200(in USA) * Channel + 87.5MHz //channel=(freq-87.5)/0.2; //Freq(MHz) = 0.100(in Europe) * Channel + 87.5MHz //channel=(freq-87.5)/0.1; int newChannel = channel * 10; newChannel -= 8750; if (_region==1){ newChannel /= 20; // US } else { newChannel /= 10; // Europe } //These steps come from AN230 page 20 rev 0.5 readRegisters(); si4703_registers[CHANNEL] &= 0xFE00; //Clear out the channel bits si4703_registers[CHANNEL] |= newChannel; //Mask in the new channel si4703_registers[CHANNEL] |= (1<<TUNE); //Set the TUNE bit to start updateRegisters(); //delay(60); //Wait 60ms - you can use or skip this delay //set timeout duration long endTime = millis() + 2000; //Poll to see if STC is set while(millis() < endTime) { readRegisters(); if( (si4703_registers[STATUSRSSI] & (1<<STC)) != 0) break; //Tuning complete! } readRegisters(); si4703_registers[CHANNEL] &= ~(1<<TUNE); //Clear the tune after a tune has completed updateRegisters(); //set timeout duration endTime = millis() + 2000; //Wait for the si4703 to clear the STC as well while(millis() < endTime) { readRegisters(); if( (si4703_registers[STATUSRSSI] & (1<<STC)) == 0) break; //Tuning complete! } }
double RHD2000Thread::setUpperBandwidth(double upper) { desiredUpperBandwidth = upper; updateRegisters(); return actualUpperBandwidth; }
static int update(void* userData, PDUI* uiFuncs, PDReader* inEvents, PDWriter* writer) { uint32_t event; DissassemblyData* data = (DissassemblyData*)userData; data->requestDisassembly = false; while ((event = PDRead_getEvent(inEvents)) != 0) { switch (event) { case PDEventType_setDisassembly: { setDisassemblyCode(data, inEvents); break; } case PDEventType_setExceptionLocation: { uint64_t location = 0; PDRead_findU64(inEvents, &location, "address", 0); if (location != data->location) { data->location = location; data->requestDisassembly = true; } PDRead_findU8(inEvents, &data->locationSize, "address_size", 0); break; } case PDEventType_setRegisters: { updateRegisters(data, inEvents); break; } } } renderUI(data, uiFuncs); if (data->requestDisassembly) { int pc = (int)(data->pc) & ~(BlockSize - 1); PDWrite_eventBegin(writer, PDEventType_getDisassembly); PDWrite_u64(writer, "address_start", (uint64_t)pc); PDWrite_u32(writer, "instruction_count", (uint32_t)BlockSize / 3); PDWrite_eventEnd(writer); } return 0; }
static int update(void* user_data, PDUI* uiFuncs, PDReader* inEvents, PDWriter* outEvents) { uint32_t event; RegistersData* data = (RegistersData*)user_data; (void)outEvents; // Loop over all the in events while ((event = PDRead_get_event(inEvents)) != 0) { switch (event) { case PDEventType_SetRegisters: updateRegisters(data, inEvents); break; } } showUI(data, uiFuncs); return 0; }
bool handleEvents(CPUState* cpuState, Session* session) { uint32_t event = 0; PDReader* reader = session->reader; PDBinaryReader_initStream(reader, PDBinaryWriter_getData(session->currentWriter), PDBinaryWriter_getSize(session->currentWriter)); while ((event = PDRead_getEvent(reader)) != 0) { if (event == PDEventType_setRegisters) { updateRegisters(cpuState, reader); return true; } } return false; }
static int update(void* userData, PDUI* uiFuncs, PDReader* inEvents, PDWriter* writer) { uint32_t event; DissassemblyData* data = (DissassemblyData*)userData; while ((event = PDRead_getEvent(inEvents)) != 0) { switch (event) { case PDEventType_setDisassembly: { setDisassemblyCode(data, inEvents); break; } case PDEventType_setExceptionLocation: { PDRead_findU64(inEvents, &data->location, "address", 0); PDRead_findU8(inEvents, &data->locationSize, "address_size", 0); break; } case PDEventType_setRegisters: updateRegisters(data, inEvents); break; } } renderUI(data, uiFuncs); // Temporary req PDWrite_eventBegin(writer, PDEventType_getDisassembly); PDWrite_u64(writer, "address_start", 0); PDWrite_u32(writer, "instruction_count", (uint32_t)10); PDWrite_eventEnd(writer); return 0; }
void Si4703_Breakout::toggleMute(){ readRegisters(); si4703_registers[POWERCFG] ^= (1<<DMUTE); //Toggle Mute bit updateRegisters(); }
void* Bridge::processMessage(GUIMSG type, void* param1, void* param2) { if(dbgStopped) //there can be no more messages if the debugger stopped = BUG __debugbreak(); switch(type) { case GUI_DISASSEMBLE_AT: emit disassembleAt((int_t)param1, (int_t)param2); break; case GUI_SET_DEBUG_STATE: emit dbgStateChanged((DBGSTATE)(int_t)param1); break; case GUI_ADD_MSG_TO_LOG: emit addMsgToLog(QString((const char*)param1)); break; case GUI_CLEAR_LOG: emit clearLog(); break; case GUI_UPDATE_REGISTER_VIEW: emit updateRegisters(); break; case GUI_UPDATE_DISASSEMBLY_VIEW: emit repaintGui(); break; case GUI_UPDATE_BREAKPOINTS_VIEW: emit updateBreakpoints(); break; case GUI_UPDATE_WINDOW_TITLE: emit updateWindowTitle(QString((const char*)param1)); break; case GUI_GET_WINDOW_HANDLE: return winId; case GUI_DUMP_AT: emit dumpAt((int_t)param1); break; case GUI_SCRIPT_ADD: { BridgeResult result; emit scriptAdd((int)param1, (const char**)param2); result.Wait(); } break; case GUI_SCRIPT_CLEAR: emit scriptClear(); break; case GUI_SCRIPT_SETIP: emit scriptSetIp((int)param1); break; case GUI_SCRIPT_ERROR: { BridgeResult result; emit scriptError((int)param1, QString((const char*)param2)); result.Wait(); } break; case GUI_SCRIPT_SETTITLE: emit scriptSetTitle(QString((const char*)param1)); break; case GUI_SCRIPT_SETINFOLINE: emit scriptSetInfoLine((int)param1, QString((const char*)param2)); break; case GUI_SCRIPT_MESSAGE: { BridgeResult result; emit scriptMessage(QString((const char*)param1)); result.Wait(); } break; case GUI_SCRIPT_MSGYN: { BridgeResult result; emit scriptQuestion(QString((const char*)param1)); return (void*)result.Wait(); } break; case GUI_SCRIPT_ENABLEHIGHLIGHTING: emit scriptEnableHighlighting((bool)param1); break; case GUI_SYMBOL_UPDATE_MODULE_LIST: emit updateSymbolList((int)param1, (SYMBOLMODULEINFO*)param2); break; case GUI_SYMBOL_LOG_ADD: emit addMsgToSymbolLog(QString((const char*)param1)); break; case GUI_SYMBOL_LOG_CLEAR: emit clearSymbolLog(); break; case GUI_SYMBOL_SET_PROGRESS: emit setSymbolProgress((int)param1); break; case GUI_REF_ADDCOLUMN: emit referenceAddColumnAt((int)param1, QString((const char*)param2)); break; case GUI_REF_SETROWCOUNT: emit referenceSetRowCount((int_t)param1); break; case GUI_REF_GETROWCOUNT: return (void*)referenceManager->currentReferenceView()->mList->getRowCount(); case GUI_REF_DELETEALLCOLUMNS: GuiReferenceInitialize("References"); break; case GUI_REF_SETCELLCONTENT: { CELLINFO* info = (CELLINFO*)param1; emit referenceSetCellContent(info->row, info->col, QString(info->str)); } break; case GUI_REF_GETCELLCONTENT: return (void*)referenceManager->currentReferenceView()->mList->getCellContent((int)param1, (int)param2).toUtf8().constData(); case GUI_REF_RELOADDATA: emit referenceReloadData(); break; case GUI_REF_SETSINGLESELECTION: emit referenceSetSingleSelection((int)param1, (bool)param2); break; case GUI_REF_SETPROGRESS: emit referenceSetProgress((int)param1); break; case GUI_REF_SETSEARCHSTARTCOL: emit referenceSetSearchStartCol((int)param1); break; case GUI_REF_INITIALIZE: { BridgeResult result; emit referenceInitialize(QString((const char*)param1)); result.Wait(); } break; case GUI_STACK_DUMP_AT: emit stackDumpAt((uint_t)param1, (uint_t)param2); break; case GUI_UPDATE_DUMP_VIEW: emit updateDump(); break; case GUI_UPDATE_THREAD_VIEW: emit updateThreads(); break; case GUI_UPDATE_MEMORY_VIEW: emit updateMemory(); break; case GUI_ADD_RECENT_FILE: emit addRecentFile(QString((const char*)param1)); break; case GUI_SET_LAST_EXCEPTION: emit setLastException((unsigned int)param1); break; case GUI_GET_DISASSEMBLY: { uint_t parVA = (uint_t)param1; char* text = (char*)param2; if(!text || !parVA || !DbgIsDebugging()) return 0; byte_t wBuffer[16]; if(!DbgMemRead(parVA, wBuffer, 16)) return 0; QBeaEngine disasm(-1); Instruction_t instr = disasm.DisassembleAt(wBuffer, 16, 0, 0, parVA); BeaTokenizer::TokenizeInstruction(&instr.tokens, &instr.disasm, -1); QList<RichTextPainter::CustomRichText_t> richText; BeaTokenizer::TokenToRichText(&instr.tokens, &richText, 0); QString finalInstruction = ""; for(int i = 0; i < richText.size(); i++) finalInstruction += richText.at(i).text; strcpy_s(text, GUI_MAX_DISASSEMBLY_SIZE, finalInstruction.toUtf8().constData()); return (void*)1; } break; case GUI_MENU_ADD: { BridgeResult result; emit menuAddMenu((int)param1, QString((const char*)param2)); return (void*)result.Wait(); } break; case GUI_MENU_ADD_ENTRY: { BridgeResult result; emit menuAddMenuEntry((int)param1, QString((const char*)param2)); return (void*)result.Wait(); } break; case GUI_MENU_ADD_SEPARATOR: { BridgeResult result; emit menuAddSeparator((int)param1); result.Wait(); } break; case GUI_MENU_CLEAR: { BridgeResult result; emit menuClearMenu((int)param1); result.Wait(); } break; case GUI_SELECTION_GET: { int hWindow = (int)param1; SELECTIONDATA* selection = (SELECTIONDATA*)param2; if(!DbgIsDebugging()) return (void*)false; BridgeResult result; switch(hWindow) { case GUI_DISASSEMBLY: emit selectionDisasmGet(selection); break; case GUI_DUMP: emit selectionDumpGet(selection); break; case GUI_STACK: emit selectionStackGet(selection); break; default: return (void*)false; } result.Wait(); if(selection->start > selection->end) //swap start and end { int_t temp = selection->end; selection->end = selection->start; selection->start = temp; } return (void*)true; } break; case GUI_SELECTION_SET: { int hWindow = (int)param1; const SELECTIONDATA* selection = (const SELECTIONDATA*)param2; if(!DbgIsDebugging()) return (void*)false; BridgeResult result; switch(hWindow) { case GUI_DISASSEMBLY: emit selectionDisasmSet(selection); break; case GUI_DUMP: emit selectionDumpSet(selection); break; case GUI_STACK: emit selectionStackSet(selection); break; default: return (void*)false; } return (void*)result.Wait(); } break; case GUI_GETLINE_WINDOW: { QString text = ""; BridgeResult result; emit getStrWindow(QString((const char*)param1), &text); if(result.Wait()) { strcpy_s((char*)param2, GUI_MAX_LINE_SIZE, text.toUtf8().constData()); return (void*)true; } return (void*)false; //cancel/escape } break; case GUI_AUTOCOMPLETE_ADDCMD: emit autoCompleteAddCmd(QString((const char*)param1)); break; case GUI_AUTOCOMPLETE_DELCMD: emit autoCompleteDelCmd(QString((const char*)param1)); break; case GUI_AUTOCOMPLETE_CLEARALL: emit autoCompleteClearAll(); break; case GUI_ADD_MSG_TO_STATUSBAR: emit addMsgToStatusBar(QString((const char*)param1)); break; case GUI_UPDATE_SIDEBAR: emit updateSideBar(); break; case GUI_REPAINT_TABLE_VIEW: emit repaintTableView(); break; case GUI_UPDATE_PATCHES: emit updatePatches(); break; case GUI_UPDATE_CALLSTACK: emit updateCallStack(); break; case GUI_SYMBOL_REFRESH_CURRENT: emit symbolRefreshCurrent(); break; case GUI_LOAD_SOURCE_FILE: emitLoadSourceFile(QString((const char*)param1), (int)param2); break; case GUI_MENU_SET_ICON: { int hMenu = (int)param1; const ICONDATA* icon = (const ICONDATA*)param2; BridgeResult result; if(!icon) emit setIconMenu(hMenu, QIcon()); else { QImage img; img.loadFromData((uchar*)icon->data, icon->size); QIcon qIcon(QPixmap::fromImage(img)); emit setIconMenu(hMenu, qIcon); } result.Wait(); } break; case GUI_MENU_SET_ENTRY_ICON: { int hEntry = (int)param1; const ICONDATA* icon = (const ICONDATA*)param2; BridgeResult result; if(!icon) emit setIconMenuEntry(hEntry, QIcon()); else { QImage img; img.loadFromData((uchar*)icon->data, icon->size); QIcon qIcon(QPixmap::fromImage(img)); emit setIconMenuEntry(hEntry, qIcon); } result.Wait(); } break; case GUI_SHOW_CPU: emit showCpu(); break; case GUI_ADD_QWIDGET_TAB: emit addQWidgetTab((QWidget*)param1); break; case GUI_SHOW_QWIDGET_TAB: emit showQWidgetTab((QWidget*)param1); break; case GUI_CLOSE_QWIDGET_TAB: emit closeQWidgetTab((QWidget*)param1); break; case GUI_EXECUTE_ON_GUI_THREAD: GuiAddLogMessage(QString().sprintf("thread id (bridge) %X\n", GetCurrentThreadId()).toUtf8().constData()); emit executeOnGuiThread(param1); break; case GUI_UPDATE_TIME_WASTED_COUNTER: emit updateTimeWastedCounter(); break; } return nullptr; }
void RHD2000Thread::scanPorts() { if (!deviceFound) //Safety to avoid crashes if board not present { return; } // Scan SPI ports int delay, stream, id; //int numChannelsOnPort[4] = {0, 0, 0, 0}; Array<int> chipId; chipId.insertMultiple(0,-1,8); setSampleRate(16, true); // set to 30 kHz temporarily // Enable all data streams, and set sources to cover one or two chips // on Ports A-D. evalBoard->setDataSource(0, Rhd2000EvalBoard::PortA1); evalBoard->setDataSource(1, Rhd2000EvalBoard::PortA2); evalBoard->setDataSource(2, Rhd2000EvalBoard::PortB1); evalBoard->setDataSource(3, Rhd2000EvalBoard::PortB2); evalBoard->setDataSource(4, Rhd2000EvalBoard::PortC1); evalBoard->setDataSource(5, Rhd2000EvalBoard::PortC2); evalBoard->setDataSource(6, Rhd2000EvalBoard::PortD1); evalBoard->setDataSource(7, Rhd2000EvalBoard::PortD2); evalBoard->enableDataStream(0, true); evalBoard->enableDataStream(1, true); evalBoard->enableDataStream(2, true); evalBoard->enableDataStream(3, true); evalBoard->enableDataStream(4, true); evalBoard->enableDataStream(5, true); evalBoard->enableDataStream(6, true); evalBoard->enableDataStream(7, true); std::cout << "Number of enabled data streams: " << evalBoard->getNumEnabledDataStreams() << std::endl; evalBoard->selectAuxCommandBank(Rhd2000EvalBoard::PortA, Rhd2000EvalBoard::AuxCmd3, 0); evalBoard->selectAuxCommandBank(Rhd2000EvalBoard::PortB, Rhd2000EvalBoard::AuxCmd3, 0); evalBoard->selectAuxCommandBank(Rhd2000EvalBoard::PortC, Rhd2000EvalBoard::AuxCmd3, 0); evalBoard->selectAuxCommandBank(Rhd2000EvalBoard::PortD, Rhd2000EvalBoard::AuxCmd3, 0); // Since our longest command sequence is 60 commands, we run the SPI // interface for 60 samples. evalBoard->setMaxTimeStep(60); evalBoard->setContinuousRunMode(false); Rhd2000DataBlock* dataBlock = new Rhd2000DataBlock(evalBoard->getNumEnabledDataStreams()); Array<int> sumGoodDelays; sumGoodDelays.insertMultiple(0,0,8); Array<int> indexFirstGoodDelay; indexFirstGoodDelay.insertMultiple(0,-1,8); Array<int> indexSecondGoodDelay; indexSecondGoodDelay.insertMultiple(0,-1,8); // Run SPI command sequence at all 16 possible FPGA MISO delay settings // to find optimum delay for each SPI interface cable. std::cout << "Checking for connected amplifier chips..." << std::endl; for (delay = 0; delay < 16; delay++)//(delay = 0; delay < 16; ++delay) { evalBoard->setCableDelay(Rhd2000EvalBoard::PortA, delay); evalBoard->setCableDelay(Rhd2000EvalBoard::PortB, delay); evalBoard->setCableDelay(Rhd2000EvalBoard::PortC, delay); evalBoard->setCableDelay(Rhd2000EvalBoard::PortD, delay); // Start SPI interface. evalBoard->run(); // Wait for the 60-sample run to complete. while (evalBoard->isRunning()) { ; } // Read the resulting single data block from the USB interface. evalBoard->readDataBlock(dataBlock); // Read the Intan chip ID number from each RHD2000 chip found. // Record delay settings that yield good communication with the chip. for (stream = 0; stream < MAX_NUM_DATA_STREAMS; ++stream)//MAX_NUM_DATA_STREAMS; ++stream) { // std::cout << "Stream number " << stream << ", delay = " << delay << std::endl; id = deviceId(dataBlock, stream); if (id > 0) // 1 = RHD2132, 2 = RHD2216 { // std::cout << "Device ID found: " << id << std::endl; sumGoodDelays.set(stream,sumGoodDelays[stream] + 1); if (indexFirstGoodDelay[stream] == -1) { indexFirstGoodDelay.set(stream, delay); chipId.set(stream,id); } else if (indexSecondGoodDelay[stream] == -1) { indexSecondGoodDelay.set(stream,delay); chipId.set(stream,id); } } } } // std::cout << "Chip IDs found: "; // for (int i = 0; i < MAX_NUM_DATA_STREAMS; ++i) // { // std::cout << chipId[i] << " "; // } //std::cout << std::endl; // Now, disable data streams where we did not find chips present. for (stream = 0; stream < MAX_NUM_DATA_STREAMS; ++stream) { if (chipId[stream] > 0) { //std::cout << "Enabling headstage on stream " << stream << std::endl; enableHeadstage(stream, true); } else { enableHeadstage(stream, false); } } std::cout << "Number of enabled data streams: " << evalBoard->getNumEnabledDataStreams() << std::endl; // Set cable delay settings that yield good communication with each // RHD2000 chip. Array<int> optimumDelay; optimumDelay.insertMultiple(0,0,8); for (stream = 0; stream < MAX_NUM_DATA_STREAMS; ++stream) { if (sumGoodDelays[stream] == 1 || sumGoodDelays[stream] == 2) { optimumDelay.set(stream,indexFirstGoodDelay[stream]); } else if (sumGoodDelays[stream] > 2) { optimumDelay.set(stream,indexSecondGoodDelay[stream]); } } evalBoard->setCableDelay(Rhd2000EvalBoard::PortA, optimumDelay[0]); evalBoard->setCableDelay(Rhd2000EvalBoard::PortB, optimumDelay[1]); evalBoard->setCableDelay(Rhd2000EvalBoard::PortC, optimumDelay[2]); evalBoard->setCableDelay(Rhd2000EvalBoard::PortD, optimumDelay[3]); cableLengthPortA = evalBoard->estimateCableLengthMeters(optimumDelay[0]); cableLengthPortB = evalBoard->estimateCableLengthMeters(optimumDelay[1]); cableLengthPortC = evalBoard->estimateCableLengthMeters(optimumDelay[2]); cableLengthPortD = evalBoard->estimateCableLengthMeters(optimumDelay[3]); setSampleRate(savedSampleRateIndex); // restore saved sample rate updateRegisters(); }
void RHD2000Thread::initializeBoard() { String bitfilename; File executable = File::getSpecialLocation(File::currentExecutableFile); #if defined(__APPLE__) const String executableDirectory = executable.getParentDirectory().getParentDirectory().getParentDirectory().getParentDirectory().getFullPathName(); #else const String executableDirectory = executable.getParentDirectory().getFullPathName(); #endif bitfilename = executableDirectory; bitfilename += File::separatorString; bitfilename += "rhd2000.bit"; if (!uploadBitfile(bitfilename)) { return; } // Initialize the board std::cout << "Initializing acquisition board." << std::endl; evalBoard->initialize(); // This applies the following settings: // - sample rate to 30 kHz // - aux command banks to zero // - aux command lengths to zero // - continuous run mode to 'true' // - maxTimeStep to 2^32 - 1 // - all cable lengths to 3 feet // - dspSettle to 'false' // - data source mapping as 0->PortA1, 1->PortB1, 2->PortC1, 3->PortD1, etc. // - enables all data streams // - clears the ttlOut // - disables all DACs and sets gain to 0 // Select RAM Bank 0 for AuxCmd3 initially, so the ADC is calibrated. evalBoard->selectAuxCommandBank(Rhd2000EvalBoard::PortA, Rhd2000EvalBoard::AuxCmd3, 0); evalBoard->selectAuxCommandBank(Rhd2000EvalBoard::PortB, Rhd2000EvalBoard::AuxCmd3, 0); evalBoard->selectAuxCommandBank(Rhd2000EvalBoard::PortC, Rhd2000EvalBoard::AuxCmd3, 0); evalBoard->selectAuxCommandBank(Rhd2000EvalBoard::PortD, Rhd2000EvalBoard::AuxCmd3, 0); // Since our longest command sequence is 60 commands, run the SPI interface for // 60 samples evalBoard->setMaxTimeStep(60); evalBoard->setContinuousRunMode(false); // Start SPI interface evalBoard->run(); // Wait for the 60-sample run to complete while (evalBoard->isRunning()) { ; } // Read the resulting single data block from the USB interface. We don't // need to do anything with this, since it was only used for ADC calibration Rhd2000DataBlock* dataBlock = new Rhd2000DataBlock(evalBoard->getNumEnabledDataStreams()); // evalBoard->readDataBlock(dataBlock); // Now that ADC calibration has been performed, we switch to the command sequence // that does not execute ADC calibration. evalBoard->selectAuxCommandBank(Rhd2000EvalBoard::PortA, Rhd2000EvalBoard::AuxCmd3, fastSettleEnabled ? 2 : 1); evalBoard->selectAuxCommandBank(Rhd2000EvalBoard::PortB, Rhd2000EvalBoard::AuxCmd3, fastSettleEnabled ? 2 : 1); evalBoard->selectAuxCommandBank(Rhd2000EvalBoard::PortC, Rhd2000EvalBoard::AuxCmd3, fastSettleEnabled ? 2 : 1); evalBoard->selectAuxCommandBank(Rhd2000EvalBoard::PortD, Rhd2000EvalBoard::AuxCmd3, fastSettleEnabled ? 2 : 1); updateRegisters(); // Let's turn one LED on to indicate that the board is now connected int ledArray[8] = {1, 0, 0, 0, 0, 0, 0, 0}; evalBoard->setLedDisplay(ledArray); }