Trident IoT SDK
 
Loading...
Searching...
No Matches
T32CM11_wdog.h
Go to the documentation of this file.
1
13
14#ifndef T32CM11_WDOG_H_
15#define T32CM11_WDOG_H_
16
17#include "tr_hal_platform.h"
18
24
25
35#define CHIP_MEMORY_MAP_WDOG_BASE (0xA0900000UL)
36
37
41typedef struct
42{
43 // this is the value the watchdog timer starts at, and counts down from
44 __IO uint32_t initial_value; // 0x00
45
46 // this is the CURRENT value of the timer
47 __IO uint32_t current_value; // 0x04
48
49 // this enables the wdog, interrupt, reset, prescalar and can lock settings
50 __IO uint32_t control; // 0x08
51
52 // write 0x0000A5A5 to pet the watchdog and reset the counter to initial value
53 __IO uint32_t reset_watchdog; // 0x0C
54
55 // this counts wdog resets up to 255
56 __IO uint32_t reset_counter; // 0x10
57
58 // clears active interrupt
59 __IO uint32_t interrupt_clear; // 0x14
60
61 // when current value gets to this value the interrupt will fire
62 __IO uint32_t interrupt_on_value; // 0x18
63
64 // there needs to be at least this much time passed before the wdog timer can be reset
65 __IO uint32_t min_time_before_reset; // 0x18
66
68
69// *****************************************************************
70// these defines help when dealing with the INITIAL VALUE (0x00)
71
72// we set the minimum value to be at least 1 second
73// if we are using a prescalar of 1024
74#define TR_HAL_WDOG_MINIMUM_INITIAL_VALUE 40000
75
76
77// *****************************************************************
78// these defines help when dealing with the CONTROL REGISTER (0x08)
79
80// bit 1 = lockout bit (disables changes when set)
81#define TR_HAL_WDOG_CTRL_LOCKOUT 0x01
82// bits 2,3,4 = clock prescalar
83#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_1 0x00
84#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_16 0x04
85#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_256 0x08
86#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_32 0x0C
87#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_128 0x10
88#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_1024 0x14
89#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_4096 0x18
90// need to test this and see if it is really the same result as 0x18
91#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_ALSO_4096 0x1C
92// bit 5 = reset enabled
93#define TR_HAL_WDOG_CTRL_RESET_ENABLED 0x20
94#define TR_HAL_WDOG_CTRL_RESET_DISABLED 0x00
95// bit 6 = interrupt enabled
96#define TR_HAL_WDOG_CTRL_INTERRUPT_ENABLED 0x40
97#define TR_HAL_WDOG_CTRL_INTERRUPT_DISABLED 0x00
98// bit 7 = watchdog enabled
99#define TR_HAL_WDOG_CTRL_TIMER_ENABLED 0x80
100#define TR_HAL_WDOG_CTRL_TIMER_DISABLED 0x00
101
102
103// *****************************************************************
104// these defines help when dealing with the RESET WATCHDOG REGISTER (0x0C)
105#define TR_HAL_WDOG_RESET_WATCHDOG_VALUE 0xA5A5
106
107// *****************************************************************
108// these defines help when dealing with the RESET_COUNTER REGISTER (0x10)
109#define TR_HAL_WDOG_CLEAR_RESET_COUNTER 0x01
110
111// *****************************************************************
112// these defines help when dealing with the INTERRUPT CLEAR REGISTER (0x14)
113#define TR_HAL_WDOG_CLEAR_INTERRUPT 0x01
114
115// *****************************************************************
116// these defines help when dealing with the MIN TIME BEFORE RESET REGISTER (0x18)
117#define TR_HAL_WDOG_DEFAULT_MIN_TIME_BEFORE_RESET 0
118
119
120// *****************************************************************
121// this orients the WDOG_REGISTERS struct with the correct address
122// so referencing a field will now read/write the correct WDOG
123// register chip address
124#define WDOG_REGISTERS ((WDOG_REGISTERS_T *) CHIP_MEMORY_MAP_WDOG_BASE)
125
126
142
143
147
148// value to set for the wdog timer to get one second
149// needs to be paired with correct prescalar
150#define TR_HAL_WDOG_1_SECOND_TIMER_VALUE 40000
151
152// value to set for the prescalar to get one second
153// needs to be paired with correct timer value
154#define TR_HAL_WDOG_1_SECOND_PRESCALAR_VALUE TR_HAL_WDOG_CLK_PRESCALAR_1024
155
156
162
168#define TR_HAL_WDOG_EVENT_INT_TRIGGERED 0x00000001
169
173typedef void (*tr_hal_wdog_event_callback_t) (uint32_t event_bitmask);
174
179typedef struct
180{
181 // **** basic watchdog settings ****
182
183 // if this is FALSE nothing else matters, watchdog is DISABLED
185
186 // do we reset when timer hits zero?
188
189 // initial time and clock prescalar - relates to how fast the timer runs down
192
193
194 // **** advanced watchdog settings ****
195
196 // should we clear reset counter when initialized
198
199 // are settings locked
201
202 // can configure a minimum time before a second timer reset will work
204
205
206 // **** interrupt settings ****
207
208 // if we want to enable an interrupt we also set the time when tyhe interrupt fires
209 // when the watchdog timer gets to this time, the interrupt fires
212
213 // set the INT priority
215
216 // event callback from HAL to App when the watchdog interrupt
217 // if the app doesn't want this, then set it to NULL
219
221
222
232#define DEFAULT_WDOG_CONFIG \
233 { \
234 .watchdog_enabled = true, \
235 .reset_enabled = true, \
236 .clock_prescalar = TR_HAL_WDOG_1_SECOND_PRESCALAR_VALUE, \
237 .initial_value = (6 * TR_HAL_WDOG_1_SECOND_TIMER_VALUE), \
238 .clear_reset_counter_on_init = false, \
239 .lockout_enabled = false, \
240 .min_time_before_reset = TR_HAL_WDOG_DEFAULT_MIN_TIME_BEFORE_RESET,\
241 .interrupt_enabled = false, \
242 .interrupt_time_value = 0, \
243 .interrupt_priority = TR_HAL_INTERRUPT_PRIORITY_5, \
244 .event_handler_fx = NULL, \
245 }
246
247
251
252
253#endif // T32CM11_WDOG_H_
This file contains the CHIP SPECIFIC types and defines for the T32CM11.
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
#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_32
Definition T32CM11_wdog.h:86
tr_hal_wdog_prescalar_t
this enum is used for setting the clock prescalar in the settings struct
Definition T32CM11_wdog.h:132
void(* tr_hal_wdog_event_callback_t)(uint32_t event_bitmask)
Definition T32CM11_wdog.h:173
#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_128
Definition T32CM11_wdog.h:87
#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_4096
Definition T32CM11_wdog.h:89
WDOG_REGISTERS_T * tr_hal_wdog_get_register_address(void)
#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_1
Definition T32CM11_wdog.h:83
#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_256
Definition T32CM11_wdog.h:85
#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_16
Definition T32CM11_wdog.h:84
#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_1024
Definition T32CM11_wdog.h:88
@ TR_HAL_WDOG_CLK_PRESCALAR_128
Definition T32CM11_wdog.h:137
@ TR_HAL_WDOG_CLK_PRESCALAR_4096
Definition T32CM11_wdog.h:139
@ TR_HAL_WDOG_CLK_PRESCALAR_32
Definition T32CM11_wdog.h:136
@ TR_HAL_WDOG_CLK_PRESCALAR_256
Definition T32CM11_wdog.h:135
@ TR_HAL_WDOG_CLK_PRESCALAR_1024
Definition T32CM11_wdog.h:138
@ TR_HAL_WDOG_CLK_PRESCALAR_16
Definition T32CM11_wdog.h:134
@ TR_HAL_WDOG_CLK_PRESCALAR_1
Definition T32CM11_wdog.h:133
tr_hal_wdog_prescalar_t
this enum is used for setting the clock prescalar in the settings struct
Definition T32CZ20_wdog.h:145
the struct we use so we can address registers using field names
Definition T32CM11_wdog.h:42
__IO uint32_t initial_value
Definition T32CM11_wdog.h:44
__IO uint32_t interrupt_clear
Definition T32CM11_wdog.h:59
__IO uint32_t min_time_before_reset
Definition T32CM11_wdog.h:65
__IO uint32_t current_value
Definition T32CM11_wdog.h:47
__IO uint32_t reset_watchdog
Definition T32CM11_wdog.h:53
__IO uint32_t reset_counter
Definition T32CM11_wdog.h:56
__IO uint32_t control
Definition T32CM11_wdog.h:50
__IO uint32_t interrupt_on_value
Definition T32CM11_wdog.h:62
Definition T32CM11_wdog.h:180
bool watchdog_enabled
Definition T32CM11_wdog.h:184
bool interrupt_enabled
Definition T32CM11_wdog.h:210
bool lockout_enabled
Definition T32CM11_wdog.h:200
tr_hal_wdog_event_callback_t event_handler_fx
Definition T32CM11_wdog.h:218
bool clear_reset_counter_on_init
Definition T32CM11_wdog.h:197
tr_hal_wdog_prescalar_t clock_prescalar
Definition T32CM11_wdog.h:190
bool reset_enabled
Definition T32CM11_wdog.h:187
uint32_t initial_value
Definition T32CM11_wdog.h:191
uint32_t interrupt_time_value
Definition T32CM11_wdog.h:211
tr_hal_int_pri_t interrupt_priority
Definition T32CM11_wdog.h:214
uint32_t min_time_before_reset
Definition T32CM11_wdog.h:203