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

Detailed Description

I/O pin registry code.

This job of this class is to make sure that we are not using same hardware pin for two different purposes.

Date
Jan 15, 2013
Author
Andrey Belomutskiy, (c) 2012-2020

Definition in file pin_repository.cpp.

Functions

static size_t getBrainPinTotalNum ()
 
const char *& getBrainUsedPin (size_t index)
 
bool isBrainPinValid (brain_pin_e brainPin)
 
int brainPin_to_index (Gpio brainPin)
 
bool brain_pin_markUsed (Gpio brainPin, const char *msg)
 
void brain_pin_markUnused (brain_pin_e brainPin)
 
void pinDiag2string (char *buffer, size_t size, brain_pin_diag_e pin_diag)
 
static brain_pin_e index_to_brainPin (unsigned int i)
 
static void reportPins ()
 
 __attribute__ ((weak)) const char *getBoardSpecificPinName(brain_pin_e)
 
const charhwOnChipPhysicalPinName (ioportid_t hwPort, int hwPin)
 
const charhwPhysicalPinName (Gpio brainPin)
 
const charhwPortname (brain_pin_e brainPin)
 
void initPinRepository (void)
 
bool brain_pin_is_onchip (brain_pin_e brainPin)
 
bool brain_pin_is_ext (brain_pin_e brainPin)
 
bool gpio_pin_markUsed (ioportid_t port, ioportmask_t pin, const char *msg)
 
void gpio_pin_markUnused (ioportid_t port, ioportmask_t pin)
 
const chargetPinFunction (brain_input_pin_e brainPin)
 

Variables

PinRepository pinRepository CCM_OPTIONAL
 
static MemoryStream portNameStream
 
static char portNameBuffer [20]
 

Function Documentation

◆ __attribute__()

__attribute__ ( (weak)  ) const

Definition at line 195 of file pin_repository.cpp.

195 {
196 return nullptr;
197}

◆ brain_pin_is_ext()

bool brain_pin_is_ext ( brain_pin_e  brainPin)

Definition at line 270 of file pin_repository.cpp.

271{
272 if (brainPin > BRAIN_PIN_ONCHIP_LAST)
273 return true;
274
275 return false;
276}

Referenced by efiReadPin(), and startSimplePwm().

Here is the caller graph for this function:

◆ brain_pin_is_onchip()

bool brain_pin_is_onchip ( brain_pin_e  brainPin)

Definition at line 262 of file pin_repository.cpp.

263{
264 if ((brainPin < Gpio::A0) || (brainPin > BRAIN_PIN_ONCHIP_LAST))
265 return false;
266
267 return true;
268}

Referenced by directWritePad(), efiReadPin(), efiSetPadModeWithoutOwnershipAcquisition(), efiSetPadUnused(), OutputPin::getDiag(), getHwPin(), hwPhysicalPinName(), and OutputPin::initPin().

Here is the caller graph for this function:

◆ brain_pin_markUnused()

void brain_pin_markUnused ( brain_pin_e  brainPin)

See also brain_pin_markUsed()

Definition at line 83 of file pin_repository.cpp.

83 {
84#ifndef EFI_BOOTLOADER
85// efiPrintf("pin_markUnused: %s", hwPortname(brainPin));
86#endif
87 int index = brainPin_to_index(brainPin);
88 if (index < 0)
89 return;
90
91 getBrainUsedPin(index) = nullptr;
92}
int brainPin_to_index(Gpio brainPin)
const char *& getBrainUsedPin(size_t index)

Referenced by deInitAuxDigital(), efiExtiDisablePin(), efiSetPadUnused(), setEepromTestConfiguration(), and stopSwitchPins().

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

◆ brain_pin_markUsed()

bool brain_pin_markUsed ( Gpio  brainPin,
const char msg 
)

See also brain_pin_markUnused()

Returns
true if this pin was already used, false otherwise

Definition at line 53 of file pin_repository.cpp.

