Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
RailcomDriverBase< HW > Class Template Referenceabstract

Base class for railcom drivers. More...

#include <Railcom.hxx>

Inheritance diagram for RailcomDriverBase< HW >:
RailcomDriver Node RailcomDriver Node Stm32RailcomDriver< HW > TivaRailcomDriver< HW > TivaRailcomDriver< HW >

Public Member Functions

 RailcomDriverBase (const char *name)
 Constructor.
 
void os_interrupt_handler ()
 Implementation of the interrupt handler running at the kernel interrupt priority.
 
 RailcomDriverBase (const char *name)
 Constructor.
 
void os_interrupt_handler ()
 Implementation of the interrupt handler running at the kernel interrupt priority.
 
- Public Member Functions inherited from RailcomDriver
virtual void feedback_sample ()=0
 Call to the driver for sampling the current sensors.
 
virtual void start_cutout ()=0
 Instructs the driver that the railcom cutout is starting now.
 
virtual void middle_cutout ()=0
 Notifies the driver that the railcom cutout has reached the middle point, i.e., the first window is passed and the second window is starting.
 
virtual void end_cutout ()=0
 Instructs the driver that the railcom cutout is over now.
 
virtual void no_cutout ()=0
 Called instead of start/mid/end-cutout at the end of the current packet if there was no cutout requested.
 
virtual void send_ch1 (const DCCFeedback *ch1_pkt)
 Specifies what packet should be sent for the channel1 cutout.
 
virtual void send_ch2 (const DCCFeedback *ch2_pkt)
 Specifies what packet should be sent for the channel2 cutout.
 

Protected Member Functions

dcc::Feedbackalloc_new_packet (uint8_t channel)
 Takes a new empty packet at the front of the queue, fills in feedback key and channel information.
 
void add_sample (int sample)
 Adds a sample for a preamble bit.
 
dcc::Feedbackalloc_new_packet (uint8_t channel)
 Takes a new empty packet at the front of the queue, fills in feedback key and channel information.
 
void add_sample (int sample)
 Adds a sample for a preamble bit.
 

Protected Attributes

NotifiablereadableNotifiable_
 Notify this when we have data in our buffers.
 
FixedQueue< dcc::Feedback, HW::Q_SIZE > feedbackQueue_
 The packets we have read so far.
 
uint32_t feedbackKey_
 Stores the key for the next packets to read.
 
dcc::FeedbackreturnedPackets_ [HW::CHANNEL_COUNT]
 Stores pointers to packets we are filling right now, one for each channel.
 

Private Member Functions

ssize_t write (File *, const void *, size_t) OVERRIDE
 Write to a file or device.
 
ssize_t read (File *file, void *buf, size_t count) OVERRIDE
 Read from a file or device.
 
void flush_buffers () OVERRIDE
 Instructs the device driver to drop all TX and RX queues.
 
int ioctl (File *file, unsigned long int key, unsigned long data) override
 Request an ioctl transaction.
 
void set_feedback_key (uint32_t key) OVERRIDE
 Specifies the feedback key to write into the received railcom data packets.
 
virtual void int_set_pending (unsigned int_nr)=0
 Sets a given software interrupt pending.
 
ssize_t write (File *, const void *, size_t) OVERRIDE
 Write to a file or device.
 
ssize_t read (File *file, void *buf, size_t count) OVERRIDE
 Read from a file or device.
 
void flush_buffers () OVERRIDE
 Instructs the device driver to drop all TX and RX queues.
 
int ioctl (File *file, unsigned long int key, unsigned long data) override
 Request an ioctl transaction.
 
void set_feedback_key (uint32_t key) OVERRIDE
 Specifies the feedback key to write into the received railcom data packets.
 
- Private Member Functions inherited from Node
 Node (const char *name)
 Constructor.
 
virtual ~Node ()
 Destructor.
 
virtual void enable ()=0
 This will be called once when reference-count goes from 0 to positive.
 
virtual void disable ()=0
 This will be called when reference count goes from non-zero to 0.
 
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.
 
- Private Member Functions inherited from Device
 Device (const char *name)
 Constructor.
 
virtual ~Device ()
 Destructor.
 
