Minor fixes (#1442)

* exti trigger: mark pins used, handle errors

* MC33810 add to smart gpios
This commit is contained in:
dron0gus 2020-05-17 02:15:49 +03:00 committed by GitHub
parent a0efd3ad68
commit 2e9cff8596
8 changed files with 36 additions and 10 deletions

View File

@ -70,6 +70,9 @@
#define BOARD_TLE8888_COUNT 0 #define BOARD_TLE8888_COUNT 0
#endif #endif
#ifndef BOARD_MC33810_COUNT
#define BOARD_MC33810_COUNT 0
#endif
#undef EFI_CONSOLE_TX_BRAIN_PIN #undef EFI_CONSOLE_TX_BRAIN_PIN
#define EFI_CONSOLE_TX_BRAIN_PIN GPIOA_0 #define EFI_CONSOLE_TX_BRAIN_PIN GPIOA_0

View File

@ -146,6 +146,10 @@
#define BOARD_TLE8888_COUNT 1 #define BOARD_TLE8888_COUNT 1
#endif #endif
#ifndef BOARD_MC33810_COUNT
#define BOARD_MC33810_COUNT 0
#endif
#define EFI_ANALOG_SENSORS TRUE #define EFI_ANALOG_SENSORS TRUE
#ifndef EFI_MAX_31855 #ifndef EFI_MAX_31855

View File

@ -50,6 +50,10 @@
#define BOARD_TLE8888_COUNT 1 #define BOARD_TLE8888_COUNT 1
#endif #endif
#ifndef BOARD_MC33810_COUNT
#define BOARD_MC33810_COUNT 0
#endif
#undef EFI_CAN_SUPPORT #undef EFI_CAN_SUPPORT
#define EFI_CAN_SUPPORT TRUE #define EFI_CAN_SUPPORT TRUE

View File

@ -11,6 +11,7 @@
#include "digital_input_exti.h" #include "digital_input_exti.h"
#include "efi_gpio.h" #include "efi_gpio.h"
#include "error_handling.h" #include "error_handling.h"
#include "pin_repository.h"
/** /**
* EXTI is a funny thing: you can only use same pin on one port. For example, you can use * EXTI is a funny thing: you can only use same pin on one port. For example, you can use
@ -23,23 +24,23 @@
static ioportmask_t ext_used = 0; static ioportmask_t ext_used = 0;
// EXT is not able to give you the front direction but you could read the pin in the callback. // EXT is not able to give you the front direction but you could read the pin in the callback.
void efiExtiEnablePin(const char *msg, brain_pin_e brainPin, uint32_t mode, palcallback_t cb, void *cb_data) { int efiExtiEnablePin(const char *msg, brain_pin_e brainPin, uint32_t mode, palcallback_t cb, void *cb_data) {
/* paranoid check, in case of GPIO_UNASSIGNED getHwPort will return NULL /* paranoid check, in case of GPIO_UNASSIGNED getHwPort will return NULL
* and we will fail on next check */ * and we will fail on next check */
if (brainPin == GPIO_UNASSIGNED) if (brainPin == GPIO_UNASSIGNED)
return; return -1;
ioportid_t port = getHwPort(msg, brainPin); ioportid_t port = getHwPort(msg, brainPin);
if (port == NULL) if (port == NULL)
return; return -1;
int index = getHwPin(msg, brainPin); int index = getHwPin(msg, brainPin);
/* is this index already used? */ /* is this index already used? */
if (ext_used & PAL_PORT_BIT(index)) { if (ext_used & PAL_PORT_BIT(index)) {
firmwareError(CUSTOM_ERR_PIN_ALREADY_USED_2, "%s: pin %d: exti index already used", msg, brainPin); firmwareError(CUSTOM_ERR_PIN_ALREADY_USED_2, "%s: pin %d: exti index already used", msg, brainPin);
return; return -1;
} }
ioline_t line = PAL_LINE(port, index); ioline_t line = PAL_LINE(port, index);
@ -48,6 +49,9 @@ void efiExtiEnablePin(const char *msg, brain_pin_e brainPin, uint32_t mode, palc
/* mark used */ /* mark used */
ext_used |= PAL_PORT_BIT(index); ext_used |= PAL_PORT_BIT(index);
brain_pin_markUsed(brainPin, msg);
return 0;
} }
void efiExtiDisablePin(brain_pin_e brainPin) void efiExtiDisablePin(brain_pin_e brainPin)
@ -73,6 +77,7 @@ void efiExtiDisablePin(brain_pin_e brainPin)
/* mark unused */ /* mark unused */
ext_used &= ~PAL_PORT_BIT(index); ext_used &= ~PAL_PORT_BIT(index);
brain_pin_markUnused(brainPin);
} }
#endif /* HAL_USE_PAL && EFI_PROD_CODE */ #endif /* HAL_USE_PAL && EFI_PROD_CODE */

