rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions
can_hw.h File Reference

Detailed Description

Date
Dec 11, 2013
Author
Andrey Belomutskiy, (c) 2012-2020

Definition in file can_hw.h.

Functions

void initCan ()
 
void setCanType (int type)
 
void setCanVss (int type)
 
void stopCanPins ()
 
void startCanPins ()
 
bool getIsCanEnabled (void)
 

Function Documentation

◆ getIsCanEnabled()

bool getIsCanEnabled ( void  )

Definition at line 295 of file can_hw.cpp.

295 {
296 return isCanEnabled;
297}
static bool isCanEnabled
Definition can_hw.cpp:25

◆ initCan()

void initCan ( )

Definition at line 207 of file can_hw.cpp.

207 {
208 addConsoleAction("caninfo", canInfo);
209
210 isCanEnabled = false;
211
212 // No CAN features enabled, nothing more to do.
214 return;
215 }
216
217 // Determine physical CAN peripherals based on selected pins
218 auto device1 = getCanDevice(0);
219 auto device2 = getCanDevice(1);
220#if (EFI_CAN_BUS_COUNT >= 3)
221 auto device3 = getCanDevice(2);
222#endif
223
224 // If all devices are null, a firmware error was already thrown by detectCanDevice, but we shouldn't continue
225 if (!device1 && !device2) {
226#if (EFI_CAN_BUS_COUNT >= 3)
227 if (!device3)
228#endif
229 return;
230 }
231
232 // Devices can't be the same!
233 if (((device1 == device2) && device1) ||
234#if (EFI_CAN_BUS_COUNT >= 3)
235 ((device2 == device3) && device2) ||
236 ((device3 == device1) && device3) ||
237#endif
238 0) {
239 criticalError("CAN pins must be set to different devices");
240 return;
241 }
242
243 // Initialize peripherals
244 if (device1) {
245 // Config based on baud rate
246 // Pointer to this local canConfig is stored inside CANDriver
247 // even it is used only during canStart this is wierd
248 CANConfig canConfig;
249 memcpy(&canConfig, findCanConfig(engineConfiguration->canBaudRate), sizeof(canConfig));
251 canStart(device1, &canConfig);
252
253 // Plumb CAN devices to tx system
254 CanTxMessage::setDevice(0, device1);
255 }
256
257 if (device2) {
258 CANConfig canConfig;
259 memcpy(&canConfig, findCanConfig(engineConfiguration->can2BaudRate), sizeof(canConfig));
261 canStart(device2, &canConfig);
262
263 // Plumb CAN devices to tx system
264 CanTxMessage::setDevice(1, device2);
265 }
266
267#if (EFI_CAN_BUS_COUNT >= 3)
268 if (device3) {
269 CANConfig canConfig;
270 memcpy(&canConfig, findCanConfig(engineConfiguration->can3BaudRate), sizeof(canConfig));
272 canStart(device3, &canConfig);
273
274 // Plumb CAN devices to tx system
275 CanTxMessage::setDevice(2, device3);
276 }
277#endif
278
279 // fire up threads, as necessary
281 canWrite.start();
282 }
283
285 canRead1.start(device1);
286 canRead2.start(device2);
287#if (EFI_CAN_BUS_COUNT >= 3)
288 canRead3.start(device3);
289#endif
290 }
291
292 isCanEnabled = true;
293}
static void applyListenOnly(CANConfig *canConfig, bool isListenOnly)
Definition can_hw.cpp:193
static void canInfo()
Definition can_hw.cpp:106
static CCM_OPTIONAL CanRead canRead1(0)
static CANDriver * getCanDevice(size_t index)
Definition can_hw.cpp:89
static CCM_OPTIONAL CanRead canRead3(2)
static CCM_OPTIONAL CanRead canRead2(1)
const CANConfig * findCanConfig(can_baudrate_e rate)
Definition can_hw.cpp:36
static void setDevice(size_t idx, CANDriver *device)
void addConsoleAction(const char *token, Void callback)
Register console action without parameters.
static constexpr engine_configuration_s * engineConfiguration

Referenced by initHardware().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setCanType()

void setCanType ( int  type)

Definition at line 136 of file can_hw.cpp.

Here is the call graph for this function:

◆ setCanVss()

void setCanVss ( int  type)

◆ startCanPins()

void startCanPins ( )

Definition at line 153 of file can_hw.cpp.

153 {
154 // nothing to do if we aren't enabled...
155 if (!isCanEnabled) {
156 return;
157 }
158
159 // Validate pins
162 // todo: smarter online change of settings, kill isCanEnabled with fire
163 return;
164 }
166 return;
167 }
168
171 // todo: smarter online change of settings, kill isCanEnabled with fire
172 return;
173 }
175 return;
176 }
177
178#if EFI_PROD_CODE
179 efiSetPadModeIfConfigurationChanged("CAN TX", canTxPin, PAL_MODE_ALTERNATE(EFI_CAN_TX_AF));
180 efiSetPadModeIfConfigurationChanged("CAN RX", canRxPin, PAL_MODE_ALTERNATE(EFI_CAN_RX_AF));
181
182 efiSetPadModeIfConfigurationChanged("CAN2 TX", can2TxPin, PAL_MODE_ALTERNATE(EFI_CAN_TX_AF));
183 efiSetPadModeIfConfigurationChanged("CAN2 RX", can2RxPin, PAL_MODE_ALTERNATE(EFI_CAN_RX_AF));
184
185#if (EFI_CAN_BUS_COUNT >= 3)
186 efiSetPadModeIfConfigurationChanged("CAN3 TX", can3TxPin, PAL_MODE_ALTERNATE(EFI_CAN3_TX_AF));
187 efiSetPadModeIfConfigurationChanged("CAN3 RX", can3RxPin, PAL_MODE_ALTERNATE(EFI_CAN3_RX_AF));
188#endif // EFI_CAN_BUS_COUNT >= 3
189#endif // EFI_PROD_CODE
190}
bool isValidCanRxPin(brain_pin_e pin)
Definition at32_can.cpp:89
bool isValidCanTxPin(brain_pin_e pin)
Definition at32_can.cpp:85
void firmwareError(ObdCode code, const char *fmt,...)
@ CUSTOM_OBD_70
const char * hwPortname(brain_pin_e brainPin)
bool isBrainPinValid(brain_pin_e brainPin)

Referenced by startHardware().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stopCanPins()

void stopCanPins ( )

Definition at line 141 of file can_hw.cpp.

141 {
142 efiSetPadUnusedIfConfigurationChanged(canTxPin);
143 efiSetPadUnusedIfConfigurationChanged(canRxPin);
144 efiSetPadUnusedIfConfigurationChanged(can2TxPin);
145 efiSetPadUnusedIfConfigurationChanged(can2RxPin);
146#if (EFI_CAN_BUS_COUNT >= 3)
147 efiSetPadUnusedIfConfigurationChanged(can3TxPin);
148 efiSetPadUnusedIfConfigurationChanged(can3RxPin);
149#endif
150}

Referenced by applyNewHardwareSettings().

Here is the caller graph for this function:

Go to the source code of this file.