From 264f2654201887bd431bad2bdf72f5107976628b Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 5 Mar 2023 00:52:57 -0500 Subject: [PATCH] CAN GPIO #4096 only:hellen-honda-k --- firmware/hw_layer/drivers/gpio/can_gpio.cpp | 32 +++++++++++++++++++- firmware/hw_layer/hardware.cpp | 2 +- simulator/simulator/efifeatures.h | 5 +++ simulator/simulator/rusEfiFunctionalTest.cpp | 10 ++++++ 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/firmware/hw_layer/drivers/gpio/can_gpio.cpp b/firmware/hw_layer/drivers/gpio/can_gpio.cpp index 1f69e69073..8e584b067e 100644 --- a/firmware/hw_layer/drivers/gpio/can_gpio.cpp +++ b/firmware/hw_layer/drivers/gpio/can_gpio.cpp @@ -3,19 +3,49 @@ */ #include "pch.h" +#include "gpio/gpio_ext.h" #include "can_gpio.h" +#if EFI_CAN_GPIO + +static SEMAPHORE_DECL(wakeSemaphore, 3 /* todo: is that right number? probably not. */); static THD_WORKING_AREA(canGpio_thread_1_wa, 256); +struct CanOutputs : public GpioChip { + uint8_t state[4]; + + CanOutputs() { + memset(&state, 0, sizeof(state)); + } + + void wakeThread() { + /* Entering a reentrant critical zone.*/ + chibios_rt::CriticalSectionLocker csl; + + chSemSignalI(&wakeSemaphore); + } + + /* pin argument is pin number within gpio chip, not a global number */ + int writePad(size_t pin, int value) override { + state[pin] = value; + wakeThread(); + return 0; + } +}; + static THD_FUNCTION(canGpio_driver_thread, p) { (void)p; chRegSetThreadName("CanGpio"); + while (1) { + chSemWaitTimeout(&wakeSemaphore, TIME_MS2I(1200 /*random number, ms*/)); + } } -#if EFI_CAN_GPIO void initCanGpio() { +// CAN_PIN_0 + chThdCreateStatic(canGpio_thread_1_wa, sizeof(canGpio_thread_1_wa), PRIO_GPIOCHIP, canGpio_driver_thread, NULL); } diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index c0601ea0a0..cd37bfef5f 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -540,7 +540,7 @@ void initHardware() { initSpiModules(engineConfiguration); #endif /* HAL_USE_SPI */ -#if EFI_PROD_CODE && (BOARD_EXT_GPIOCHIPS > 0) +#if (EFI_PROD_CODE || EFI_SIMULATOR) && (BOARD_EXT_GPIOCHIPS > 0) // initSmartGpio depends on 'initSpiModules' initSmartGpio(); #endif diff --git a/simulator/simulator/efifeatures.h b/simulator/simulator/efifeatures.h index 6222df02bf..50163c3cf7 100644 --- a/simulator/simulator/efifeatures.h +++ b/simulator/simulator/efifeatures.h @@ -16,6 +16,11 @@ #define EFI_TCU FALSE +/** + * todo: we *plan* an (integration) test + */ +#define EFI_CAN_GPIO TRUE + #define EFI_ANTILAG_SYSTEM TRUE #define ENABLE_PERF_TRACE FALSE diff --git a/simulator/simulator/rusEfiFunctionalTest.cpp b/simulator/simulator/rusEfiFunctionalTest.cpp index 29251ba1c3..55db551785 100644 --- a/simulator/simulator/rusEfiFunctionalTest.cpp +++ b/simulator/simulator/rusEfiFunctionalTest.cpp @@ -83,6 +83,9 @@ static void runChprintfTest() { } +static void runCanGpioTest() { +} + void rusEfiFunctionalTest(void) { printToConsole("Running rusEFI simulator version:"); static char versionBuffer[20]; @@ -116,7 +119,14 @@ void rusEfiFunctionalTest(void) { void initMmcCard(); initMmcCard(); + /** + * !!!! TESTS ! + */ runChprintfTest(); + runCanGpioTest(); + /** + * end of TESTS ! + */ initPeriodicEvents();