Disable DMA on server exit
This commit is contained in:
parent
1c26688d93
commit
ecefa2dd5a
|
@ -14,6 +14,7 @@
|
|||
#include <boost/asio.hpp>
|
||||
|
||||
#include "puzzlefw.hpp"
|
||||
#include "logging.hpp"
|
||||
#include "interrupt_manager.hpp"
|
||||
#include "data_server.hpp"
|
||||
|
||||
|
@ -115,6 +116,14 @@ void run_data_server(puzzlefw::PuzzleFwDevice& device)
|
|||
|
||||
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 1/4 of the DMA buffer for timetagger data.
|
||||
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,
|
||||
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.
|
||||
device.clear_dma_errors();
|
||||
device.set_dma_enabled(true);
|
||||
|
||||
acq_server.start_server();
|
||||
timetagger_server.start_server();
|
||||
acq_stream.set_enabled(true);
|
||||
// TODO -- timetagger
|
||||
timetagger_stream.set_enabled(true);
|
||||
|
||||
log(LOG_INFO, "Running, press Ctrl-C to stop");
|
||||
io.run();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue