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

298 {
299 return isCanEnabled;
300}
static bool isCanEnabled
Definition can_hw.cpp:25

◆ initCan()

void initCan ( )

Definition at line 210 of file can_hw.cpp.

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

Here is the call graph for this function:

◆ setCanVss()

void setCanVss ( int  type)

◆ startCanPins()

void startCanPins ( )

Definition at line 156 of file can_hw.cpp.

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

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

Referenced by applyNewHardwareSettings().

Here is the caller graph for this function:

Go to the source code of this file.