Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
DccDecoder< Module > Class Template Reference

Device driver for decoding a DCC signal using a Timer resource. More...

#include <DccDecoder.hxx>

Inheritance diagram for DccDecoder< Module >:
Node Device FileIO

Public Member Functions

 DccDecoder (const char *name, RailcomDriver *railcom_driver)
 Constructor.
 
void set_packet_processor (dcc::PacketProcessor *p)
 Installs a hook that will be called in the interrupt context for each incoming packet.
 
void interrupt_handler ()
 Handles a raw interrupt.
 
void rcom_interrupt_handler ()
 Handles interrupt from the second timer used for railcom timing.
 
void os_interrupt_handler ()
 Handles a software interrupt to FreeRTOS.
 
- Public Member Functions inherited from Device
 Device (const char *name)
 Constructor.
 
virtual ~Device ()
 Destructor.
 

Private Types

typedef DCCPacket input_data_type
 

Private Member Functions

ssize_t read (File *file, void *buf, size_t count) OVERRIDE
 Read from a file or device.
 
ssize_t write (File *file, const void *buf, size_t count) OVERRIDE
 Write to a file or device.
 
bool select (File *file, int mode) OVERRIDE
 Device select method.
 
void enable () override
 function to enable device
 
void disable () override
 function to disable device
 
void flush_buffers () override
 Discards all pending buffers.
 
 DISALLOW_COPY_AND_ASSIGN (DccDecoder)
 

Private Attributes

DeviceBuffer< DCCPacket > * inputData_
 
bool nextPacketFilled_ {false}
 
uint32_t lastTimerValue_
 Holds the value of the free running timer at the time we captured the previous edge.
 
uint32_t nextSample_
 Holds the timer value when we should be taking an occupancy sample the next time.
 
bool sampleActive_ = false
 true if the next edge we shall sample.
 
unsigned lastLevel_
 Seems unused?
 
bool waitSampleForOverflow_ = false
 if true then sampling will be suspended until the timer overflows.
 
bool inCutout_ = false
 True if the current internal state is the cutout state.
 
bool prepCutout_ = false
 True for the last bit time before the cutout, to prevent sampling fro colliding with cutout.
 
uint32_t cutoutState_
 Which window of the cutout we are in.
 
uint32_t packetId_ = 0
 Counts unique identifiers for DCC packets to be returned.
 
RailcomDriverrailcomDriver_
 How many times did we lose a DCC packet due to no buffer available.
 
dcc::PacketProcessorpacketProcessor_ = nullptr
 notified for every arrived DCC / MM packet within the interrupt.
 
dcc::DccDecoder decoder_ {Module::get_ticks_per_usec()}
 DCC packet decoder state machine and internal state.
 

Static Private Attributes

static const auto RAILCOM_CUTOUT_PRE = 26
 How many usec the railcom has before the cutout (measured from the packet end 1 bit complete)
 
static const auto RAILCOM_CUTOUT_MID = 185
 How many usec the railcom has to the middle of window (measured from the packet end 1 bit complete)
 
static const auto RAILCOM_CUTOUT_END = 471
 How many usec the railcom has to the end of the window (measured from the packet end 1 bit complete)
 

Additional Inherited Members

- Static Public Member Functions inherited from Device
static int open (struct _reent *reent, const char *path, int flags, int mode)
 Open a file or device.
 
static int close (struct _reent *reent, int fd)
 Close a file or device.
 
static int stat (struct _reent *reent, const char *path, struct stat *stat)
 Get the status information of a file or device.
 
static int select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, long long timeout)
 POSIX select().
 
static void select_clear ()
 Clears the current thread's select bits.
 
- Static Public Member Functions inherited from FileIO
static ssize_t read (struct _reent *reent, int fd, void *buf, size_t count)
 Read from a file or device.
 
static ssize_t write (struct _reent *reent, int fd, const void *buf, size_t count)
 Write to a file or device.
 