53 {
54#ifndef EFI_BOOTLOADER
55// efiPrintf("pin_markUsed: %s on %s", msg, hwPortname(brainPin));
56#endif
57
58 int index = brainPin_to_index(brainPin);
59 if (index < 0)
60 return true;
61
62 if (pinRepository.getBrainUsedPin(index) != nullptr) {
63 // hwPortname and share a buffer behind the scenes, even while they probably never use it for different
64 // values here let's have an explicit second buffer to make this more reliable
65 char physicalPinName[32];
66 strncpy(physicalPinName, hwPhysicalPinName(brainPin), sizeof(physicalPinName) - 1);
67 criticalError("Pin \"%s\" (%s) required by \"%s\" but is used by \"%s\"",
68 hwPortname(brainPin),
69 physicalPinName,
70 msg,
71 getBrainUsedPin(index));
72 return true;
73 }
74
75 getBrainUsedPin(index) = msg;
76 return false;
77}
PinRepository pinRepository
const char *& getBrainUsedPin(size_t idx)
const char * hwPhysicalPinName(Gpio brainPin)
const char * hwPortname(brain_pin_e brainPin)

Referenced by efiSetPadMode().

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

◆ brainPin_to_index()

int brainPin_to_index ( Gpio  brainPin)

Definition at line 36 of file pin_repository.cpp.

36 {
37 if (brainPin < Gpio::A0)
38 return -1;
39
40 size_t i = brainPin - Gpio::A0;
41
42 if (i >= getBrainPinTotalNum())
43 return -1;
44
45 return i;
46}
static size_t getBrainPinTotalNum()

Referenced by brain_pin_markUnused(), brain_pin_markUsed(), getPinFunction(), and setPin().

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

◆ getBrainPinTotalNum()

static size_t getBrainPinTotalNum ( )
static

Definition at line 16 of file pin_repository.cpp.

16 {
17 return BRAIN_PIN_TOTAL_PINS;
18}

Referenced by brainPin_to_index(), index_to_brainPin(), and reportPins().

Here is the caller graph for this function:

◆ getBrainUsedPin()

const char *& getBrainUsedPin ( size_t  index)

Definition at line 20 of file pin_repository.cpp.

20 {
21 return pinRepository.getBrainUsedPin(index);
22}

Referenced by brain_pin_markUnused(), brain_pin_markUsed(), getPinFunction(), gpio_pin_markUnused(), gpio_pin_markUsed(), and reportPins().

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

◆ getPinFunction()

const char * getPinFunction ( brain_input_pin_e  brainPin)

Definition at line 313 of file pin_repository.cpp.

313 {
314 int index;
315
316 index = brainPin_to_index(brainPin);
317 if (index < 0)
318 return NULL;
319
320 return getBrainUsedPin(index);
321}
Here is the call graph for this function:

◆ gpio_pin_markUnused()

void gpio_pin_markUnused ( ioportid_t  port,
ioportmask_t  pin 
)

Marks on-chip gpio port-pin as UNused. Works only for on-chip gpios To be replaced with brain_pin_markUnused later

Definition at line 307 of file pin_repository.cpp.

307 {
308 int index = getPortPinIndex(port, pin);
309
310 getBrainUsedPin(index) = nullptr;
311}
int getPortPinIndex(ioportid_t port, ioportmask_t pin)
brain_pin_e pin
Definition stm32_adc.cpp:15

Referenced by BitbangI2c::deinit().

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

◆ gpio_pin_markUsed()

bool gpio_pin_markUsed ( ioportid_t  port,
ioportmask_t  pin,
const char msg 
)

Marks on-chip gpio port-pin as used. Works only for on-chip gpios To be replaced with brain_pin_markUsed later

todo: the problem is that this warning happens before the console is even connected, so the warning is never displayed on the console and that's quite a problem!

Definition at line 283 of file pin_repository.cpp.

283 {
284 int index = getPortPinIndex(port, pin);
285#ifndef EFI_BOOTLOADER
286// efiPrintf("pin_markUsed: %s on %s", msg, hwOnChipPhysicalPinName(port, pin));
287#endif
288
289 if (getBrainUsedPin(index) != NULL) {
290 /**
291 * todo: the problem is that this warning happens before the console is even
292 * connected, so the warning is never displayed on the console and that's quite a problem!
293 */
294// warning(ObdCode::OBD_PCM_Processor_Fault, "%s%d req by %s used by %s", portname(port), pin, msg, getBrainUsedPin(index));
295 firmwareError(ObdCode::CUSTOM_ERR_PIN_ALREADY_USED_1, "%s%d req by %s used by %s", portname(port), (int)pin, msg, getBrainUsedPin(index));
296 return true;
297 }
298 getBrainUsedPin(index) = msg;
299 return false;
300}
const char * portname(ioportid_t GPIOx)
void firmwareError(ObdCode code, const char *fmt,...)
@ CUSTOM_ERR_PIN_ALREADY_USED_1

