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 59 of file openblt_can.cpp.

59 {
60 // init pins
61 palSetPadMode(OPENBLT_CAN_TX_PORT, OPENBLT_CAN_TX_PIN, PAL_MODE_ALTERNATE(EFI_CAN_TX_AF));
62 palSetPadMode(OPENBLT_CAN_RX_PORT, OPENBLT_CAN_RX_PIN, PAL_MODE_ALTERNATE(EFI_CAN_RX_AF));
63
64 auto cfg = findCanConfig(B500KBPS);
65 canStart(&OPENBLT_CAND, cfg);
66}
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 114 of file openblt_can.cpp.

115{
116 constexpr blt_int32u rxMsgId = BOOT_COM_CAN_RX_MSG_ID;
117 CANRxFrame frame;
118
119 if (MSG_OK != canReceiveTimeout(&OPENBLT_CAND, CAN_ANY_MAILBOX, &frame, TIME_IMMEDIATE)) {
120 // no message was waiting
121 return BLT_FALSE;
122 }
123
124 // Check that the ID type matches this frame (std vs ext)
125 constexpr bool configuredAsExt = (rxMsgId & 0x80000000) != 0;
126 if (configuredAsExt != frame.IDE) {
127 // Wrong frame type
128 goto wrong;
129 }
130
131 // Check that the frame's ID matches
132 if (frame.IDE) {
133 if (frame.EID != (rxMsgId & ~0x80000000)) {
134 // Wrong ID
135 goto wrong;
136 }
137 } else {
138 if (frame.SID != rxMsgId) {
139 // Wrong ID
140 goto wrong;
141 }
142 }
143
144 // Copy data and length out
145 *len = frame.DLC;
146 memcpy(data, frame.data8, frame.DLC);
147
148 return BLT_TRUE;
149
150wrong:
151
152#ifdef BOOTLOADER_CAN_LISTENER
153 boardCanListener(&frame);
154#endif
155
156 return BLT_FALSE;
157}
void boardCanListener(CANRxFrame *frame)
Receives a communication interface packet if one is present.
uint32_t SID
Standard identifier.
Definition can_mocks.h:48
uint8_t IDE
Identifier type.
Definition can_mocks.h:44
uint32_t EID
Extended identifier.
Definition can_mocks.h:51
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 76 of file openblt_can.cpp.

77{
78 blt_int32u txMsgId = BOOT_COM_CAN_TX_MSG_ID;
79 CANTxFrame frame;
80
81 if ((txMsgId & 0x80000000) == 0)
82 {
83 /* set the 11-bit CAN identifier. */
84 frame.SID = txMsgId;
85 frame.IDE = CAN_IDE_STD;
86 }
87 else
88 {
89 txMsgId &= ~0x80000000;
90 /* set the 29-bit CAN identifier. */
91 frame.EID = txMsgId;
92 frame.IDE = CAN_IDE_EXT;
93 }
94
95 // Copy data/DLC
96 frame.DLC = len;
97 memcpy(frame.data8, data, len);
98
99 canTransmitTimeout(&OPENBLT_CAND, CAN_ANY_MAILBOX, &frame, TIME_MS2I(100));
100}
uint8_t data8[8]
Frame data.
Definition can_mocks.h:27
uint32_t SID
Standard identifier.
Definition can_mocks.h:20
uint8_t DLC
Data length.
Definition can_mocks.h:14
uint32_t EID
Extended identifier.
Definition can_mocks.h:23
uint8_t IDE
Identifier type.
Definition can_mocks.h:16

◆ 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.