static _off_t lseek (struct _reent *reent, int fd, _off_t offset, int whence)
 Change the offset index of a file or device.
 
static int fstat (struct _reent *reent, int fd, struct stat *stat)
 Get the status information of a file or device.
 
static int ioctl (int fd, unsigned long int key, unsigned long data)
 Request and ioctl transaction.
 
static int fcntl (int fd, int cmd, unsigned long data)
 Manipulate a file descriptor.
 
static bool is_device (int fd)
 Test if the file descriptor belongs to a device.
 
- Protected Member Functions inherited from Node
 Node (const char *name)
 Constructor.
 
virtual ~Node ()
 Destructor.
 
int open (File *, const char *, int, int) OVERRIDE
 Open method.
 
int close (File *) OVERRIDE
 Close method.
 
virtual int fstat (File *file, struct stat *stat) override
 Get the status information of a file or device.
 
- Protected Member Functions inherited from FileIO
 FileIO (const char *name)
 Constructor.
 
virtual ~FileIO ()
 Destructor.
 
virtual off_t lseek (File *f, off_t offset, int whence)
 Seek method.
 
virtual int ioctl (File *file, unsigned long int key, unsigned long data)
 Request an ioctl transaction.
 
virtual int fcntl (File *file, int cmd, unsigned long data)
 Manipulate a file descriptor.
 
- Static Protected Member Functions inherited from Device
static void select_insert (SelectInfo *info)
 Add client to list of clients needing woken.
 
static void select_wakeup (SelectInfo *info)
 Wakeup the list of clients needing woken.
 
static void select_wakeup_from_isr (SelectInfo *info, int *woken)
 Wakeup the list of clients needing woken.
 
- Static Protected Member Functions inherited from FileIO
static int fd_alloc (void)
 Allocate a free file descriptor.
 
static void fd_free (int fd)
 Free up a file descriptor.
 
static Filefile_lookup (int fd)
 Looks up a reference to a File corresponding to a given file descriptor.
 
static int fd_lookup (File *file)
 Looks up a file descriptor corresponding to a given File reference.
 
- Protected Attributes inherited from Node
OSMutex lock_
 protects internal structures.
 
mode_t mode_
 File open mode, such as O_NONBLOCK.
 
unsigned int references_
 number of open references
 
- Protected Attributes inherited from FileIO
const char * name
 device name
 
- Static Protected Attributes inherited from FileIO
static const unsigned int numOpenFiles = 20
 
static File files []
 File descriptor pool.
 
static OSMutex mutex
 mutual exclusion for fileio
 

Detailed Description

template<class Module>
class DccDecoder< Module >

Device driver for decoding a DCC signal using a Timer resource.

This driver exports a filesystem device node, which will be readable for decoded DCC packets (read into struct DCCPacket). All writes fail.

The additional feature supported by this device driver is that it is able to tell a RailcomDriver when the railcom cutout is supposed to start, when we're in the middle and when it is over. This is necessary for the correct functionality of the railcom driver.

Usage:

Define a module for accessing the timer. See the following two examples: {} { Stm32DccTimerModule }. In the HwInit.cxx, instantiate the driver with passing the module as a template argument. The above example modules themselves take a template argument with static definitions. Module API:NRZ_PinTIMER_MAX_VALUESAMPLE_PERIOD_CLOCKSQ_SIZETICKS_PER_USECmodule_init()module_enable()module_disable()trigger_os_interrupt()dcc_before_cutout_hook()dcc_packet_finished_hook()after_feedback_hook()int_get_and_clear_capture_event()get_capture_counter()int_get_and_clear_delay_event()set_cap_timer_capture()set_cap_timer_time()set_cap_timer_delay_usec()stop_cap_timer_time()

Definition at line 84 of file DccDecoder.hxx.

Member Typedef Documentation

◆ input_data_type

