Disable DMA on server exit

This commit is contained in:
Joris van Rantwijk 2024-09-20 15:36:26 +02:00
parent 1c26688d93
commit ecefa2dd5a
1 changed files with 19 additions and 1 deletions

View File

@ -14,6 +14,7 @@
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include "puzzlefw.hpp" #include "puzzlefw.hpp"
#include "logging.hpp"
#include "interrupt_manager.hpp" #include "interrupt_manager.hpp"
#include "data_server.hpp" #include "data_server.hpp"
@ -115,6 +116,14 @@ void run_data_server(puzzlefw::PuzzleFwDevice& device)
asio::io_context io; asio::io_context io;
// Catch Ctrl-C for controlled shut down.
asio::signal_set signals(io, SIGINT);
signals.async_wait(
[&io](auto& ec, int sig) {
log(LOG_INFO, "Got SIGINT, stopping server");
io.stop();
});
// Reserve 3/4 of the DMA buffer for analog acquisition data. // Reserve 3/4 of the DMA buffer for analog acquisition data.
// Reserve 1/4 of the DMA buffer for timetagger data. // Reserve 1/4 of the DMA buffer for timetagger data.
size_t acq_buf_size = 3 * 4096 * (device.dma_buffer_size() / 4096 / 4); size_t acq_buf_size = 3 * 4096 * (device.dma_buffer_size() / 4096 / 4);
@ -145,14 +154,23 @@ void run_data_server(puzzlefw::PuzzleFwDevice& device)
device, device,
std::chrono::milliseconds(100)); std::chrono::milliseconds(100));
// Disable DMA engine on exit from this function.
struct ScopeGuard {
PuzzleFwDevice& m_device;
ScopeGuard(PuzzleFwDevice& device) : m_device(device) { }
~ScopeGuard() { m_device.set_dma_enabled(false); }
} scope_guard(device);
// Clear DMA errors, then enable DMA engine. // Clear DMA errors, then enable DMA engine.
device.clear_dma_errors(); device.clear_dma_errors();
device.set_dma_enabled(true); device.set_dma_enabled(true);
acq_server.start_server(); acq_server.start_server();
timetagger_server.start_server();
acq_stream.set_enabled(true); acq_stream.set_enabled(true);
// TODO -- timetagger timetagger_stream.set_enabled(true);
log(LOG_INFO, "Running, press Ctrl-C to stop");
io.run(); io.run();
} }