diff options
Diffstat (limited to 'os/hal/src')
-rw-r--r-- | os/hal/src/hal_community.c | 4 | ||||
-rw-r--r-- | os/hal/src/hal_fsmc.c | 201 | ||||
-rw-r--r-- | os/hal/src/hal_sdram.c | 122 | ||||
-rw-r--r-- | os/hal/src/hal_sram.c | 146 |
4 files changed, 473 insertions, 0 deletions
diff --git a/os/hal/src/hal_community.c b/os/hal/src/hal_community.c index ad05fe4..02de5cd 100644 --- a/os/hal/src/hal_community.c +++ b/os/hal/src/hal_community.c @@ -84,6 +84,10 @@ void halCommunityInit(void) { #if HAL_USE_COMP || defined(__DOXYGEN__)
compInit();
#endif
+
+#if HAL_USE_FSMC || defined(__DOXYGEN__)
+ fsmcInit();
+#endif
}
#endif /* HAL_USE_COMMUNITY */
diff --git a/os/hal/src/hal_fsmc.c b/os/hal/src/hal_fsmc.c new file mode 100644 index 0000000..c3f2a99 --- /dev/null +++ b/os/hal/src/hal_fsmc.c @@ -0,0 +1,201 @@ +/* + ChibiOS/HAL - Copyright (C) 2014 Uladzimir Pylinsky aka barthess + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance 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_fsmc.c + * @brief FSMC Driver subsystem low level driver source template. + * + * @addtogroup FSMC + * @{ + */ +#include "hal.h" + +#if (HAL_USE_SDRAM == TRUE) || (HAL_USE_SRAM == TRUE) || (HAL_USE_NAND == TRUE) || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + + + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/** + * @brief FSMC1 driver identifier. + */ +#if STM32_FSMC_USE_FSMC1 || defined(__DOXYGEN__) +FSMCDriver FSMCD1; +#endif + +/*===========================================================================*/ +/* Driver local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables and types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver interrupt handlers. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief Low level FSMC driver initialization. + * + * @notapi + */ +void fsmcInit(void) { + + if (FSMCD1.state == FSMC_UNINIT) { + FSMCD1.state = FSMC_STOP; +#if HAL_USE_SRAM +#if STM32_SRAM_USE_SRAM1 + FSMCD1.sram1 = (FSMC_SRAM_TypeDef *)(FSMC_Bank1_R_BASE); +#endif + +#if STM32_SRAM_USE_SRAM2 + FSMCD1.sram2 = (FSMC_SRAM_TypeDef *)(FSMC_Bank1_R_BASE + 8); +#endif + +#if STM32_SRAM_USE_SRAM3 + FSMCD1.sram3 = (FSMC_SRAM_TypeDef *)(FSMC_Bank1_R_BASE + 8 * 2); +#endif + +#if STM32_SRAM_USE_SRAM4 + FSMCD1.sram4 = (FSMC_SRAM_TypeDef *)(FSMC_Bank1_R_BASE + 8 * 3); +#endif +#endif + +#if HAL_USE_NAND +#if STM32_NAND_USE_NAND1 + FSMCD1.nand1 = (FSMC_NAND_TypeDef *)FSMC_Bank2_R_BASE; +#endif + +#if STM32_NAND_USE_NAND2 + FSMCD1.nand2 = (FSMC_NAND_TypeDef *)FSMC_Bank3_R_BASE; +#endif +#endif + +#if HAL_USE_SDRAM +#if (defined(STM32F427xx) || defined(STM32F437xx) || \ + defined(STM32F429xx) || defined(STM32F439xx) || \ + defined(STM32F745xx) || defined(STM32F746xx) || \ + defined(STM32F756xx) || defined(STM32F767xx) || \ + defined(STM32F769xx) || defined(STM32F777xx) || \ + defined(STM32F779xx)) + #if STM32_SDRAM_USE_SDRAM1 || STM32_SDRAM_USE_SDRAM2 + FSMCD1.sdram = (FSMC_SDRAM_TypeDef *)FSMC_Bank5_6_R_BASE; + #endif +#endif +#endif + } +} + +/** + * @brief Configures and activates the FSMC peripheral. + * + * @param[in] fsmcp pointer to the @p FSMCDriver object + * + * @notapi + */ +void fsmcStart(FSMCDriver *fsmcp) { + + osalDbgAssert((fsmcp->state == FSMC_STOP) || (fsmcp->state == FSMC_READY), + "invalid state"); + + if (fsmcp->state == FSMC_STOP) { + /* Enables the peripheral.*/ +#if STM32_FSMC_USE_FSMC1 + if (&FSMCD1 == fsmcp) { +#ifdef rccResetFSMC + rccResetFSMC(); +#endif + rccEnableFSMC(FALSE); +#if HAL_USE_NAND + nvicEnableVector(STM32_FSMC_NUMBER, STM32_FSMC_FSMC1_IRQ_PRIORITY); +#endif + } +#endif /* STM32_FSMC_USE_FSMC1 */ + + fsmcp->state = FSMC_READY; + } +} + +/** + * @brief Deactivates the FSMC peripheral. + * + * @param[in] emcp pointer to the @p FSMCDriver object + * + * @notapi + */ +void fsmcStop(FSMCDriver *fsmcp) { + + if (fsmcp->state == FSMC_READY) { + /* Resets the peripheral.*/ +#ifdef rccResetFSMC + rccResetFSMC(); +#endif + + /* Disables the peripheral.*/ +#if STM32_FSMC_USE_FSMC1 + if (&FSMCD1 == fsmcp) { +#if HAL_USE_NAND + nvicDisableVector(STM32_FSMC_NUMBER); +#endif + rccDisableFSMC(); + } +#endif /* STM32_FSMC_USE_FSMC1 */ + + fsmcp->state = FSMC_STOP; + } +} + +/** + * @brief FSMC shared interrupt handler. + * + * @notapi + */ +CH_IRQ_HANDLER(STM32_FSMC_HANDLER) { + + CH_IRQ_PROLOGUE(); +#if HAL_USE_NAND +#if STM32_NAND_USE_NAND1 + if (FSMCD1.nand1->SR & FSMC_SR_ISR_MASK) { + NANDD1.isr_handler(&NANDD1); + } +#endif +#if STM32_NAND_USE_NAND2 + if (FSMCD1.nand2->SR & FSMC_SR_ISR_MASK) { + NANDD2.isr_handler(&NANDD2); + } +#endif +#endif + CH_IRQ_EPILOGUE(); +} + +#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 */ + +/** @} */ |