source: rtems/c/src/lib/libbsp/arm/lpc176x/watchdog/watchdog.c @ 19260fb

4.115
Last change on this file since 19260fb was 19260fb, checked in by Martin Boretto <martin.boretto@…>, on Jun 9, 2014 at 2:27:18 PM

bsp/lpc176x: New BSP

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/**
2 * @file watchdog.c
3 *
4 * @ingroup lpc176x
5 *
6 * @brief Watchdog controller for the mbed lpc176x family boards.
7 */
8
9/*
10 * Copyright (c) 2014 Taller Technologies.
11 *
12 * @author  Boretto Martin    (martin.boretto@tallertechnologies.com)
13 * @author  Diaz Marcos (marcos.diaz@tallertechnologies.com)
14 * @author  Lenarduzzi Federico  (federico.lenarduzzi@tallertechnologies.com)
15 * @author  Daniel Chicco  (daniel.chicco@tallertechnologies.com)
16 *
17 * The license and distribution terms for this file may be
18 * found in the file LICENSE in this distribution or at
19 * http://www.rtems.com/license/LICENSE.
20 */
21
22#include <assert.h>
23#include <rtems/status-checks.h>
24#include <bsp.h>
25#include <bsp/irq.h>
26#include <bsp/watchdog.h>
27#include <bsp/io.h>
28
29inline bool lpc176x_been_reset_by_watchdog( void )
30{
31  return ( ( LPC176X_WDMOD & LPC176X_WWDT_MOD_WDTOF ) ==
32           LPC176X_WWDT_MOD_WDTOF );
33}
34
35inline void lpc176x_watchdog_reset( void )
36{
37  LPC176X_WDFEED = LPC176X_WDFEED_CON;
38  LPC176X_WDFEED = LPC176X_WDFEED_CFG;
39}
40
41/**
42 * @brief Enables the watchdog module, sets wd clock and wd timer.
43 *
44 * @param  tcount Timer's out value.
45 * @return RTEMS_SUCCESSFUL if the configuration was done successfully.
46 */
47static inline rtems_status_code enable_module_and_set_clocksel(
48  const lpc176x_microseconds tcount )
49{
50  rtems_status_code status_code;
51
52  /* Sets clock. */
53  LPC176X_WDCLKSEL = LPC176X_WWDT_CLKSEL_WDSEL_PCLK;
54
55  /* Enables the watchdog module.  */
56  status_code = lpc176x_module_enable( LPC176X_MODULE_WD,
57    LPC176X_MODULE_PCLK_DEFAULT );
58  RTEMS_CHECK_SC( status_code, "Enabling the watchdog module." );
59
60  /* Set the watchdog timer constant value. */
61  LPC176X_WDTC = ( LPC176X_CCLK / LPC176X_WD_PRESCALER_DIVISOR ) * tcount;
62
63  return status_code;
64}
65
66rtems_status_code lpc176x_watchdog_config( const lpc176x_microseconds tcount )
67{
68  rtems_status_code status_code = enable_module_and_set_clocksel( tcount );
69
70  /* Setup the Watchdog timer operating mode in WDMOD register. */
71  LPC176X_WDMOD = LPC176X_WWDT_MOD_WDEN | LPC176X_WWDT_MOD_WDRESET;
72
73  /* Enable the Watchdog by writing 0xAA followed by 0x55 to the
74      WDFEED register. */
75  lpc176x_watchdog_reset();
76
77  return status_code;
78}
79
80rtems_status_code lpc176x_watchdog_config_with_interrupt(
81  const lpc176x_wd_isr_funct interrupt,
82  const lpc176x_microseconds tcount
83)
84{
85  rtems_status_code status_code = enable_module_and_set_clocksel( tcount );
86
87  /* Setup the Watchdog timer operating mode in WDMOD register. */
88  LPC176X_WDMOD = LPC176X_WWDT_MOD_WDEN | LPC176X_WWDT_MOD_WDINT;
89
90  status_code = rtems_interrupt_handler_install(
91    LPC176X_WD_INTERRUPT_VECTOR_NUMBER,
92    "watchdog_interrupt",
93    RTEMS_INTERRUPT_UNIQUE,
94    interrupt,
95    NULL );
96
97  /* Enable the Watchdog by writing 0xAA followed by 0x55 to the
98      WDFEED register. */
99  lpc176x_watchdog_reset();
100
101  return status_code;
102}
Note: See TracBrowser for help on using the repository browser.