diff --git a/Source/Processors/DataThreads/FPGAThread.cpp b/Source/Processors/DataThreads/FPGAThread.cpp index 34fb9995d69e1db6ec2214b35c39f40651ab2587..1ed54e1b87f4accfb5ba40d1c0f44127f45003c9 100644 --- a/Source/Processors/DataThreads/FPGAThread.cpp +++ b/Source/Processors/DataThreads/FPGAThread.cpp @@ -24,19 +24,18 @@ #include "FPGAThread.h" FPGAThread::FPGAThread(SourceNode* sn) : DataThread(sn), - isRunning(false), + isTransmitting(false), numchannels(32), - m_u32SegmentSize(1048576) + deviceFound(false) { - // Initialize the FPGA with our configuration bitfile. - printf("New device created.\n"); + const char* bitfilename = "./pipetest.bit"; printf("---- Opal Kelly ---- PipeTest Application v1.0 ----\n"); - if (FALSE == okFrontPanelDLL_LoadLib(NULL)) { + if (!okFrontPanelDLL_LoadLib(NULL)) { printf("FrontPanel DLL could not be loaded.\n"); } @@ -47,24 +46,19 @@ FPGAThread::FPGAThread(SourceNode* sn) : DataThread(sn), strncpy(bitfile, bitfilename, 128); - if (!initializeFPGA(dev, bitfile)) { + // Initialize the FPGA with our configuration bitfile. + deviceFound = initializeFPGA(true); + + if (!deviceFound) { printf("FPGA could not be initialized.\n"); + } else { + printf("FPGA interface initialized.\n"); } Ndatabytes = numchannels*3; - std::cout << "FPGA interface initialized." << std::endl; - - std::cout << "DataBuffer address is " << dataBuffer << std::endl; - dataBuffer = new DataBuffer(32, 10000); - std::cout << "DataBuffer address is " << dataBuffer << std::endl; - - //deviceFound = true; - - //startThread(); - } @@ -76,27 +70,72 @@ FPGAThread::~FPGAThread() { } +int FPGAThread::getNumChannels() +{ + return 32; +} + +float FPGAThread::getSampleRate() +{ + return 25000.0; +} + +bool FPGAThread::foundInputSource() +{ + + if (deviceFound) + { + if (okCFrontPanel::NoError != dev->ConfigureFPGA(bitfile)) + { + printf("FPGA configuration failed.\n"); + deviceFound = false; + return false; + } + + } else { + + // if (!initializeFPGA(false)) + // { + // return false; + // } else { + // deviceFound = true; + // } + + } + +} + bool FPGAThread::startAcquisition() { - startThread(); + startThread(); - //isTransmitting = true; + isTransmitting = true; - return true; + return true; } bool FPGAThread::stopAcquisition() { + + isTransmitting = false; + if (isThreadRunning()) { + signalThreadShouldExit(); } + return true; } bool FPGAThread::updateBuffer() { + + long return_code; - dev->ReadFromPipeOut(0xA0, sizeof(pBuffer), pBuffer); + return_code = dev->ReadFromPipeOut(0xA0, sizeof(pBuffer), pBuffer); + + if (return_code == 0) + return false; int j = 0; @@ -141,40 +180,48 @@ bool FPGAThread::updateBuffer() { -bool FPGAThread::initializeFPGA(okCFrontPanel *dev, char *bitfile) +bool FPGAThread::initializeFPGA(bool verbose) { + if (okCFrontPanel::NoError != dev->OpenBySerial()) { - delete dev; - printf("Device could not be opened. Is one connected?\n"); - return(NULL); + if (verbose) + printf("Device could not be opened. Is one connected?\n"); + return false; } - printf("Found a device: %s\n", dev->GetBoardModelString(dev->GetBoardModel()).c_str()); + if (verbose) + printf("Found a device: %s\n", dev->GetBoardModelString(dev->GetBoardModel()).c_str()); dev->LoadDefaultPLLConfiguration(); // Get some general information about the XEM. - std::string str; - printf("Device firmware version: %d.%d\n", dev->GetDeviceMajorVersion(), dev->GetDeviceMinorVersion()); - str = dev->GetSerialNumber(); - printf("Device serial number: %s\n", str.c_str()); - str = dev->GetDeviceID(); - printf("Device device ID: %s\n", str.c_str()); + if (verbose) { + std::string str; + printf("Device firmware version: %d.%d\n", dev->GetDeviceMajorVersion(), dev->GetDeviceMinorVersion()); + str = dev->GetSerialNumber(); + printf("Device serial number: %s\n", str.c_str()); + str = dev->GetDeviceID(); + printf("Device device ID: %s\n", str.c_str()); + } // Download the configuration file. if (okCFrontPanel::NoError != dev->ConfigureFPGA(bitfile)) { - printf("FPGA configuration failed.\n"); - return(false); + if (verbose) + printf("FPGA configuration failed.\n"); + return false; } // Check for FrontPanel support in the FPGA configuration. - if (dev->IsFrontPanelEnabled()) - printf("FrontPanel support is enabled.\n"); - else - printf("FrontPanel support is not enabled.\n"); + if (verbose) { + if (dev->IsFrontPanelEnabled()) + printf("FrontPanel support is enabled.\n"); + else + printf("FrontPanel support is not enabled.\n"); + } - return(true); + return true; + // this is not executed dev->SetWireInValue(0x00, 1<<2); // set reset bit in cmd wire to 1 and back to 0 dev->UpdateWireIns(); dev->SetWireInValue(0x00, 0<<2); diff --git a/Source/Processors/DataThreads/FPGAThread.h b/Source/Processors/DataThreads/FPGAThread.h index 7bc294011efed3f30d1d44f3bbb5373a7d33fece..d351ed933f38c734239883a87426d8056cd4f252 100644 --- a/Source/Processors/DataThreads/FPGAThread.h +++ b/Source/Processors/DataThreads/FPGAThread.h @@ -25,12 +25,10 @@ #define __FPGATHREAD_H_FBB22A45__ +#include "../../../JuceLibraryCode/JuceHeader.h" + #include <stdio.h> #include <string.h> -#include <iostream> -#include <time.h> - -#include "../../../JuceLibraryCode/JuceHeader.h" #include "okFrontPanelDLL.h" #include "DataThread.h" @@ -52,28 +50,25 @@ public: FPGAThread(SourceNode* sn); ~FPGAThread(); - bool foundInputSource(); // {return true;} - int getNumChannels();// {return 32;} - float getSampleRate();// {return 25000.0;} + bool foundInputSource(); + int getNumChannels(); + float getSampleRate(); private: okCFrontPanel* dev; char bitfile[128]; char dll_date[32], dll_time[32]; - UINT32 i; + bool isTransmitting; + bool deviceFound; - bool initializeFPGA(okCFrontPanel*, char*); + bool initializeFPGA(bool); bool closeFPGA(); bool startAcquisition(); bool stopAcquisition(); - int m_u32SegmentSize; - - unsigned char pBuffer[50000]; // request a 1MB block of data - - bool isRunning; + unsigned char pBuffer[50000]; // request a 50kb block of data float thisSample[32]; diff --git a/Source/Processors/ProcessorGraph.cpp b/Source/Processors/ProcessorGraph.cpp index 33b5fa2e99160e4f3868822987fb18d9a3373906..8a73cdd271b27bd385552f4d1a85b776931f85e8 100644 --- a/Source/Processors/ProcessorGraph.cpp +++ b/Source/Processors/ProcessorGraph.cpp @@ -314,6 +314,7 @@ GenericProcessor* ProcessorGraph::createProcessorFromDescription(String& descrip } std::cout << "Creating a new data source." << std::endl; + } else if (subProcessorType.equalsIgnoreCase("Signal Generator")) { processor = new SignalGenerator(); diff --git a/Source/Processors/SourceNode.cpp b/Source/Processors/SourceNode.cpp index 37c6fd713269f862f77c643eab14086ecaca63e2..3fa8e709d97d59ae1b7d3efa8efba810bebe980c 100644 --- a/Source/Processors/SourceNode.cpp +++ b/Source/Processors/SourceNode.cpp @@ -36,7 +36,7 @@ SourceNode::SourceNode(const String& name_) if (getName().equalsIgnoreCase("Intan Demo Board")) { dataThread = new IntanThread(this); } else if (getName().equalsIgnoreCase("Custom FPGA")) { - dataThread = new FPGAThread(this); + dataThread = new FPGAThread(this);//FPGAThread(this); } else if (getName().equalsIgnoreCase("File Reader")) { dataThread = new FileReaderThread(this); }