- Private 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 fcntl (File *file, int cmd, unsigned long data)
 Manipulate a file descriptor.
 
virtual bool select (File *file, int mode)
 Device select method.
 

Additional Inherited Members

- Static Private 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 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 Private 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.
 
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.
 
- Private 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
 
- Private Attributes inherited from FileIO
const char * name
 device name
 
- Static Private 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 HW>
class RailcomDriverBase< HW >

Base class for railcom drivers.

Base class for railcom driver implementations.

Ideally this base class should be non-specific to the hardwsre or the TivaWare driver library.

Todo:
(balazs.racz) factor this class out into freertos_drivers/common/Railcom.hxx.

Definition at line 132 of file Railcom.hxx.

Constructor & Destructor Documentation

◆ RailcomDriverBase() [1/2]

template<class HW >
RailcomDriverBase< HW >::RailcomDriverBase ( const char *  name)
inline

Constructor.

Parameters
nameis the device node (e.g. "/dev/railcom0").

Definition at line 136 of file Railcom.hxx.

◆ ~RailcomDriverBase() [1/2]

template<class HW >
RailcomDriverBase< HW >::~RailcomDriverBase ( )
inline

Definition at line 145 of file Railcom.hxx.

◆ RailcomDriverBase() [2/2]

template<class HW >
RailcomDriverBase< HW >::RailcomDriverBase ( const char *  name)
inline

Constructor.

Parameters
nameis the device node (e.g. "/dev/railcom0").

Definition at line 127 of file RailcomImpl.hxx.

◆ ~RailcomDriverBase() [2/2]

template<class HW >
RailcomDriverBase< HW >::~RailcomDriverBase ( )
inline

Definition at line 134 of file RailcomImpl.hxx.

Member Function Documentation

◆ add_sample() [1/2]

template<class HW >
void RailcomDriverBase< HW >::add_sample ( int  sample)
inlineprotected

Adds a sample for a preamble bit.

Parameters
sampleis the next sample to return to the application layer (usually a bitmask setting which channels are active).

Definition at line 261 of file Railcom.hxx.

◆ add_sample() [2/2]

template<class HW >
void RailcomDriverBase< HW >::add_sample ( int  sample)
inlineprotected

Adds a sample for a preamble bit.

Parameters
sampleis the next sample to return to the application layer (usually a bitmask setting which channels are active).

Definition at line 253 of file RailcomImpl.hxx.

◆ alloc_new_packet() [1/2]

template<class HW >
dcc::Feedback * RailcomDriverBase< HW >::alloc_new_packet ( uint8_t  channel)
inlineprotected

Takes a new empty packet at the front of the queue, fills in feedback key and channel information.

Parameters
channelis which channel to set the packet for.
Returns
a packet pointer to write into. If there is no space, returns nullptr.

Definition at line 245 of file Railcom.hxx.

◆ alloc_new_packet() [2/2]

template<class HW >
dcc::Feedback * RailcomDriverBase< HW >::alloc_new_packet ( uint8_t  channel)
inlineprotected

Takes a new empty packet at the front of the queue, fills in feedback key and channel information.

Parameters
channelis which channel to set the packet for.
Returns
a packet pointer to write into. If there is no space, returns nullptr.

Definition at line 237 of file RailcomImpl.hxx.

◆ flush_buffers() [1/2]

template<class HW >
void RailcomDriverBase< HW >::flush_buffers ( )
inlineprivatevirtual

Instructs the device driver to drop all TX and RX queues.

This is called after disable() still under the device lock.

Implements Node.

Definition at line 173 of file Railcom.hxx.

◆ flush_buffers() [2/2]

template<class HW >
void RailcomDriverBase< HW >::flush_buffers ( )
inlineprivatevirtual

Instructs the device driver to drop all TX and RX queues.

This is called after disable() still under the device lock.

Implements Node.

Definition at line 165 of file RailcomImpl.hxx.

◆ int_set_pending()

template<class HW >
virtual void RailcomDriverBase< HW >::int_set_pending ( unsigned  int_nr)
privatepure virtual

Sets a given software interrupt pending.

Parameters
int_nrinterrupt number (will be HW::OS_INTERRUPT)

