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

Detailed Description

Date
Jul 27, 2014
Author
Andrey Belomutskiy, (c) 2012-2020
andreika prome.nosp@m.theu.nosp@m.s.pcb.nosp@m.@gma.nosp@m.il.co.nosp@m.m

Definition in file mpu_util.cpp.

Functions

void startWatchdog (int)
 
void tryResetWatchdog ()
 
void setWatchdogResetPeriod (int)
 
void baseMCUInit ()
 
void _unhandled_exception (void)
 
void DebugMonitorVector (void)
 
void UsageFaultVector (void)
 
void BusFaultVector (void)
 
void HardFaultVector (void)
 
static int getSpiAf (SPIDriver *driver)
 
void turnOnSpi (spi_device_e device)
 
void initSpiModule (SPIDriver *driver, brain_pin_e sck, brain_pin_e miso, brain_pin_e mosi, int sckMode, int mosiMode, int misoMode)
 
void initSpiCsNoOccupy (SPIConfig *spiConfig, brain_pin_e csPin)
 
void initSpiCs (SPIConfig *spiConfig, brain_pin_e csPin)
 
int spiGetBaseClock (SPIDriver *)
 
int spiCalcClockDiv (SPIDriver *, SPIConfig *, unsigned int)
 
BOR_Level_t BOR_Get (void)
 
BOR_Result_t BOR_Set (BOR_Level_t BORValue)
 
static bool isValidCan1RxPin (brain_pin_e pin)
 
static bool isValidCan1TxPin (brain_pin_e pin)
 
static bool isValidCan2RxPin (brain_pin_e pin)
 
static bool isValidCan2TxPin (brain_pin_e pin)
 
bool isValidCanTxPin (brain_pin_e pin)
 
bool isValidCanRxPin (brain_pin_e pin)
 
CANDriver * detectCanDevice (brain_pin_e pinRx, brain_pin_e pinTx)
 
void canHwInfo (CANDriver *cand)
 
bool mcuCanFlashWhileRunning ()
 
size_t flashSectorSize (flashsector_t sector)
 Get the size of sector.
 
uintptr_t getFlashAddrFirstCopy ()
 
uintptr_t getFlashAddrSecondCopy ()
 
void portInitAdc ()
 
float getMcuTemperature ()
 
float getMcuVrefVoltage ()
 
bool readSlowAnalogInputs (adcsample_t *convertedSamples)
 
AdcToken enableFastAdcChannel (const char *, adc_channel_e channel)
 
adcsample_t getFastAdc (AdcToken token)
 
Reset_Cause_t getMCUResetCause ()
 
const chargetMCUResetCause (Reset_Cause_t)
 

Variables

bool isSpiInitialized [SPI_TOTAL_COUNT+1] = { true, false, false, false, false, false, false }
 

Function Documentation

◆ _unhandled_exception()

void _unhandled_exception ( void  )

Definition at line 29 of file mpu_util.cpp.

29 {
30/*lint -restore*/
31
32 chDbgPanic3("_unhandled_exception", __FILE__, __LINE__);
33 while (true) {
34 }
35}
void chDbgPanic3(const char *, const char *, int)
Here is the call graph for this function:

◆ baseMCUInit()

void baseMCUInit ( )

Definition at line 26 of file mpu_util.cpp.

26 {
27}

◆ BOR_Get()

BOR_Level_t BOR_Get ( void  )

Definition at line 176 of file mpu_util.cpp.

176 {
177 return BOR_Level_None;
178}
@ BOR_Level_None

◆ BOR_Set()

BOR_Result_t BOR_Set ( BOR_Level_t  BORValue)

Definition at line 180 of file mpu_util.cpp.

180 {
181 return BOR_Result_Ok;
182}
@ BOR_Result_Ok
Definition mpu_util.h:96

◆ BusFaultVector()

void BusFaultVector ( void  )

Definition at line 49 of file mpu_util.cpp.

49 {
50 chDbgPanic3("BusFaultVector", __FILE__, __LINE__);
51 while (TRUE) {
52 }
53}
Here is the call graph for this function:

◆ canHwInfo()

void canHwInfo ( CANDriver *  cand)

Definition at line 218 of file mpu_util.cpp.

219{
220 /* TODO: */
221 (void)cand;
222}

◆ DebugMonitorVector()

void DebugMonitorVector ( void  )

Definition at line 37 of file mpu_util.cpp.

37 {
38 chDbgPanic3("DebugMonitorVector", __FILE__, __LINE__);
39 while (TRUE)
40 ;
41}
Here is the call graph for this function:

◆ detectCanDevice()

