From 2f3fb088697387cddb37e879e0d50b1050133e71 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 23 Jan 2015 15:25:10 -0600 Subject: [PATCH] Add support for the EFM32 reset management unit (RMU). From Pierre-noel Bouteville --- arch/arm/src/efm32/Kconfig | 4 ++ arch/arm/src/efm32/Make.defs | 4 ++ arch/arm/src/efm32/efm32_rmu.c | 125 +++++++++++++++++++++++++++++++++ arch/arm/src/efm32/efm32_rmu.h | 68 ++++++++++++++++++ 4 files changed, 201 insertions(+) create mode 100644 arch/arm/src/efm32/efm32_rmu.c create mode 100644 arch/arm/src/efm32/efm32_rmu.h diff --git a/arch/arm/src/efm32/Kconfig b/arch/arm/src/efm32/Kconfig index 1f7f8f8528..18d6d7ec53 100644 --- a/arch/arm/src/efm32/Kconfig +++ b/arch/arm/src/efm32/Kconfig @@ -128,6 +128,10 @@ config EFM32_DMA default n select ARCH_DMA +config EFM32_RMU + bool "Reset Management Unit (RMU) " + default n + config EFM32_USART0 bool "USART0" default n diff --git a/arch/arm/src/efm32/Make.defs b/arch/arm/src/efm32/Make.defs index 6df8b4eddf..c730fb5218 100644 --- a/arch/arm/src/efm32/Make.defs +++ b/arch/arm/src/efm32/Make.defs @@ -111,6 +111,10 @@ CHIP_CSRCS += efm32_serial.c endif endif +ifeq ($(CONFIG_EFM32_RMU),y) +CHIP_CSRCS += efm32_rmu.c +endif + ifeq ($(CONFIG_EFM32_USART_ISSPI),y) CHIP_CSRCS += efm32_spi.c endif diff --git a/arch/arm/src/efm32/efm32_rmu.c b/arch/arm/src/efm32/efm32_rmu.c new file mode 100644 index 0000000000..93a16ce63f --- /dev/null +++ b/arch/arm/src/efm32/efm32_rmu.c @@ -0,0 +1,125 @@ +/************************************************************************************ + * arch/arm/src/efm32/efm32_rmu.c + * + * Copyright (C) 2015 Pierre-Noel Bouteville. All rights reserved. + * Author: Pierre-Noel Bouteville + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include "up_arch.h" + +#include "chip/efm32_emu.h" +#include "chip/efm32_rmu.h" + +#include "emf32_rmu.h" + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ + +/************************************************************************************ + * Private Types + ************************************************************************************/ + +/************************************************************************************ + * Private Data + ************************************************************************************/ + +/************************************************************************************ + * Public Data + ************************************************************************************/ + +/* Variable old last reset cause of cpu. */ + +uint32_t g_efm32_rstcause; + +/************************************************************************************ + * Private Functions + ************************************************************************************/ + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: efm32_rmu_initialize + * + * Description: + * Store reset cause into g_efm32_rstcause then clear reset cause register. + * + ************************************************************************************/ + +void efm32_rmu_initialize(void) +{ + uint32_t locked; + + g_efm32_rstcause = getreg32(EFM32_RMU_RSTCAUSE); + + /* Now clear reset cause */ + + putreg32(RMU_CMD_RCCLR,EFM32_RMU_CMD); + + /* Clear some reset causes not cleared with RMU CMD register + * (If EMU registers locked, they must be unlocked first) + */ + + locked = getreg32(EFM32_EMU_LOCK) & EMU_LOCK_LOCKKEY_LOCKED; + if (locked) + { + /* EMU unlock */ + + putreg32(EMU_LOCK_LOCKKEY_LOCK,EMU_LOCK_LOCKKEY_UNLOCK); + } + + modifyreg32(EFM32_EMU_AUXCTRL,0,EMU_AUXCTRL_HRCCLR); + modifyreg32(EFM32_EMU_AUXCTRL,EMU_AUXCTRL_HRCCLR,0); + + if (locked) + { + /* EMU lock */ + + putreg32(EMU_LOCK_LOCKKEY_LOCK,EMU_LOCK_LOCKKEY_LOCK); + } +} diff --git a/arch/arm/src/efm32/efm32_rmu.h b/arch/arm/src/efm32/efm32_rmu.h new file mode 100644 index 0000000000..2887afe655 --- /dev/null +++ b/arch/arm/src/efm32/efm32_rmu.h @@ -0,0 +1,68 @@ +/***************************************************************************** + * arch/arm/src/efm32/efm32_rmu.h + * + * Copyright (C) 2015 Pierre-noel Bouteville . All rights reserved. + * Authors: Pierre-noel Bouteville + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_EFM32_EFM32_RMU_H +#define __ARCH_ARM_SRC_EFM32_EFM32_RMU_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include "chip/efm32_rmu.h" + +#ifdef CONFIG_EFM32_RMU + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +extern uint32_t g_efm32_rstcause; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ +/************************************************************************************ + * Name: efm32_rmu_initialize + * + * Description: + * Store reset cause into g_efm32_rstcause then clear reset cause register. + * + ************************************************************************************/ + +void efm32_rmu_initialize(void); + +#endif /* CONFIG_EFM32_RMU */ +#endif /* __ARCH_ARM_SRC_EFM32_EFM32_RMU_H */