View File

@ -10,6 +10,6 @@
#include "digital_input.h" #include "digital_input.h"
#if HAL_USE_PAL #if HAL_USE_PAL
void efiExtiEnablePin(const char *msg, brain_pin_e pin, uint32_t mode, palcallback_t cb, void *cb_data); int efiExtiEnablePin(const char *msg, brain_pin_e pin, uint32_t mode, palcallback_t cb, void *cb_data);
void efiExtiDisablePin(brain_pin_e brainPin); void efiExtiDisablePin(brain_pin_e brainPin);
#endif /* HAL_USE_PAL */ #endif /* HAL_USE_PAL */

View File

@ -221,7 +221,6 @@ void stopDigitalCapture(const char *msg, brain_pin_e brainPin) {
if (brainPin == GPIO_UNASSIGNED) { if (brainPin == GPIO_UNASSIGNED) {
return; return;
} }
brain_pin_markUnused(brainPin);
ICUDriver *driver = getInputCaptureDriver(msg, brainPin); ICUDriver *driver = getInputCaptureDriver(msg, brainPin);
if (driver == NULL) { if (driver == NULL) {

View File

@ -12,7 +12,11 @@
#include "drivers/gpio/tle6240.h" #include "drivers/gpio/tle6240.h"
#include "drivers/gpio/mc33972.h" #include "drivers/gpio/mc33972.h"
#include "drivers/gpio/tle8888.h" #include "drivers/gpio/tle8888.h"
#define BOARD_EXT_PINREPOPINS (BOARD_TLE6240_COUNT * TLE6240_OUTPUTS + BOARD_MC33972_COUNT * MC33972_INPUTS + BOARD_TLE8888_COUNT * TLE8888_OUTPUTS) #define BOARD_EXT_PINREPOPINS \
(BOARD_TLE6240_COUNT * TLE6240_OUTPUTS + \
BOARD_MC33972_COUNT * MC33972_INPUTS + \
BOARD_TLE8888_COUNT * TLE8888_OUTPUTS + \
BOARD_MC33810_COUNT * MC33810_OUTPUTS)
#else /* EFI_PROD_CODE */ #else /* EFI_PROD_CODE */
#define BOARD_EXT_PINREPOPINS 0 #define BOARD_EXT_PINREPOPINS 0
@ -21,7 +25,11 @@
#if EFI_UNIT_TEST #if EFI_UNIT_TEST
#define BOARD_EXT_GPIOCHIPS 3 #define BOARD_EXT_GPIOCHIPS 3
#else #else
#define BOARD_EXT_GPIOCHIPS (BOARD_TLE6240_COUNT + BOARD_MC33972_COUNT + BOARD_TLE8888_COUNT) #define BOARD_EXT_GPIOCHIPS \
(BOARD_TLE6240_COUNT + \
BOARD_MC33972_COUNT + \
BOARD_TLE8888_COUNT + \
BOARD_MC33810_COUNT)
#endif #endif
void initSmartGpio(void); void initSmartGpio(void);

View File

@ -76,6 +76,7 @@ static void cam_callback(void *arg) {
/*==========================================================================*/ /*==========================================================================*/
int extiTriggerTurnOnInputPin(const char *msg, int index, bool isTriggerShaft) { int extiTriggerTurnOnInputPin(const char *msg, int index, bool isTriggerShaft) {
int ret;
brain_pin_e brainPin = isTriggerShaft ? CONFIG(triggerInputPins)[index] : engineConfiguration->camInputs[index]; brain_pin_e brainPin = isTriggerShaft ? CONFIG(triggerInputPins)[index] : engineConfiguration->camInputs[index];
scheduleMsg(logger, "extiTriggerTurnOnInputPin %s %s", msg, hwPortname(brainPin)); scheduleMsg(logger, "extiTriggerTurnOnInputPin %s %s", msg, hwPortname(brainPin));
@ -83,8 +84,10 @@ int extiTriggerTurnOnInputPin(const char *msg, int index, bool isTriggerShaft) {
/* TODO: /* TODO:
* * do not set to both edges if we need only one * * do not set to both edges if we need only one
* * simplify callback in case of one edge */ * * simplify callback in case of one edge */
ioline_t pal_line = PAL_LINE(getHwPort("trg", brainPin), getHwPin("trg", brainPin)); ioline_t pal_line = PAL_LINE(getHwPort(msg, brainPin), getHwPin(msg, brainPin));
efiExtiEnablePin(msg, brainPin, PAL_EVENT_MODE_BOTH_EDGES, isTriggerShaft ? shaft_callback : cam_callback, (void *)pal_line); ret = efiExtiEnablePin(msg, brainPin, PAL_EVENT_MODE_BOTH_EDGES, isTriggerShaft ? shaft_callback : cam_callback, (void *)pal_line);
if (ret)
return ret;
return 0; return 0;
} }