65 struct can_frame *can_frame)
67 uint32_t
id = message->msgSID.SID;
68 if (message->msgEID.IDE)
70 SET_CAN_FRAME_EFF(*can_frame);
72 id |= message->msgEID.EID;
73 SET_CAN_FRAME_ID_EFF(*can_frame,
id);
77 CLR_CAN_FRAME_EFF(*can_frame);
78 SET_CAN_FRAME_ID(*can_frame,
id);
80 if (message->msgEID.RTR)
82 SET_CAN_FRAME_RTR(*can_frame);
86 CLR_CAN_FRAME_RTR(*can_frame);
88 CLR_CAN_FRAME_ERR(*can_frame);
90 can_frame->can_dlc = message->msgEID.DLC;
91 memcpy(can_frame->data, message->data, can_frame->can_dlc);
100 CANTxMessageBuffer *message)
102 message->messageWord[0] = 0;
103 message->messageWord[1] = 0;
104 if (IS_CAN_FRAME_EFF(*can_frame))
106 uint32_t
id = GET_CAN_FRAME_ID_EFF(*can_frame);
107 message->msgEID.IDE = 1;
108 message->msgSID.SID =
id >> 18;
109 message->msgEID.EID =
id & ((1 << 19) - 1);
116 message->msgSID.SID = GET_CAN_FRAME_ID(*can_frame);
117 message->msgEID.IDE = 0;
119 if (IS_CAN_FRAME_RTR(*can_frame))
121 message->msgEID.RTR = 1;
125 message->msgEID.RTR = 0;
127 message->msgEID.DLC = can_frame->can_dlc;
128 memcpy(message->data, can_frame->data, can_frame->can_dlc);
133 struct can_frame *can_frame =
static_cast<struct can_frame *
>(buf);
138 while (count >=
sizeof(
struct can_frame))
148 taskENTER_CRITICAL();
149 CANRxMessageBuffer *message =
150 (CANRxMessageBuffer *)CANGetRxMessage(
hw_, CAN_CHANNEL1);
153 CANUpdateChannel(
hw_, CAN_CHANNEL1);
166 count -=
sizeof(
struct can_frame);
167 result +=
sizeof(
struct can_frame);
175 if (result || (flags & O_NONBLOCK))
191 CANEnableChannelEvent(
hw_, CAN_CHANNEL1, CAN_RX_CHANNEL_NOT_EMPTY,
193 DeviceBufferBase::block_until_condition(file,
true);
198 CANEnableChannelEvent(
hw_, CAN_CHANNEL1, CAN_RX_CHANNEL_NOT_EMPTY,
201 if (!result && (file->
flags & O_NONBLOCK))
212 const struct can_frame *can_frame =
213 static_cast<const struct can_frame *
>(buf);
218 while (count >=
sizeof(
struct can_frame))
220 taskENTER_CRITICAL();
221 CANTxMessageBuffer *message =
222 CANGetTxMessageBuffer(
hw_, CAN_CHANNEL0);
229 CANUpdateChannel(
hw_, CAN_CHANNEL0);
240 CANFlushTxChannel(
hw_, CAN_CHANNEL0);
242 count -=
sizeof(
struct can_frame);
243 result +=
sizeof(
struct can_frame);
250 if (flags & O_NONBLOCK)
259 CANEnableChannelEvent(
hw_, CAN_CHANNEL0, CAN_TX_CHANNEL_NOT_FULL,
261 DeviceBufferBase::block_until_condition(file,
false);
266 CANEnableChannelEvent(
hw_, CAN_CHANNEL0, CAN_TX_CHANNEL_NOT_FULL,
269 if (!result && (file->
flags & O_NONBLOCK))
322 CANEnableModule(
hw_, TRUE);
327 CANSetOperatingMode(
hw_, CAN_CONFIGURATION);
328 while (CANGetOperatingMode(
hw_) != CAN_CONFIGURATION)
338 CAN_BIT_CONFIG canBitConfig;
339 canBitConfig.phaseSeg2Tq = CAN_BIT_3TQ;
340 canBitConfig.phaseSeg1Tq = CAN_BIT_3TQ;
341 canBitConfig.propagationSegTq = CAN_BIT_3TQ;
342 canBitConfig.phaseSeg2TimeSelect = TRUE;
343 canBitConfig.sample3Time = TRUE;
344 canBitConfig.syncJumpWidth = CAN_BIT_2TQ;
346 CANSetSpeed(
hw_, &canBitConfig, configCPU_CLOCK_HZ,
347 config_nmranet_can_bitrate());
353 CANAssignMemoryBuffer(
355 16 * (config_can_tx_buffer_size() + config_can_rx_buffer_size()));
364 CANConfigureChannelForTx(
hw_, CAN_CHANNEL0, 1, CAN_TX_RTR_DISABLED,
365 CAN_LOW_MEDIUM_PRIORITY);
366 CANConfigureChannelForRx(
hw_, CAN_CHANNEL1, config_can_rx_buffer_size(),
367 CAN_RX_FULL_RECEIVE);
370 CANConfigureFilterMask(
hw_, CAN_FILTER_MASK0, 0, CAN_EID, CAN_FILTER_MASK_ANY_TYPE);
371 CANEnableFilter(
hw_, CAN_FILTER0, FALSE);
372 while(CANIsFilterDisabled(
hw_, CAN_FILTER0) == FALSE);
373 CANConfigureFilter(
hw_, CAN_FILTER0, 0, CAN_EID);
374 CANLinkFilterToChannel(
hw_, CAN_FILTER0, CAN_FILTER_MASK0, CAN_CHANNEL1);
375 CANEnableFilter(
hw_, CAN_FILTER0, TRUE);
377 CANEnableModuleEvent(
hw_, CAN_RX_EVENT, TRUE);
378 CANEnableModuleEvent(
hw_, CAN_TX_EVENT, TRUE);
384 INTSetVectorPriority(
can_vector(), INT_PRIORITY_LEVEL_2);
385 INTSetVectorSubPriority(
can_vector(), INT_SUB_PRIORITY_LEVEL_0);
386 INTEnable(
can_int(), INT_ENABLED);
390 CANSetOperatingMode(
hw_, CAN_NORMAL_OPERATION);
391 while (CANGetOperatingMode(
hw_) != CAN_NORMAL_OPERATION)