Referenced by hellen154hyundai_f7_boardInitHardware().

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

◆ hwOnChipPhysicalPinName()

const char * hwOnChipPhysicalPinName ( ioportid_t  hwPort,
int  hwPin 
)

Definition at line 199 of file pin_repository.cpp.

199 {
200 portNameStream.eos = 0; // reset
201 if (!hwPort) {
202 return "NONE";
203 }
204 chprintf((BaseSequentialStream *) &portNameStream, "%s%d", portname(hwPort), hwPin);
205 portNameStream.buffer[portNameStream.eos] = 0; // need to terminate explicitly
206 return portNameBuffer;
207}
static char portNameBuffer[20]
static MemoryStream portNameStream

Referenced by hwPhysicalPinName().

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

◆ hwPhysicalPinName()

const char * hwPhysicalPinName ( Gpio  brainPin)

Definition at line 209 of file pin_repository.cpp.

209 {
210 if (brainPin == Gpio::Invalid) {
211 return "INVALID";
212 }
213 if (brainPin == Gpio::Unassigned) {
214 return "NONE";
215 }
216
217 if (brain_pin_is_onchip(brainPin)) {
218 ioportid_t hwPort = getHwPort("hostname", brainPin);
219 int hwPin = getHwPin("hostname", brainPin);
220 return hwOnChipPhysicalPinName(hwPort, hwPin);
221 }
222 #if (BOARD_EXT_GPIOCHIPS > 0)
223 else {
224 portNameStream.eos = 0; // reset
225 const char *pin_name = gpiochips_getPinName(brainPin);
226
227 if (pin_name) {
228 chprintf((BaseSequentialStream *) &portNameStream, "ext:%s",
229 pin_name);
230 } else {
231 chprintf((BaseSequentialStream *) &portNameStream, "ext:%s.%d",
232 gpiochips_getChipName(brainPin), gpiochips_getPinOffset(brainPin));
233 }
234 portNameStream.buffer[portNameStream.eos] = 0; // need to terminate explicitly
235 return portNameBuffer;
236 }
237 #endif
238 return "unexpected";
239}
@ Unassigned
@ Invalid
const char * gpiochips_getChipName(brain_pin_e pin)
Get external chip name.
Definition core.cpp:148
const char * gpiochips_getPinName(brain_pin_e pin)
Get external chip port name.
Definition core.cpp:162
int gpiochips_getPinOffset(brain_pin_e pin)
Definition core.cpp:132
ioportid_t getHwPort(const char *msg, brain_pin_e brainPin)
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin)
GPIO_TypeDef * ioportid_t
Port Identifier.
const char * hwOnChipPhysicalPinName(ioportid_t hwPort, int hwPin)
bool brain_pin_is_onchip(brain_pin_e brainPin)

Referenced by brain_pin_markUsed(), and hwPortname().

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

◆ hwPortname()

const char * hwPortname ( brain_pin_e  brainPin)

Definition at line 241 of file pin_repository.cpp.

241 {
242 const char * boardSpecificPinName = getBoardSpecificPinName(brainPin);
243 if (boardSpecificPinName != nullptr) {
244 return boardSpecificPinName;
245 }
246 return hwPhysicalPinName(brainPin);
247}
const char * getBoardSpecificPinName(brain_pin_e brainPin)

Referenced by adcTriggerTurnOnInputPin(), benchSetPinValue(), brain_pin_markUsed(), canInfo(), OutputPin::deInit(), detectCanDevice(), doStartCranking(), efiExtiEnablePin(), extiTriggerTurnOnInputPin(), initElectronicThrottle(), OutputPin::initPin(), initQcBenchControls(), initWave(), onConfigurationChangeTriggerCallback(), printGpsInfo(), printMmcPinout(), printOutPin(), printSpiConfig(), printTsStats(), readPin(), runBench(), setIgnitionPin(), setIndividualPin(), setLogicInputPin(), setTriggerInputPin(), setTriggerSimulatorPin(), startCanPins(), startPwm(), triggerInfo(), and turnOnTriggerInputPin().

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

