SmartSnippets DA1459x SDK
hw_watchdog.h
Go to the documentation of this file.
1 
42 #ifndef HW_WATCHDOG_H_
43 #define HW_WATCHDOG_H_
44 
45 
46 #include <stdbool.h>
47 #include <stdint.h>
48 #include <sdk_defs.h>
49 
50 #define NMI_MAGIC_NUMBER 0xDEADBEEF
51 
58 extern volatile uint32_t nmi_event_data[9];
59 
66 typedef enum {
69 } HW_WDG_RESET;
70 
77 typedef void (*hw_watchdog_interrupt_cb)(unsigned long *exception_args);
78 
79 
86 __ALWAYS_RETAINED_CODE bool hw_watchdog_freeze(void);
87 
94 __RETAINED_CODE bool hw_watchdog_unfreeze(void);
95 
99 __STATIC_FORCEINLINE bool hw_watchdog_check_write_busy(void)
100 {
101  return (!!(REG_GETF(SYS_WDOG, WATCHDOG_CTRL_REG, WRITE_BUSY)));
102 }
103 
115 __STATIC_INLINE void hw_watchdog_write_value_ctrl(bool enable)
116 {
118  if (enable) {
119  REG_SETF(SYS_WDOG, WATCHDOG_REG, WDOG_WEN, 0x0);
120  }
121  else {
122  REG_SETF(SYS_WDOG, WATCHDOG_REG, WDOG_WEN, 0xff);
123  }
124 }
125 
136 __STATIC_FORCEINLINE void hw_watchdog_set_pos_val(uint16_t value)
137 {
138  uint32_t tmp;
139 
140  ASSERT_WARNING(SYS_WDOG_WATCHDOG_REG_WDOG_VAL_Msk >= value); // check if reload value is greater than max allowed value
141  ASSERT_WARNING(!REG_GETF(SYS_WDOG, WATCHDOG_REG, WDOG_WEN)); // can not write register if WDOG_WEN is not zero
142  tmp = SYS_WDOG->WATCHDOG_REG;
143  REG_SET_FIELD(SYS_WDOG, WATCHDOG_REG, WDOG_VAL_NEG, tmp, 0);
144  REG_SET_FIELD(SYS_WDOG, WATCHDOG_REG, WDOG_VAL, tmp, value);
145 
146  /* Wait until a new WDOG_VAL can be written in the Watchdog timer */
148 
149  /* Write a new WDOG_VAL in the Watchdog timer */
150  SYS_WDOG->WATCHDOG_REG = tmp;
151 
152 }
153 
162 __STATIC_INLINE void hw_watchdog_set_neg_val(uint16_t value)
163 {
164  uint32_t tmp;
165 
166  ASSERT_WARNING(SYS_WDOG_WATCHDOG_REG_WDOG_VAL_Msk >= value); // check if reload value is greater than max allowed value
167  ASSERT_WARNING(!REG_GETF(SYS_WDOG, WATCHDOG_REG, WDOG_WEN)); // can not write register if WDOG_WEN is not zero
168  tmp = SYS_WDOG->WATCHDOG_REG;
169  REG_SET_FIELD(SYS_WDOG, WATCHDOG_REG, WDOG_VAL_NEG, tmp, 1);
170  REG_SET_FIELD(SYS_WDOG, WATCHDOG_REG, WDOG_VAL, tmp, value);
171 
172  /* Wait until a new WDOG_VAL can be written in the Watchdog timer */
174 
175  /* Write a new WDOG_VAL in the Watchdog timer */
176  SYS_WDOG->WATCHDOG_REG = tmp;
177 
178 }
179 
184 __STATIC_INLINE uint16_t hw_watchdog_get_val(void)
185 {
186  // The watchdog value cannot be read while watchdog is busy writing a new value
188 
189  return REG_GETF(SYS_WDOG, WATCHDOG_REG, WDOG_VAL);
190 }
191 
196 __STATIC_FORCEINLINE void hw_watchdog_gen_RST(void)
197 {
198  REG_SET_BIT(SYS_WDOG, WATCHDOG_CTRL_REG, NMI_RST);
199 }
200 
205 __STATIC_FORCEINLINE void hw_watchdog_gen_NMI(void)
206 {
207  REG_CLR_BIT(SYS_WDOG, WATCHDOG_CTRL_REG, NMI_RST);
208 }
209 
221 __STATIC_INLINE void hw_watchdog_freeze_ctrl(bool enable)
222 {
223  if (enable) {
224  REG_SET_BIT(SYS_WDOG, WATCHDOG_CTRL_REG, WDOG_FREEZE_EN);
225  }
226  else {
227  REG_CLR_BIT(SYS_WDOG, WATCHDOG_CTRL_REG, WDOG_FREEZE_EN);
228  }
229 }
230 
238 
243 __RETAINED_CODE void hw_watchdog_unregister_int(void);
244 
251 __RETAINED_CODE void hw_watchdog_handle_int(unsigned long *hardfault_args);
252 
262 
263 
264 #endif /* HW_WATCHDOG_H_ */
265 
266 
hw_watchdog_check_write_busy
__STATIC_FORCEINLINE bool hw_watchdog_check_write_busy(void)
Check if watchdog is busy writing the watchdog counter.
Definition: hw_watchdog.h:99
hw_watchdog_freeze
__ALWAYS_RETAINED_CODE bool hw_watchdog_freeze(void)
Freeze the watchdog.
REG_SETF
#define REG_SETF(base, reg, field, new_val)
Set the value of a register field.
Definition: sdk_defs.h:738
REG_CLR_BIT
#define REG_CLR_BIT(base, reg, field)
Clear a bit of a register.
Definition: sdk_defs.h:781
REG_SET_BIT
#define REG_SET_BIT(base, reg, field)
Set a bit of a register.
Definition: sdk_defs.h:766
hw_watchdog_interrupt_cb
void(* hw_watchdog_interrupt_cb)(unsigned long *exception_args)
Watchdog timer interrupt callback.
Definition: hw_watchdog.h:77
hw_watchdog_get_val
__STATIC_INLINE uint16_t hw_watchdog_get_val(void)
Get reload value of the watchdog timer.
Definition: hw_watchdog.h:184
HW_WDG_RESET_NMI
Definition: hw_watchdog.h:67
sdk_defs.h
Central include header file with platform definitions.
hw_watchdog_is_irq_or_rst_gen
HW_WDG_RESET hw_watchdog_is_irq_or_rst_gen(void)
Check what is generated when watchdog reaches 0 value.
HW_WDG_RESET
HW_WDG_RESET
Types of generated states if reload value is 0.
Definition: hw_watchdog.h:66
hw_watchdog_freeze_ctrl
__STATIC_INLINE void hw_watchdog_freeze_ctrl(bool enable)
Enable/disable Watchdog freeze functionality.
Definition: hw_watchdog.h:221
hw_watchdog_set_pos_val
__STATIC_FORCEINLINE void hw_watchdog_set_pos_val(uint16_t value)
Set positive reload value of the watchdog timer.
Definition: hw_watchdog.h:136
hw_watchdog_register_int
void hw_watchdog_register_int(hw_watchdog_interrupt_cb handler)
Register an interrupt handler.
SYS_WDOG_WATCHDOG_REG_WDOG_VAL_Msk
#define SYS_WDOG_WATCHDOG_REG_WDOG_VAL_Msk
Definition: DA1459x-00.h:4957
HW_WDG_RESET_RST
Definition: hw_watchdog.h:68
nmi_event_data
volatile uint32_t nmi_event_data[9]
Holds the stack contents when an NMI occurs.
hw_watchdog_unfreeze
__RETAINED_CODE bool hw_watchdog_unfreeze(void)
Unfreeze the watchdog.
hw_watchdog_write_value_ctrl
__STATIC_INLINE void hw_watchdog_write_value_ctrl(bool enable)
Enable/disable writing the Watchdog timer reload value. This filter prevents unintentionally setting ...
Definition: hw_watchdog.h:115
hw_watchdog_gen_NMI
__STATIC_FORCEINLINE void hw_watchdog_gen_NMI(void)
Generate an NMI when reload value reaches 0.
Definition: hw_watchdog.h:205
REG_GETF
#define REG_GETF(base, reg, field)
Return the value of a register field.
Definition: sdk_defs.h:711
REG_SET_FIELD
#define REG_SET_FIELD(base, reg, field, var, val)
Set register field value.
Definition: sdk_defs.h:626
hw_watchdog_set_neg_val
__STATIC_INLINE void hw_watchdog_set_neg_val(uint16_t value)
Set negative reload value of the watchdog timer.
Definition: hw_watchdog.h:162
hw_watchdog_gen_RST
__STATIC_FORCEINLINE void hw_watchdog_gen_RST(void)
Generate a reset signal of the system when reload value reaches 0.
Definition: hw_watchdog.h:196
hw_watchdog_handle_int
__RETAINED_CODE void hw_watchdog_handle_int(unsigned long *hardfault_args)
Handle NMI interrupt.
hw_watchdog_unregister_int
__RETAINED_CODE void hw_watchdog_unregister_int(void)
Unregister an interrupt handler.