CANDriver * detectCanDevice ( brain_pin_e  pinRx,
brain_pin_e  pinTx 
)

Definition at line 210 of file mpu_util.cpp.

210 {
211 if (isValidCan1RxPin(pinRx) && isValidCan1TxPin(pinTx))
212 return &CAND1;
213 if (isValidCan2RxPin(pinRx) && isValidCan2TxPin(pinTx))
214 return &CAND2;
215 return NULL;
216}
static bool isValidCan2RxPin(brain_pin_e pin)
Definition mpu_util.cpp:201
static bool isValidCan1RxPin(brain_pin_e pin)
Definition mpu_util.cpp:193
static bool isValidCan2TxPin(brain_pin_e pin)
Definition mpu_util.cpp:205
static bool isValidCan1TxPin(brain_pin_e pin)
Definition mpu_util.cpp:197
Here is the call graph for this function:

◆ enableFastAdcChannel()

AdcToken enableFastAdcChannel ( const char msg,
adc_channel_e  channel 
)

Definition at line 285 of file mpu_util.cpp.

285 {
287 return invalidAdcToken;
288 }
289
290 // TODO: implement me!
291 return invalidAdcToken;
292}
static constexpr AdcToken invalidAdcToken
Definition adc_inputs.h:110
bool isAdcChannelValid(adc_channel_e hwChannel)
Definition adc_inputs.h:23
uint16_t channel
Definition adc_inputs.h:104
Here is the call graph for this function:

◆ flashSectorSize()

size_t flashSectorSize ( flashsector_t  sector)

Get the size of sector.

Returns
sector size in bytes.

Definition at line 230 of file mpu_util.cpp.

230 {
231 // sectors 0..11 are the 1st memory bank (1Mb), and 12..23 are the 2nd (the same structure).
232 if (sector <= 3 || (sector >= 12 && sector <= 15))
233 return 16 * 1024;
234 else if (sector == 4 || sector == 16)
235 return 64 * 1024;
236 else if ((sector >= 5 && sector <= 11) || (sector >= 17 && sector <= 23))
237 return 128 * 1024;
238 return 0;
239}

◆ getFastAdc()

adcsample_t getFastAdc ( AdcToken  token)

Definition at line 294 of file mpu_util.cpp.

294 {
295 if (token == invalidAdcToken) {
296 return 0;
297 }
298
299 // TODO: implement me!
300 return 0;
301}

◆ getFlashAddrFirstCopy()

uintptr_t getFlashAddrFirstCopy ( void  )

Flex Non Volatile Memory is faster than flash It also has smaller pages so it takes less time to erase

There is no remote access to FlexNVM meaning that we cannot erase settings externally

Definition at line 249 of file mpu_util.cpp.

249 {
250 return 0x10000000;
251}

◆ getFlashAddrSecondCopy()

uintptr_t getFlashAddrSecondCopy ( void  )

Definition at line 253 of file mpu_util.cpp.

253 {
254 return 0x10008000;
255}

◆ getMCUResetCause() [1/2]

Reset_Cause_t getMCUResetCause ( )

Definition at line 303 of file mpu_util.cpp.

303 {
304 return Reset_Cause_Unknown;
305}
@ Reset_Cause_Unknown
Definition mpu_util.h:105

◆ getMCUResetCause() [2/2]

const char * getMCUResetCause ( Reset_Cause_t  cause)

Definition at line 307 of file mpu_util.cpp.

307 {
308 return "Unknown";
309}

◆ getMcuTemperature()

float getMcuTemperature ( )

Definition at line 270 of file mpu_util.cpp.

270 {
271 // TODO: implement me!
272 return 0;
273}

◆ getMcuVrefVoltage()

float getMcuVrefVoltage ( )

Definition at line 275 of file mpu_util.cpp.

275 {
276 // TODO: implement me!
278}
static constexpr engine_configuration_s * engineConfiguration

◆ getSpiAf()

static int getSpiAf ( SPIDriver *  driver)
static

Definition at line 64 of file mpu_util.cpp.

64 {
65#if STM32_SPI_USE_SPI1
66 if (driver == &SPID1) {
67 return EFI_SPI1_AF;
68 }
69#endif
70#if STM32_SPI_USE_SPI2
71 if (driver == &SPID2) {
72 return EFI_SPI2_AF;
73 }
74#endif
75#if STM32_SPI_USE_SPI3
76 if (driver == &SPID3) {
77 return EFI_SPI3_AF;
78 }
79#endif
80 return -1;
81}
SPIDriver SPID1
SPI0 driver identifier.
Definition hal_spi_lld.c:42
SPIDriver SPID2
SPI1 driver identifier.
Definition hal_spi_lld.c:47

