rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
mpu_util.h
Go to the documentation of this file.
1#pragma once
2
3#include "rusefi_types.h"
4
5#include "port_mpu_util.h"
6#include "mpu_watchdog.h"
7
8#ifdef __cplusplus
9
10// Base MCU
11void baseMCUInit();
13#if EFI_USE_OPENBLT
14void jump_to_openblt();
15#endif
16void causeHardFault();
17
18// If mcu can erase/write part of its internal memory without stalling CPU
20
21#if defined(STM32F4)
22bool isStm32F42x();
23#endif // STM32F4
24
25// ADC
26#if HAL_USE_ADC
27
29brain_pin_e getAdcChannelBrainPin(const char *msg, adc_channel_e hwChannel);
30bool adcIsMuxedInput(adc_channel_e hwChannel);
32int getAdcInternalChannel(ADC_TypeDef *adc, adc_channel_e hwChannel);
33adc_channel_e getHwChannelForAdcInput(ADC_TypeDef *adc, size_t hwIndex);
34
35// deprecated - migrate to 'getAdcChannelBrainPin'
36ioportid_t getAdcChannelPort(const char *msg, adc_channel_e hwChannel);
37// deprecated - migrate to 'getAdcChannelBrainPin'
38int getAdcChannelPin(adc_channel_e hwChannel);
39
40void portInitAdc();
41float getMcuTemperature();
42float getMcuVrefVoltage();
43// Convert all slow ADC inputs. Returns true if the conversion succeeded, false if a failure occured.
44bool readSlowAnalogInputs(adcsample_t* convertedSamples);
45#endif
46
47// CAN bus
48#if HAL_USE_CAN
51CANDriver* detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx);
52void canHwInfo(CANDriver* cand);
53#endif // HAL_USE_CAN
54
55// Serial
56#if EFI_AUX_SERIAL
59#endif //EFI_AUX_SERIAL
60
61// SPI
62#if HAL_USE_SPI
63void initSpiModule(SPIDriver *driver, brain_pin_e sck, brain_pin_e miso,
64 brain_pin_e mosi,
65 int sckMode,
66 int mosiMode,
67 int misoMode);
68
69void initSpiCsNoOccupy(SPIConfig *spiConfig, brain_pin_e csPin);
70void initSpiCs(SPIConfig *spiConfig, brain_pin_e csPin);
72int spiGetBaseClock(SPIDriver *spip);
73int spiCalcClockDiv(SPIDriver *spip, SPIConfig *spiConfig, unsigned int clk);
74#endif // HAL_USE_SPI
75
76#if HAL_USE_ICU
77bool getIcuParams(brain_pin_e hwPin, iomode_t *af_ptr, ICUDriver ** icu_ptr, icuchannel_t *channel_ptr, uint32_t *clock_ptr);
78#endif
79
80// MMC Card
81#if HAL_USE_MMC_SPI
82// HS = max 50MHz SPI
83extern SPIConfig mmc_hs_spicfg;
84// LS = max 25MHz SPI
85extern SPIConfig mmc_ls_spicfg;
86#endif
87
88// Hardware PWM
90 static hardware_pwm* tryInitPin(const char* msg, brain_pin_e pin, float frequencyHz, float duty);
91 virtual void setDuty(float duty) = 0;
92};
93
94// Brownout Reset
99
100BOR_Level_t BOR_Get(void);
102
103// Reset Cause
104typedef enum {
106 Reset_Cause_IWatchdog, // Independent hardware watchdog (we use it)
107 Reset_Cause_WWatchdog, // Window watchdog
108 Reset_Cause_Soft_Reset, // NVIC_SystemReset or by debugger
109 Reset_Cause_NRST_Pin, // Reset from NRST pin
110 Reset_Cause_POR, // POR/PDR reset
111 Reset_Cause_Illegal_Mode, // Reset after illegal Stop, Standby or Shutdown mode entry
112 Reset_Cause_BOR, // BOR reset
113 Reset_Cause_Firewall, // Firewall reset
114 Reset_Cause_Option_Byte, // Option byte load reset
116
118const char *getMCUResetCause(Reset_Cause_t cause);
119
120#ifdef AT32F4XX
121int at32GetMcuType(uint32_t id, const char **pn, const char **package, uint32_t *flashSize);
122int at32GetRamSizeKb(void);
123#endif
124
125extern "C"
126{
127#endif /* __cplusplus */
128
129// these need to be declared with C linkage - they're called from C and asm files
130void DebugMonitorVector(void);
131void UsageFaultVector(void);
132void BusFaultVector(void);
133void HardFaultVector(void);
134
135#ifdef __cplusplus
136}
137#endif /* __cplusplus */
138
139// search:openblt_version
140// ascii 'BL03' in reverse LBS byte order
141#define BLT_CURRENT_VERSION 0x33304C42
142#define BLT_BIN_VERSION_ADDR ((uint32_t)0x08000024U) /*! 3rd reserved DWORD in vector table search:openblt_version */
143
144#if EFI_USE_OPENBLT
145#define getOpenBltVersion() (((uint32_t *)BLT_BIN_VERSION_ADDR)[0])
146#endif
uint16_t adc
Definition adc_inputs.h:103
BOR_Level_t
uint16_t adcsample_t
ADC sample data type.
GPIO_TypeDef * ioportid_t
Port Identifier.
uint32_t iomode_t
Digital I/O modes.
Definition hal_pal_lld.h:83
static Lps25 device
Definition init_baro.cpp:4
bool isValidSerialRxPin(brain_pin_e pin)
bool isStm32F42x()
Reset_Cause_t getMCUResetCause()
CANDriver * detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx)
Definition at32_can.cpp:93
int spiGetBaseClock(SPIDriver *spip)
Definition at32_spi.cpp:254
void HardFaultVector(void)
Definition mpu_util.cpp:62
void BusFaultVector(void)
Definition mpu_util.cpp:56
BOR_Level_t BOR_Get(void)
brain_pin_e getAdcChannelBrainPin(const char *msg, adc_channel_e hwChannel)
bool readSlowAnalogInputs(adcsample_t *convertedSamples)
Definition mpu_util.cpp:274
int getAdcInternalChannel(ADC_TypeDef *adc, adc_channel_e hwChannel)
BOR_Result_t BOR_Set(BOR_Level_t BORValue)
SPIConfig mmc_hs_spicfg
Definition at32_spi.cpp:273
void jump_to_openblt()
int getAdcChannelPin(adc_channel_e hwChannel)
bool isValidCanRxPin(brain_pin_e pin)
Definition at32_can.cpp:89
bool getIcuParams(brain_pin_e hwPin, iomode_t *af_ptr, ICUDriver **icu_ptr, icuchannel_t *channel_ptr, uint32_t *clock_ptr)
void DebugMonitorVector(void)
Definition mpu_util.cpp:44
void initSpiModule(SPIDriver *driver, brain_pin_e sck, brain_pin_e miso, brain_pin_e mosi, int sckMode, int mosiMode, int misoMode)
Definition at32_spi.cpp:206
void baseMCUInit()
bool mcuCanFlashWhileRunning()
Definition mpu_util.cpp:10
SPIConfig mmc_ls_spicfg
Definition at32_spi.cpp:288
bool adcIsMuxedInput(adc_channel_e hwChannel)
int at32GetMcuType(uint32_t id, const char **pn, const char **package, uint32_t *flashSize)
void initSpiCsNoOccupy(SPIConfig *spiConfig, brain_pin_e csPin)
Definition at32_spi.cpp:234
void causeHardFault()
void UsageFaultVector(void)
Definition mpu_util.cpp:50
BOR_Result_t
Definition mpu_util.h:95
@ BOR_Result_Ok
Definition mpu_util.h:96
@ BOR_Result_Error
Definition mpu_util.h:97
void jump_to_bootloader()
Reset_Cause_t
Definition mpu_util.h:104
@ Reset_Cause_WWatchdog
Definition mpu_util.h:107
@ Reset_Cause_Firewall
Definition mpu_util.h:113
@ Reset_Cause_Soft_Reset
Definition mpu_util.h:108
@ Reset_Cause_Illegal_Mode
Definition mpu_util.h:111
@ Reset_Cause_NRST_Pin
Definition mpu_util.h:109
@ Reset_Cause_Unknown
Definition mpu_util.h:105
@ Reset_Cause_POR
Definition mpu_util.h:110
@ Reset_Cause_IWatchdog
Definition mpu_util.h:106
@ Reset_Cause_BOR
Definition mpu_util.h:112
@ Reset_Cause_Option_Byte
Definition mpu_util.h:114
void turnOnSpi(spi_device_e device)
Definition at32_spi.cpp:151
adc_channel_e getHwChannelForAdcInput(ADC_TypeDef *adc, size_t hwIndex)
adc_channel_e getAdcChannel(brain_pin_e pin)
float getMcuVrefVoltage()
Definition mpu_util.cpp:269
bool isValidSerialTxPin(brain_pin_e pin)
bool isValidCanTxPin(brain_pin_e pin)
Definition at32_can.cpp:85
adc_channel_e adcMuxedGetParent(adc_channel_e hwChannel)
int at32GetRamSizeKb(void)
ioportid_t getAdcChannelPort(const char *msg, adc_channel_e hwChannel)
void initSpiCs(SPIConfig *spiConfig, brain_pin_e csPin)
Definition at32_spi.cpp:241
float getMcuTemperature()
Definition mpu_util.cpp:264
void portInitAdc()
Definition mpu_util.cpp:256
void canHwInfo(CANDriver *cand)
Definition at32_can.cpp:129
int spiCalcClockDiv(SPIDriver *spip, SPIConfig *spiConfig, unsigned int clk)
Definition at32_spi.cpp:260
Hardware Independent Watchdog (IWDG) high-level API.
spi_device_e
static uint16_t flashSize()
Definition mpu_util.cpp:21
brain_pin_e pin
Definition stm32_adc.cpp:15
static hardware_pwm * tryInitPin(const char *msg, brain_pin_e pin, float frequencyHz, float duty)
Definition mpu_util.cpp:257
virtual void setDuty(float duty)=0
static float duty