summaryrefslogtreecommitdiffstats
path: root/bsps/sparc/leon3/btimer/watchdog.c
diff options
context:
space:
mode:
Diffstat (limited to 'bsps/sparc/leon3/btimer/watchdog.c')
-rw-r--r--bsps/sparc/leon3/btimer/watchdog.c52
1 files changed, 37 insertions, 15 deletions
diff --git a/bsps/sparc/leon3/btimer/watchdog.c b/bsps/sparc/leon3/btimer/watchdog.c
index 4e8f428f78..919744496f 100644
--- a/bsps/sparc/leon3/btimer/watchdog.c
+++ b/bsps/sparc/leon3/btimer/watchdog.c
@@ -1,3 +1,5 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
/* GPTIMER Watchdog timer routines. On some systems the first GPTIMER
* core's last Timer instance underflow signal is connected to system
* reset.
@@ -5,20 +7,35 @@
* COPYRIGHT (c) 2012.
* Cobham Gaisler AB.
*
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rtems.org/license/LICENSE.
+ * 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.
+ *
+ * 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.
*/
#include <bsp.h>
+#include <bsp/leon3.h>
#include <bsp/watchdog.h>
-#include <grlib/grlib.h>
-
-extern volatile struct gptimer_regs *LEON3_Timer_Regs;
struct gptimer_watchdog_priv {
- struct gptimer_regs *regs;
- struct gptimer_timer_regs *timer;
+ gptimer *regs;
+ gptimer_timer *timer;
int timerno;
};
@@ -41,10 +58,10 @@ int bsp_watchdog_init(void)
* functionality is available or not, we assume that it is if we
* reached this function.
*/
- bsp_watchdogs[0].regs = (struct gptimer_regs *)LEON3_Timer_Regs;
+ bsp_watchdogs[0].regs = LEON3_Timer_Regs;
/* Find Timer that has watchdog functionality */
- timercnt = bsp_watchdogs[0].regs->cfg & 0x7;
+ timercnt = grlib_load_32(&bsp_watchdogs[0].regs->config) & 0x7;
if (timercnt < 2) /* First timer system clock timer */
return 0;
@@ -57,6 +74,9 @@ int bsp_watchdog_init(void)
void bsp_watchdog_reload(int watchdog, unsigned int reload_value)
{
+ gptimer_timer *timer;
+ uint32_t tctrl;
+
if (bsp_watchdog_count == 0)
bsp_watchdog_init();
@@ -64,10 +84,12 @@ void bsp_watchdog_reload(int watchdog, unsigned int reload_value)
return;
/* Kick watchdog, and clear interrupt pending bit */
- bsp_watchdogs[watchdog].timer->reload = reload_value;
- bsp_watchdogs[watchdog].timer->ctrl =
- (GPTIMER_TIMER_CTRL_LD | GPTIMER_TIMER_CTRL_EN) |
- (bsp_watchdogs[watchdog].timer->ctrl & ~(1<<4));
+ timer = bsp_watchdogs[watchdog].timer;
+ grlib_store_32(&timer->trldval, reload_value);
+ tctrl = grlib_load_32(&timer->tctrl);
+ tctrl |= GPTIMER_TCTRL_LD | GPTIMER_TCTRL_EN;
+ tctrl &= ~GPTIMER_TCTRL_IP;
+ grlib_store_32(&timer->tctrl, tctrl);
}
void bsp_watchdog_stop(int watchdog)
@@ -79,7 +101,7 @@ void bsp_watchdog_stop(int watchdog)
return;
/* Stop watchdog timer */
- bsp_watchdogs[watchdog].timer->ctrl = 0;
+ grlib_store_32(&bsp_watchdogs[watchdog].timer->tctrl, 0);
}
/* Use watchdog timer to reset system */