7
mirror of https://github.com/EEVengers/ThunderScope.git synced 2025-04-08 06:25:30 +00:00

Linked Up To Controller

This commit is contained in:
Daniel Vasile 2021-03-22 20:55:51 -04:00
parent cf4bd7da0b
commit 547f658ced
5 changed files with 68 additions and 31 deletions
Software/waveview/scope_link

View File

@ -62,14 +62,18 @@ class PCIeLink {
public:
bool connected;
PCIeLink();
PCIeLink(boost::lockfree::queue<buffer*, boost::lockfree::fixed_sized<false>> *outputQueue);
int Connect();
void InitBoard();
void Read(uint8_t* buff);
void Write(ScopeCommand command, void* val);
void Pause();
void UnPause();
void Stop();
void ClockTick1();
void ClockTick2();
void PrintTimeDelta();
@ -89,6 +93,10 @@ private:
LARGE_INTEGER freq; //used for perforamnce testing
int64_t last_chunk_read;
std::atomic<bool> _run;
std::atomic<bool> _pause;
std::thread PCIeReadThread;
//output queue in which read data from the FPGA is shoved into
boost::lockfree::queue<buffer*, boost::lockfree::fixed_sized<false>> *outputQueue;

View File

@ -21,8 +21,9 @@
#define BUFFER_256K 262144
#define BUFFER_512K 524288
#define BUFFER_1024K 1048576
#define BUFFER_8M (1 << 23)
#define BUFFER_SIZE BUFFER_8K
#define BUFFER_SIZE BUFFER_8M
// Window size in buffers
#define DEFAULT_WINDOW 10

View File

@ -10,6 +10,7 @@
#include <boost/tokenizer.hpp>
#include <fstream>
#include <iostream>
#include "controller.hpp"
uint32_t testSize = 1000;
@ -206,6 +207,7 @@ void runSocketTest ()
delete bridgeThread_1;
}
boost::lockfree::queue<buffer*, boost::lockfree::fixed_sized<false>> testerDataQueue{1000};
/*******************************************************************************
* runPCIeTEST()
@ -218,32 +220,19 @@ void runSocketTest ()
* None
******************************************************************************/
void runPCIeTest() {
PCIeLink* pcieLink = new PCIeLink();
pcieLink->Connect();
pcieLink->Write(board_enable,nullptr);
pcieLink->Write(clk_enable,nullptr);
pcieLink->Write(adc_enable,nullptr);
pcieLink->Write(dataMover_enable,nullptr);
//pcieLink->Write(dataMover_disable,nullptr);
uint8_t* buff = (uint8_t*)malloc(sizeof(uint8_t) * (1 << 23));
controller* troller = new controller(&testerDataQueue);
troller->controllerUnPause();
//read 5 times
for(int i = 0; i < 3; i++) {
pcieLink->ClockTick1();
pcieLink->Read(buff);
pcieLink->ClockTick2();
pcieLink->PrintTimeDelta();
}
std::this_thread::sleep_for(std::chrono::milliseconds(500));
FILE* fp = fopen("TestData.txt","w");
/*FILE* fp = fopen("TestData.txt","w");
for(int i = 0; i < (1 << 23); i+= 8) {
fprintf(fp,"%X,%X,%X,%X,%X,%X,%X,%X\n",
buff[i],buff[i + 1],buff[i + 2],buff[i + 3],buff[i + 4],buff[i + 5],buff[i + 6],buff[i + 7]);
}
fclose(fp); */
fclose(fp);
free(buff);
delete pcieLink;
delete troller;
}

View File

@ -167,12 +167,31 @@ void PCIeLink::Read(uint8_t* buff) {
}
last_chunk_read = current_chunk;
int64_t reading_offset = current_chunk * (1 << 23);
//INFO << "Reading from current current chunk: " << current_chunk;
//INFO << "Offset: " << reading_offset;
INFO << "Reading from current current chunk: " << current_chunk;
INFO << "Offset: " << reading_offset;
//Read the data from ddr3 memory
_Read(c2h_0_handle,reading_offset,buff,1 << 23);
}
void PCIeLink::InitBoard() {
Write(board_enable,nullptr);
Write(clk_enable,nullptr);
Write(adc_enable,nullptr);
Write(dataMover_enable,nullptr);
}
void PCIeLink::Pause() {
_pause.store(true);
}
void PCIeLink::UnPause() {
_pause.store(false);
}
void PCIeLink::Stop() {
_run.store(false);
}
/************************************************************
* Write()
* Takes in a valid command that the changes a function/value on the scope
@ -380,12 +399,20 @@ void PCIeLink::_Write(HANDLE hPCIE, int64_t address, uint8_t* buff, int bytesToW
}
}
PCIeLink::PCIeLink() {
user_handle = INVALID_HANDLE_VALUE;
c2h_0_handle = INVALID_HANDLE_VALUE;
dataMoverReg[0] = 0x00;
last_chunk_read = -1;
QueryPerformanceFrequency(&freq);
void PCIeLink::_Job() {
while(_run.load()) {
while(_pause.load()) {
std::this_thread::sleep_for(std::chrono::milliseconds(2));
}
//allocate a buffer
buffer* buff;
buff = bufferAllocator.allocate(1);
bufferAllocator.construct(buff);
//read from the PCIeLink
Read((uint8_t*)buff->data);
//push to queue
outputQueue->push(buff);
}
}
PCIeLink::PCIeLink(boost::lockfree::queue<buffer*, boost::lockfree::fixed_sized<false>> *outputQueue) {
@ -393,8 +420,13 @@ PCIeLink::PCIeLink(boost::lockfree::queue<buffer*, boost::lockfree::fixed_sized<
c2h_0_handle = INVALID_HANDLE_VALUE;
dataMoverReg[0] = 0x00;
last_chunk_read = -1;
_run = true;
_pause = true;
QueryPerformanceFrequency(&freq);
this->outputQueue = outputQueue;
Connect();
InitBoard();
PCIeReadThread = std::thread(&PCIeLink::_Job, this);
}
PCIeLink::~PCIeLink() {
@ -402,6 +434,11 @@ PCIeLink::~PCIeLink() {
CloseHandle(user_handle);
if(c2h_0_handle != INVALID_HANDLE_VALUE)
CloseHandle(c2h_0_handle);
_pause.store(false);
_run.store(true);
PCIeReadThread.join();
}
void PCIeLink::ClockTick1() {

View File

@ -24,7 +24,7 @@ controller::controller(boost::lockfree::queue<buffer*, boost::lockfree::fixed_si
triggerThread = new Trigger(dataQueue, &triggerProcessorQueue, triggerLevel);
processorThread = new Processor(&triggerProcessorQueue, &processorPostProcessorQueue_1);
postProcessorThread = new postProcessor(&processorPostProcessorQueue_1, &controllerQueue_tx);
pcieLinkThread = new PCIeLink(dataQueue);
// set default values
setCh(1);
@ -427,6 +427,7 @@ void controller::controllerPause()
processorThread->processorPause();
triggerThread->triggerPause();
postProcessorThread->postProcessorPause();
pcieLinkThread->Pause();
}
/*******************************************************************************
@ -446,6 +447,7 @@ void controller::controllerUnPause()
processorThread->processorUnpause();
triggerThread->triggerUnpause();
postProcessorThread->postProcessorUnpause();
pcieLinkThread->UnPause();
}
/*******************************************************************************