Implemented in Stm32RailcomDriver< HW >, and TivaRailcomDriver< HW >.

◆ ioctl() [1/2]

template<class HW >
int RailcomDriverBase< HW >::ioctl ( File file,
unsigned long int  key,
unsigned long  data 
)
inlineoverrideprivatevirtual

Request an ioctl transaction.

Parameters
filefile reference for this device
keyioctl key
datakey data
Returns
0 upon success or negative error number upon error.

Reimplemented from FileIO.

Definition at line 182 of file Railcom.hxx.

◆ ioctl() [2/2]

template<class HW >
int RailcomDriverBase< HW >::ioctl ( File file,
unsigned long int  key,
unsigned long  data 
)
inlineoverrideprivatevirtual

Request an ioctl transaction.

Parameters
filefile reference for this device
keyioctl key
datakey data
Returns
0 upon success or negative error number upon error.

Reimplemented from FileIO.

Definition at line 174 of file RailcomImpl.hxx.

◆ os_interrupt_handler() [1/2]

template<class HW >
void RailcomDriverBase< HW >::os_interrupt_handler ( )
inline

Implementation of the interrupt handler running at the kernel interrupt priority.

Call this function from the hardware interrupt handler.

Definition at line 219 of file Railcom.hxx.

◆ os_interrupt_handler() [2/2]

template<class HW >
void RailcomDriverBase< HW >::os_interrupt_handler ( )
inline

Implementation of the interrupt handler running at the kernel interrupt priority.

Call this function from the hardware interrupt handler.

Definition at line 211 of file RailcomImpl.hxx.

◆ read() [1/2]

template<class HW >
ssize_t RailcomDriverBase< HW >::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 157 of file Railcom.hxx.

◆ read() [2/2]

template<class HW >
ssize_t RailcomDriverBase< HW >::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 149 of file RailcomImpl.hxx.

◆ set_feedback_key() [1/2]

template<class HW >
void RailcomDriverBase< HW >::set_feedback_key ( uint32_t  key)
inlineprivatevirtual

Specifies the feedback key to write into the received railcom data packets.

This feedback key is used by the application layer to correlate the stream of DCC packets to the stream of Railcom packets. This method shall be called before start_cutout. The feedback key set here is used until this method is called again.

Parameters
keyis the new feedback key.

Implements RailcomDriver.

Definition at line 234 of file Railcom.hxx.

◆ set_feedback_key() [2/2]

template<class HW >
void RailcomDriverBase< HW >::set_feedback_key ( uint32_t  key)
inlineprivatevirtual

Specifies the feedback key to write into the received railcom data packets.

This feedback key is used by the application layer to correlate the stream of DCC packets to the stream of Railcom packets. This method shall be called before start_cutout. The feedback key set here is used until this method is called again.

Parameters
keyis the new feedback key.

Implements RailcomDriver.

Definition at line 226 of file RailcomImpl.hxx.

◆ write() [1/2]

template<class HW >
ssize_t RailcomDriverBase< HW >::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 151 of file Railcom.hxx.

◆ write() [2/2]

template<class HW >
ssize_t RailcomDriverBase< HW >::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 143 of file RailcomImpl.hxx.

Member Data Documentation

◆ feedbackKey_

template<class HW >
uint32_t RailcomDriverBase< HW >::feedbackKey_
protected

Stores the key for the next packets to read.

Definition at line 282 of file Railcom.hxx.

◆ feedbackQueue_

template<class HW >
FixedQueue< dcc::Feedback, HW::Q_SIZE > RailcomDriverBase< HW >::feedbackQueue_
protected

The packets we have read so far.

Definition at line 280 of file Railcom.hxx.

◆ readableNotifiable_

template<class HW >
Notifiable * RailcomDriverBase< HW >::readableNotifiable_
protected

Notify this when we have data in our buffers.

Definition at line 278 of file Railcom.hxx.

◆ returnedPackets_

template<class HW >
dcc::Feedback * RailcomDriverBase< HW >::returnedPackets_
protected

Stores pointers to packets we are filling right now, one for each channel.

Definition at line 285 of file Railcom.hxx.


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