◆ index_to_brainPin()

static brain_pin_e index_to_brainPin ( unsigned int  i)
static

Definition at line 132 of file pin_repository.cpp.

133{
134 if (i < getBrainPinTotalNum())
135 return Gpio::A0 + i;
136
137 return Gpio::Invalid;
138}

Referenced by reportPins().

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

◆ initPinRepository()

void initPinRepository ( void  )

this method cannot use console because this method is invoked before console is initialized

Definition at line 249 of file pin_repository.cpp.

249 {
250 /**
251 * this method cannot use console because this method is invoked before console is initialized
252 */
253
254 addConsoleAction(CMD_PINS, reportPins);
255
256#if (BOARD_TLE8888_COUNT > 0)
258 addConsoleAction("tle8888init", tle8888_req_init);
259#endif
260}
void addConsoleAction(const char *token, Void callback)
Register console action without parameters.
static void reportPins()
void tle8888_dump_regs()
Definition tle8888.cpp:1279
void tle8888_req_init()
Definition tle8888.cpp:1272

Referenced by initHardwareNoConfig().

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

◆ isBrainPinValid()

bool isBrainPinValid ( brain_pin_e  brainPin)

Definition at line 25 of file pin_repository.cpp.

25 {
26 if ((brainPin == Gpio::Unassigned) || (brainPin == Gpio::Invalid))
27 return false;
28
29 if (brainPin > BRAIN_PIN_LAST)
30 /* something terribly wrong */
31 return false;
32
33 return true;
34}

Referenced by applyIACposition(), boardGetAnalogDiagnostic(), cdmIonInit(), NitrousController::checkTriggerPinState(), FrequencySensor::deInit(), HellaOilLevelSensor::deInit(), OutputPin::deInit(), deInitFlexSensor(), directWritePad(), efiExtiDisablePin(), efiExtiEnablePin(), efiReadPin(), efiSetPadMode(), getAdcChannelForTrigger(), getBrakePedalState(), getClutchDownState(), getClutchUpState(), getHwPin(), getHwPort(), TriggerCentral::handleShaftSignal(), handleVvtCamSignal(), hasAcToggle(), TachometerModule::init(), GenericGearController::init(), HellaOilLevelSensor::init(), BitbangI2c::init(), initAccelerometer(), initAlternatorCtrl(), initAuxValves(), initBoostCtrl(), initDac(), initGpPwm(), StepDirectionStepper::initialize(), FrequencySensor::initIfValid(), OutputPin::initPin(), initPotentiometers(), initSmartGpio(), initSpeedometer(), initVrThresholdPwm(), initWave(), isBoostControlSolenoidMode(), isGpsEnabled(), isIgnVoltage(), AntilagSystemBase::isInsideALSSwitchCondition(), LaunchControlBase::isInsideSwitchCondition(), isMilEnabled(), isSdCardEnabled(), lua_getAuxDigital(), lua_readpin(), onConfigurationChangeTriggerCallback(), onEcuStartDoSomethingTriggerInputPins(), AlternatorController::onFastCallback(), HarleyAcr::onSlowCallback(), SensorChecker::onSlowCallback(), printOutPin(), recalculateAuxValveTiming(), OutputPin::setValue(), startBoostPin(), startCanPins(), startSent(), startSerialChannels(), startTriggerEmulatorPins(), ButtonDebounce::stopConfiguration(), stopLogicAnalyzerPins(), stopSent(), triggerInfo(), turnOnTriggerInputPin(), turnVvtPidOn(), GenericGearController::update(), ShiftTorqueReductionController::updateTriggerPinState(), updateVrThresholdPwm(), validateConfigOnStartUpOrBurn(), and validateTriggerInputs().

◆ pinDiag2string()

void pinDiag2string ( char buffer,
size_t  size,
brain_pin_diag_e  pin_diag 
)

Definition at line 115 of file pin_repository.cpp.

