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

Detailed Description

I/O pin registry header.

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

Definition in file pin_repository.h.

Functions

bool isBrainPinValid (Gpio brainPin)
 
const charhwOnChipPhysicalPinName (ioportid_t hwPort, int hwPin)
 
void initPinRepository ()
 
bool brain_pin_is_onchip (Gpio brainPin)
 
bool brain_pin_is_ext (Gpio brainPin)
 
void pinDiag2string (char *buffer, size_t size, brain_pin_diag_e pin_diag)
 
bool brain_pin_markUsed (brain_pin_e brainPin, const char *msg)
 
const chargetPinFunction (brain_input_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)
 
int getPortPinIndex (ioportid_t port, ioportmask_t pin)
 
ioportid_t getBrainPinPort (brain_pin_e brainPin)
 
int getBrainPinIndex (Gpio brainPin)
 
size_t getBrainPinOnchipNum ()
 
const charhwPortname (Gpio brainPin)
 
const charhwPhysicalPinName (Gpio brainPin)
 
const chargetBoardSpecificPinName (Gpio brainPin)
 
void debugBrainPin (char *buffer, size_t size, brain_pin_e brainPin)
 
const char *& getBrainUsedPin (size_t idx)
 

Function Documentation

◆ brain_pin_is_ext()

bool brain_pin_is_ext ( Gpio  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 ( Gpio  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_markUsed()

bool brain_pin_markUsed ( Gpio  brainPin,
const char msg 
)

Usually high-level code would invoke efiSetPadMode, not this method directly

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)
int brainPin_to_index(Gpio brainPin)
const char *& getBrainUsedPin(size_t index)
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:

◆ debugBrainPin()

void debugBrainPin ( char buffer,
size_t  size,
brain_pin_e  brainPin 
)

Definition at line 199 of file cypress_pins.cpp.

200{
201 buffer[0] = '\0';
202}
static BigBufferHandle buffer

Referenced by reportPins().

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

◆ getBoardSpecificPinName()

const char * getBoardSpecificPinName ( Gpio  brainPin)

Definition at line 7 of file generated_ts_name_by_pin.cpp.

7 {
8 switch(brainPin) {
9 case Gpio::B7: return "Injector 3Z";
10 case Gpio::B8: return "Injector 3Y";
11 case Gpio::B9: return "Injector 3W";
12 case Gpio::C13: return "Injector 2M";
13 case Gpio::C7: return "Coil 1H";
14 case Gpio::C9: return "Coil 1F";
15 case Gpio::D3: return "Injector 3U";
16 case Gpio::D5: return "Injector 3X";
17 case Gpio::D7: return "Injector 2N";
18 case Gpio::D8: return "Coil 1O";
19 case Gpio::D9: return "Coil 1P";
20 case Gpio::E10: return "Coil 1I";
21 case Gpio::E12: return "Coil 1M";
22 case Gpio::E14: return "Coil 1G";
23 case Gpio::E2: return "Injector 3V";
24 case Gpio::E3: return "Injector 3S";
25 case Gpio::E4: return "Injector 3T";
26 case Gpio::E5: return "Injector 2O";
27 case Gpio::E6: return "Injector 2P";
28 case Gpio::E8: return "Coil 1L";
29 default: return nullptr;
30 }
31 return nullptr;
32}

Referenced by hwPortname(), printSentInfo(), and reportPins().

Here is the caller graph for this function:

◆ getBrainPinIndex()

int getBrainPinIndex ( Gpio  brainPin)

Definition at line 39 of file cypress_pins.cpp.

39 {
40 return (brainPin - Gpio::A0) % PORT_SIZE;
41}

Referenced by boardInitMfs(), debugBrainPin(), detectHellenBoardId(), getHwPin(), HellenBoardIdFinder< NumPins >::measureChargingTimes(), and reportPins().

Here is the caller graph for this function:

◆ getBrainPinOnchipNum()

size_t getBrainPinOnchipNum ( )

Definition at line 195 of file cypress_pins.cpp.

195 {
196 return BRAIN_PIN_ONCHIP_PINS;
197}

Referenced by reportPins().

Here is the caller graph for this function:

◆ getBrainPinPort()

ioportid_t getBrainPinPort ( brain_pin_e  brainPin)

Definition at line 43 of file cypress_pins.cpp.

43 {
44 return getGpioPorts()[(brainPin - Gpio::A0) / PORT_SIZE];
45}
ioportid_t * getGpioPorts()

Referenced by boardInitMfs(), debugBrainPin(), detectHellenBoardId(), HellenBoardIdFinder< NumPins >::measureChargingTimes(), and reportPins().

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

◆ getBrainUsedPin()

const char *& getBrainUsedPin ( size_t  idx)

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:

◆ getPortPinIndex()

int getPortPinIndex ( ioportid_t  port,
ioportmask_t  pin 
)

Definition at line 132 of file cypress_pins.cpp.

132 {
133 int portIndex = getPortIndex(port);
134 return portIndex * PORT_SIZE + pin;
135}
static int getPortIndex(ioportid_t port)
brain_pin_e pin
Definition stm32_adc.cpp:15

Referenced by gpio_pin_markUnused(), and gpio_pin_markUsed().

Here is the call graph for this function:
Here is the caller 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)

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 ( Gpio  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:

◆ initPinRepository()

void initPinRepository ( )

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 ( Gpio  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

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

Here is the caller graph for this function:

Go to the source code of this file.