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

CAN-bus device driver for the Pic32MX. More...

#include <Pic32mxCan.hxx>

Inheritance diagram for Pic32mxCan:
Node Device FileIO

Public Member Functions

 Pic32mxCan (CAN_MODULE module, const char *dev, unsigned irq_vector)
 Constructor.
 
void isr ()
 Implementation of the interrupt handler.
 
- Public Member Functions inherited from Device
 Device (const char *name)
 Constructor.
 
virtual ~Device ()
 Destructor.
 

Private Member Functions

void enable ()
 function to enable device
 
void disable ()
 function to disable device
 
void flush_buffers () OVERRIDE
 function to disable device
 
ssize_t read (File *file, void *buf, size_t count)
 Read from a file or device.
 
ssize_t write (File *file, const void *buf, size_t count)
 Write to a file or device.
 
bool select (File *file, int mode) OVERRIDE
 Device select method.
 
INT_SOURCE can_int ()
 
INT_VECTOR can_vector ()
 
 DISALLOW_COPY_AND_ASSIGN (Pic32mxCan)
 

Private Attributes

CAN_MODULE hw_
 Hardware (enumeration value).
 
int overrunCount_
 How many times did we drop a frame because we did not have enough hardware buffers.
 
unsigned irqVector_
 Hardware interrupt vector number. Do not delete!
 
void * messageFifoArea_
 Points to the shared RAM area between the hardware and the driver.
 
SelectInfo txSelect_
 
SelectInfo rxSelect_
 

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

CAN-bus device driver for the Pic32MX.

This driver does not inherit from the shared Can driver, because the RX and RX buffering is different. The shared CAN driver has a DeviceBuffer for transmit and receive in the format of struct can_frame; whereas the PIC32 can write directly into the memory area of the CAN controller as the queues are long enough and the CAN controller is a bus master.

Definition at line 54 of file Pic32mxCan.hxx.

Constructor & Destructor Documentation

◆ Pic32mxCan()

Pic32mxCan::Pic32mxCan ( CAN_MODULE  module,
const char *  dev,
unsigned  irq_vector 
)

Constructor.

Parameters
moduledefines which CAN hardware to use. (can0 or can1).
devfilename of the device to create (e.g. "/dev/can0");
irq_vectorfill with can1_interrupt_vector_number or can2_interrupt_vector_number.

Definition at line 43 of file Pic32mxCan.cxx.

◆ ~Pic32mxCan()

Pic32mxCan::~Pic32mxCan ( )

Definition at line 53 of file Pic32mxCan.cxx.

Member Function Documentation

◆ can_int()

INT_SOURCE Pic32mxCan::can_int ( )
inlineprivate
Returns
the interrupt source as used by the internal tables of the peripheral library.

Definition at line 121 of file Pic32mxCan.hxx.

◆ can_vector()

INT_VECTOR Pic32mxCan::can_vector ( )
inlineprivate
Returns
the interrupt vector enum as used by the internal tables of the peripheral library.

Definition at line 128 of file Pic32mxCan.hxx.

◆ disable()

void Pic32mxCan::disable ( )
privatevirtual

function to disable device

Implements Node.

Definition at line 395 of file Pic32mxCan.cxx.

◆ enable()

void Pic32mxCan::enable ( )
privatevirtual

function to enable device

Todo:
(balazs.racz) why is the tx buffer length 1?

Implements Node.

Definition at line 320 of file Pic32mxCan.cxx.

◆ flush_buffers()

void Pic32mxCan::flush_buffers ( )
inlineprivatevirtual

function to disable device

Implements Node.

Definition at line 107 of file Pic32mxCan.hxx.

◆ isr()

void Pic32mxCan::isr ( )
inline

Implementation of the interrupt handler.

Definition at line 68 of file Pic32mxCan.hxx.

◆ read()

ssize_t Pic32mxCan::read ( File file,
void *  buf,
size_t  count 
)
privatevirtual

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 131 of file Pic32mxCan.cxx.

◆ select()

bool Pic32mxCan::select ( File file,
int  mode 
)
privatevirtual

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 283 of file Pic32mxCan.cxx.

◆ write()

ssize_t Pic32mxCan::write ( File file,
const void *  buf,
size_t  count 
)
privatevirtual

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 210 of file Pic32mxCan.cxx.

Member Data Documentation

◆ hw_

CAN_MODULE Pic32mxCan::hw_
private

Hardware (enumeration value).

Definition at line 134 of file Pic32mxCan.hxx.

◆ irqVector_

unsigned Pic32mxCan::irqVector_
private

Hardware interrupt vector number. Do not delete!

Definition at line 139 of file Pic32mxCan.hxx.

◆ messageFifoArea_

void* Pic32mxCan::messageFifoArea_
private

Points to the shared RAM area between the hardware and the driver.

Definition at line 141 of file Pic32mxCan.hxx.

◆ overrunCount_

int Pic32mxCan::overrunCount_
private

How many times did we drop a frame because we did not have enough hardware buffers.

Definition at line 137 of file Pic32mxCan.hxx.

◆ rxSelect_

SelectInfo Pic32mxCan::rxSelect_
private

Definition at line 145 of file Pic32mxCan.hxx.

◆ txSelect_

SelectInfo Pic32mxCan::txSelect_
private

Definition at line 143 of file Pic32mxCan.hxx.


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