115 {
116 /* use autogeneraged helpers here? */
117 if (pin_diag == PIN_OK) {
118 chsnprintf(buffer, size, "Ok");
119 } else if (pin_diag != PIN_UNKNOWN) {
120 chsnprintf(buffer, size, "%s%s%s%s%s%s",
121 pin_diag & PIN_DRIVER_OFF ? "driver_off " : "",
122 pin_diag & PIN_OPEN ? "open_load " : "",
123 pin_diag & PIN_SHORT_TO_GND ? "short_to_gnd " : "",
124 pin_diag & PIN_SHORT_TO_BAT ? "short_to_bat " : "",
125 pin_diag & PIN_OVERLOAD ? "overload " : "",
126 pin_diag & PIN_DRIVER_OVERTEMP ? "overtemp": "");
127 } else {
128 chsnprintf(buffer, size, "INVALID");
129 }
130}
composite packet size
static BigBufferHandle buffer

Referenced by benchOff(), SensorChecker::onSlowCallback(), and reportPins().

Here is the caller graph for this function:

◆ reportPins()

static void reportPins ( )
static

Definition at line 140 of file pin_repository.cpp.

140 {
141 int totalPinsUsed = 0;
142
143 for (unsigned int i = 0; i < getBrainPinOnchipNum(); i++) {
144 const char *pin_user = getBrainUsedPin(i);
145
146 /* show used pins */
147 if (pin_user) {
148 static char pin_state[64];
149 brain_pin_e brainPin = index_to_brainPin(i);
150 int pin = getBrainPinIndex(brainPin);
151 ioportid_t port = getBrainPinPort(brainPin);
152 debugBrainPin(pin_state, sizeof(pin_state), brainPin);
153
154 const char *boardPinName = getBoardSpecificPinName(brainPin);
155 efiPrintf("pin %s%d (%s): %s %s", portname(port), pin, boardPinName, pin_user, pin_state);
156 totalPinsUsed++;
157 }
158 }
159
160 #if (BOARD_EXT_GPIOCHIPS > 0)
161 for (unsigned int i = getBrainPinOnchipNum() ; i < getBrainPinTotalNum(); i++) {
162 static char pin_error[64];
163 brain_pin_e brainPin = index_to_brainPin(i);
164
165 const char *pin_name = gpiochips_getPinName(brainPin);
166 const char *pin_user = getBrainUsedPin(i);
167 brain_pin_diag_e pin_diag = gpiochips_getDiag(brainPin);
168
169 pinDiag2string(pin_error, sizeof(pin_error), pin_diag);
170
171 /* here show all pins, unused too */
172 if (pin_name) {
173 // this probably uses a lot of output buffer!
174 efiPrintf("ext %s: %s diagnostic: %s",
175 pin_name, pin_user ? pin_user : "free", pin_error);
176 } else {
177 const char *chip_name = gpiochips_getChipName(brainPin);
178 /* if chip exist */
179 if (chip_name) {
180 efiPrintf("ext %s.%d: %s diagnostic: %s",
181 chip_name, gpiochips_getPinOffset(brainPin), pin_user ? pin_user : "free", pin_error);
182 }
183 }
184 if (pin_user) {
185 totalPinsUsed++;
186 }
187 }
188 #endif
189
190 efiPrintf("Total pins used: %d", totalPinsUsed);
191
193}
void gpiochips_debug(void)
Definition core.cpp:413
brain_pin_diag_e gpiochips_getDiag(brain_pin_e pin)
Get diagnostic for given gpio.
Definition core.cpp:381
void pinDiag2string(char *buffer, size_t size, brain_pin_diag_e pin_diag)
static brain_pin_e index_to_brainPin(unsigned int i)
size_t getBrainPinOnchipNum()
int getBrainPinIndex(Gpio brainPin)
void debugBrainPin(char *buffer, size_t size, brain_pin_e brainPin)
ioportid_t getBrainPinPort(brain_pin_e brainPin)
brain_pin_diag_e

Referenced by initPinRepository().

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

Variable Documentation

◆ CCM_OPTIONAL

Definition at line 14 of file pin_repository.cpp.

◆ portNameBuffer

char portNameBuffer[20]
static

◆ portNameStream

MemoryStream portNameStream
static

Go to the source code of this file.