From 655ea2923c387a2ff9323bea8e3a8186603d824c Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sat, 13 Nov 2021 12:40:02 +0000 Subject: [PATCH] Added elfAcquireBus()/eflReleaseBus() functions to EFL driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15070 27425a3e-05d8-49a3-a47f-9c15f0e5edd8 --- os/hal/include/hal_efl.h | 26 ++++++++++++++++++++----- os/hal/src/hal_efl.c | 41 +++++++++++++++++++++++++++++++++++++++- readme.txt | 1 + 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/os/hal/include/hal_efl.h b/os/hal/include/hal_efl.h index 7180942fe..d68266cc7 100644 --- a/os/hal/include/hal_efl.h +++ b/os/hal/include/hal_efl.h @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2021 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -35,6 +35,14 @@ /* Driver pre-compile time settings. */ /*===========================================================================*/ +/** + * @brief Enables the @p eflAcquireUse() and @p eflReleaseUse() APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(EFL_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__) +#define EFL_USE_MUTUAL_EXCLUSION TRUE +#endif + /*===========================================================================*/ /* Derived constants and error checks. */ /*===========================================================================*/ @@ -96,10 +104,16 @@ typedef struct hal_efl_config { */ struct hal_efl_driver { /** - * @brief SNORDriver Virtual Methods Table. + * @brief EFlashDriver Virtual Methods Table. */ const struct EFlashDriverVMT *vmt; _efl_driver_data +#if (EFL_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__) + /** + * @brief Mutex protecting EFL. + */ + mutex_t mutex; +#endif /* EFL_USE_MUTUAL_EXCLUSION == TRUE */ /* End of the mandatory fields.*/ efl_lld_driver_fields; }; @@ -115,10 +129,12 @@ struct hal_efl_driver { #ifdef __cplusplus extern "C" { #endif - void eflInit(void); - void eflObjectInit(EFlashDriver *eflp); + void eflInit(void); + void eflObjectInit(EFlashDriver *eflp); msg_t eflStart(EFlashDriver *eflp, const EFlashConfig *config); - void eflStop(EFlashDriver *eflp); + void eflStop(EFlashDriver *eflp); + void eflAcquireBus(EFlashDriver *eflp); + void eflReleaseBus(EFlashDriver *eflp); #ifdef __cplusplus } #endif diff --git a/os/hal/src/hal_efl.c b/os/hal/src/hal_efl.c index 8b12e8804..34e078c90 100644 --- a/os/hal/src/hal_efl.c +++ b/os/hal/src/hal_efl.c @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2021 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -80,6 +80,9 @@ void eflObjectInit(EFlashDriver *eflp) { eflp->vmt = &vmt; eflp->state = FLASH_STOP; +#if EFL_USE_MUTUAL_EXCLUSION == TRUE + osalMutexObjectInit(&eflp->mutex); +#endif } /** @@ -145,6 +148,42 @@ void eflStop(EFlashDriver *eflp) { osalSysUnlock(); } +#if (EFL_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__) +/** + * @brief Gains exclusive access to EFL. + * @details This function tries to gain ownership of EFL. If EFL + * is already being used then the invoking thread is queued. + * @pre In order to use this function the option @p EFL_USE_MUTUAL_EXCLUSION + * must be enabled. + * + * @param[in] eflp pointer to the @p EFlashDriver object + * + * @api + */ +void eflAcquireBus(EFlashDriver *eflp) { + + osalDbgCheck(eflp != NULL); + + osalMutexLock(&eflp->mutex); +} + +/** + * @brief Releases exclusive access to EFL. + * @pre In order to use this function the option @p EFL_USE_MUTUAL_EXCLUSION + * must be enabled. + * + * @param[in] eflp pointer to the @p EFlashDriver object + * + * @api + */ +void eflReleaseBus(EFlashDriver *eflp) { + + osalDbgCheck(eflp != NULL); + + osalMutexUnlock(&eflp->mutex); +} +#endif /* EFL_USE_MUTUAL_EXCLUSION == TRUE */ + #endif /* HAL_USE_EFL == TRUE */ /** @} */ diff --git a/readme.txt b/readme.txt index 8933fb56b..c30ef18b2 100644 --- a/readme.txt +++ b/readme.txt @@ -74,6 +74,7 @@ ***************************************************************************** *** Next *** +- NEW: Added elfAcquireBus()/eflReleaseBus() functions to EFL driver. - NEW: Increased stacks size in RT test suite from 128 to 192. added an option to override the stack size by defining THREADS_STACK_SIZE in the makefile.