|
Open Model Railroad Network (OpenMRN)
|
Device driver for decoding a DCC signal using a Timer resource. More...
#include <DccDecoder.hxx>
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. | |
| RailcomDriver * | railcomDriver_ |
| How many times did we lose a DCC packet due to no buffer available. | |
| dcc::PacketProcessor * | packetProcessor_ = 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 File * | file_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 | |
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.
|
private |
Definition at line 205 of file DccDecoder.hxx.
| DccDecoder< Module >::DccDecoder | ( | const char * | name, |
| RailcomDriver * | railcom_driver | ||
| ) |
Constructor.
| name | name of device node, e.g. "/dev/dccdecode0" |
| railcom_driver | is the associated railcom driver, which will get the callbacks from the timing of the acquired signal. |
Definition at line 256 of file DccDecoder.hxx.
|
inline |
Definition at line 94 of file DccDecoder.hxx.
|
overrideprivatevirtual |
|
overrideprivatevirtual |
|
inlineoverrideprivatevirtual |
Discards all pending buffers.
Called after disable().
Implements Node.
Definition at line 196 of file DccDecoder.hxx.
|
inline |
Handles a raw interrupt.
Definition at line 289 of file DccDecoder.hxx.
|
inline |
Handles a software interrupt to FreeRTOS.
Definition at line 429 of file DccDecoder.hxx.
|
inline |
Handles interrupt from the second timer used for railcom timing.
Definition at line 391 of file DccDecoder.hxx.
|
inlineprivatevirtual |
Read from a file or device.
| file | file reference for this device |
| buf | location to place read data |
| count | number of bytes to read |
Implements FileIO.
Definition at line 124 of file DccDecoder.hxx.
|
inlineprivatevirtual |
Device select method.
Default impementation returns true.
| file | reference to the file |
| mode | FREAD for read active, FWRITE for write active, 0 for exceptions |
Reimplemented from FileIO.
Definition at line 168 of file DccDecoder.hxx.
|
inline |
Installs a hook that will be called in the interrupt context for each incoming packet.
| p | the hook interface to be called. |
Definition at line 102 of file DccDecoder.hxx.
|
inlineprivatevirtual |
Write to a file or device.
| file | file reference for this device |
| buf | location to find write data |
| count | number of bytes to write |
Implements FileIO.
Definition at line 157 of file DccDecoder.hxx.
|
private |
Which window of the cutout we are in.
Definition at line 227 of file DccDecoder.hxx.
|
private |
DCC packet decoder state machine and internal state.
Definition at line 240 of file DccDecoder.hxx.
|
private |
True if the current internal state is the cutout state.
Definition at line 222 of file DccDecoder.hxx.
|
private |
Definition at line 206 of file DccDecoder.hxx.
|
private |
|
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.
|
private |
Definition at line 208 of file DccDecoder.hxx.
|
private |
Holds the timer value when we should be taking an occupancy sample the next time.
Definition at line 214 of file DccDecoder.hxx.
|
private |
Counts unique identifiers for DCC packets to be returned.
Definition at line 229 of file DccDecoder.hxx.
|
private |
notified for every arrived DCC / MM packet within the interrupt.
Definition at line 237 of file DccDecoder.hxx.
|
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.
|
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.
|
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.
|
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.
|
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.
|
private |
true if the next edge we shall sample.
Definition at line 216 of file DccDecoder.hxx.
|
private |
if true then sampling will be suspended until the timer overflows.
Definition at line 220 of file DccDecoder.hxx.