From 915b474b02349add9c17fa43ff0351503c3c5020 Mon Sep 17 00:00:00 2001 From: Fabien Poussin Date: Wed, 30 Oct 2019 12:52:31 +0100 Subject: Re-organised FSMC drivers --- os/hal/src/hal_fsmc.c | 153 +++++-------------------------------------------- os/hal/src/hal_sdram.c | 122 +++++++++++++++++++++++++++++++++++++++ os/hal/src/hal_sram.c | 146 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 282 insertions(+), 139 deletions(-) create mode 100644 os/hal/src/hal_sdram.c create mode 100644 os/hal/src/hal_sram.c (limited to 'os/hal/src') diff --git a/os/hal/src/hal_fsmc.c b/os/hal/src/hal_fsmc.c index cdbb387..7d30720 100644 --- a/os/hal/src/hal_fsmc.c +++ b/os/hal/src/hal_fsmc.c @@ -23,7 +23,7 @@ */ #include "hal.h" -#if (HAL_USE_FSMC_SDRAM == TRUE) || (HAL_USE_FSMC_SRAM == TRUE) || (HAL_USE_FSMC_NAND == TRUE) || defined(__DOXYGEN__) +#if (HAL_USE_SDRAM == TRUE) || (HAL_USE_SRAM == TRUE) || (HAL_USE_NAND == TRUE) || defined(__DOXYGEN__) /*===========================================================================*/ /* Driver local definitions. */ @@ -72,27 +72,27 @@ void fsmcInit(void) { if (FSMCD1.state == FSMC_UNINIT) { FSMCD1.state = FSMC_STOP; -#if STM32_FSMC_USE_SRAM1 - FSMCD1.sram1 = (FSMC_SRAM_NOR_TypeDef *)(FSMC_Bank1_R_BASE); +#if STM32_SRAM_USE_SRAM1 + FSMCD1.sram1 = (FSMC_SRAM_TypeDef *)(FSMC_Bank1_R_BASE); #endif -#if STM32_FSMC_USE_SRAM2 - FSMCD1.sram2 = (FSMC_SRAM_NOR_TypeDef *)(FSMC_Bank1_R_BASE + 8); +#if STM32_SRAM_USE_SRAM2 + FSMCD1.sram2 = (FSMC_SRAM_TypeDef *)(FSMC_Bank1_R_BASE + 8); #endif -#if STM32_FSMC_USE_SRAM3 - FSMCD1.sram3 = (FSMC_SRAM_NOR_TypeDef *)(FSMC_Bank1_R_BASE + 8 * 2); +#if STM32_SRAM_USE_SRAM3 + FSMCD1.sram3 = (FSMC_SRAM_TypeDef *)(FSMC_Bank1_R_BASE + 8 * 2); #endif -#if STM32_FSMC_USE_SRAM4 - FSMCD1.sram4 = (FSMC_SRAM_NOR_TypeDef *)(FSMC_Bank1_R_BASE + 8 * 3); +#if STM32_SRAM_USE_SRAM4 + FSMCD1.sram4 = (FSMC_SRAM_TypeDef *)(FSMC_Bank1_R_BASE + 8 * 3); #endif -#if STM32_FSMC_USE_NAND1 +#if STM32_NAND_USE_NAND1 FSMCD1.nand1 = (FSMC_NAND_TypeDef *)FSMC_Bank2_R_BASE; #endif -#if STM32_FSMC_USE_NAND2 +#if STM32_NAND_USE_NAND2 FSMCD1.nand2 = (FSMC_NAND_TypeDef *)FSMC_Bank3_R_BASE; #endif @@ -102,7 +102,7 @@ void fsmcInit(void) { defined(STM32F756xx) || defined(STM32F767xx) || \ defined(STM32F769xx) || defined(STM32F777xx) || \ defined(STM32F779xx)) - #if STM32_FSMC_USE_SDRAM1 || STM32_FSMC_USE_SDRAM2 + #if STM32_SDRAM_USE_SDRAM1 || STM32_SDRAM_USE_SDRAM2 FSMCD1.sdram = (FSMC_SDRAM_TypeDef *)FSMC_Bank5_6_R_BASE; #endif #endif @@ -176,12 +176,12 @@ void fsmcStop(FSMCDriver *fsmcp) { CH_IRQ_HANDLER(STM32_FSMC_HANDLER) { CH_IRQ_PROLOGUE(); -#if STM32_FSMC_USE_NAND1 +#if STM32_NAND_USE_NAND1 if (FSMCD1.nand1->SR & FSMC_SR_ISR_MASK) { NANDD1.isr_handler(&NANDD1); } #endif -#if STM32_FSMC_USE_NAND2 +#if STM32_NAND_USE_NAND2 if (FSMCD1.nand2->SR & FSMC_SR_ISR_MASK) { NANDD2.isr_handler(&NANDD2); } @@ -189,131 +189,6 @@ CH_IRQ_HANDLER(STM32_FSMC_HANDLER) { CH_IRQ_EPILOGUE(); } -#if (HAL_USE_FSMC_SDRAM == TRUE) - -#include "hal_fsmc_sdram_lld.h" -/** - * @brief FSMC SDRAM Driver init - */ -void fsmcSdramInit(void) { - - fsmcInit(); - SDRAMD.sdram = FSMCD1.sdram; - SDRAMD.state = SDRAM_STOP; -} - -/** - * @brief Configures and activates the SDRAM peripheral. - * - * @param[in] sdramp pointer to the @p SDRAMDriver object - * @param[in] cfgp pointer to the @p SDRAMConfig object - */ -void fsmcSdramStart(SDRAMDriver *sdramp, const SDRAMConfig *cfgp) { - - if (FSMCD1.state == FSMC_STOP) - fsmcStart(&FSMCD1); - - osalDbgAssert((sdramp->state == SDRAM_STOP) || (sdramp->state == SDRAM_READY), - "SDRAM. Invalid state."); - - if (sdramp->state == SDRAM_STOP) { - - lld_sdram_start(sdramp, cfgp); - - sdramp->state = SDRAM_READY; - } -} - -/** - * @brief Deactivates the SDRAM peripheral. - * - * @param[in] sdramp pointer to the @p SDRAMDriver object - * - * @notapi - */ -void fsmcSdramStop(SDRAMDriver *sdramp) { - - if (sdramp->state == SDRAM_READY) { - lld_sdram_stop(sdramp); - sdramp->state = SDRAM_STOP; - } -} -#endif /* HAL_USE_FSMC_SDRAM == TRUE */ - - -#if (HAL_USE_FSMC_SRAM == TRUE) - -#include "hal_fsmc_sram_lld.h" - -/** - * @brief Low level SRAM driver initialization. - * - * @notapi - */ -void fsmcSramInit(void) { - - fsmcInit(); - -#if STM32_FSMC_USE_SRAM1 - SRAMD1.sram = FSMCD1.sram1; - SRAMD1.state = SRAM_STOP; -#endif /* STM32_FSMC_USE_SRAM1 */ - -#if STM32_FSMC_USE_SRAM2 - SRAMD2.sram = FSMCD1.sram2; - SRAMD2.state = SRAM_STOP; -#endif /* STM32_FSMC_USE_SRAM2 */ - -#if STM32_FSMC_USE_SRAM3 - SRAMD3.sram = FSMCD1.sram3; - SRAMD3.state = SRAM_STOP; -#endif /* STM32_FSMC_USE_SRAM3 */ - -#if STM32_FSMC_USE_SRAM4 - SRAMD4.sram = FSMCD1.sram4; - SRAMD4.state = SRAM_STOP; -#endif /* STM32_FSMC_USE_SRAM4 */ -} - -/** - * @brief Configures and activates the SRAM peripheral. - * - * @param[in] sramp pointer to the @p SRAMDriver object - * @param[in] cfgp pointer to the @p SRAMConfig object - * - * @notapi - */ -void fsmcSramStart(SRAMDriver *sramp, const SRAMConfig *cfgp) { - - if (FSMCD1.state == FSMC_STOP) - fsmcStart(&FSMCD1); - - osalDbgAssert((sramp->state == SRAM_STOP) || (sramp->state == SRAM_READY), - "invalid state"); - - if (sramp->state == SRAM_STOP) { - lld_sram_start(sramp, cfgp); - sramp->state = SRAM_READY; - } -} - -/** - * @brief Deactivates the SRAM peripheral. - * - * @param[in] sramp pointer to the @p SRAMDriver object - * - * @notapi - */ -void fsmcSramStop(SRAMDriver *sramp) { - - if (sramp->state == SRAM_READY) { - lld_sram_stop(sramp); - sramp->state = SRAM_STOP; - } -} - -#endif /* HAL_USE_FSMC_SRAM == TRUE */ - #endif /* HAL_USE_FSMC */ /** @} */ diff --git a/os/hal/src/hal_sdram.c b/os/hal/src/hal_sdram.c new file mode 100644 index 0000000..efa876b --- /dev/null +++ b/os/hal/src/hal_sdram.c @@ -0,0 +1,122 @@ +/* + ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio + Copyright (C) 2017 Fabien Poussin (fabien.poussin (at) google's mail) + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in sdramliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/** + * @file hal_sdram.c + * @brief SDRAM Driver code. + * + * @addtogroup SDRAM + * @{ + */ + +#include "hal.h" + +#if HAL_USE_SDRAM || defined(__DOXYGEN__) + + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables and types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +#include "hal_sdram_lld.h" + +/** + * @brief SDRAM Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. + * + * @init + */ +void sdramInit(void) { + fsmcInit(); + sdramObjectInit(&SDRAMD1); +} + +/** + * @brief Initializes the standard part of a @p SDRAMDriver structure. + * + * @param[out] sdramp pointer to the @p SDRAMDriver object + * + * @init + */ +void sdramObjectInit(SDRAMDriver *sdramp) { + + sdramp->sdram = FSMCD1.sdram; + sdramp->state = SDRAM_STOP; +} + +/** + * @brief Configures and activates the SDRAM peripheral. + * + * @param[in] sdramp pointer to the @p SDRAMDriver object + * @param[in] config pointer to the @p SDRAMConfig object + * + * @api + */ +void sdramStart(SDRAMDriver *sdramp, const SDRAMConfig *config) { + + osalDbgCheck((sdramp != NULL) && (config != NULL)); + + if (FSMCD1.state == FSMC_STOP) + fsmcStart(&FSMCD1); + + osalSysLock(); + osalDbgAssert((sdramp->state == SDRAM_STOP) || (sdramp->state == SDRAM_READY), + "invalid state"); + sdram_lld_start(sdramp, config); + sdramp->state = SDRAM_READY; + osalSysUnlock(); +} + +/** + * @brief Deactivates the SDRAM peripheral. + * + * @param[in] sdramp pointer to the @p SDRAMDriver object + * + * @api + */ +void sdramStop(SDRAMDriver *sdramp) { + + osalDbgCheck(sdramp != NULL); + + osalSysLock(); + osalDbgAssert((sdramp->state == SDRAM_STOP) || (sdramp->state == SDRAM_READY), + "invalid state"); + sdram_lld_stop(sdramp); + sdramp->state = SDRAM_STOP; + osalSysUnlock(); +} + +#endif /* HAL_USE_SDRAM */ + +/** @} */ diff --git a/os/hal/src/hal_sram.c b/os/hal/src/hal_sram.c new file mode 100644 index 0000000..892e9a2 --- /dev/null +++ b/os/hal/src/hal_sram.c @@ -0,0 +1,146 @@ +/* + ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio + Copyright (C) 2017 Fabien Poussin (fabien.poussin (at) google's mail) + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in sramliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/** + * @file hal_sram.c + * @brief SRAM Driver code. + * + * @addtogroup SRAM + * @{ + */ + +#include "hal.h" + +#if HAL_USE_SRAM || defined(__DOXYGEN__) + + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables and types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +#include "hal_sram_lld.h" + +/** + * @brief SRAM Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. + * + * @init + */ +void sramInit(void) { + + fsmcInit(); + +#if STM32_SRAM_USE_SRAM1 + SRAMD1.sram = FSMCD1.sram1; + SRAMD1.state = SRAM_STOP; + sramObjectInit(&SRAMD1); +#endif /* STM32_SRAM_USE_SRAM1 */ + +#if STM32_SRAM_USE_SRAM2 + SRAMD2.sram = FSMCD1.sram2; + SRAMD2.state = SRAM_STOP; + sramObjectInit(&SRAMD2); +#endif /* STM32_SRAM_USE_SRAM2 */ + +#if STM32_SRAM_USE_SRAM3 + SRAMD3.sram = FSMCD1.sram3; + SRAMD3.state = SRAM_STOP; + sramObjectInit(&SRAMD3); +#endif /* STM32_SRAM_USE_SRAM3 */ + +#if STM32_SRAM_USE_SRAM4 + SRAMD4.sram = FSMCD1.sram4; + SRAMD4.state = SRAM_STOP; + sramObjectInit(&SRAMD4); +#endif /* STM32_SRAM_USE_SRAM4 */ + +} + +/** + * @brief Initializes the standard part of a @p SRAMDriver structure. + * + * @param[out] sramp pointer to the @p SRAMDriver object + * + * @init + */ +void sramObjectInit(SRAMDriver *sramp) { + + sramp->state = SRAM_STOP; +} + +/** + * @brief Configures and activates the SRAM peripheral. + * + * @param[in] sramp pointer to the @p SRAMDriver object + * @param[in] config pointer to the @p SRAMConfig object + * + * @api + */ +void sramStart(SRAMDriver *sramp, const SRAMConfig *config) { + + osalDbgCheck((sramp != NULL) && (config != NULL)); + + if (FSMCD1.state == FSMC_STOP) + fsmcStart(&FSMCD1); + + osalSysLock(); + osalDbgAssert((sramp->state == SRAM_STOP) || (sramp->state == SRAM_READY), + "invalid state"); + sram_lld_start(sramp, config); + sramp->state = SRAM_READY; + osalSysUnlock(); +} + +/** + * @brief Deactivates the SRAM peripheral. + * + * @param[in] sramp pointer to the @p SRAMDriver object + * + * @api + */ +void sramStop(SRAMDriver *sramp) { + + osalDbgCheck(sramp != NULL); + + osalSysLock(); + osalDbgAssert((sramp->state == SRAM_STOP) || (sramp->state == SRAM_READY), + "invalid state"); + sram_lld_stop(sramp); + sramp->state = SRAM_STOP; + osalSysUnlock(); +} + +#endif /* HAL_USE_SRAM */ + +/** @} */ -- cgit v1.2.3