Extgpios integration 1 (#734)

* pin repository: add brain_pin_markUsed and brain_pin_markUnused

This is part of external gpio chips integration

* pin repository: simplify getPinFunction()

* pin repository: add brain_pin_is_onchip()

This is part of external gpio chips integration

* pin repository: kill signed vs unsigned warning
This commit is contained in:
dron0gus 2019-04-05 01:53:27 +03:00 committed by rusefi
parent d30009af16
commit be70420a71
2 changed files with 84 additions and 5 deletions

View File

@ -50,6 +50,22 @@ static int initialized = FALSE;
static LoggingWithStorage logger("pin repos");
static int totalPinsUsed = 0;
static int brainPin_to_index(brain_pin_e brainPin)
{
int index;
if (brainPin < GPIOA_0)
return -1;
index = brainPin - GPIOA_0;
/* if index outside array boundary */
if ((unsigned)index > (sizeof(PIN_USED) / sizeof(PIN_USED[0])))
return -1;
return index;
}
PinRepository::PinRepository() {
}
@ -86,7 +102,9 @@ static int getPortIndex(ioportid_t port) {
}
static void reportPins(void) {
for (int i = 0; i < PIN_REPO_SIZE; i++) {
unsigned int i;
for (i = 0; i < PIN_REPO_SIZE; i++) {
const char *name = PIN_USED[i];
int portIndex = i / PORT_SIZE;
int pin = i % PORT_SIZE;
@ -161,10 +179,47 @@ static int getIndex(ioportid_t port, ioportmask_t pin) {
return portIndex * PORT_SIZE + pin;
}
bool brain_pin_is_onchip(brain_pin_e brainPin)
{
if ((brainPin < GPIOA_0) || (brainPin > GPIOH_15))
return false;
return true;
}
/**
* See also unmarkPin()
* @return true if this pin was already used, false otherwise
*/
bool brain_pin_markUsed(brain_pin_e brainPin, const char *msg)
{
int index;
if (!initialized) {
firmwareError(CUSTOM_ERR_PIN_REPO, "repository not initialized");
return false;
}
index = brainPin_to_index(brainPin);
if (index < 0)
return true;
if (PIN_USED[index] != NULL) {
/* TODO: get readable name of brainPin... */
/**
* 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!
*/
// warning(OBD_PCM_Processor_Fault, "brain pin %d req by %s used by %s", brainPin, msg, PIN_USED[index]);
firmwareError(CUSTOM_ERR_PIN_ALREADY_USED_1, "brain pin %d req by %s used by %s", brainPin, msg, PIN_USED[index]);
return true;
}
PIN_USED[index] = msg;
totalPinsUsed++;
return false;
}
bool markUsed(ioportid_t port, ioportmask_t pin, const char *msg) {
if (!initialized) {
firmwareError(CUSTOM_ERR_PIN_REPO, "repository not initialized");
@ -189,6 +244,25 @@ bool markUsed(ioportid_t port, ioportmask_t pin, const char *msg) {
/**
* See also markUsed()
*/
void brain_pin_markUnused(brain_pin_e brainPin)
{
int index;
if (!initialized) {
firmwareError(CUSTOM_ERR_PIN_REPO, "repository not initialized");
return;
}
index = brainPin_to_index(brainPin);
if (index < 0)
return;
if (PIN_USED[index] != NULL)
totalPinsUsed--;
PIN_USED[index] = NULL;
}
void markUnused(ioportid_t port, ioportmask_t pin) {
if (!initialized) {
firmwareError(CUSTOM_ERR_PIN_REPO, "repository not initialized");
@ -201,11 +275,13 @@ void markUnused(ioportid_t port, ioportmask_t pin) {
PIN_USED[index] = NULL;
}
const char * getPinFunction(brain_input_pin_e brainPin) {
ioportid_t port = getHwPort("getF", brainPin);
ioportmask_t pin = getHwPin("getF", brainPin);
const char *getPinFunction(brain_input_pin_e brainPin) {
int index;
index = brainPin_to_index(brainPin);
if (index < 0)
return NULL;
int index = getIndex(port, pin);
return PIN_USED[index];
}

View File

@ -34,8 +34,11 @@ class PinRepository {
#endif
void initPinRepository(void);
EXTERNC bool brain_pin_is_onchip(brain_pin_e brainPin);
EXTERNC bool markUsed(ioportid_t port, ioportmask_t pin, const char *msg);
EXTERNC bool brain_pin_markUsed(brain_pin_e brainPin, const char *msg);
EXTERNC void markUnused(ioportid_t port, ioportmask_t pin);
EXTERNC void brain_pin_markUnused(brain_pin_e brainPin);
const char * getPinFunction(brain_input_pin_e brainPin);
void unmarkPin(brain_pin_e brainPin);