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 _unhandled_exception (void)
 
void DebugMonitorVector (void)
 
void UsageFaultVector (void)
 
void BusFaultVector (void)
 
void HardFaultVector (void)
 
void startWatchdog (int)
 
void tryResetWatchdog ()
 
void setWatchdogResetPeriod (int)
 
void baseMCUInit ()
 
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 36 of file mpu_util.cpp.

36 {
37/*lint -restore*/
38
39 chDbgPanic3("_unhandled_exception", __FILE__, __LINE__);
40 while (true) {
41 }
42}
void chDbgPanic3(const char *, const char *, int)
Here is the call graph for this function:

◆ baseMCUInit()

void baseMCUInit ( )

Definition at line 33 of file mpu_util.cpp.

33 {
34}

◆ BOR_Get()

BOR_Level_t BOR_Get ( void  )

Definition at line 183 of file mpu_util.cpp.

183 {
184 return BOR_Level_None;
185}
@ BOR_Level_None

◆ BOR_Set()

BOR_Result_t BOR_Set ( BOR_Level_t  BORValue)

Definition at line 187 of file mpu_util.cpp.

187 {
188 return BOR_Result_Ok;
189}
@ BOR_Result_Ok
Definition mpu_util.h:96

◆ BusFaultVector()

void BusFaultVector ( void  )

Definition at line 56 of file mpu_util.cpp.

56 {
57 chDbgPanic3("BusFaultVector", __FILE__, __LINE__);
58 while (TRUE) {
59 }
60}
Here is the call graph for this function:

◆ canHwInfo()

void canHwInfo ( CANDriver *  cand)

Definition at line 225 of file mpu_util.cpp.

226{
227 /* TODO: */
228 (void)cand;
229}

◆ DebugMonitorVector()

void DebugMonitorVector ( void  )

Definition at line 44 of file mpu_util.cpp.

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

◆ detectCanDevice()

CANDriver * detectCanDevice ( brain_pin_e  pinRx,
brain_pin_e  pinTx 
)

Definition at line 217 of file mpu_util.cpp.

217 {
218 if (isValidCan1RxPin(pinRx) && isValidCan1TxPin(pinTx))
219 return &CAND1;
220 if (isValidCan2RxPin(pinRx) && isValidCan2TxPin(pinTx))
221 return &CAND2;
222 return NULL;
223}
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 279 of file mpu_util.cpp.

279 {
281 return invalidAdcToken;
282 }
283
284 // TODO: implement me!
285 return invalidAdcToken;
286}
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

◆ flashSectorSize()

size_t flashSectorSize ( flashsector_t  sector)

Get the size of sector.

Returns
sector size in bytes.

Definition at line 237 of file mpu_util.cpp.

237 {
238 // sectors 0..11 are the 1st memory bank (1Mb), and 12..23 are the 2nd (the same structure).
239 if (sector <= 3 || (sector >= 12 && sector <= 15))
240 return 16 * 1024;
241 else if (sector == 4 || sector == 16)
242 return 64 * 1024;
243 else if ((sector >= 5 && sector <= 11) || (sector >= 17 && sector <= 23))
244 return 128 * 1024;
245 return 0;
246}

Referenced by flashSectorSize().

Here is the caller graph for this function:

◆ getFastAdc()

adcsample_t getFastAdc ( AdcToken  token)

Definition at line 288 of file mpu_util.cpp.

288 {
289 if (token == invalidAdcToken) {
290 return 0;
291 }
292
293 // TODO: implement me!
294 return 0;
295}

◆ getFlashAddrFirstCopy()

uintptr_t getFlashAddrFirstCopy ( void  )

Definition at line 248 of file mpu_util.cpp.

248 {
249 return FLASH_ADDR;
250}

Referenced by getFlashAddrSecondCopy().

Here is the caller graph for this function:

◆ getFlashAddrSecondCopy()

uintptr_t getFlashAddrSecondCopy ( void  )

Definition at line 252 of file mpu_util.cpp.

252 {
253 return FLASH_ADDR_SECOND_COPY;
254}

◆ getMCUResetCause() [1/2]

Reset_Cause_t getMCUResetCause ( )

Definition at line 297 of file mpu_util.cpp.

297 {
298 return Reset_Cause_Unknown;
299}
@ Reset_Cause_Unknown
Definition mpu_util.h:105

◆ getMCUResetCause() [2/2]

const char * getMCUResetCause ( Reset_Cause_t  cause)

