Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
MbedRawUSBSerial Class Reference

This class is an empty wrapper around MBed's USB CDC class. More...

Inheritance diagram for MbedRawUSBSerial:
Serial Node Device FileIO

Public Member Functions

 MbedRawUSBSerial (const char *name, uint16_t vendor_id=0x1f00, uint16_t product_id=0x2012, uint16_t product_release=0x0001)
 Constructor.
 
- Public Member Functions inherited from Device
 Device (const char *name)
 Constructor.
 
virtual ~Device ()
 Destructor.
 

Protected Member Functions

bool EP2_OUT_callback () override
 Callback when EP2_OUT is active.
 
bool EP2_IN_callback () override
 Callback when EP2_IN is active.
 
- Protected Member Functions inherited from Serial
 Serial (const char *name, size_t tx_buffer_size=config_serial_tx_buffer_size(), size_t rx_buffer_size=config_serial_rx_buffer_size())
 Constructor.
 
 ~Serial ()
 Destructor.
 
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.
 
int ioctl (File *file, unsigned long int key, unsigned long data) OVERRIDE
 Request an ioctl transaction.
 
bool select (File *file, int mode) OVERRIDE
 Device select method.
 
void flush_buffers () OVERRIDE
 Discards all pending buffers.
 
- 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 fcntl (File *file, int cmd, unsigned long data)
 Manipulate a file descriptor.
 

Private Member Functions

void enable () override
 function to enable device
 
void disable () override
 function to disable device
 
void tx_char () override
 function to try and transmit a character
 
bool TxHelper ()
 Transmits count bytes from the txData buffer.
 
void RxThread ()
 

Static Private Member Functions

static void * _RxThread (void *arg)
 Entry point to receiving thread.
 

Private Attributes

uint8_t txData [MAX_TX_PACKET_LENGTH]
 packet assemby buffer to host
 
uint32_t rxSize
 number of valid characters in rxData
 
uint8_t rxData [MAX_RX_PACKET_LENGTH]
 packet assembly buffer from host
 
bool txPending
 transmission currently pending
 
os_sem_t rxSem
 Semaphore to wake up receiving thread.
 

Static Private Attributes

static const unsigned MAX_TX_PACKET_LENGTH = 64
 What's the maximum packet length for transmit.
 
static const unsigned MAX_RX_PACKET_LENGTH = 64
 What's the maximum packet length for receive.
 

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.
 
- 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 Serial
DeviceBuffer< uint8_t > * txBuf
 transmit buffer
 
DeviceBuffer< uint8_t > * rxBuf
 receive buffer
 
unsigned int overrunCount
 overrun count
 
- 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

This class is an empty wrapper around MBed's USB CDC class.

The difference between this and mbed::USBSerial is that this class does not have any buffering and no interaction with stdio, whereas mbed::USBSerial has the following buffering: it has a 128-byte receive buffer. it has an fd it has a FILE* with a default-sized send/receive buffer it requires mbed's custom glue code in the open(2) method, without which it crashes.

Definition at line 85 of file mbed_usbserial.cpp.

Constructor & Destructor Documentation

◆ MbedRawUSBSerial()

MbedRawUSBSerial::MbedRawUSBSerial ( const char *  name,
uint16_t  vendor_id = 0x1f00,
uint16_t  product_id = 0x2012,
uint16_t  product_release = 0x0001 
)
inline

Constructor.

Parameters
namedevice path to export (e.g. /dev/usbser0).
vendor_idUSB vendor ID to report
product_idUSB device ID to report
product_releaseUSB product version to report.

Definition at line 93 of file mbed_usbserial.cpp.

◆ ~MbedRawUSBSerial()

MbedRawUSBSerial::~MbedRawUSBSerial ( )
inline

Definition at line 105 of file mbed_usbserial.cpp.

Member Function Documentation

◆ _RxThread()

static void * MbedRawUSBSerial::_RxThread ( void *  arg)
inlinestaticprivate

Entry point to receiving thread.

Parameters
argis the UsbServial object to run upon.
Returns
null.

Definition at line 243 of file mbed_usbserial.cpp.

◆ disable()

void MbedRawUSBSerial::disable ( )
inlineoverrideprivatevirtual

function to disable device

Implements Node.

Definition at line 148 of file mbed_usbserial.cpp.

◆ enable()

void MbedRawUSBSerial::enable ( )
inlineoverrideprivatevirtual

function to enable device

Implements Node.

Definition at line 145 of file mbed_usbserial.cpp.

◆ EP2_IN_callback()

bool MbedRawUSBSerial::EP2_IN_callback ( )
inlineoverrideprotected

Callback when EP2_IN is active.

Definition at line 122 of file mbed_usbserial.cpp.

◆ EP2_OUT_callback()

bool MbedRawUSBSerial::EP2_OUT_callback ( )
inlineoverrideprotected

Callback when EP2_OUT is active.

Definition at line 112 of file mbed_usbserial.cpp.

◆ RxThread()

void MbedRawUSBSerial::RxThread ( )
inlineprivate
Todo:
(balazs.racz) this needs to be replaced with something that works in the new select based model.

Definition at line 216 of file mbed_usbserial.cpp.

◆ tx_char()

void MbedRawUSBSerial::tx_char ( )
inlineoverrideprivatevirtual

function to try and transmit a character

Implements Serial.

Definition at line 153 of file mbed_usbserial.cpp.

◆ TxHelper()

bool MbedRawUSBSerial::TxHelper ( )
inlineprivate

Transmits count bytes from the txData buffer.

Sets txPending and bytesLost as needed.

Returns
true if we consumed some data from the tx buffer.

Definition at line 178 of file mbed_usbserial.cpp.

Member Data Documentation

◆ MAX_RX_PACKET_LENGTH

const unsigned MbedRawUSBSerial::MAX_RX_PACKET_LENGTH = 64
staticprivate

What's the maximum packet length for receive.

Definition at line 173 of file mbed_usbserial.cpp.

◆ MAX_TX_PACKET_LENGTH

const unsigned MbedRawUSBSerial::MAX_TX_PACKET_LENGTH = 64
staticprivate

What's the maximum packet length for transmit.

Definition at line 171 of file mbed_usbserial.cpp.

◆ rxData

uint8_t MbedRawUSBSerial::rxData[MAX_RX_PACKET_LENGTH]
private

packet assembly buffer from host

Definition at line 251 of file mbed_usbserial.cpp.

◆ rxSem

os_sem_t MbedRawUSBSerial::rxSem
private

Semaphore to wake up receiving thread.

Definition at line 255 of file mbed_usbserial.cpp.

◆ rxSize

uint32_t MbedRawUSBSerial::rxSize
private

number of valid characters in rxData

Definition at line 250 of file mbed_usbserial.cpp.

◆ txData

uint8_t MbedRawUSBSerial::txData[MAX_TX_PACKET_LENGTH]
private

packet assemby buffer to host

Definition at line 249 of file mbed_usbserial.cpp.

◆ txPending

bool MbedRawUSBSerial::txPending
private

transmission currently pending

Definition at line 253 of file mbed_usbserial.cpp.


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