Skip to content
Snippets Groups Projects

Fixing the WZ DMA initialization / teardown

Merged Petr Zejdl requested to merge fix_wz_dma_init_failures into master
Files
4
+ 13
5
@@ -18,6 +18,7 @@ WZDmaInputFilter::WZDmaInputFilter(size_t packetBufferSize,
sconeHost_ {conf.getSconeHost()}, sconePort_ {conf.getSconePort()},
sconeBoard_ {conf.getSconeBoard()} {
// Initialize the DMA subsystem
dma_is_initialized_ = false;
if (wz_init(&dma_) < 0) {
std::string msg = "Cannot initialize WZ DMA device";
if (errno == ENOENT) {
@@ -27,6 +28,7 @@ WZDmaInputFilter::WZDmaInputFilter(size_t packetBufferSize,
}
throw std::system_error(errno, std::system_category(), msg);
}
dma_is_initialized_ = true;
// Start the DMA
if (wz_start_dma(&dma_) < 0) {
@@ -38,8 +40,11 @@ WZDmaInputFilter::WZDmaInputFilter(size_t packetBufferSize,
}
WZDmaInputFilter::~WZDmaInputFilter() {
wz_stop_dma(&dma_);
wz_close(&dma_);
if (dma_is_initialized_) {
wz_stop_dma(&dma_);
wz_close(&dma_);
dma_is_initialized_ = false;
}
LOG(TRACE) << "Destroyed WZ DMA input filter";
}
@@ -51,22 +56,25 @@ inline ssize_t WZDmaInputFilter::read_packet_from_dma(char **buffer) {
bytes_read = wz_read_start(&dma_, buffer);
if (bytes_read < 0) {
int errno_saved = errno;
stats.nbDmaErrors++;
LOG(ERROR) << tools::strerror(
"#" + std::to_string(nbReads()) +
": Read failed, returned: " + std::to_string(bytes_read));
": Read failed, returned: " + std::to_string(bytes_read)) << ", errno: " << errno_saved;
if (errno == EIO) {
if (errno_saved == EIO) {
LOG(ERROR) << "#" << nbReads() << ": Trying to restart DMA (attempt #"
<< tries << "):";
wz_stop_dma(&dma_);
wz_close(&dma_);
dma_is_initialized_ = false;
// Initialize the DMA subsystem
if (wz_init(&dma_) < 0) {
throw std::system_error(errno, std::system_category(),
"Cannot initialize WZ DMA device");
}
dma_is_initialized_ = true;
if (wz_start_dma(&dma_) < 0) {
throw std::system_error(errno, std::system_category(),
@@ -81,7 +89,7 @@ inline ssize_t WZDmaInputFilter::read_packet_from_dma(char **buffer) {
}
continue;
}
throw std::system_error(errno, std::system_category(),
throw std::system_error(errno_saved, std::system_category(),
"FATAL: Unrecoverable DMA error detected.");
}
break;
Loading