Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Pic32mxCan.hxx
Go to the documentation of this file.
1
35#ifndef _FREERTOS_DRIVERS_PIC32MX_PIC32MXCAN_HXX_
36#define _FREERTOS_DRIVERS_PIC32MX_PIC32MXCAN_HXX_
37
38#include "Devtab.hxx"
39
40#include "GenericTypeDefs.h"
41#include <xc.h>
42extern "C" {
43#include "peripheral/CAN.h"
44#include "peripheral/int.h"
45}
46
54class Pic32mxCan : public Node
55{
56public:
63 Pic32mxCan(CAN_MODULE module, const char *dev, unsigned irq_vector);
64
66
68 inline void isr()
69 {
70 int woken = 0;
71 if ((CANGetModuleEvent(hw_) & CAN_RX_EVENT) != 0)
72 // if(CANGetPendingEventCode(hw_) == CAN_CHANNEL1_EVENT)
73 {
74 /* This means that channel 1 caused the event.
75 * The CAN_RX_CHANNEL_NOT_EMPTY event is persistent. You
76 * could either read the channel in the ISR
77 * to clear the event condition or as done
78 * here, disable the event source, and set
79 * an application flag to indicate that a message
80 * has been received. The event can be
81 * enabled by the application when it has processed
82 * one message.
83 *
84 * Note that leaving the event enabled would
85 * cause the CPU to keep executing the ISR since
86 * the CAN_RX_CHANNEL_NOT_EMPTY event is persistent (unless
87 * the not empty condition is cleared.)
88 * */
89 CANEnableChannelEvent(
90 hw_, CAN_CHANNEL1, CAN_RX_CHANNEL_NOT_EMPTY, FALSE);
91 Device::select_wakeup_from_isr(&rxSelect_, &woken);
92 }
93 if ((CANGetModuleEvent(hw_) & CAN_TX_EVENT) != 0)
94 // if(CANGetPendingEventCode(hw_) == CAN_CHANNEL0_EVENT)
95 {
96 /* Same with the TX event. */
97 CANEnableChannelEvent(
98 hw_, CAN_CHANNEL0, CAN_TX_CHANNEL_NOT_FULL, FALSE);
99 Device::select_wakeup_from_isr(&txSelect_, &woken);
100 }
101 INTClearFlag(can_int());
102 }
103
104private:
105 void enable();
106 void disable();
109 ssize_t read(File *file, void *buf, size_t count);
110 ssize_t write(File *file, const void *buf, size_t count);
117 bool select(File* file, int mode) OVERRIDE;
118
121 INT_SOURCE can_int()
122 {
123 return (INT_SOURCE)(INT_SOURCE_CAN(hw_));
124 }
125
128 INT_VECTOR can_vector()
129 {
130 return (INT_VECTOR)(INT_VECTOR_CAN(hw_));
131 }
132
134 CAN_MODULE hw_;
139 unsigned irqVector_;
142 // Select for the transmit buffers.
143 SelectInfo txSelect_;
144 // Select for the receive buffers.
145 SelectInfo rxSelect_;
146
148};
149
150
151#endif // _FREERTOS_DRIVERS_PIC32MX_PIC32MXCAN_HXX_
Node information.
Definition Devtab.hxx:549
CAN-bus device driver for the Pic32MX.
unsigned irqVector_
Hardware interrupt vector number. Do not delete!
void * messageFifoArea_
Points to the shared RAM area between the hardware and the driver.
void isr()
Implementation of the interrupt handler.
ssize_t read(File *file, void *buf, size_t count)
Read from a file or device.
CAN_MODULE hw_
Hardware (enumeration value).
bool select(File *file, int mode) OVERRIDE
Device select method.
INT_VECTOR can_vector()
void disable()
function to disable device
INT_SOURCE can_int()
ssize_t write(File *file, const void *buf, size_t count)
Write to a file or device.
void enable()
function to enable device
void flush_buffers() OVERRIDE
function to disable device
int overrunCount_
How many times did we drop a frame because we did not have enough hardware buffers.
#define OVERRIDE
Function attribute for virtual functions declaring that this funciton is overriding a funciton that s...
Definition macros.h:180
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.
Definition macros.h:171
Select wakeup information.
Definition Devtab.hxx:491
static void select_wakeup_from_isr(SelectInfo *info, int *woken)
Wakeup the list of clients needing woken.
Definition Select.cxx:224
File information.
Definition Devtab.hxx:52