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 when using a
73// 40 MHz clock. note: when checking this the prescalar needs to
74// be taken into account
75#define TR_HAL_WDOG_MINIMUM_INITIAL_VALUE 40000000
76
77
78// *****************************************************************
79// these defines help when dealing with the CONTROL REGISTER (0x08)
80
81// bit 0 = lockout bit (disables changes when set)
82#define TR_HAL_WDOG_CTRL_LOCKOUT 0x01
83// bit 1 = reserved
84//
85// bits 2,3,4 = clock prescalar
86#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_1 0x00
87#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_16 0x04
88#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_256 0x08
89#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_32 0x0C
90#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_128 0x10
91#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_1024 0x14
92#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_4096 0x18
93#define TR_HAL_WDOG_CTRL_CLK_PRESCALAR_MASK 0x1C
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 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 (0x18)
121#define TR_HAL_WDOG_DEFAULT_MIN_TIME_BEFORE_RESET 0
122
123
124// *****************************************************************
125// this orients the WDOG_REGISTERS struct with the correct address
126// so referencing a field will now read/write the correct WDOG
127// register chip address
128#define WDOG_REGISTERS ((WDOG_REGISTERS_T *) CHIP_MEMORY_MAP_WDOG_BASE)
129
130
146
147
151
152// value to set for the wdog timer to get one second
153// needs to be paired with correct prescalar
154#define TR_HAL_WDOG_1_SECOND_TIMER_VALUE 40000
155
156// value to set for the prescalar to get one second
157// needs to be paired with correct timer value
158#define TR_HAL_WDOG_1_SECOND_PRESCALAR_VALUE TR_HAL_WDOG_CLK_PRESCALAR_1024
159
160
166
172#define TR_HAL_WDOG_EVENT_INT_TRIGGERED 0x00000001
173
177typedef void (*tr_hal_wdog_event_callback_t) (uint32_t event_bitmask);
178
183typedef struct
184{
185 // **** basic watchdog settings ****
186
187 // if this is FALSE nothing else matters, watchdog is DISABLED
189
190 // do we reset when timer hits zero?
192
193 // initial time and clock prescalar - relates to how fast the timer runs down
196
197
198 // **** advanced watchdog settings ****
199
200 // should we clear reset counter when initialized
202
203 // are settings locked
205
206 // can configure a minimum time before a second timer reset will work
208
209
210 // **** interrupt settings ****
211
212 // if we want to enable an interrupt we also set the time when tyhe interrupt fires
213 // when the watchdog timer gets to this time, the interrupt fires
216
217 // set the INT priority
219
220 // event callback from HAL to App when the watchdog interrupt
221 // if the app doesn't want this, then set it to NULL
223
224 // for read function only: this is the CURRENT value of the countdown timer
226
228
229
239#define DEFAULT_WDOG_CONFIG \
240 { \
241 .watchdog_enabled = false, \
242 .reset_enabled = true, \
243 .clock_prescalar = TR_HAL_WDOG_1_SECOND_PRESCALAR_VALUE, \
244 .initial_value = (6 * TR_HAL_WDOG_1_SECOND_TIMER_VALUE), \
245 .clear_reset_counter_on_init = false, \
246 .lockout_enabled = false, \
247 .min_time_before_reset = TR_HAL_WDOG_DEFAULT_MIN_TIME_BEFORE_RESET,\
248 .interrupt_enabled = false, \
249 .interrupt_time_value = 0, \
250 .interrupt_priority = TR_HAL_INTERRUPT_PRIORITY_5, \
251 .event_handler_fx = NULL, \
252 }
253
254
258
259
260#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: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
WDOG_REGISTERS_T * tr_hal_wdog_get_register_address(void)
#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
tr_hal_wdog_prescalar_t
this enum is used for setting the clock prescalar in the settings struct
Definition T32CZ20_wdog.h:144
void(* tr_hal_wdog_event_callback_t)(uint32_t event_bitmask)
Definition T32CZ20_wdog.h:185
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:184
bool watchdog_enabled
Definition T32CM11_wdog.h:188
bool interrupt_enabled
Definition T32CM11_wdog.h:214
bool lockout_enabled
Definition T32CM11_wdog.h:204
tr_hal_wdog_event_callback_t event_handler_fx
Definition T32CM11_wdog.h:222
bool clear_reset_counter_on_init
Definition T32CM11_wdog.h:201
tr_hal_wdog_prescalar_t clock_prescalar
Definition T32CM11_wdog.h:194
bool reset_enabled
Definition T32CM11_wdog.h:191
uint32_t initial_value
Definition T32CM11_wdog.h:195
uint32_t interrupt_time_value
Definition T32CM11_wdog.h:215
tr_hal_int_pri_t interrupt_priority
Definition T32CM11_wdog.h:218
uint32_t min_time_before_reset
Definition T32CM11_wdog.h:207
uint32_t current_value
Definition T32CM11_wdog.h:225