File indexing completed on 2025-05-11 08:23:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #include <assert.h>
0023 #include <rtems/status-checks.h>
0024 #include <bsp.h>
0025 #include <bsp/irq.h>
0026 #include <bsp/watchdog.h>
0027 #include <bsp/io.h>
0028
0029 inline bool lpc176x_been_reset_by_watchdog( void )
0030 {
0031 return ( ( LPC176X_WDMOD & LPC176X_WWDT_MOD_WDTOF ) ==
0032 LPC176X_WWDT_MOD_WDTOF );
0033 }
0034
0035 inline void lpc176x_watchdog_reset( void )
0036 {
0037 LPC176X_WDFEED = LPC176X_WDFEED_CON;
0038 LPC176X_WDFEED = LPC176X_WDFEED_CFG;
0039 }
0040
0041
0042
0043
0044
0045
0046
0047 static inline rtems_status_code enable_module_and_set_clocksel(
0048 const lpc176x_microseconds tcount )
0049 {
0050 rtems_status_code status_code;
0051
0052
0053 LPC176X_WDCLKSEL = LPC176X_WWDT_CLKSEL_WDSEL_PCLK;
0054
0055
0056 status_code = lpc176x_module_enable( LPC176X_MODULE_WD,
0057 LPC176X_MODULE_PCLK_DEFAULT );
0058 RTEMS_CHECK_SC( status_code, "Enabling the watchdog module." );
0059
0060
0061 LPC176X_WDTC = ( LPC176X_CCLK / LPC176X_WD_PRESCALER_DIVISOR ) * tcount;
0062
0063 return status_code;
0064 }
0065
0066 rtems_status_code lpc176x_watchdog_config( const lpc176x_microseconds tcount )
0067 {
0068 rtems_status_code status_code = enable_module_and_set_clocksel( tcount );
0069
0070
0071 LPC176X_WDMOD = LPC176X_WWDT_MOD_WDEN | LPC176X_WWDT_MOD_WDRESET;
0072
0073
0074
0075 lpc176x_watchdog_reset();
0076
0077 return status_code;
0078 }
0079
0080 rtems_status_code lpc176x_watchdog_config_with_interrupt(
0081 const lpc176x_wd_isr_funct interrupt,
0082 const lpc176x_microseconds tcount
0083 )
0084 {
0085 rtems_status_code status_code = enable_module_and_set_clocksel( tcount );
0086
0087
0088 LPC176X_WDMOD = LPC176X_WWDT_MOD_WDEN | LPC176X_WWDT_MOD_WDINT;
0089
0090 status_code = rtems_interrupt_handler_install(
0091 LPC176X_WD_INTERRUPT_VECTOR_NUMBER,
0092 "watchdog_interrupt",
0093 RTEMS_INTERRUPT_UNIQUE,
0094 interrupt,
0095 NULL );
0096
0097
0098
0099 lpc176x_watchdog_reset();
0100
0101 return status_code;
0102 }