Trident IoT SDK
 
Loading...
Searching...
No Matches
T32CZ20_wdog.h
Go to the documentation of this file.
1
13
14#ifndef T32CZ20_WDOG_H_
15#define T32CZ20_WDOG_H_
16
17#include "tr_hal_platform.h"
18
19
25
26
36#ifdef WDT_SECURE_EN
37 #define CHIP_MEMORY_MAP_WDOG_BASE (0x50010000UL)
38#else
39 #define CHIP_MEMORY_MAP_WDOG_BASE (0x40010000UL)
40#endif //WDT_SECURE_EN
41
42
46typedef struct
47{
48 // this is the value the watchdog timer starts at, and counts down from
49 __IO uint32_t initial_value; // 0x00
50
51 // this is the CURRENT value of the timer
52 __IO uint32_t current_value; // 0x04
53
54 // this enables the wdog, interrupt, reset, prescalar and can lock settings
55 __IO uint32_t control; // 0x08
56
57 // write 0x0000A5A5 to pet the watchdog and reset the counter to initial value
58 __IO uint32_t reset_watchdog; // 0x0C
59
60 // this counts wdog resets up to 255
61 __IO uint32_t reset_counter; // 0x10
62
63 // clears active interrupt
64 __IO uint32_t interrupt_clear; // 0x14
65
66 // when current value gets to this value the interrupt will fire
67 __IO uint32_t interrupt_on_value; // 0x18
68
69 // there needs to be at least this much time passed before the wdog timer can be reset
70 __IO uint32_t min_time_before_reset; // 0x1C
71
72 // timer clock is divided by this +1 unless this is 0 then it is not used
73 __IO uint32_t clock_prescale; // 0x20
74
76
77
78// *****************************************************************
79// these defines help when dealing with the INITIAL VALUE (0x00)
80
81// we set the minimum value to be at least 1 second when using a 32 MHz
82// clock. note: when checking this the prescalar needs to be taken into
83// account
84#define TR_HAL_WDOG_MINIMUM_INITIAL_VALUE 32000000
85
86
87// *****************************************************************
88// these defines help when dealing with the CONTROL REGISTER (0x08)
89
90// bit 1 = lockout bit (disables changes when set)
91#define TR_HAL_WDOG_CTRL_LOCKOUT 0x01
92// bits 2,3,4 = reserved (docs say clock prescalar but that does not work)
93
94// beed to test this and see if it is really the same result as 0x18
95#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_ALSO_4096 0x1C
96// bit 5 = reset enabled
97#define TR_HAL_WDOG_CTRL_RESET_ENABLED 0x20
98#define TR_HAL_WDOG_CTRL_RESET_DISABLED 0x00
99// bit 6 = interrupt enabled
100#define TR_HAL_WDOG_CTRL_INTERRUPT_ENABLED 0x40
101#define TR_HAL_WDOG_CTRL_INTERRUPT_DISABLED 0x00
102// bit 7 = watchdog enabled
103#define TR_HAL_WDOG_CTRL_TIMER_ENABLED 0x80
104#define TR_HAL_WDOG_CTRL_TIMER_DISABLED 0x00
105
106
107// *****************************************************************
108// these defines help when dealing with the RESET WATCHDOG REGISTER (0x0C)
109#define TR_HAL_WDOG_RESET_WATCHDOG_VALUE 0xA5A5
110
111// *****************************************************************
112// these defines help when dealing with the RESET_COUNTER REGISTER (0x10)
113#define TR_HAL_WDOG_CLEAR_RESET_COUNTER 0x01
114
115// *****************************************************************
116// these defines help when dealing with the INTERRUPT CLEAR REGISTER (0x14)
117#define TR_HAL_WDOG_CLEAR_INTERRUPT 0x01
118
119// *****************************************************************
120// these defines help when dealing with the MIN TIME BEFORE RESET REGISTER (0x1C)
121#define TR_HAL_WDOG_DEFAULT_MIN_TIME_BEFORE_RESET 0
122
123// *****************************************************************
124// these defines help when dealing with the CLOCK PRESCALE (0x20)
125#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_1 0
126#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_16 15
127#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_32 31
128#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_128 127
129#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_256 255
130#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_1024 1023
131#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_4096 4095
132
133// *****************************************************************
134// this orients the WDOG_REGISTERS struct with the correct address
135// so referencing a field will now read/write the correct WDOG
136// register chip address
137#define WDOG_REGISTERS ((WDOG_REGISTERS_T *) CHIP_MEMORY_MAP_WDOG_BASE)
138
139
155
156
160
161// value to set for the wdog timer to get one second
162// needs to be paired with correct prescalar
163#define TR_HAL_WDOG_1_SECOND_TIMER_VALUE 32000
164
165// value to set for the prescalar to get one second
166// needs to be paired with correct timer value
167#define TR_HAL_WDOG_1_SECOND_PRESCALAR_VALUE TR_HAL_WDOG_CLK_PRESCALAR_1024
168
169
175
181#define TR_HAL_WDOG_EVENT_INT_TRIGGERED 0x00000001
182
186typedef void (*tr_hal_wdog_event_callback_t) (uint32_t event_bitmask);
187
192typedef struct
193{
194 // **** basic watchdog settings ****
195
196 // if this is FALSE nothing else matters, watchdog is DISABLED
197 bool watchdog_enabled;
198
199 // do we reset when timer hits zero?
200 bool reset_enabled;
201
202 // initial time and clock prescalar - relates to how fast the timer runs down
203 tr_hal_wdog_prescalar_t clock_prescalar;
204 uint32_t initial_value;
205
206
207 // **** advanced watchdog settings ****
208
209 // should we clear reset counter when initialized
210 bool clear_reset_counter_on_init;
211
212 // are settings locked
213 bool lockout_enabled;
214
215 // can configure a minimum time before a second timer reset will work
216 uint32_t min_time_before_reset;
217
218
219 // **** interrupt settings ****
220
221 // if we want to enable an interrupt we also set the time when tyhe interrupt fires
222 // when the watchdog timer gets to this time, the interrupt fires
223 bool interrupt_enabled;
224 uint32_t interrupt_time_value;
225
226 // set the INT priority
227 tr_hal_int_pri_t interrupt_priority;
228
229 // event callback from HAL to App when the watchdog interrupt
230 // if the app doesn't want this, then set it to NULL
231 tr_hal_wdog_event_callback_t event_handler_fx;
232
234
235
245#define DEFAULT_WDOG_CONFIG \
246 { \
247 .watchdog_enabled = true, \
248 .reset_enabled = true, \
249 .clock_prescalar = TR_HAL_WDOG_1_SECOND_PRESCALAR_VALUE, \
250 .initial_value = (6 * TR_HAL_WDOG_1_SECOND_TIMER_VALUE), \
251 .clear_reset_counter_on_init = false, \
252 .lockout_enabled = false, \
253 .min_time_before_reset = TR_HAL_WDOG_DEFAULT_MIN_TIME_BEFORE_RESET,\
254 .interrupt_enabled = false, \
255 .interrupt_time_value = 0, \
256 .interrupt_priority = TR_HAL_INTERRUPT_PRIORITY_5, \
257 .event_handler_fx = NULL, \
258 }
259
260
264
265
266#endif // T32CZ20_WDOG_H_
tr_hal_int_pri_t
values and a range checking function for setting the interrupt priority in the Trident HAL APIs
Definition tr_hal_platform.h:34
This file contains the CHIP SPECIFIC types and defines for the T32CZ20.
tr_hal_wdog_prescalar_t
this enum is used for setting the clock prescalar in the settings struct
Definition T32CM11_wdog.h:132
#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_32
Definition T32CZ20_wdog.h:127
tr_hal_wdog_prescalar_t
this enum is used for setting the clock prescalar in the settings struct
Definition T32CZ20_wdog.h:145
void(* tr_hal_wdog_event_callback_t)(uint32_t event_bitmask)
Definition T32CZ20_wdog.h:186
#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_128
Definition T32CZ20_wdog.h:128
#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_4096
Definition T32CZ20_wdog.h:131
WDOG_REGISTERS_T * tr_hal_wdog_get_register_address(void)
#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_1
Definition T32CZ20_wdog.h:125
#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_256
Definition T32CZ20_wdog.h:129
#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_16
Definition T32CZ20_wdog.h:126
#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_1024
Definition T32CZ20_wdog.h:130
@ TR_HAL_WDOG_CLK_PRESCALAR_128
Definition T32CZ20_wdog.h:150
@ TR_HAL_WDOG_CLK_PRESCALAR_4096
Definition T32CZ20_wdog.h:152
@ TR_HAL_WDOG_CLK_PRESCALAR_32
Definition T32CZ20_wdog.h:149
@ TR_HAL_WDOG_CLK_PRESCALAR_256
Definition T32CZ20_wdog.h:148
@ TR_HAL_WDOG_CLK_PRESCALAR_1024
Definition T32CZ20_wdog.h:151
@ TR_HAL_WDOG_CLK_PRESCALAR_16
Definition T32CZ20_wdog.h:147
@ TR_HAL_WDOG_CLK_PRESCALAR_1
Definition T32CZ20_wdog.h:146
the struct we use so we can address registers using field names
Definition T32CM11_wdog.h:42
__IO uint32_t clock_prescale
Definition T32CZ20_wdog.h:73
Definition T32CM11_wdog.h:180