Skip to content

Commit

Permalink
Merge pull request #778 from slaclab/ESROGUE-498-2
Browse files Browse the repository at this point in the history
Fifo: Expose status information to python (for version v4)
  • Loading branch information
slacrherbst authored Apr 20, 2021
2 parents 973ed23 + 7f99198 commit 3b10c8f
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 15 deletions.
16 changes: 14 additions & 2 deletions include/rogue/interfaces/stream/Fifo.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,19 @@ namespace rogue {
std::shared_ptr<rogue::Logging> log_;

// Configurations
uint32_t trimSize_;
uint32_t maxDepth_;
uint32_t trimSize_;
bool noCopy_;

// Drop frame counter
std::size_t dropFrameCnt_;

// Queue
rogue::Queue<std::shared_ptr<rogue::interfaces::stream::Frame>> queue_;

// Transmission thread
std::thread* thread_;
bool threadEn_;
std::thread* thread_;

// Thread background
void runThread();
Expand All @@ -85,6 +88,15 @@ namespace rogue {
// Destroy the Fifo
~Fifo();

// Return the number of elements in the Fifo
std::size_t size();

// Return the number of dropped frames
std::size_t dropCnt() const;

// Clear counters
void clearCnt();

// Receive frame from Master
void acceptFrame ( std::shared_ptr<rogue::interfaces::stream::Frame> frame );

Expand Down
61 changes: 61 additions & 0 deletions python/pyrogue/interfaces/stream/_Fifo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#-----------------------------------------------------------------------------
# Title : AXI Stream FIFO
#-----------------------------------------------------------------------------
# Description:
# Python wrapper for the AXI Stream FIFO C++ device.
#-----------------------------------------------------------------------------
# This file is part of the rogue software platform. It is subject to
# the license terms in the LICENSE.txt file found in the top-level directory
# of this distribution and at:
# https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
# No part of the rogue software platform, including this file, may be
# copied, modified, propagated, or distributed except according to the terms
# contained in the LICENSE.txt file.
#-----------------------------------------------------------------------------

import rogue
import pyrogue

class Fifo(pyrogue.Device):
def __init__(self, name, description, maxDepth, trimSize, noCopy, **kwargs):
pyrogue.Device.__init__(self, name=name, description=description, **kwargs)
self._fifo = rogue.interfaces.stream.Fifo(maxDepth, trimSize, noCopy)

# Maximum Depth
self.add(pyrogue.LocalVariable(
name='MaxDepth',
description='Maximum depth of the Fifo',
mode='RO',
value=maxDepth))

# Number of elements in the Fifo
self.add(pyrogue.LocalVariable(
name='Size',
description='Number of elements in the Fifo',
mode='RO',
value=0,
typeStr='UInt64',
pollInterval=1,
localGet=self._fifo.size))

# Number of dropped frames
self.add(pyrogue.LocalVariable(
name='FrameDropCnt',
description='Number of dropped frames',
mode='RO',
value=0,
typeStr='UInt64',
pollInterval=1,
localGet=self._fifo.dropCnt))

# Command to clear all the counters
self.add(pyrogue.LocalCommand(
name='ClearCnt',
description='Clear all counters',
function=self._fifo.clearCnt))

def _getStreamSlave(self):
return self._fifo

def _getStreamMaster(self):
return self._fifo
11 changes: 11 additions & 0 deletions python/pyrogue/interfaces/stream/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#-----------------------------------------------------------------------------
# This file is part of the rogue software platform. It is subject to
# the license terms in the LICENSE.txt file found in the top-level directory
# of this distribution and at:
# https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
# No part of the rogue software platform, including this file, may be
# copied, modified, propagated, or distributed except according to the terms
# contained in the LICENSE.txt file.
#-----------------------------------------------------------------------------

from pyrogue.interfaces.stream._Fifo import *
50 changes: 37 additions & 13 deletions src/rogue/interfaces/stream/Fifo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,29 @@ ris::FifoPtr ris::Fifo::create(uint32_t maxDepth, uint32_t trimSize, bool noCopy
//! Setup class in python
void ris::Fifo::setup_python() {
#ifndef NO_PYTHON
bp::class_<ris::Fifo, ris::FifoPtr, bp::bases<ris::Master,ris::Slave>, boost::noncopyable >("Fifo",bp::init<uint32_t,uint32_t,bool>());
bp::class_<ris::Fifo, ris::FifoPtr, bp::bases<ris::Master,ris::Slave>, boost::noncopyable >("Fifo",bp::init<uint32_t,uint32_t,bool>())
.def("size", &Fifo::size)
.def("dropCnt", &Fifo::dropCnt)
.def("clearCnt", &Fifo::clearCnt)
;
#endif
}

//! Creator with version constant
ris::Fifo::Fifo(uint32_t maxDepth, uint32_t trimSize, bool noCopy ) : ris::Master(), ris::Slave() {
maxDepth_ = maxDepth;
trimSize_ = trimSize;
noCopy_ = noCopy;

ris::Fifo::Fifo(uint32_t maxDepth, uint32_t trimSize, bool noCopy )
:
ris::Master ( ),
ris::Slave ( ),
log_ ( rogue::Logging::create("stream.Fifo") ),
maxDepth_ ( maxDepth ),
trimSize_ ( trimSize ),
noCopy_ ( noCopy ),
dropFrameCnt_ ( 0 ),
threadEn_ ( true ),
thread_ ( new std::thread(&ris::Fifo::runThread, this) )
{
queue_.setThold(maxDepth);

log_ = rogue::Logging::create("stream.Fifo");

// Start read thread
threadEn_ = true;
thread_ = new std::thread(&ris::Fifo::runThread, this);

// Set a thread name
#ifndef __MACH__
pthread_setname_np( thread_->native_handle(), "Fifo" );
Expand All @@ -77,6 +82,22 @@ ris::Fifo::~Fifo() {
rogue::GilRelease noGil;
queue_.stop();
thread_->join();
delete thread_;
}

//! Return the number of elements in the Fifo
std::size_t ris::Fifo::size() {
return queue_.size();
};

//! Return the number of dropped frames
std::size_t ris::Fifo::dropCnt() const {
return dropFrameCnt_;
}

//! Clear counters
void ris::Fifo::clearCnt() {
dropFrameCnt_ = 0;
}

//! Accept a frame from master
Expand All @@ -87,7 +108,10 @@ void ris::Fifo::acceptFrame ( ris::FramePtr frame ) {
ris::FrameIterator dst;

// FIFO is full, drop frame
if ( queue_.busy() ) return;
if ( queue_.busy() ) {
++dropFrameCnt_;
return;
}

rogue::GilRelease noGil;
ris::FrameLockPtr lock = frame->lock();
Expand Down

0 comments on commit 3b10c8f

Please sign in to comment.