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,5 = reserved
93
94// need 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 6 = interrupt enabled
97#define TR_HAL_WDOG_CTRL_INTERRUPT_ENABLED 0x40
98#define TR_HAL_WDOG_CTRL_INTERRUPT_DISABLED 0x00
99// bit 7 = watchdog enabled
100#define TR_HAL_WDOG_CTRL_TIMER_ENABLED 0x80
101#define TR_HAL_WDOG_CTRL_TIMER_DISABLED 0x00
102
103
104// *****************************************************************
105// these defines help when dealing with the RESET WATCHDOG REGISTER (0x0C)
106#define TR_HAL_WDOG_RESET_WATCHDOG_VALUE 0xA5A5
107
108// *****************************************************************
109// these defines help when dealing with the RESET_COUNTER REGISTER (0x10)
110#define TR_HAL_WDOG_CLEAR_RESET_COUNTER 0x01
111
112// *****************************************************************
113// these defines help when dealing with the INTERRUPT CLEAR REGISTER (0x14)
114#define TR_HAL_WDOG_CLEAR_INTERRUPT 0x01
115
116// *****************************************************************
117// these defines help when dealing with the MIN TIME BEFORE RESET REGISTER (0x1C)
118#define TR_HAL_WDOG_DEFAULT_MIN_TIME_BEFORE_RESET 0
119
120// *****************************************************************
121// these defines help when dealing with the CLOCK PRESCALE (0x20)
122#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_1 0
123#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_16 15
124#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_32 31
125#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_128 127
126#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_256 255
127#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_1024 1023
128#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_4096 4095
129
130#define TR_HAL_WDOG_PRESCALAR_MAX_VALUE TR_HAL_WDOG_CTRL_CLK_PRESCALAR_4096
131
132// *****************************************************************
133// this orients the WDOG_REGISTERS struct with the correct address
134// so referencing a field will now read/write the correct WDOG
135// register chip address
136#define WDOG_REGISTERS ((WDOG_REGISTERS_T *) CHIP_MEMORY_MAP_WDOG_BASE)
137
138
154
155
159
160// value to set for the wdog timer to get one second
161// needs to be paired with correct prescalar
162#define TR_HAL_WDOG_1_SECOND_TIMER_VALUE 32000
163
164// value to set for the prescalar to get one second
165// needs to be paired with correct timer value
166#define TR_HAL_WDOG_1_SECOND_PRESCALAR_VALUE TR_HAL_WDOG_CLK_PRESCALAR_1024
167
168
174
180#define TR_HAL_WDOG_EVENT_INT_TRIGGERED 0x00000001
181
185typedef void (*tr_hal_wdog_event_callback_t) (uint32_t event_bitmask);
186
191typedef struct
192{
193 // **** basic watchdog settings ****
194
195 // if this is FALSE nothing else matters, watchdog is DISABLED
196 bool watchdog_enabled;
197
198 // initial time and clock prescalar - relates to how fast the timer runs down
199 tr_hal_wdog_prescalar_t clock_prescalar;
200 uint32_t initial_value;
201
202
203 // **** advanced watchdog settings ****
204
205 // should we clear reset counter when initialized
206 bool clear_reset_counter_on_init;
207
208 // are settings locked
209 bool lockout_enabled;
210
211 // can configure a minimum time before a second timer reset will work
212 uint32_t min_time_before_reset;
213
214
215 // **** interrupt settings ****
216
217 // if we want to enable an interrupt we also set the time when tyhe interrupt fires
218 // when the watchdog timer gets to this time, the interrupt fires
219 bool interrupt_enabled;
220 uint32_t interrupt_time_value;
221
222 // set the INT priority
223 tr_hal_int_pri_t interrupt_priority;
224
225 // event callback from HAL to App when the watchdog interrupt
226 // if the app doesn't want this, then set it to NULL
227 tr_hal_wdog_event_callback_t event_handler_fx;
228
229 // for read function only: this is the CURRENT value of the countdown timer
230 uint32_t current_value;
231
233
234
244#define DEFAULT_WDOG_CONFIG \
245 { \
246 .watchdog_enabled = false, \
247 .clock_prescalar = TR_HAL_WDOG_1_SECOND_PRESCALAR_VALUE, \
248 .initial_value = (6 * TR_HAL_WDOG_1_SECOND_TIMER_VALUE), \
249 .clear_reset_counter_on_init = false, \
250 .lockout_enabled = false, \
251 .min_time_before_reset = TR_HAL_WDOG_DEFAULT_MIN_TIME_BEFORE_RESET,\
252 .interrupt_enabled = false, \
253 .interrupt_time_value = 0, \
254 .interrupt_priority = TR_HAL_INTERRUPT_PRIORITY_5, \
255 .event_handler_fx = NULL, \
256 }
257
258
262
263
264#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.
#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_32
Definition T32CM11_wdog.h:89
tr_hal_wdog_prescalar_t
this enum is used for setting the clock prescalar in the settings struct
Definition T32CM11_wdog.h:136
void(* tr_hal_wdog_event_callback_t)(uint32_t event_bitmask)
Definition T32CM11_wdog.h:177
#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_128
Definition T32CM11_wdog.h:90
#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_4096
Definition T32CM11_wdog.h:92
#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_1
Definition T32CM11_wdog.h:86
#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_256
Definition T32CM11_wdog.h:88
#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_16
Definition T32CM11_wdog.h:87
#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_1024
Definition T32CM11_wdog.h:91
@ TR_HAL_WDOG_CLK_PRESCALAR_128
Definition T32CM11_wdog.h:141
@ TR_HAL_WDOG_CLK_PRESCALAR_4096
Definition T32CM11_wdog.h:143
@ TR_HAL_WDOG_CLK_PRESCALAR_32
Definition T32CM11_wdog.h:140
@ TR_HAL_WDOG_CLK_PRESCALAR_256
Definition T32CM11_wdog.h:139
@ TR_HAL_WDOG_CLK_PRESCALAR_1024
Definition T32CM11_wdog.h:142
@ TR_HAL_WDOG_CLK_PRESCALAR_16
Definition T32CM11_wdog.h:138
@ TR_HAL_WDOG_CLK_PRESCALAR_1
Definition T32CM11_wdog.h:137
WDOG_REGISTERS_T * tr_hal_wdog_get_register_address(void)
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:184