From 9d32f2c40a481e0fdb32fe767048bd2739f02f77 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 11 Aug 2019 15:23:15 -0400 Subject: [PATCH] refactoring: ChibiOS now offers native 'lockAnyContext' pattern --- firmware/controllers/engine_controller.cpp | 18 +++++++++--------- firmware/hw_layer/drivers/gpio/tle8888.c | 8 ++++---- firmware/svnversion.h | 6 +++--- firmware/util/os_util.c | 4 ++++ 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 12ae38fe6b..0e8ba153ce 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -179,7 +179,8 @@ efitimeus_t getTimeNowUs(void) { //todo: macro to save method invocation efitick_t getTimeNowNt(void) { #if EFI_PROD_CODE - bool alreadyLocked = lockAnyContext(); + /* Entering a reentrant critical zone.*/ + syssts_t sts = chSysGetStatusAndLockX(); efitime_t localH = halTime.state.highBits; uint32_t localLow = halTime.state.lowBits; @@ -192,9 +193,8 @@ efitick_t getTimeNowNt(void) { efitime_t result = localH + value; - if (!alreadyLocked) { - unlockAnyContext(); - } + /* Leaving the critical zone.*/ + chSysRestoreStatusX(sts); return result; #else /* EFI_PROD_CODE */ // todo: why is this implementation not used? @@ -299,11 +299,11 @@ static void doPeriodicSlowCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) { /** * We need to push current value into the 64 bit counter often enough so that we do not miss an overflow */ - bool alreadyLocked = lockAnyContext(); + /* Entering a reentrant critical zone.*/ + syssts_t sts = chSysGetStatusAndLockX(); updateAndSet(&halTime.state, getTimeNowLowerNt()); - if (!alreadyLocked) { - unlockAnyContext(); - } + /* Leaving the critical zone.*/ + chSysRestoreStatusX(sts); int timeSeconds = getTimeNowSeconds(); if (previousSecond != timeSeconds) { previousSecond = timeSeconds; @@ -812,6 +812,6 @@ int getRusEfiVersion(void) { if (initBootloader() != 0) return 123; #endif /* EFI_BOOTLOADER_INCLUDE_CODE */ - return 20190809; + return 20190810; } #endif /* EFI_UNIT_TEST */ diff --git a/firmware/hw_layer/drivers/gpio/tle8888.c b/firmware/hw_layer/drivers/gpio/tle8888.c index 8ba4773cf5..68e62056da 100644 --- a/firmware/hw_layer/drivers/gpio/tle8888.c +++ b/firmware/hw_layer/drivers/gpio/tle8888.c @@ -263,7 +263,8 @@ static int tle8888_wake_driver(struct tle8888_priv *chip) { (void)chip; - int wasLocked = lockAnyContext(); + /* Entering a reentrant critical zone.*/ + syssts_t sts = chSysGetStatusAndLockX(); if (isIsrContext()) { // this is for normal runtime chSemSignalI(&tle8888_wake); @@ -271,9 +272,8 @@ static int tle8888_wake_driver(struct tle8888_priv *chip) // this is for start-up to not hang up chSemSignalS(&tle8888_wake); } - if (!wasLocked) { - unlockAnyContext(); - } + /* Leaving the critical zone.*/ + chSysRestoreStatusX(sts); return 0; } diff --git a/firmware/svnversion.h b/firmware/svnversion.h index 0b0ce870f9..1edb65178a 100644 --- a/firmware/svnversion.h +++ b/firmware/svnversion.h @@ -1,12 +1,12 @@ // This file was generated by Version2Header -// Thu Aug 08 00:19:27 EDT 2019 +// Sun Aug 11 15:18:31 EDT 2019 #ifndef GIT_HASH -#define GIT_HASH "51110b33ad6a0867421728746311e7a5019b5f11" +#define GIT_HASH "0625b9140462581910d166e08180450e85b56476" #endif #ifndef VCS_VERSION -#define VCS_VERSION "19679" +#define VCS_VERSION "19704" #endif diff --git a/firmware/util/os_util.c b/firmware/util/os_util.c index b741e31969..0b9407640b 100644 --- a/firmware/util/os_util.c +++ b/firmware/util/os_util.c @@ -44,6 +44,7 @@ void chVTSetAny(virtual_timer_t *vtp, systime_t time, vtfunc_t vtfunc, void *par /** * @return TRUE if already in locked context + * TODO: refactor to new 'syssts_t sts = chSysGetStatusAndLockX();' pattern */ bool lockAnyContext(void) { int alreadyLocked = isLocked(); @@ -63,6 +64,9 @@ bool lockAnyContext(void) { return false; } +/** + * TODO: refactor to new 'chSysRestoreStatusX(sts);' pattern + */ void unlockAnyContext(void) { #if USE_PORT_LOCK port_unlock();