37#include "driverlib/can.h"
38#include "driverlib/interrupt.h"
39#include "driverlib/rom.h"
40#include "driverlib/rom_map.h"
41#include "driverlib/sysctl.h"
42#include "inc/hw_can.h"
43#include "inc/hw_ints.h"
44#include "inc/hw_memmap.h"
45#include "inc/hw_types.h"
61 , interrupt(interrupt)
70 MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0);
74 MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN1);
81 uint32_t ftq = config_nmranet_can_bitrate() * 16;
84 HASSERT(cm3_cpu_clock_hz % ftq == 0);
101 tCANBitClkParms clk_params = {
102 .ui32SyncPropPhase1Seg = 11,
105 .ui32QuantumPrescaler = cm3_cpu_clock_hz / ftq
107 MAP_CANBitTimingSet(
base, &clk_params);
108 MAP_CANIntEnable(
base, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS);
110 tCANMsgObject can_message;
111 can_message.ui32MsgID = 0;
112 can_message.ui32MsgIDMask = 0;
113 can_message.ui32Flags = MSG_OBJ_RX_INT_ENABLE | MSG_OBJ_USE_ID_FILTER;
114 can_message.ui32MsgLen = 8;
115 MAP_CANMessageSet(
base, 1, &can_message, MSG_OBJ_TYPE_RX);
135 MAP_CANBitRateSet(
base, cm3_cpu_clock_hz, config_nmranet_can_bitrate());
139 MAP_IntPrioritySet(
interrupt, configKERNEL_INTERRUPT_PRIORITY);
151 MAP_CANDisable(
base);
160 struct can_frame *can_frame;
165 tCANMsgObject can_message;
166 can_message.ui32MsgID = can_frame->can_id;
167 can_message.ui32MsgIDMask = 0;
168 can_message.ui32Flags = MSG_OBJ_TX_INT_ENABLE;
169 if (can_frame->can_eff)
171 can_message.ui32Flags |= MSG_OBJ_EXTENDED_ID;
173 if (can_frame->can_rtr)
175 can_message.ui32Flags |= MSG_OBJ_REMOTE_FRAME;
177 can_message.ui32MsgLen = can_frame->can_dlc;
179 can_message.pui8MsgData = can_frame->data;
181 MAP_CANMessageSet(
base, 2, &can_message, MSG_OBJ_TYPE_TX);
196 uint32_t status = MAP_CANIntStatus(
base, CAN_INT_STS_CAUSE);
200 if (status == CAN_INT_INTID_STATUS)
202 bool cancel_queue =
false;
204 status = MAP_CANStatusGet(
base, CAN_STS_CONTROL);
206 if (status & CAN_STATUS_BUS_OFF)
217 if (status & CAN_STATUS_EWARN)
222 if (status & CAN_STATUS_EPASS)
228 if (status & CAN_STATUS_LEC_STUFF)
232 if (status & CAN_STATUS_LEC_FORM)
236 if (status & CAN_STATUS_LEC_ACK)
240 if (status & CAN_STATUS_LEC_CRC)
253 else if (status == 1)
258 struct can_frame *can_frame;
262 tCANMsgObject can_message;
263 can_message.pui8MsgData = can_frame->data;
265 MAP_CANMessageGet(
base, 1, &can_message, 1 );
267 can_frame->can_id = can_message.ui32MsgID;
268 can_frame->can_rtr = (can_message.ui32Flags & MSG_OBJ_REMOTE_FRAME) ? 1 : 0;
269 can_frame->can_eff = (can_message.ui32Flags & MSG_OBJ_EXTENDED_ID) ? 1 : 0;
270 can_frame->can_err = 0;
271 can_frame->can_dlc = can_message.ui32MsgLen;
273 ++numReceivedPackets_;
289 tCANMsgObject can_message;
290 can_message.pui8MsgData = can_frame->data;
292 MAP_CANMessageGet(
base, 1, &can_message, 1 );
295 else if (status == 2)
298 MAP_CANIntClear(
base, 2);
303 ++numTransmittedPackets_;
315 struct can_frame *can_frame;
320 tCANMsgObject can_message;
321 can_message.ui32MsgID = can_frame->can_id;
322 can_message.ui32MsgIDMask = 0;
323 can_message.ui32Flags = MSG_OBJ_TX_INT_ENABLE;
324 if (can_frame->can_eff)
326 can_message.ui32Flags |= MSG_OBJ_EXTENDED_ID;
328 if (can_frame->can_rtr)
330 can_message.ui32Flags |= MSG_OBJ_REMOTE_FRAME;
332 can_message.ui32MsgLen = can_frame->can_dlc;
334 can_message.pui8MsgData = can_frame->data;
336 MAP_CANMessageSet(
base, 2, &can_message, MSG_OBJ_TYPE_TX);
344 os_isr_exit_yield_test(woken);
static CC32xxUart * instances[2]
Instance pointers help us get context from the interrupt handler(s)
void can0_interrupt_handler(void)
This is the interrupt handler for the can0 device.
static TivaCan * instances[2]
Instance pointers help us get context from the interrupt handler(s)
void can1_interrupt_handler(void)
This is the interrupt handler for the can1 device.
Base class for a CAN device for the Arduino environment.
unsigned int overrunCount
overrun count
unsigned int softErrorCount
soft error count
DeviceBuffer< struct can_frame > * txBuf
transmit buffer
unsigned int busOffCount
bus-off count
DeviceBuffer< struct can_frame > * rxBuf
receive buffer
void flush()
flush all the data out of the buffer and reset the buffer.
size_t advance(size_t items)
Add a number of items to the buffer by advancing the writeIndex.
void signal_condition()
Signal the wakeup condition.
size_t consume(size_t items)
Remove a number of items from the buffer by advancing the readIndex.
void signal_condition_from_isr()
Signal the wakeup condition from an ISR context.
size_t data_write_pointer(T **buf)
Get a reference to the current location in the buffer for write.
size_t data_read_pointer(T **buf)
Get a reference to the current location in the buffer for read.
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.
Specialization of CAN driver for Tiva CAN.
int ioctl(File *file, unsigned long int key, unsigned long data) override
Request an ioctl transaction.
unsigned long interrupt
interrupt of this device
void interrupt_handler()
handle an interrupt.
uint8_t canState
current state of the CAN-bus.
unsigned long base
base address of this device
void enable() override
function to enable device
bool txPending
transmission currently pending
void tx_msg() override
function to try and transmit a message
TivaCan()
Default constructor.
void disable() override
function to disable device
#define CAN_STATE_BUS_OFF
CAN bus off.
#define CAN_STATE_ACTIVE
CAN bus active.
#define SIOCGCANSTATE
Read the CAN state.
uint32_t can_state_t
CAN state type.
#define CAN_STATE_STOPPED
CAN bus stopped.
#define CAN_STATE_BUS_PASSIVE
CAN bus error passive.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.