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

223 {
224 return isCanEnabled;
225}
static bool isCanEnabled
Definition can_hw.cpp:25

◆ initCan()

void initCan ( )

Definition at line 166 of file can_hw.cpp.

166 {
167 addConsoleAction("caninfo", canInfo);
168
169 isCanEnabled = false;
170
171 // No CAN features enabled, nothing more to do.
173 return;
174 }
175
176 // Determine physical CAN peripherals based on selected pins
179
180 // If both devices are null, a firmware error was already thrown by detectCanDevice, but we shouldn't continue
181 if (!device1 && !device2) {
182 return;
183 }
184
185 // Devices can't be the same!
186 if (device1 == device2) {
187 criticalError("CAN pins must be set to different devices");
188 return;
189 }
190
191 // Initialize peripherals
192 if (device1) {
193 // Config based on baud rate
194 CANConfig canConfig;
195 memcpy(&canConfig, findCanConfig(engineConfiguration->canBaudRate), sizeof(canConfig));
197 canStart(device1, &canConfig);
198 }
199
200 if (device2) {
201 CANConfig canConfig;
202 memcpy(&canConfig, findCanConfig(engineConfiguration->can2BaudRate), sizeof(canConfig));
204 canStart(device2, &canConfig);
205 }
206
207 // Plumb CAN devices to tx system
208 CanTxMessage::setDevice(device1, device2);
209
210 // fire up threads, as necessary
212 canWrite.start();
213 }
214
216 canRead1.start(device1);
217 canRead2.start(device2);
218 }
219
220 isCanEnabled = true;
221}
CANDriver * detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx)
Definition at32_can.cpp:93
static void applyListenOnly(CANConfig *canConfig, bool isListenOnly)
Definition can_hw.cpp:156
static void canInfo()
Definition can_hw.cpp:85
static CCM_OPTIONAL CanRead canRead1(0)
static CCM_OPTIONAL CanRead canRead2(1)
const CANConfig * findCanConfig(can_baudrate_e rate)
Definition can_hw.cpp:36
static void setDevice(CANDriver *device1, CANDriver *device2)
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 109 of file can_hw.cpp.

Here is the call graph for this function:

◆ setCanVss()

void setCanVss ( int  type)

◆ startCanPins()

void startCanPins ( )

Definition at line 122 of file can_hw.cpp.

122 {
123 // nothing to do if we aren't enabled...
124 if (!isCanEnabled) {
125 return;
126 }
127
128 // Validate pins
131 // todo: smarter online change of settings, kill isCanEnabled with fire
132 return;
133 }
135 return;
136 }
137
140 // todo: smarter online change of settings, kill isCanEnabled with fire
141 return;
142 }
144 return;
145 }
146
147#if EFI_PROD_CODE
148 efiSetPadModeIfConfigurationChanged("CAN TX", canTxPin, PAL_MODE_ALTERNATE(EFI_CAN_TX_AF));
149 efiSetPadModeIfConfigurationChanged("CAN RX", canRxPin, PAL_MODE_ALTERNATE(EFI_CAN_RX_AF));
150
151 efiSetPadModeIfConfigurationChanged("CAN2 TX", can2TxPin, PAL_MODE_ALTERNATE(EFI_CAN_TX_AF));
152 efiSetPadModeIfConfigurationChanged("CAN2 RX", can2RxPin, PAL_MODE_ALTERNATE(EFI_CAN_RX_AF));
153#endif // EFI_PROD_CODE
154}
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 114 of file can_hw.cpp.

114 {
115 efiSetPadUnusedIfConfigurationChanged(canTxPin);
116 efiSetPadUnusedIfConfigurationChanged(canRxPin);
117 efiSetPadUnusedIfConfigurationChanged(can2TxPin);
118 efiSetPadUnusedIfConfigurationChanged(can2RxPin);
119}

Referenced by applyNewHardwareSettings().

Here is the caller graph for this function:

Go to the source code of this file.