◆ HardFaultVector()

void HardFaultVector ( void  )

Definition at line 55 of file mpu_util.cpp.

55 {
56 while (TRUE) {
57 }
58}

◆ initSpiCs()

void initSpiCs ( SPIConfig *  spiConfig,
brain_pin_e  csPin 
)

Definition at line 148 of file mpu_util.cpp.

148 {
149 /* TODO: why this is here? */
150#ifdef _CHIBIOS_RT_CONF_VER_6_1_
151 spiConfig->end_cb = nullptr;
152#else
153 spiConfig->data_cb = nullptr;
154 spiConfig->error_cb = nullptr;
155#endif
156
157 initSpiCsNoOccupy(spiConfig, csPin);
158 // CS is controlled inside 'hal_spi_lld' driver using both software and hardware methods.
159 //efiSetPadMode("chip select", csPin, PAL_MODE_OUTPUT_OPENDRAIN);
160}
void initSpiCsNoOccupy(SPIConfig *spiConfig, brain_pin_e csPin)
Definition mpu_util.cpp:148
Here is the call graph for this function:

◆ initSpiCsNoOccupy()

void initSpiCsNoOccupy ( SPIConfig *  spiConfig,
brain_pin_e  csPin 
)

Definition at line 141 of file mpu_util.cpp.

141 {
142 ioportid_t port = getHwPort("spi", csPin);
143 ioportmask_t pin = getHwPin("spi", csPin);
144 spiConfig->ssport = port;
145 spiConfig->sspad = pin;
146}
ioportid_t getHwPort(const char *msg, brain_pin_e brainPin)
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin)
uint32_t ioportmask_t
Digital I/O port sized unsigned type.
Definition hal_pal_lld.h:78
GPIO_TypeDef * ioportid_t
Port Identifier.
brain_pin_e pin
Definition stm32_adc.cpp:15
Here is the call graph for this function:

◆ initSpiModule()

void initSpiModule ( SPIDriver *  driver,
brain_pin_e  sck,
brain_pin_e  miso,
brain_pin_e  mosi,
int  sckMode,
int  mosiMode,
int  misoMode 
)

See https://github.com/rusefi/rusefi/pull/664/

Info on the silicon defect can be found in this document, section 2.5.2: https://www.st.com/content/ccc/resource/technical/document/errata_sheet/0a/98/58/84/86/b6/47/a2/DM00037591.pdf/files/DM00037591.pdf/jcr:content/translations/en.DM00037591.pdf

Definition at line 123 of file mpu_util.cpp.

127 {
128
129 /**
130 * See https://github.com/rusefi/rusefi/pull/664/
131 *
132 * Info on the silicon defect can be found in this document, section 2.5.2:
133 * https://www.st.com/content/ccc/resource/technical/document/errata_sheet/0a/98/58/84/86/b6/47/a2/DM00037591.pdf/files/DM00037591.pdf/jcr:content/translations/en.DM00037591.pdf
134 */
135 efiSetPadMode("SPI CLK ", sck, PAL_MODE_ALTERNATE(getSpiAf(driver)) | sckMode | PAL_STM32_OSPEED_HIGHEST);
136
137 efiSetPadMode("SPI MOSI", mosi, PAL_MODE_ALTERNATE(getSpiAf(driver)) | mosiMode | PAL_STM32_OSPEED_HIGHEST);
138 efiSetPadMode("SPI MISO", miso, PAL_MODE_ALTERNATE(getSpiAf(driver)) | misoMode | PAL_STM32_OSPEED_HIGHEST);
139}
void efiSetPadMode(const char *msg, brain_pin_e brainPin, iomode_t mode)
static int getSpiAf(SPIDriver *driver)
Definition mpu_util.cpp:71
Here is the call graph for this function:

◆ isValidCan1RxPin()

static bool isValidCan1RxPin ( brain_pin_e  pin)
static

Definition at line 186 of file mpu_util.cpp.

186 {
187 return pin == Gpio::A11 || pin == Gpio::B8 || pin == Gpio::D0;
188}

◆ isValidCan1TxPin()

static bool isValidCan1TxPin ( brain_pin_e  pin)
static

Definition at line 190 of file mpu_util.cpp.

190 {
191 return pin == Gpio::A12 || pin == Gpio::B9 || pin == Gpio::D1;
192}

◆ isValidCan2RxPin()

static bool isValidCan2RxPin ( brain_pin_e  pin)
static

Definition at line 194 of file mpu_util.cpp.

194 {
195 return pin == Gpio::B5 || pin == Gpio::B12;
196}

◆ isValidCan2TxPin()

