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 296 of file can_hw.cpp.

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

◆ initCan()

void initCan ( )

Definition at line 208 of file can_hw.cpp.

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

Here is the call graph for this function:

◆ setCanVss()

void setCanVss ( int  type)

◆ startCanPins()

void startCanPins ( )

Definition at line 154 of file can_hw.cpp.

154 {
155 // nothing to do if we aren't enabled...
156 if (!isCanEnabled) {
157 return;
158 }
159
160 // Validate pins
163 // todo: smarter online change of settings, kill isCanEnabled with fire
164 return;
165 }
167 return;
168 }
169
172 // todo: smarter online change of settings, kill isCanEnabled with fire
173 return;
174 }
176 return;
177 }
178
179#if EFI_PROD_CODE
180 efiSetPadModeIfConfigurationChanged("CAN TX", canTxPin, PAL_MODE_ALTERNATE(EFI_CAN_TX_AF));
181 efiSetPadModeIfConfigurationChanged("CAN RX", canRxPin, PAL_MODE_ALTERNATE(EFI_CAN_RX_AF));
182
183 efiSetPadModeIfConfigurationChanged("CAN2 TX", can2TxPin, PAL_MODE_ALTERNATE(EFI_CAN_TX_AF));
184 efiSetPadModeIfConfigurationChanged("CAN2 RX", can2RxPin, PAL_MODE_ALTERNATE(EFI_CAN_RX_AF));
185
186#if (EFI_CAN_BUS_COUNT >= 3)
187 efiSetPadModeIfConfigurationChanged("CAN3 TX", can3TxPin, PAL_MODE_ALTERNATE(EFI_CAN3_TX_AF));
188 efiSetPadModeIfConfigurationChanged("CAN3 RX", can3RxPin, PAL_MODE_ALTERNATE(EFI_CAN3_RX_AF));
189#endif // EFI_CAN_BUS_COUNT >= 3
190#endif // EFI_PROD_CODE
191}
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 142 of file can_hw.cpp.

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

Referenced by applyNewHardwareSettings().

Here is the caller graph for this function:

Go to the source code of this file.