template<class Module >
typedef DCCPacket DccDecoder< Module >::input_data_type
private

Definition at line 205 of file DccDecoder.hxx.

Constructor & Destructor Documentation

◆ DccDecoder()

template<class Module >
DccDecoder< Module >::DccDecoder ( const char *  name,
RailcomDriver railcom_driver 
)

Constructor.

Parameters
namename of device node, e.g. "/dev/dccdecode0"
railcom_driveris the associated railcom driver, which will get the callbacks from the timing of the acquired signal.

Definition at line 256 of file DccDecoder.hxx.

◆ ~DccDecoder()

template<class Module >
DccDecoder< Module >::~DccDecoder ( )
inline

Definition at line 94 of file DccDecoder.hxx.

Member Function Documentation

◆ disable()

template<class Module >
void DccDecoder< Module >::disable ( )
overrideprivatevirtual

function to disable device

Implements Node.

Definition at line 283 of file DccDecoder.hxx.

◆ enable()

template<class Module >
void DccDecoder< Module >::enable ( )
overrideprivatevirtual

function to enable device

Implements Node.

Definition at line 265 of file DccDecoder.hxx.

◆ flush_buffers()

template<class Module >
void DccDecoder< Module >::flush_buffers ( )
inlineoverrideprivatevirtual

Discards all pending buffers.

Called after disable().

Implements Node.

Definition at line 196 of file DccDecoder.hxx.

◆ interrupt_handler()

template<class Module >
void DccDecoder< Module >::interrupt_handler ( )
inline

Handles a raw interrupt.

Definition at line 289 of file DccDecoder.hxx.

◆ os_interrupt_handler()

template<class Module >
void DccDecoder< Module >::os_interrupt_handler ( )
inline

Handles a software interrupt to FreeRTOS.

Definition at line 429 of file DccDecoder.hxx.

◆ rcom_interrupt_handler()

template<class Module >
void DccDecoder< Module >::rcom_interrupt_handler ( )
inline

Handles interrupt from the second timer used for railcom timing.

Definition at line 391 of file DccDecoder.hxx.

◆ read()

template<class Module >
ssize_t DccDecoder< Module >::read ( File file,
void *  buf,
size_t  count 
)
inlineprivatevirtual

Read from a file or device.

Parameters
filefile reference for this device
buflocation to place read data
countnumber of bytes to read
Returns
number of bytes read upon success, -1 upon failure with errno containing the cause

Implements FileIO.

Definition at line 124 of file DccDecoder.hxx.

◆ select()

template<class Module >
bool DccDecoder< Module >::select ( File file,
int  mode 
)
inlineprivatevirtual

Device select method.

Default impementation returns true.

Parameters
filereference to the file
modeFREAD for read active, FWRITE for write active, 0 for exceptions
Returns
true if active, false if inactive

Reimplemented from FileIO.

Definition at line 168 of file DccDecoder.hxx.

◆ set_packet_processor()

template<class Module >
void DccDecoder< Module >::set_packet_processor ( dcc::PacketProcessor p)
inline

Installs a hook that will be called in the interrupt context for each incoming packet.

Parameters
pthe hook interface to be called.

Definition at line 102 of file DccDecoder.hxx.

◆ write()

template<class Module >
ssize_t DccDecoder< Module >::write ( File file,
const void *  buf,
size_t  count 
)
inlineprivatevirtual

Write to a file or device.

Parameters
filefile reference for this device
buflocation to find write data
countnumber of bytes to write
Returns
number of bytes written upon success, -1 upon failure with errno containing the cause

Implements FileIO.

Definition at line 157 of file DccDecoder.hxx.

Member Data Documentation

◆ cutoutState_

template<class Module >
uint32_t DccDecoder< Module >::cutoutState_
private

Which window of the cutout we are in.

Definition at line 227 of file DccDecoder.hxx.

◆ decoder_

