mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-26 01:17:51 +08:00
Implement STM32 IWDG driver
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4612 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
@@ -63,7 +63,7 @@ endif
|
||||
|
||||
CHIP_ASRCS =
|
||||
CHIP_CSRCS = stm32_allocateheap.c stm32_start.c stm32_rcc.c stm32_lse.c \
|
||||
stm32_gpio.c stm32_exti.c stm32_flash.c stm32_irq.c \
|
||||
stm32_lsi.c stm32_gpio.c stm32_exti.c stm32_flash.c stm32_irq.c \
|
||||
stm32_timerisr.c stm32_dma.c stm32_lowputc.c stm32_serial.c \
|
||||
stm32_spi.c stm32_sdio.c stm32_tim.c stm32_i2c.c stm32_waste.c
|
||||
|
||||
@@ -121,8 +121,12 @@ ifeq ($(CONFIG_CAN),y)
|
||||
CHIP_CSRCS += stm32_can.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIT_STM32_WWDG),y)
|
||||
CHIP_CSRCS += stm32_wdg.c
|
||||
ifeq ($(CONFIG_STM32_IWDG),y)
|
||||
CHIP_CSRCS += stm32_iwdg.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_STM32_WWDG),y)
|
||||
CHIP_CSRCS += stm32_wwdg.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_DEBUG),y)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/************************************************************************************
|
||||
* arch/arm/src/stm32/chip/stm32_wdg.h
|
||||
*
|
||||
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Copyright (C) 2009, 2011-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -61,14 +61,14 @@
|
||||
|
||||
/* Register Addresses ***************************************************************/
|
||||
|
||||
#define STM32_IWDG_KR (STM32_IWDG_OFFSET+STM32_IWDG_KR_OFFSET)
|
||||
#define STM32_IWDG_PR (STM32_IWDG_OFFSET+STM32_IWDG_PR_OFFSET)
|
||||
#define STM32_IWDG_RLR (STM32_IWDG_OFFSET+STM32_IWDG_RLR_OFFSET)
|
||||
#define STM32_IWDG_SR (STM32_IWDG_OFFSET+STM32_IWDG_SR_OFFSET)
|
||||
#define STM32_IWDG_KR (STM32_IWDG_BASE+STM32_IWDG_KR_OFFSET)
|
||||
#define STM32_IWDG_PR (STM32_IWDG_BASE+STM32_IWDG_PR_OFFSET)
|
||||
#define STM32_IWDG_RLR (STM32_IWDG_BASE+STM32_IWDG_RLR_OFFSET)
|
||||
#define STM32_IWDG_SR (STM32_IWDG_BASE+STM32_IWDG_SR_OFFSET)
|
||||
|
||||
#define STM32_WWDG_CR (STM32_WWDG_OFFSET+STM32_WWDG_CR_OFFSET)
|
||||
#define STM32_WWDG_CFR (STM32_WWDG_OFFSET+STM32_WWDG_CFR_OFFSET)
|
||||
#define STM32_WWDG_SR (STM32_WWDG_OFFSET+STM32_WWDG_SR_OFFSET)
|
||||
#define STM32_WWDG_CR (STM32_WWDG_BASE+STM32_WWDG_CR_OFFSET)
|
||||
#define STM32_WWDG_CFR (STM32_WWDG_BASE+STM32_WWDG_CFR_OFFSET)
|
||||
#define STM32_WWDG_SR (STM32_WWDG_BASE+STM32_WWDG_SR_OFFSET)
|
||||
|
||||
/* Register Bitfield Definitions ****************************************************/
|
||||
|
||||
@@ -77,6 +77,11 @@
|
||||
#define IWDG_KR_KEY_SHIFT (0) /* Bits 15-0: Key value (write only, read 0000h) */
|
||||
#define IWDG_KR_KEY_MASK (0xffff << IWDG_KR_KEY_SHIFT)
|
||||
|
||||
#define IWDG_KR_KEY_ENABLE (0x5555) /* Enable register access */
|
||||
#define IWDG_KR_KEY_DISABLE (0x0000) /* Disable register access */
|
||||
#define IWDG_KR_KEY_RELOAD (0xaaaa) /* Reload the counter */
|
||||
#define IWDG_KR_KEY_START (0xcccc) /* Start the watchdog */
|
||||
|
||||
/* Prescaler register (32-bit) */
|
||||
|
||||
#define IWDG_PR_SHIFT (0) /* Bits 2-0: Prescaler divider */
|
||||
@@ -94,6 +99,8 @@
|
||||
#define IWDG_RLR_RL_SHIFT (0) /* Bits11:0 RL[11:0]: Watchdog counter reload value */
|
||||
#define IWDG_RLR_RL_MASK (0x0fff << IWDG_RLR_RL_SHIFT)
|
||||
|
||||
#define IWDG_RLR_MAX (0xfff)
|
||||
|
||||
/* Status register (32-bit) */
|
||||
|
||||
#define IWDG_SR_PVU (1 << 0) /* Bit 0: Watchdog prescaler value update */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,94 @@
|
||||
/****************************************************************************
|
||||
* arch/arm/src/stm32/stm32_lsi.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.orgr>
|
||||
*
|
||||
* 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 <nuttx/config.h>
|
||||
|
||||
#include "up_arch.h"
|
||||
|
||||
#include "stm32_rcc.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_rcc_enablelsi
|
||||
*
|
||||
* Description:
|
||||
* Enable the Internal Low-Speed (LSI) RC Oscillator.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void stm32_rcc_enablelsi(void)
|
||||
{
|
||||
/* Enable the Internal Low-Speed (LSI) RC Oscillator by setting the LSION bit
|
||||
* the RCC CSR register.
|
||||
*/
|
||||
|
||||
modifyreg16(STM32_RCC_CSR, 0, RCC_CSR_LSION);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_rcc_disablelsi
|
||||
*
|
||||
* Description:
|
||||
* Disable the Internal Low-Speed (LSI) RC Oscillator.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void stm32_rcc_disablelsi(void)
|
||||
{
|
||||
/* Enable the Internal Low-Speed (LSI) RC Oscillator by setting the LSION bit
|
||||
* the RCC CSR register.
|
||||
*/
|
||||
|
||||
modifyreg16(STM32_RCC_CSR, RCC_CSR_LSION, 0);
|
||||
}
|
||||
@@ -185,6 +185,16 @@ EXTERN void stm32_clockconfig(void);
|
||||
|
||||
EXTERN void stm32_rcc_enablelse(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_rcc_enablelsi
|
||||
*
|
||||
* Description:
|
||||
* Enable the Internal Low-Speed (LSI) RC Oscillator.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN void stm32_rcc_enablelsi(void);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
||||
@@ -62,24 +62,45 @@ extern "C" {
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_wdginitialize
|
||||
* Name: stm32_iwdginitialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the watchdog time. The watchdog timer is intialized and
|
||||
* registers as /dev/watchdog0. The initial state of the watchdog time
|
||||
* is disabled.
|
||||
* Initialize the IWDG watchdog time. The watchdog timer is intialized and
|
||||
* registers as 'devpath. The initial state of the watchdog time is
|
||||
* disabled.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
* devpath - The full path to the watchdog. This should be of the form
|
||||
* /dev/watchdog0
|
||||
* lsifreq - The calibrated LSI clock frequency
|
||||
*
|
||||
* Returned Values:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN void stm32_wdginitialize(void);
|
||||
EXTERN void stm32_iwdginitialize(FAR const char *devpath, uint32_t lsifreq);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_wwdginitialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the WWDG watchdog time. The watchdog timer is intialized and
|
||||
* registers as 'devpath. The initial state of the watchdog time is
|
||||
* disabled.
|
||||
*
|
||||
* Input Parameters:
|
||||
* devpath - The full path to the watchdog. This should be of the form
|
||||
* /dev/watchdog0
|
||||
*
|
||||
* Returned Values:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN void stm32_wwdginitialize(FAR const char *devpath);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* arch/arm/src/stm32/stm32_pwm.c
|
||||
* arch/arm/src/stm32/stm32_wwdg.c
|
||||
*
|
||||
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -48,7 +48,7 @@
|
||||
#include "up_arch.h"
|
||||
#include "stm32_wdg.h"
|
||||
|
||||
#if defined(CONFIT_STM32_WWDG)
|
||||
#if defined(CONFIG_WATCHDOG) && defined(CONFIG_STM32_WWDG)
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
@@ -90,7 +90,7 @@ static int stm32_getstatus(FAR struct watchdog_lowerhalf_s *lower,
|
||||
static int stm32_settimeout(FAR struct watchdog_lowerhalf_s *lower,
|
||||
uint32_t timeout);
|
||||
static xcpt_t stm32_capture(FAR struct watchdog_lowerhalf_s *lower,
|
||||
static xcpt_t handler);
|
||||
xcpt_t handler);
|
||||
static int stm32_ioctl(FAR struct watchdog_lowerhalf_s *lower, int cmd,
|
||||
unsigned long arg);
|
||||
|
||||
@@ -218,7 +218,7 @@ static void stm32_putreg(uint32_t val, uint32_t addr)
|
||||
|
||||
static int stm32_start(FAR struct watchdog_lowerhalf_s *lower)
|
||||
{
|
||||
FAR struct stm32_lowerhalf_s *priv = ( FAR struct stm32_lowerhalf_s)lower;
|
||||
FAR struct stm32_lowerhalf_s *priv = (FAR struct stm32_lowerhalf_s *)lower;
|
||||
|
||||
DEBUGASSERT(priv);
|
||||
#warning "Missing logic"
|
||||
@@ -242,7 +242,7 @@ static int stm32_start(FAR struct watchdog_lowerhalf_s *lower)
|
||||
|
||||
static int stm32_stop(FAR struct watchdog_lowerhalf_s *lower)
|
||||
{
|
||||
FAR struct stm32_lowerhalf_s *priv = ( FAR struct stm32_lowerhalf_s)lower;
|
||||
FAR struct stm32_lowerhalf_s *priv = (FAR struct stm32_lowerhalf_s *)lower;
|
||||
|
||||
DEBUGASSERT(priv);
|
||||
#warning "Missing logic"
|
||||
@@ -250,7 +250,7 @@ static int stm32_stop(FAR struct watchdog_lowerhalf_s *lower)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name:
|
||||
* Name: stm32_keepalive
|
||||
*
|
||||
* Description:
|
||||
* Reset the watchdog timer to the current timeout value, prevent any
|
||||
@@ -268,7 +268,7 @@ static int stm32_stop(FAR struct watchdog_lowerhalf_s *lower)
|
||||
|
||||
static int stm32_keepalive(FAR struct watchdog_lowerhalf_s *lower)
|
||||
{
|
||||
FAR struct stm32_lowerhalf_s *priv = ( FAR struct stm32_lowerhalf_s)lower;
|
||||
FAR struct stm32_lowerhalf_s *priv = (FAR struct stm32_lowerhalf_s *)lower;
|
||||
|
||||
DEBUGASSERT(priv);
|
||||
#warning "Missing logic"
|
||||
@@ -294,7 +294,7 @@ static int stm32_keepalive(FAR struct watchdog_lowerhalf_s *lower)
|
||||
static int stm32_getstatus(FAR struct watchdog_lowerhalf_s *lower,
|
||||
FAR struct watchdog_status_s *status)
|
||||
{
|
||||
FAR struct stm32_lowerhalf_s *priv = ( FAR struct stm32_lowerhalf_s)lower;
|
||||
FAR struct stm32_lowerhalf_s *priv = (FAR struct stm32_lowerhalf_s *)lower;
|
||||
|
||||
DEBUGASSERT(priv);
|
||||
#warning "Missing logic"
|
||||
@@ -320,7 +320,7 @@ static int stm32_getstatus(FAR struct watchdog_lowerhalf_s *lower,
|
||||
static int stm32_settimeout(FAR struct watchdog_lowerhalf_s *lower,
|
||||
uint32_t timeout)
|
||||
{
|
||||
FAR struct stm32_lowerhalf_s *priv = ( FAR struct stm32_lowerhalf_s)lower;
|
||||
FAR struct stm32_lowerhalf_s *priv = (FAR struct stm32_lowerhalf_s *)lower;
|
||||
|
||||
DEBUGASSERT(priv);
|
||||
#warning "Missing logic"
|
||||
@@ -350,9 +350,9 @@ static int stm32_settimeout(FAR struct watchdog_lowerhalf_s *lower,
|
||||
****************************************************************************/
|
||||
|
||||
static xcpt_t stm32_capture(FAR struct watchdog_lowerhalf_s *lower,
|
||||
static xcpt_t handler)
|
||||
xcpt_t handler)
|
||||
{
|
||||
FAR struct stm32_lowerhalf_s *priv = ( FAR struct stm32_lowerhalf_s)lower;
|
||||
FAR struct stm32_lowerhalf_s *priv = (FAR struct stm32_lowerhalf_s *)lower;
|
||||
|
||||
DEBUGASSERT(priv);
|
||||
#warning "Missing logic"
|
||||
@@ -380,9 +380,9 @@ static xcpt_t stm32_capture(FAR struct watchdog_lowerhalf_s *lower,
|
||||
****************************************************************************/
|
||||
|
||||
static int stm32_ioctl(FAR struct watchdog_lowerhalf_s *lower, int cmd,
|
||||
unsigned long arg);
|
||||
unsigned long arg)
|
||||
{
|
||||
FAR struct stm32_lowerhalf_s *priv = ( FAR struct stm32_lowerhalf_s)lower;
|
||||
FAR struct stm32_lowerhalf_s *priv = (FAR struct stm32_lowerhalf_s *)lower;
|
||||
|
||||
DEBUGASSERT(priv);
|
||||
#warning "Missing logic"
|
||||
@@ -394,22 +394,23 @@ static int stm32_ioctl(FAR struct watchdog_lowerhalf_s *lower, int cmd,
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_wdginitialize
|
||||
* Name: stm32_wwdginitialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the watchdog time. The watchdog timer is intialized and
|
||||
* registers as /dev/watchdog0. The initial state of the watchdog time
|
||||
* is disabled.
|
||||
* Initialize the WWDG watchdog time. The watchdog timer is intialized and
|
||||
* registers as 'devpath. The initial state of the watchdog time is
|
||||
* disabled.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
* devpath - The full path to the watchdog. This should be of the form
|
||||
* /dev/watchdog0
|
||||
*
|
||||
* Returned Values:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void stm32_wdginitialize(void)
|
||||
void stm32_wwdginitialize(FAR const char *devpath)
|
||||
{
|
||||
FAR struct stm32_lowerhalf_s *priv = &g_wdgdev;
|
||||
|
||||
@@ -418,11 +419,11 @@ void stm32_wdginitialize(void)
|
||||
* only called once so it is never necessary to re-zero the structure.
|
||||
*/
|
||||
|
||||
priv->ops = &g_wdgops;
|
||||
priv->ops = &g_wdgops;
|
||||
|
||||
/* Register the watchdog driver as /dev/watchdog0 */
|
||||
|
||||
(void)watchdog_register("/dev/watchdog0", (FAR struct watchdog_lowerhalf_s *)priv);
|
||||
(void)watchdog_register(devpath, (FAR struct watchdog_lowerhalf_s *)priv);
|
||||
}
|
||||
|
||||
#endif /* CONFIT_STM32_WWDG */
|
||||
#endif /* CONFIG_WATCHDOG && CONFIG_STM32_WWDG */
|
||||
Reference in New Issue
Block a user