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

Detailed Description

CAN bus low level code.

todo: this file should be split into two - one for CAN transport level ONLY and another one with actual messages

See also
can_verbose.cpp for higher level logic
obd2.cpp for OBD-II messages via CAN
Date
Dec 11, 2013
Author
Andrey Belomutskiy, (c) 2012-2020

Definition in file can_hw.cpp.

Functions

const CANConfig * findCanConfig (can_baudrate_e rate)
 
static CCM_OPTIONAL CanRead canRead1 (0)
 
static CCM_OPTIONAL CanRead canRead2 (1)
 
static void canInfo ()
 
void setCanType (int type)
 
void stopCanPins ()
 
void startCanPins ()
 
static void applyListenOnly (CANConfig *canConfig, bool isListenOnly)
 
void initCan ()
 
bool getIsCanEnabled (void)
 

Variables

static bool isCanEnabled = false
 
static const CANConfig canConfig_dummy
 
static CanWrite canWrite CCM_OPTIONAL
 

Function Documentation

◆ applyListenOnly()

static void applyListenOnly ( CANConfig *  canConfig,
bool  isListenOnly 
)
static

Definition at line 156 of file can_hw.cpp.

156 {
157#if defined(STM32F4XX) || defined(STM32F7XX)
158 if (isListenOnly)
159 canConfig->btr += CAN_BTR_SILM;
160#else
161 if (isListenOnly)
162 criticalError("CAN:ListenOnly not implemented yet");
163#endif
164}

Referenced by initCan().

Here is the caller graph for this function:

◆ canInfo()

static void canInfo ( )
static

Definition at line 85 of file can_hw.cpp.

85 {
86 if (!isCanEnabled) {
87 efiPrintf("CAN is not enabled, please enable & restart");
88 return;
89 }
90
92 efiPrintf("CAN1 RX %s", hwPortname(engineConfiguration->canRxPin));
94
96 efiPrintf("CAN2 RX %s", hwPortname(engineConfiguration->can2RxPin));
98
99 efiPrintf("type=%d canReadEnabled=%s canWriteEnabled=%s period=%d", engineConfiguration->canNbcType,
102
103 efiPrintf("CAN rx_cnt=%d/tx_ok=%d/tx_not_ok=%d",
107}
CANDriver * detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx)
Definition at32_can.cpp:93
void canHwInfo(CANDriver *cand)
Definition at32_can.cpp:129
const char * getCan_baudrate_e(can_baudrate_e value)
static bool isCanEnabled
Definition can_hw.cpp:25
TunerStudioOutputChannels outputChannels
Definition engine.h:109
const char * boolToString(bool value)
Definition efilib.cpp:19
static EngineAccessor engine
Definition engine.h:413
static constexpr engine_configuration_s * engineConfiguration
const char * hwPortname(brain_pin_e brainPin)

Referenced by initCan(), and setCanType().

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

◆ canRead1()

static CCM_OPTIONAL CanRead canRead1 ( )
static

Referenced by initCan().

Here is the caller graph for this function:

◆ canRead2()

static CCM_OPTIONAL CanRead canRead2 ( )
static

Referenced by initCan().

Here is the caller graph for this function:

◆ findCanConfig()

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 initCan().

Here is the caller graph for this function:

◆ getIsCanEnabled()

bool getIsCanEnabled ( void  )

Definition at line 223 of file can_hw.cpp.

223 {
224 return isCanEnabled;
225}

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

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.

109 {
111 canInfo();
112}
can_nbc_e
Here is the call graph for this function:

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

Variable Documentation

◆ canConfig_dummy

const CANConfig canConfig_dummy
static

Definition at line 34 of file can_hw.cpp.

Referenced by findCanConfig().

◆ CCM_OPTIONAL

CanWrite canWrite CCM_OPTIONAL
static

Definition at line 83 of file can_hw.cpp.

◆ isCanEnabled

bool isCanEnabled = false
static

Definition at line 25 of file can_hw.cpp.

Referenced by canInfo(), getIsCanEnabled(), initCan(), and startCanPins().

Go to the source code of this file.