|
Open Model Railroad Network (OpenMRN)
|
Specialization of CAN driver for Tiva CAN. More...
#include <MCP2515Can.hxx>
Classes | |
| class | Buffer |
| CAN TX and RX buffer structure. More... | |
| class | BufferRead |
| Setup a buffer read transfer structure. More... | |
| class | BufferWrite |
| Setup a buffer read transfer structure. More... | |
| struct | Config1 |
| Configuration resgister 1 structure. More... | |
| struct | Config2 |
| Configuration resgister 2 structure. More... | |
| struct | Config3 |
| Configuration resgister 3 structure. More... | |
| struct | MCP2515Baud |
| Baud rate table entry. More... | |
Public Member Functions | |
| MCP2515Can (const char *name, void(*interrupt_enable)(), void(*interrupt_disable)()) | |
| Constructor. | |
| ~MCP2515Can () | |
| Destructor. | |
| void | init (const char *spi_name, uint32_t freq, uint32_t baud) |
| Initialize CAN device settings. | |
| void | interrupt_handler () |
| Handle an interrupt. | |
| OSMutex * | get_spi_bus_lock () |
| Return a mutex that can be used by another SPI driver instance sharing the same bus as its bus lock. | |
Public Member Functions inherited from Can | |
| int | available () |
| int | availableForWrite () |
| int | read (struct can_frame *frame) |
| Read a frame if there is one available. | |
| int | write (const struct can_frame *frame) |
| Send a frame if there is space available. | |
Public Member Functions inherited from Device | |
| Device (const char *name) | |
| Constructor. | |
| virtual | ~Device () |
| Destructor. | |
Public Member Functions inherited from OSThread | |
| OSThread (const char *name, int priority, size_t stack_size, void *(*start_routine)(void *), void *arg) | |
| Create a thread. | |
| OSThread () | |
| Creates a thread via inheritance. | |
| void | start (const char *name, int priority, size_t stack_size) |
| Starts the thread. | |
| virtual | ~OSThread () |
| Default destructor. | |
| bool | is_created () |
| void | inherit () |
| Inherits the current thread. | |
| os_thread_t | get_handle () |
| void | lock_to_thread () |
| Sets the thread handle to the current calling thread's. | |
| void | unlock_from_thread () |
| Resets the thread handle to none. | |
Private Types | |
| enum | Registers { RXF0SIDH = 0 , RXF0SIDL , RXF0SEID8 , RXF0EID0 , RXF1SIDH , RXF1SIDL , RXF1SEID8 , RXF1EID0 , RXF2SIDH , RXF2SIDL , RXF2SEID8 , RXF2EID0 , BFPCTRL , TXRTSCTRL , CANSTAT , CANCTRL , RXF3SIDH = 16 , RXF3SIDL , RXF3EID8 , RXF3EID0 , RXF4SIDH , RXF4SIDL , RXF4EID8 , RXF4EID0 , RXF5SIDH , RXF5SIDL , RXF5EID8 , RXF5EID0 , TEC , RED , RXM0SIDH = 32 , RXM0SIDL , RXM0EID8 , RXM0EID0 , RXM1SIDH , RXM1SIDL , RXM1EID8 , RXM1EID0 , CNF3 , CNF2 , CNF1 , CANINTE , CANINTF , EFLG , TXB0CTRL = 48 , TXB0SIDH , TXB0SIDL , TXB0EID8 , TXB0EID0 , TXB0DLC , TXB0D0 , TXB0D1 , TXB0D2 , TXB0D3 , TXB0D4 , TXB0D5 , TXB0D6 , TXB0D7 , TXB1CTRL = 64 , TXB1SIDH , TXB1SIDL , TXB1EID8 , TXB1EID0 , TXB1DLC , TXB1D0 , TXB1D1 , TXB1D2 , TXB1D3 , TXB1D4 , TXB1D5 , TXB1D6 , TXB1D7 , TXB2CTRL = 80 , TXB2SIDH , TXB2SIDL , TXB2EID8 , TXB2EID0 , TXB2DLC , TXB2D0 , TXB2D1 , TXB2D2 , TXB2D3 , TXB2D4 , TXB2D5 , TXB2D6 , TXB2D7 , RXB0CTRL = 96 , RXB0SIDH , RXB0SIDL , RXB0EID8 , RXB0EID0 , RXB0DLC , RXB0D0 , RXB0D1 , RXB0D2 , RXB0D3 , RXB0D4 , RXB0D5 , RXB0D6 , RXB0D7 , RXB1CTRL = 112 , RXB1SIDH , RXB1SIDL , RXB1EID8 , RXB1EID0 , RXB1DLC , RXB1D0 , RXB1D1 , RXB1D2 , RXB1D3 , RXB1D4 , RXB1D5 , RXB1D6 , RXB1D7 } |
| SPI registers. More... | |
| enum | ControlFields { CLKPRE = 0x03 , CLKEN = 0x04 , OSM = 0x08 , ABAT = 0x10 , REQOP = 0xE0 } |
| Fields of the control register. More... | |
| enum | InterruptFlags { RX0I = 0x01 , RX1I = 0x02 , TX0I = 0x04 , TX1I = 0x08 , TX2I = 0x10 , ERRI = 0x20 , WAKI = 0x40 , MERR = 0x80 } |
| interrupt flag masks More... | |
| enum | ErrorFlags { EWARN = 0x01 , RXWARN = 0x02 , TXWARN = 0x04 , RXEP = 0x08 , TXEP = 0x10 , TXBO = 0x20 , RX0OVR = 0x40 , RX1OVR = 0x80 } |
| interrupt flag masks More... | |
| enum | Instructions { RESET = 0xC0 , READ = 0x03 , READ_RX_BUF = 0x90 , WRITE = 0x02 , LOAD_TX_BUF = 0x40 , STATUS = 0xA0 , RX_STATUS = 0xB0 , RTS = 0x80 , BIT_MODIFY = 0x05 } |
| SPI transaction instructions. More... | |
Private Member Functions | |
| int | ioctl (File *file, unsigned long int key, unsigned long data) override |
| Request an ioctl transaction. | |
| void * | entry () override |
| User entry point for the created thread. | |
| void | enable () override |
| function to enable device | |
| void | disable () override |
| function to disable device | |
| void | tx_msg () override |
| Function to try and transmit a message. | |
| void | tx_msg_locked () |
| Function to try and transmit a message while holding a lock. | |
| void | reset () |
| Reset the device. | |
| uint8_t | register_read (Registers address) |
| Read from a SPI register. | |
| void | register_write (Registers address, uint8_t data) |
| Write to a SPI register. | |
| void | bit_modify (Registers address, uint8_t data, uint8_t mask) |
| Bit modify to a SPI register. | |
| void | buffer_read (BufferRead *buf) |
| Read a message to into a receive buffer. | |
| void | buffer_write (BufferWrite *buf, struct can_frame *can_frame) |
| Write a message to a transmit buffer. | |
| void | request_gpio_operation () |
| Request that the GPIO cache be refreshed. | |
| MCP2515Can () | |
| Default constructor. | |
| DISALLOW_COPY_AND_ASSIGN (MCP2515Can) | |
Private Attributes | |
| void(* | interruptEnable_ )() |
| enable interrupt callback | |
| void(* | interruptDisable_ )() |
| disable interrupt callback | |
| unsigned | state_: 4 |
| present bus state | |
| unsigned | txPending_: 2 |
| transmission in flight | |
| unsigned | gpoData_: 2 |
| local copy of the I/O expansion output data | |
| unsigned | gpiData_: 3 |
| local copy of the I/O expansion input data | |
| unsigned | ioPending_: 1 |
| true if an I/O update is pending | |
| int | spiFd_ |
| SPI bus that accesses MCP2515. | |
| SPI * | spi_ |
| pointer to a SPI object instance | |
| OSSem | sem_ |
| semaphore for posting events | |
Static Private Attributes | |
| static constexpr uint32_t | SPI_MAX_SPEED_HZ = 10000000 |
| maximum SPI clock speed in Hz | |
| static const MCP2515Baud | BAUD_TABLE [] |
| baud rate settings table | |
Friends | |
| class | MCP2515GPO |
| Allow access to MCP2515Can from MCP2515GPO. | |
| class | MCP2515GPI |
| Allow access to MCP2515Can from MCP2515GPI. | |
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 Public Member Functions inherited from OSThread | |
| static int | getpriority (OSThread *thread) |
| Return the current thread priority. | |
| static int | get_priority (OSThread *thread) |
| Return the current thread priority. | |
| static int | get_priority_min () |
| Get the minimum thread priority. | |
| static int | get_priority_max () |
| Get the maximum thread priority. | |
Static Public Attributes inherited from Can | |
| static unsigned | numReceivedPackets_ {0} |
| static unsigned | numTransmittedPackets_ {0} |
Protected Member Functions inherited from Can | |
| Can (const char *ignored) | |
| Constructor. | |
| ~Can () | |
| Destructor. | |
| Can (const char *name, size_t tx_buffer_size=config_can_tx_buffer_size(), size_t rx_buffer_size=config_can_rx_buffer_size()) | |
| Constructor. | |
| ~Can () | |
| Destructor. | |
| bool | has_tx_buffer_space () OVERRIDE |
| bool | has_rx_buffer_data () OVERRIDE |
| void | flush_buffers () OVERRIDE |
| called after disable | |
| 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. | |
Protected Member Functions inherited from Atomic | |
| void | lock () |
| void | unlock () |
Protected Member Functions inherited from NonBlockNode | |
| NonBlockNode (const char *name) | |
| Constructor. | |
| int | ioctl (File *file, unsigned long int key, unsigned long data) OVERRIDE |
| Request an ioctl transaction. | |
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. | |
| Device (const char *name) | |
| Constructor. | |
| virtual | ~Device () |
| Destructor. | |
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. | |
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 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 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. | |
| 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 Attributes inherited from Can | |
| DeviceBuffer< struct can_frame > * | txBuf |
| transmit buffer | |
| DeviceBuffer< struct can_frame > * | rxBuf |
| receive buffer | |
| unsigned int | overrunCount |
| overrun count | |
| unsigned int | busOffCount |
| bus-off count | |
| unsigned int | softErrorCount |
| soft error count | |
Protected Attributes inherited from NonBlockNode | |
| Notifiable * | readableNotify_ |
| This will be notified if the device has data avilable for read. | |
| Notifiable * | writableNotify_ |
| This will be notified if the device has buffer avilable for write. | |
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 | |
Specialization of CAN driver for Tiva CAN.
Definition at line 56 of file MCP2515Can.hxx.
|
private |
Fields of the control register.
| Enumerator | |
|---|---|
| CLKPRE | clockout pin prescaler |
| CLKEN | clockout pin enable |
| OSM | one-shot mode |
| ABAT | abort all pending transmissions |
| REQOP | request operation mode |
Definition at line 239 of file MCP2515Can.hxx.
|
private |
interrupt flag masks
Definition at line 262 of file MCP2515Can.hxx.
|
private |
SPI transaction instructions.
Definition at line 275 of file MCP2515Can.hxx.
|
private |
interrupt flag masks
Definition at line 249 of file MCP2515Can.hxx.
|
private |
SPI registers.
Definition at line 113 of file MCP2515Can.hxx.
|
inline |
Constructor.
| name | name of this device instance in the file system |
| interrupt_enable | callback to enable the interrupt |
| interrupt_disable | callback to disable the interrupt |
Definition at line 64 of file MCP2515Can.hxx.
|
inline |
Destructor.
Definition at line 83 of file MCP2515Can.hxx.
|
inlineprivate |
Bit modify to a SPI register.
| address | address to modify |
| data | data to modify |
| mask | mask of data to modify |
Definition at line 613 of file MCP2515Can.hxx.
|
inlineprivate |
Read a message to into a receive buffer.
| buf | BuffeRead object to fill in |
Definition at line 627 of file MCP2515Can.hxx.
|
inlineprivate |
Write a message to a transmit buffer.
| buf | BufferWrite object to write out over SPI |
| can_frame | reference to a can_frame metadata structure. |
Definition at line 640 of file MCP2515Can.hxx.
|
overrideprivatevirtual |
|
overrideprivatevirtual |
|
overrideprivatevirtual |
User entry point for the created thread.
Reimplemented from OSThread.
Definition at line 261 of file MCP2515Can.cxx.
|
inline |
Return a mutex that can be used by another SPI driver instance sharing the same bus as its bus lock.
Definition at line 103 of file MCP2515Can.hxx.
| void MCP2515Can::init | ( | const char * | spi_name, |
| uint32_t | freq, | ||
| uint32_t | baud | ||
| ) |
Initialize CAN device settings.
Typically called in hw_postinit(), not hw_preinit() or hw_init().
| spi_name | spi interface that the MCP2515Can is on |
| freq | frequency in Hz that the MCP2515 clock runs at |
| baud | target baud rate in Hz |
Definition at line 88 of file MCP2515Can.cxx.
| void MCP2515Can::interrupt_handler | ( | ) |
Handle an interrupt.
Called by user provided interrupt handler.
Definition at line 464 of file MCP2515Can.cxx.
|
overrideprivatevirtual |
Request an ioctl transaction.
| file | file reference for this device |
| key | ioctl key |
| data | key data |
Reimplemented from FileIO.
Definition at line 247 of file MCP2515Can.cxx.
|
inlineprivate |
Read from a SPI register.
| address | address to read from |
Definition at line 577 of file MCP2515Can.hxx.
|
inlineprivate |
Write to a SPI register.
| address | address to write to |
| data | data to write |
Definition at line 596 of file MCP2515Can.hxx.
|
inlineprivate |
Request that the GPIO cache be refreshed.
Definition at line 651 of file MCP2515Can.hxx.
|
inlineprivate |
Reset the device.
Definition at line 560 of file MCP2515Can.hxx.
|
inlineoverrideprivatevirtual |
Function to try and transmit a message.
Implements Can.
Definition at line 541 of file MCP2515Can.hxx.
|
private |
Function to try and transmit a message while holding a lock.
Definition at line 191 of file MCP2515Can.cxx.
|
friend |
Allow access to MCP2515Can from MCP2515GPI.
Definition at line 685 of file MCP2515Can.hxx.
|
friend |
Allow access to MCP2515Can from MCP2515GPO.
Definition at line 682 of file MCP2515Can.hxx.
|
staticprivate |
baud rate settings table
Definition at line 41 of file MCP2515Can.hxx.
|
private |
local copy of the I/O expansion input data
Definition at line 665 of file MCP2515Can.hxx.
|
private |
local copy of the I/O expansion output data
Definition at line 664 of file MCP2515Can.hxx.
|
private |
disable interrupt callback
Definition at line 661 of file MCP2515Can.hxx.
|
private |
enable interrupt callback
Definition at line 660 of file MCP2515Can.hxx.
|
private |
true if an I/O update is pending
Definition at line 666 of file MCP2515Can.hxx.
|
private |
semaphore for posting events
Definition at line 669 of file MCP2515Can.hxx.
|
private |
pointer to a SPI object instance
Definition at line 668 of file MCP2515Can.hxx.
|
staticconstexprprivate |
maximum SPI clock speed in Hz
Definition at line 110 of file MCP2515Can.hxx.
|
private |
SPI bus that accesses MCP2515.
Definition at line 667 of file MCP2515Can.hxx.
|
private |
present bus state
Definition at line 662 of file MCP2515Can.hxx.
|
private |
transmission in flight
Definition at line 663 of file MCP2515Can.hxx.