rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions
openblt_can.cpp File Reference

Functions

const CANConfig * findCanConfig (can_baudrate_e rate)
 
void CanInit (void)
 Initializes the CAN controller and synchronizes it to the CAN bus.
 
void CanTransmitPacket (blt_int8u *data, blt_int8u len)
 Transmits a packet formatted for the communication interface.
 
void boardCanListener (CANRxFrame *frame)
 Receives a communication interface packet if one is present.
 
blt_bool CanReceivePacket (blt_int8u *data, blt_int8u *len)
 

Function Documentation

◆ boardCanListener()

void boardCanListener ( CANRxFrame frame)
extern

Receives a communication interface packet if one is present.

Parameters
dataPointer to byte array where the data is to be stored.
lenPointer where the length of the packet is to be stored.
Returns
BLT_TRUE is a packet was received, BLT_FALSE otherwise.

Referenced by CanReceivePacket().

Here is the caller graph for this function:

◆ CanInit()

void CanInit ( void  )

Initializes the CAN controller and synchronizes it to the CAN bus.

Returns
none.

Definition at line 68 of file openblt_can.cpp.

68 {
69 // init pins
70 palSetPadMode(OPENBLT_CAN_TX_PORT, OPENBLT_CAN_TX_PIN, PAL_MODE_ALTERNATE(EFI_CAN_TX_AF));
71 palSetPadMode(OPENBLT_CAN_RX_PORT, OPENBLT_CAN_RX_PIN, PAL_MODE_ALTERNATE(EFI_CAN_RX_AF));
72
73 auto cfg = findCanConfig(B500KBPS);
74 canStart(&OPENBLT_CAND, cfg);
75}
const CANConfig * findCanConfig(can_baudrate_e rate)
Definition can_hw.cpp:36
Here is the call graph for this function:

◆ CanReceivePacket()

blt_bool CanReceivePacket ( blt_int8u data,
blt_int8u len 
)

Definition at line 123 of file openblt_can.cpp.

124{
125 constexpr blt_int32u rxMsgId = BOOT_COM_CAN_RX_MSG_ID;
126 CANRxFrame frame;
127
128 if (MSG_OK != canReceiveTimeout(&OPENBLT_CAND, CAN_ANY_MAILBOX, &frame, TIME_IMMEDIATE)) {
129 // no message was waiting
130 return BLT_FALSE;
131 }
132
133 // Check that the ID type matches this frame (std vs ext)
134 constexpr bool configuredAsExt = (rxMsgId & 0x80000000) != 0;
135 if (configuredAsExt != CAN_ISX(frame)) {
136 // Wrong frame type
137 goto wrong;
138 }
139
140 // Check that the frame's ID matches
141 if (CAN_ISX(frame)) {
142 if (CAN_EID(frame) != (rxMsgId & ~0x80000000)) {
143 // Wrong ID
144 goto wrong;
145 }
146 } else {
147 if (CAN_SID(frame) != rxMsgId) {
148 // Wrong ID
149 goto wrong;
150 }
151 }
152
153 // Copy data and length out
154 *len = frame.DLC;
155 memcpy(data, frame.data8, frame.DLC);
156
157 return BLT_TRUE;
158
159wrong:
160
161#ifdef BOOTLOADER_CAN_LISTENER
162 boardCanListener(&frame);
163#endif
164
165 return BLT_FALSE;
166}
void boardCanListener(CANRxFrame *frame)
Receives a communication interface packet if one is present.
uint8_t data8[8]
Frame data.
Definition can_mocks.h:55
uint8_t DLC
Data length.
Definition can_mocks.h:42
unsigned int blt_int32u
Definition types.h:53
Here is the call graph for this function:

◆ CanTransmitPacket()

void CanTransmitPacket ( blt_int8u data,
blt_int8u  len 
)

Transmits a packet formatted for the communication interface.

Parameters
dataPointer to byte array with data that it to be transmitted.
lenNumber of bytes that are to be transmitted.
Returns
none.

Definition at line 85 of file openblt_can.cpp.

86{
87 blt_int32u txMsgId = BOOT_COM_CAN_TX_MSG_ID;
88 CANTxFrame frame = {};
89
90 if ((txMsgId & 0x80000000) == 0)
91 {
92 /* set the 11-bit CAN identifier. */
93 CAN_SID(frame) = txMsgId;
94 CAN_ISX(frame) = CAN_IDE_STD;
95 }
96 else
97 {
98 txMsgId &= ~0x80000000;
99 /* set the 29-bit CAN identifier. */
100 CAN_EID(frame) = txMsgId;
101 CAN_ISX(frame) = CAN_IDE_EXT;
102 }
103
104 // Copy data/DLC
105 frame.DLC = len;
106 memcpy(frame.data8, data, len);
107
108 canTransmitTimeout(&OPENBLT_CAND, CAN_ANY_MAILBOX, &frame, TIME_MS2I(100));
109}
uint8_t data8[8]
Frame data.
Definition can_mocks.h:27
uint8_t DLC
Data length.
Definition can_mocks.h:14

◆ findCanConfig()

static const CANConfig * findCanConfig ( can_baudrate_e  rate)
extern

Definition at line 36 of file can_hw.cpp.

37{
38 return &canConfig_dummy;
39}
static const CANConfig canConfig_dummy
Definition can_hw.cpp:34

Referenced by CanInit(), and initCan().

Here is the caller graph for this function:

Go to the source code of this file.