Definition at line 301 of file mpu_util.cpp.

301 {
302 return "Unknown";
303}

◆ getMcuTemperature()

float getMcuTemperature ( )

Definition at line 264 of file mpu_util.cpp.

264 {
265 // TODO: implement me!
266 return 0;
267}

Referenced by adcOnchipSlowUpdate().

Here is the caller graph for this function:

◆ getMcuVrefVoltage()

float getMcuVrefVoltage ( )

Definition at line 269 of file mpu_util.cpp.

269 {
270 // TODO: implement me!
272}
static constexpr engine_configuration_s * engineConfiguration

Referenced by adcOnchipSlowUpdate().

Here is the caller graph for this function:

◆ getSpiAf()

static int getSpiAf ( SPIDriver *  driver)
static

Definition at line 71 of file mpu_util.cpp.

71 {
72#if STM32_SPI_USE_SPI1
73 if (driver == &SPID1) {
74 return EFI_SPI1_AF;
75 }
76#endif
77#if STM32_SPI_USE_SPI2
78 if (driver == &SPID2) {
79 return EFI_SPI2_AF;
80 }
81#endif
82#if STM32_SPI_USE_SPI3
83 if (driver == &SPID3) {
84 return EFI_SPI3_AF;
85 }
86#endif
87 return -1;
88}
SPIDriver SPID1
SPI0 driver identifier.
Definition hal_spi_lld.c:42
SPIDriver SPID2
SPI1 driver identifier.
Definition hal_spi_lld.c:47

Referenced by initSpiModule().

Here is the caller graph for this function:

◆ HardFaultVector()

void HardFaultVector ( void  )

Definition at line 62 of file mpu_util.cpp.

62 {
63 while (TRUE) {
64 }
65}

◆ initSpiCs()

void initSpiCs ( SPIConfig *  spiConfig,
brain_pin_e  csPin 
)

Definition at line 155 of file mpu_util.cpp.

155 {
156 /* TODO: why this is here? */
157#ifdef _CHIBIOS_RT_CONF_VER_6_1_
158 spiConfig->end_cb = nullptr;
159#else
160 spiConfig->data_cb = nullptr;
161 spiConfig->error_cb = nullptr;
162#endif
163
164 initSpiCsNoOccupy(spiConfig, csPin);
165 // CS is controlled inside 'hal_spi_lld' driver using both software and hardware methods.
166 //efiSetPadMode("chip select", csPin, PAL_MODE_OUTPUT_OPENDRAIN);
167}
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 148 of file mpu_util.cpp.

148 {
149 ioportid_t port = getHwPort("spi", csPin);
150 ioportmask_t pin = getHwPin("spi", csPin);
151 spiConfig->ssport = port;
152 spiConfig->sspad = pin;
153}
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

Referenced by initSpiCs().

Here is the call graph for this function:
Here is the caller 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 130 of file mpu_util.cpp.

134 {
135
136 /**
137 * See https://github.com/rusefi/rusefi/pull/664/
138 *
139 * Info on the silicon defect can be found in this document, section 2.5.2:
140 * 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
141 */
142 efiSetPadMode("SPI CLK ", sck, PAL_MODE_ALTERNATE(getSpiAf(driver)) /*| sckMode | PAL_STM32_OSPEED_HIGHEST*/);
143
144 efiSetPadMode("SPI MOSI", mosi, PAL_MODE_ALTERNATE(getSpiAf(driver)) /*| mosiMode | PAL_STM32_OSPEED_HIGHEST*/);
145 efiSetPadMode("SPI MISO ", miso, PAL_MODE_ALTERNATE(getSpiAf(driver)) /*| misoMode | PAL_STM32_OSPEED_HIGHEST*/);
146}
void efiSetPadMode(const char *msg, brain_pin_e brainPin, iomode_t mode)
static int getSpiAf(SPIDriver *driver)
Definition mpu_util.cpp:71

Referenced by turnOnSpi().

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

◆ isValidCan1RxPin()

static bool isValidCan1RxPin ( brain_pin_e  pin)
static

Definition at line 193 of file mpu_util.cpp.

193 {
194 return pin == Gpio::A11 || pin == Gpio::B8 || pin == Gpio::D0;
195}

Referenced by detectCanDevice(), and isValidCanRxPin().

Here is the caller graph for this function:

◆ isValidCan1TxPin()

static bool isValidCan1TxPin ( brain_pin_e  pin)
static

Definition at line 197 of file mpu_util.cpp.

