Skip to content

Commit

Permalink
feat: DataHandler: add receive_packets flag
Browse files Browse the repository at this point in the history
  • Loading branch information
patrislav1 committed May 29, 2024
1 parent 618208a commit 02e9341
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
7 changes: 6 additions & 1 deletion inc/udmaio/DataHandlerAbstract.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,20 @@ class DataHandlerAbstract : public Logger, private boost::noncopyable {
void _start_read();
void _handle_input(const boost::system::error_code& ec);

protected:
bool _receive_packets; ///< Enable segmentation of stream into SOF/EOF delimited frames

public:
/// @brief Construct a Data Handler
/// @param dma Interface to the AXI DMA core
/// @param desc Interface to the SGDMA descriptors
/// @param mem Interface to the memory holding the SGDMA data buffers
/// @param receive_packets Receive packets/frames delimited by SOF/EOF. If not set, receive stream as-is without regard for packets
explicit DataHandlerAbstract(std::string name,
UioAxiDmaIf& dma,
UioMemSgdma& desc,
DmaBufferAbstract& mem);
DmaBufferAbstract& mem,
bool receive_packets = true);
virtual ~DataHandlerAbstract();

/// @brief Stop the data reception
Expand Down
8 changes: 5 additions & 3 deletions pyudmaio/src/DataHandlerPython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ namespace udmaio {

DataHandlerPython::DataHandlerPython(std::shared_ptr<UioAxiDmaIf> dma_ptr,
std::shared_ptr<UioMemSgdma> desc_ptr,
std::shared_ptr<DmaBufferAbstract> mem_ptr)
: DataHandlerSync("DataHandlerPython", *dma_ptr, *desc_ptr, *mem_ptr)
std::shared_ptr<DmaBufferAbstract> mem_ptr,
bool receive_packets)
: DataHandlerSync("DataHandlerPython", *dma_ptr, *desc_ptr, *mem_ptr, receive_packets)
, _dma_ptr(dma_ptr)
, _desc_ptr(desc_ptr)
, _mem_ptr(mem_ptr) {}
Expand Down Expand Up @@ -56,7 +57,8 @@ py::array_t<uint8_t> DataHandlerPython::numpy_read_nb() {
throw std::runtime_error("DMA has experienced an error");
}

auto full_bufs = _desc_ptr->get_full_buffers();
auto full_bufs =
_receive_packets ? _desc_ptr->get_next_packet() : _desc_ptr->get_full_buffers();
auto vec = new std::vector<uint8_t>(_desc_ptr->read_buffers(full_bufs));

// Callback for Python garbage collector
Expand Down
13 changes: 8 additions & 5 deletions pyudmaio/src/DataHandlerPython.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#pragma once

#include <memory>

#include <pybind11/numpy.h>

#include "udmaio/DataHandlerSync.hpp"
Expand All @@ -25,13 +26,15 @@ class DataHandlerPython : public DataHandlerSync {
std::shared_ptr<UioMemSgdma> _desc_ptr;
std::shared_ptr<DmaBufferAbstract> _mem_ptr;

public:
DataHandlerPython(std::shared_ptr<UioAxiDmaIf>, std::shared_ptr<UioMemSgdma>, std::shared_ptr<DmaBufferAbstract>);
public:
DataHandlerPython(std::shared_ptr<UioAxiDmaIf>,
std::shared_ptr<UioMemSgdma>,
std::shared_ptr<DmaBufferAbstract>,
bool receive_packets = true);

void start(int nr_pkts, size_t pkt_size, bool init_only = false);
py::array_t<uint8_t> numpy_read(uint32_t ms_timeout=0);
py::array_t<uint8_t> numpy_read(uint32_t ms_timeout = 0);
py::array_t<uint8_t> numpy_read_nb();

};

} // namespace udmaio
} // namespace udmaio
7 changes: 6 additions & 1 deletion pyudmaio/src/PythonBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ PYBIND11_MODULE(binding, m) {
data_handler
.def(py::init<std::shared_ptr<udmaio::UioAxiDmaIf>,
std::shared_ptr<udmaio::UioMemSgdma>,
std::shared_ptr<udmaio::DmaBufferAbstract>>())
std::shared_ptr<udmaio::DmaBufferAbstract>,
bool>(),
py::arg("dma"),
py::arg("desc"),
py::arg("mem"),
py::arg("receive_packets") = bool(true))
.def("start",
&udmaio::DataHandlerPython::start,
py::arg("nr_pkts"),
Expand Down
13 changes: 10 additions & 3 deletions src/DataHandlerAbstract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ namespace udmaio {
DataHandlerAbstract::DataHandlerAbstract(std::string name,
UioAxiDmaIf& dma,
UioMemSgdma& desc,
DmaBufferAbstract& mem)
: Logger(name), _dma{dma}, _desc{desc}, _mem{mem}, _svc{}, _sd{_svc, _dma.get_fd_int()} {
DmaBufferAbstract& mem,
bool receive_packets)
: Logger(name)
, _dma{dma}
, _desc{desc}
, _mem{mem}
, _svc{}
, _sd{_svc, _dma.get_fd_int()}
, _receive_packets{receive_packets} {
BOOST_LOG_SEV(_lg, bls::trace) << "ctor";
};

Expand Down Expand Up @@ -58,7 +65,7 @@ void DataHandlerAbstract::_handle_input(const boost::system::error_code& ec) {
uint32_t irq_count = _dma.clear_interrupt();
BOOST_LOG_SEV(_lg, bls::trace) << "irq count = " << irq_count;

auto full_bufs = _desc.get_full_buffers();
auto full_bufs = _receive_packets ? _desc.get_next_packet() : _desc.get_full_buffers();
if (full_bufs.empty()) {
BOOST_LOG_SEV(_lg, bls::trace) << "spurious event, got no data";
} else {
Expand Down

0 comments on commit 02e9341

Please sign in to comment.