52 lines
1.5 KiB
C++
52 lines
1.5 KiB
C++
// Copyright (2019-2023) Paul Scherrer Institute
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
#include "FPGAAcquisitionDevice.h"
|
|
|
|
void FPGAAcquisitionDevice::HW_StartAction() {
|
|
FPGA_StartAction();
|
|
|
|
stop_work_requests = false;
|
|
send_work_request_future = std::async(std::launch::async, &FPGAAcquisitionDevice::SendWorkRequestThread, this);
|
|
|
|
read_work_completion_future = std::async(std::launch::async, &FPGAAcquisitionDevice::ReadWorkCompletionThread, this);
|
|
}
|
|
|
|
void FPGAAcquisitionDevice::HW_EndAction() {
|
|
read_work_completion_future.get();
|
|
|
|
stop_work_requests = true;
|
|
send_work_request_future.get();
|
|
|
|
while (!HW_SendWorkRequest(UINT32_MAX))
|
|
std::this_thread::sleep_for(std::chrono::microseconds(10));
|
|
|
|
FPGA_EndAction();
|
|
}
|
|
|
|
void FPGAAcquisitionDevice::ReadWorkCompletionThread() {
|
|
uint32_t values[12];
|
|
|
|
Completion c;
|
|
do {
|
|
while (!HW_ReadMailbox(values))
|
|
std::this_thread::sleep_for(std::chrono::microseconds(10));
|
|
|
|
c = parse_hw_completion(values);
|
|
work_completion_queue.PutBlocking(c);
|
|
} while (c.type != Completion::Type::End);
|
|
}
|
|
|
|
void FPGAAcquisitionDevice::SendWorkRequestThread() {
|
|
while (!stop_work_requests) {
|
|
WorkRequest wr{};
|
|
if (work_request_queue.Get(wr)) {
|
|
if ( !HW_SendWorkRequest(wr.handle)) {
|
|
work_request_queue.Put(wr);
|
|
std::this_thread::sleep_for(std::chrono::microseconds(10));
|
|
}
|
|
} else {
|
|
std::this_thread::sleep_for(std::chrono::microseconds(10));
|
|
}
|
|
}
|
|
} |