197 {
198 return pin == Gpio::A12 || pin == Gpio::B9 || pin == Gpio::D1;
199}

Referenced by detectCanDevice(), and isValidCanTxPin().

Here is the caller graph for this function:

◆ isValidCan2RxPin()

static bool isValidCan2RxPin ( brain_pin_e  pin)
static

Definition at line 201 of file mpu_util.cpp.

201 {
202 return pin == Gpio::B5 || pin == Gpio::B12;
203}

Referenced by detectCanDevice(), and isValidCanRxPin().

Here is the caller graph for this function:

◆ isValidCan2TxPin()

static bool isValidCan2TxPin ( brain_pin_e  pin)
static

Definition at line 205 of file mpu_util.cpp.

205 {
206 return pin == Gpio::B6 || pin == Gpio::B13;
207}

Referenced by detectCanDevice(), and isValidCanTxPin().

Here is the caller graph for this function:

◆ isValidCanRxPin()

bool isValidCanRxPin ( brain_pin_e  pin)

Definition at line 213 of file mpu_util.cpp.

213 {
215}
Here is the call graph for this function:

◆ isValidCanTxPin()

bool isValidCanTxPin ( brain_pin_e  pin)

Definition at line 209 of file mpu_util.cpp.

209 {
211}
Here is the call graph for this function:

◆ mcuCanFlashWhileRunning()

bool mcuCanFlashWhileRunning ( )

Definition at line 233 of file mpu_util.cpp.

233 {
234 return false;
235}

◆ portInitAdc()

void portInitAdc ( )

Definition at line 256 of file mpu_util.cpp.

256 {
257 // Init slow ADC
258 adcStart(&ADCD1, NULL);
259
260 // Init fast ADC (MAP sensor)
261 adcStart(&ADCD2, NULL);
262}
ADCDriver ADCD2
ADC2 driver identifier.
Definition hal_adc_lld.c:49
ADCDriver ADCD1
ADC1 driver identifier.
Definition hal_adc_lld.c:44

Referenced by initAdcInputs().

Here is the caller graph for this function:

◆ readSlowAnalogInputs()

bool readSlowAnalogInputs ( adcsample_t convertedSamples)

Definition at line 274 of file mpu_util.cpp.

274 {
275 // TODO: implement me!
276 return true;
277}

Referenced by adcOnchipSlowUpdate().

Here is the caller graph for this function:

◆ setWatchdogResetPeriod()

void setWatchdogResetPeriod ( int  resetMs)

Definition at line 30 of file mpu_util.cpp.

30 {
31}

◆ spiCalcClockDiv()

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

Definition at line 175 of file mpu_util.cpp.

176{
177 // TODO: implement
178 return -1;
179}

◆ spiGetBaseClock()

int spiGetBaseClock ( SPIDriver *  spip)

Definition at line 169 of file mpu_util.cpp.

170{
171 // TODO: implement
172 return 0;
173}

◆ startWatchdog()

void startWatchdog ( int  timeoutMs)

Definition at line 24 of file mpu_util.cpp.

24 {
25}

◆ tryResetWatchdog()

void tryResetWatchdog ( )

Definition at line 27 of file mpu_util.cpp.

27 {
28}

◆ turnOnSpi()

void turnOnSpi ( spi_device_e  device)

Definition at line 90 of file mpu_util.cpp.

90 {
92 return; // already initialized
94 if (device == SPI_DEVICE_1) {
95// todo: introduce a nice structure with all fields for same SPI
96#if STM32_SPI_USE_SPI1
97// scheduleMsg(&logging, "Turning on SPI1 pins");
104#endif /* STM32_SPI_USE_SPI1 */
105 }
106 if (device == SPI_DEVICE_2) {
107#if STM32_SPI_USE_SPI2
108// scheduleMsg(&logging, "Turning on SPI2 pins");
115#endif /* STM32_SPI_USE_SPI2 */
116 }
117 if (device == SPI_DEVICE_3) {
118#if STM32_SPI_USE_SPI3
119// scheduleMsg(&logging, "Turning on SPI3 pins");
126#endif /* STM32_SPI_USE_SPI3 */
127 }
128}
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 50 of file mpu_util.cpp.

50 {
51 chDbgPanic3("UsageFaultVector", __FILE__, __LINE__);
52 while (TRUE)
53 ;
54}
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 69 of file mpu_util.cpp.

69{ true, false, false, false, false, false, false };

Referenced by turnOnSpi().

Go to the source code of this file.