template<class Module >
dcc::DccDecoder DccDecoder< Module >::decoder_ {Module::get_ticks_per_usec()}
private

DCC packet decoder state machine and internal state.

Definition at line 240 of file DccDecoder.hxx.

◆ inCutout_

template<class Module >
bool DccDecoder< Module >::inCutout_ = false
private

True if the current internal state is the cutout state.

Definition at line 222 of file DccDecoder.hxx.

◆ inputData_

template<class Module >
DeviceBuffer<DCCPacket>* DccDecoder< Module >::inputData_
private
Initial value:
{
static DeviceBuffer * create(size_t size, size_t level=0)
Create a DeviceBuffer instance.

Definition at line 206 of file DccDecoder.hxx.

◆ lastLevel_

template<class Module >
unsigned DccDecoder< Module >::lastLevel_
private

Seems unused?

Todo:
delete.

Definition at line 218 of file DccDecoder.hxx.

◆ lastTimerValue_

template<class Module >
uint32_t DccDecoder< Module >::lastTimerValue_
private

Holds the value of the free running timer at the time we captured the previous edge.

Definition at line 211 of file DccDecoder.hxx.

◆ nextPacketFilled_

template<class Module >
bool DccDecoder< Module >::nextPacketFilled_ {false}
private

Definition at line 208 of file DccDecoder.hxx.

◆ nextSample_

template<class Module >
uint32_t DccDecoder< Module >::nextSample_
private

Holds the timer value when we should be taking an occupancy sample the next time.

Definition at line 214 of file DccDecoder.hxx.

◆ packetId_

template<class Module >
uint32_t DccDecoder< Module >::packetId_ = 0
private

Counts unique identifiers for DCC packets to be returned.

Definition at line 229 of file DccDecoder.hxx.

◆ packetProcessor_

template<class Module >
dcc::PacketProcessor* DccDecoder< Module >::packetProcessor_ = nullptr
private

notified for every arrived DCC / MM packet within the interrupt.

Definition at line 237 of file DccDecoder.hxx.

◆ prepCutout_

template<class Module >
bool DccDecoder< Module >::prepCutout_ = false
private

True for the last bit time before the cutout, to prevent sampling fro colliding with cutout.

Definition at line 225 of file DccDecoder.hxx.

◆ RAILCOM_CUTOUT_END

template<class Module >
const auto DccDecoder< Module >::RAILCOM_CUTOUT_END = 471
staticprivate

How many usec the railcom has to the end of the window (measured from the packet end 1 bit complete)

Definition at line 250 of file DccDecoder.hxx.

◆ RAILCOM_CUTOUT_MID

template<class Module >
const auto DccDecoder< Module >::RAILCOM_CUTOUT_MID = 185
staticprivate

How many usec the railcom has to the middle of window (measured from the packet end 1 bit complete)

Definition at line 247 of file DccDecoder.hxx.

◆ RAILCOM_CUTOUT_PRE

template<class Module >
const auto DccDecoder< Module >::RAILCOM_CUTOUT_PRE = 26
staticprivate

How many usec the railcom has before the cutout (measured from the packet end 1 bit complete)

Definition at line 244 of file DccDecoder.hxx.

◆ railcomDriver_

template<class Module >
RailcomDriver* DccDecoder< Module >::railcomDriver_
private

How many times did we lose a DCC packet due to no buffer available.

notified for cutout events.

Definition at line 234 of file DccDecoder.hxx.

◆ sampleActive_

template<class Module >
bool DccDecoder< Module >::sampleActive_ = false
private

true if the next edge we shall sample.

Definition at line 216 of file DccDecoder.hxx.

◆ waitSampleForOverflow_

template<class Module >
bool DccDecoder< Module >::waitSampleForOverflow_ = false
private

if true then sampling will be suspended until the timer overflows.

Definition at line 220 of file DccDecoder.hxx.


The documentation for this class was generated from the following file: