From: Junhwan Park Date: Fri, 16 Jun 2017 02:55:20 +0000 (+0900) Subject: Added watchdog code X-Git-Tag: 1.1_Public_Release~188^2~23 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=29c8050c2cf2a5317d6588f78d544df67ceb57a0;p=rtos%2Ftinyara.git Added watchdog code --- diff --git a/os/arch/arm/src/artik053/src/artik053_boot.c b/os/arch/arm/src/artik053/src/artik053_boot.c index 802d2ad..4383115 100644 --- a/os/arch/arm/src/artik053/src/artik053_boot.c +++ b/os/arch/arm/src/artik053/src/artik053_boot.c @@ -150,6 +150,14 @@ static void board_audio_initialize(void) #endif } +static void board_wdt_initialize(void) +{ +#ifdef CONFIG_WATCHDOG + s5j_wdg_initialize(CONFIG_WATCHDOG_DEVPATH); + putreg32(0x40C, 0x80090000); +#endif +} + /***************************************************************************** * Public Functions ****************************************************************************/ @@ -246,7 +254,7 @@ void board_initialize(void) board_i2c_initialize(); board_audio_initialize(); board_sensor_initialize(); - + board_wdt_initialize(); } #endif /* CONFIG_BOARD_INITIALIZE */ diff --git a/os/arch/arm/src/s5j/Make.defs b/os/arch/arm/src/s5j/Make.defs index d99e777..28deeaf 100644 --- a/os/arch/arm/src/s5j/Make.defs +++ b/os/arch/arm/src/s5j/Make.defs @@ -117,9 +117,13 @@ endif CHIP_CSRCS += s5j_boot.c s5j_irq.c CHIP_CSRCS += s5j_serial.c CHIP_CSRCS += s5j_mac.c -CHIP_CSRCS += s5j_watchdog.c CHIP_CSRCS += s5j_systemreset.c +CHIP_CSRCS += s5j_watchdog.c +ifeq ($(CONFIG_WATCHDOG),y) +CHIP_CSRCS += s5j_watchdog_lowerhalf.c +endif + CHIP_CSRCS += s5j_gpio.c ifeq ($(CONFIG_GPIO),y) CHIP_CSRCS += s5j_gpio_lowerhalf.c diff --git a/os/arch/arm/src/s5j/chip/s5jt200_watchdog.h b/os/arch/arm/src/s5j/chip/s5jt200_watchdog.h new file mode 100644 index 0000000..b70da34 --- /dev/null +++ b/os/arch/arm/src/s5j/chip/s5jt200_watchdog.h @@ -0,0 +1,80 @@ +/**************************************************************************** + * + * Copyright 2017 Samsung Electronics All Rights Reserved. + * + * 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. + * + ****************************************************************************/ +/**************************************************************************** + * arch/arm/src/s5j/chip/s5j200_watchdog.h + * + * Copyright (C) 2009-2010, 2014-2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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_S5J_CHIP_S5JT200_WATCHDOG_H +#define __ARCH_ARM_SRC_S5J_CHIP_S5JT200_WATCHDOG_H + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Register Address *********************************************************/ +#define S5J_WDT_WTCON 0x80030000 +#define S5J_WDT_WTDAT 0x80030004 +#define S5J_WDT_WTCNT 0x80030008 +#define S5J_WDT_WTCLRINT 0x8003000C + +#define S5J_WDT_OSC (26*1000*1000) + +/* Register Bitfield Definitions ********************************************/ + +/* WTCON register */ +#define WTCON_PRESCALER(a) ((a & 0xF) << 8) +#define WTCON_WATCHDOG_EN (1 << 5) +#define WTCON_WATCHDOG_DIS (0 << 5) +#define WTCON_CLOCK(a) ((a & 0x3) << 3) +#define WTCON_IRQ_EN (1 << 2) +#define WTCON_IRQ_DIS (0 << 2) +#define WTCON_RESET_EN (1 << 0) +#define WTCON_RESET_DIS (0 << 0) + +#endif /* __ARCH_ARM_SRC_S5J_CHIP_S5JT200_WATCHDOG_H */ diff --git a/os/arch/arm/src/s5j/s5j_watchdog.c b/os/arch/arm/src/s5j/s5j_watchdog.c index cdb0c57..cba1710 100644 --- a/os/arch/arm/src/s5j/s5j_watchdog.c +++ b/os/arch/arm/src/s5j/s5j_watchdog.c @@ -79,28 +79,6 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -#define WTCON 0x0000 -#define WTDAT 0x0004 -#define WTCNT 0x0008 -#define WTCLRINT 0x000C - -#define WTCON_RESET_MASK (1 << 0) -#define WTCON_RESET_DIS (0 << 0) -#define WTCON_RESET_EN (1 << 0) - -#define WTCON_IRQ_MASK (1 << 2) -#define WTCON_IRQ_DIS (0 << 2) -#define WTCON_IRQ_EN (1 << 2) - -#define WTCON_CLK_DIV_MASK (3 << 3) -#define WTCON_CLK_DIV(x) ((x & 3) << 3) - -#define WTCON_EN_MASK (1 << 5) -#define WTCON_DIS (0 << 5) -#define WTCON_EN (1 << 5) - -#define WTCON_PRESCALER_MASK (0xF << 8) -#define WTCON_PRESCALER(x) ((x & 0xF) << 8) /**************************************************************************** * Public Functions @@ -118,8 +96,9 @@ ****************************************************************************/ void s5j_watchdog_disable(void) { - unsigned int wtcon = (getreg32(S5J_WDT_BASE + WTCON) & ~WTCON_EN_MASK) | WTCON_DIS; - putreg32(wtcon, S5J_WDT_BASE + WTCON); + unsigned int wtcon = (getreg32(S5J_WDT_WTCON) & ~WTCON_WATCHDOG_EN) | WTCON_WATCHDOG_DIS; + + putreg32(wtcon, S5J_WDT_WTCON); } #ifdef CONFIG_S5J_WATCHDOG @@ -133,8 +112,9 @@ void s5j_watchdog_disable(void) ****************************************************************************/ void s5j_watchdog_enable(void) { - unsigned int wtcon = (getreg32(S5J_WDT_BASE + WTCON) & ~WTCON_EN_MASK) | WTCON_EN; - putreg32(wtcon, S5J_WDT_BASE + WTCON); + unsigned int wtcon = (getreg32(S5J_WDT_WTCON) & ~WTCON_WATCHDOG_EN) | WTCON_WATCHDOG_EN; + + putreg32(wtcon, S5J_WDT_WTCON); } /**************************************************************************** @@ -149,8 +129,9 @@ void s5j_watchdog_enable(void) ****************************************************************************/ void s5j_watchdog_reset_disable(void) { - unsigned int wtcon = (getreg32(S5J_WDT_BASE + WTCON) & ~WTCON_RESET_MASK) | WTCON_RESET_DIS; - putreg32(wtcon, S5J_WDT_BASE + WTCON); + unsigned int wtcon = (getreg32(S5J_WDT_WTCON) & ~WTCON_RESET_EN) | WTCON_RESET_DIS; + + putreg32(wtcon, S5J_WDT_WTCON); } /**************************************************************************** @@ -163,8 +144,9 @@ void s5j_watchdog_reset_disable(void) ****************************************************************************/ void s5j_watchdog_reset_enable(void) { - unsigned int wtcon = (getreg32(S5J_WDT_BASE + WTCON) & ~WTCON_RESET_MASK) | WTCON_RESET_EN; - putreg32(wtcon, S5J_WDT_BASE + WTCON); + unsigned int wtcon = (getreg32(S5J_WDT_WTCON) & ~WTCON_RESET_EN) | WTCON_RESET_EN; + + putreg32(wtcon, S5J_WDT_WTCON); } /**************************************************************************** @@ -177,8 +159,9 @@ void s5j_watchdog_reset_enable(void) ****************************************************************************/ void s5j_watchdog_irq_disable(void) { - unsigned int wtcon = (getreg32(S5J_WDT_BASE + WTCON) & ~WTCON_IRQ_MASK) | WTCON_IRQ_DIS; - putreg32(wtcon, S5J_WDT_BASE + WTCON); + unsigned int wtcon = (getreg32(S5J_WDT_WTCON) & ~WTCON_IRQ_EN) | WTCON_IRQ_DIS; + + putreg32(wtcon, S5J_WDT_WTCON); } /**************************************************************************** @@ -191,8 +174,9 @@ void s5j_watchdog_irq_disable(void) ****************************************************************************/ void s5j_watchdog_irq_enable(void) { - unsigned int wtcon = (getreg32(S5J_WDT_BASE + WTCON) & ~WTCON_IRQ_MASK) | WTCON_IRQ_EN; - putreg32(wtcon, S5J_WDT_BASE + WTCON); + unsigned int wtcon = (getreg32(S5J_WDT_WTCON) & ~WTCON_IRQ_EN) | WTCON_IRQ_EN; + + putreg32(wtcon, S5J_WDT_WTCON); } /**************************************************************************** @@ -211,12 +195,12 @@ void s5j_watchdog_irq_enable(void) ****************************************************************************/ void s5j_watchdog_clk_set(unsigned int prescaler, unsigned int divider) { - unsigned int wtcon = getreg32(S5J_WDT_BASE + WTCON); + unsigned int wtcon = getreg32(S5J_WDT_WTCON); - wtcon &= ~(WTCON_PRESCALER_MASK | WTCON_CLK_DIV_MASK); - wtcon |= WTCON_CLK_DIV(divider) | WTCON_PRESCALER(prescaler); + wtcon &= ~(WTCON_PRESCALER(0xFF) | WTCON_CLOCK(3)); + wtcon |= WTCON_CLOCK(divider) | WTCON_PRESCALER(prescaler); - putreg32(wtcon, S5J_WDT_BASE + WTCON); + putreg32(wtcon, S5J_WDT_WTCON); } /**************************************************************************** @@ -229,7 +213,7 @@ void s5j_watchdog_clk_set(unsigned int prescaler, unsigned int divider) ****************************************************************************/ void s5j_watchdog_set_reload_val(unsigned int reload_val) { - putreg32(reload_val, S5J_WDT_BASE + WTDAT); + putreg32(reload_val, S5J_WDT_WTDAT); } /**************************************************************************** @@ -240,7 +224,7 @@ void s5j_watchdog_set_reload_val(unsigned int reload_val) ****************************************************************************/ unsigned int s5j_watchdog_get_curr(void) { - return getreg32(S5J_WDT_BASE + WTCNT); + return getreg32(S5J_WDT_WTCNT); } /**************************************************************************** @@ -252,7 +236,7 @@ unsigned int s5j_watchdog_get_curr(void) ****************************************************************************/ void s5j_watchdog_set_curr(unsigned int curr_val) { - putreg32(curr_val, S5J_WDT_BASE + WTCNT); + putreg32(curr_val, S5J_WDT_WTCNT); } /**************************************************************************** @@ -264,6 +248,6 @@ void s5j_watchdog_set_curr(unsigned int curr_val) ****************************************************************************/ void s5j_watchdog_clear_int(void) { - putreg32(0xffffffff, S5J_WDT_BASE + WTCLRINT); + putreg32(0xffffffff, S5J_WDT_WTCLRINT); } #endif diff --git a/os/arch/arm/src/s5j/s5j_watchdog.h b/os/arch/arm/src/s5j/s5j_watchdog.h index b60c739..fdd0efe 100644 --- a/os/arch/arm/src/s5j/s5j_watchdog.h +++ b/os/arch/arm/src/s5j/s5j_watchdog.h @@ -58,6 +58,10 @@ ****************************************************************************/ #include +#if defined(CONFIG_S5J_S5JT200) +#include "chip/s5jt200_watchdog.h" +#endif + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -90,10 +94,12 @@ void s5j_watchdog_set_curr(unsigned int curr_val); void s5j_watchdog_clear_int(void); #endif +int s5j_wdg_initialize(FAR const char *devpath); + #undef EXTERN #if defined(__cplusplus) } #endif -#endif /* __ASSEMBLY__ */ -#endif /* __ARCH_ARM_SRC_S5J_S5J_WATCHDOG_H */ +#endif /* __ASSEMBLY__ */ +#endif /* __ARCH_ARM_SRC_S5J_S5J_WATCHDOG_H */