static bool isValidCan2TxPin ( brain_pin_e  pin)
static

Definition at line 198 of file mpu_util.cpp.

198 {
199 return pin == Gpio::B6 || pin == Gpio::B13;
200}

◆ isValidCanRxPin()

bool isValidCanRxPin ( brain_pin_e  pin)

Definition at line 206 of file mpu_util.cpp.

206 {
208}
Here is the call graph for this function:

◆ isValidCanTxPin()

bool isValidCanTxPin ( brain_pin_e  pin)

Definition at line 202 of file mpu_util.cpp.

202 {
204}
Here is the call graph for this function:

◆ mcuCanFlashWhileRunning()

bool mcuCanFlashWhileRunning ( )

Definition at line 226 of file mpu_util.cpp.

226 {
227 return false;
228}

◆ portInitAdc()

void portInitAdc ( )

Definition at line 262 of file mpu_util.cpp.

262 {
263 // Init slow ADC
264 adcStart(&ADCD1, NULL);
265
266 // Init fast ADC (MAP sensor)
267 adcStart(&ADCD2, NULL);
268}
ADCDriver ADCD2
ADC2 driver identifier.
Definition hal_adc_lld.c:49
ADCDriver ADCD1
ADC1 driver identifier.
Definition hal_adc_lld.c:44

◆ readSlowAnalogInputs()

bool readSlowAnalogInputs ( adcsample_t convertedSamples)

Definition at line 280 of file mpu_util.cpp.

280 {
281 // TODO: implement me!
282 return true;
283}

◆ setWatchdogResetPeriod()

void setWatchdogResetPeriod ( int  resetMs)

Definition at line 23 of file mpu_util.cpp.

23 {
24}

◆ spiCalcClockDiv()

int spiCalcClockDiv ( SPIDriver *  spip,
SPIConfig *  spiConfig,
unsigned int  clk 
)

Definition at line 168 of file mpu_util.cpp.

169{
170 // TODO: implement
171 return -1;
172}

◆ spiGetBaseClock()

int spiGetBaseClock ( SPIDriver *  spip)

Definition at line 162 of file mpu_util.cpp.

163{
164 // TODO: implement
165 return 0;
166}

◆ startWatchdog()

void startWatchdog ( int  timeoutMs)

Definition at line 17 of file mpu_util.cpp.

17 {
18}

◆ tryResetWatchdog()

void tryResetWatchdog ( )

Definition at line 20 of file mpu_util.cpp.

20 {
21}

◆ turnOnSpi()

void turnOnSpi ( spi_device_e  device)

Definition at line 83 of file mpu_util.cpp.

83 {
85 return; // already initialized
87 if (device == SPI_DEVICE_1) {
88// todo: introduce a nice structure with all fields for same SPI
89#if STM32_SPI_USE_SPI1
90// scheduleMsg(&logging, "Turning on SPI1 pins");
97#endif /* STM32_SPI_USE_SPI1 */
98 }
99 if (device == SPI_DEVICE_2) {
100#if STM32_SPI_USE_SPI2
101// scheduleMsg(&logging, "Turning on SPI2 pins");
108#endif /* STM32_SPI_USE_SPI2 */
109 }
110 if (device == SPI_DEVICE_3) {
111#if STM32_SPI_USE_SPI3
112// scheduleMsg(&logging, "Turning on SPI3 pins");
119#endif /* STM32_SPI_USE_SPI3 */
120 }
121}
void initSpiModule(SPIDriver *driver, brain_pin_e sck, brain_pin_e miso, brain_pin_e mosi, int sckMode, int mosiMode, int misoMode)
Definition mpu_util.cpp:130
bool isSpiInitialized[SPI_TOTAL_COUNT+1]
Definition mpu_util.cpp:69
brain_pin_e getSckPin(spi_device_e device)
Definition hardware.cpp:126
brain_pin_e getMosiPin(spi_device_e device)
Definition hardware.cpp:106
brain_pin_e getMisoPin(spi_device_e device)
Definition hardware.cpp:86
static Lps25 device
Definition init_baro.cpp:4
Here is the call graph for this function:

◆ UsageFaultVector()

void UsageFaultVector ( void  )

Definition at line 43 of file mpu_util.cpp.

43 {
44 chDbgPanic3("UsageFaultVector", __FILE__, __LINE__);
45 while (TRUE)
46 ;
47}
Here is the call graph for this function:

Variable Documentation

◆ isSpiInitialized

bool isSpiInitialized[SPI_TOTAL_COUNT+1] = { true, false, false, false, false, false, false }

Definition at line 62 of file mpu_util.cpp.

62{ true, false, false, false, false, false, false };

Go to the source code of this file.