Trident IoT SDK
 
Loading...
Searching...
No Matches
T32CZ20_timers.h
Go to the documentation of this file.
1
17
18#ifndef T32CZ20_TIMERS_H_
19#define T32CZ20_TIMERS_H_
20
21#include "tr_hal_platform.h"
22
23
29
30
31#define TR_HAL_NUM_TIMERS 5
32
33// timer IDs
43
44// these are in a non-sequential order because that is how the chip register works
45// do not change these - these are set based on the chip
58
59
70#ifdef TIMER0_SECURE_EN
71 #define CHIP_MEMORY_MAP_TIMER0_BASE (0x5000A000UL)
72#else
73 #define CHIP_MEMORY_MAP_TIMER0_BASE (0x4000A000UL)
74#endif // TIMER0_SECURE_EN
75
76#ifdef TIMER1_SECURE_EN
77 #define CHIP_MEMORY_MAP_TIMER1_BASE (0x5000B000UL)
78#else
79 #define CHIP_MEMORY_MAP_TIMER1_BASE (0x4000B000UL)
80#endif // TIMER1_SECURE_EN
81
82#ifdef TIMER2_SECURE_EN
83 #define CHIP_MEMORY_MAP_TIMER2_BASE (0x5000C000UL)
84#else
85 #define CHIP_MEMORY_MAP_TIMER2_BASE (0x4000C000UL)
86#endif // TIMER2_SECURE_EN
87
88#ifdef TIMER32K0_SECURE_EN
89 #define CHIP_MEMORY_MAP_TIMER3_BASE (0x5000D000UL)
90#else
91 #define CHIP_MEMORY_MAP_TIMER3_BASE (0x4000D000UL)
92#endif // TIMER32K0_SECURE_EN
93
94#ifdef TIMER32K1_SECURE_EN
95 #define CHIP_MEMORY_MAP_TIMER4_BASE (0x5000E000UL)
96#else
97 #define CHIP_MEMORY_MAP_TIMER4_BASE (0x4000E000UL)
98#endif // TIMER32K1_SECURE_EN
99
100
101
106typedef struct
107{
108 // timer start value, it counts down from this
109 __IO uint32_t initial_value; // 0x00
110
111 // current countdown value
112 __IO uint32_t current_countdown_value; // 0x04
113
114 // timer control - enable, disable, mode, and set prescale value
115 __IO uint32_t control; // 0x08
116
117 // to clear the timer interrupt
118 __IO uint32_t clear_interrupt; // 0x0C
119
120 // for capture (reading input) wave forms
121 __IO uint32_t capture_clear; // 0x10
122 __IO uint32_t capture_ch_0; // 0x14
123 __IO uint32_t capture_ch_1; // 0x18
124
125 // timer prescale value. if this is 0 then the prescale field in
126 // the control register is used.
127 __IO uint32_t prescalar; // 0x1C
128
129 // capture and PWM
130 __IO uint32_t expire_value; // 0x20
131 __IO uint32_t capture_enable; // 0x24
132 __IO uint32_t capture_IO_select; // 0x28
133 __IO uint32_t PWM_threshhold; // 0x2C
134 __IO uint32_t PWM_phase; // 0x30
135
137
138
143typedef struct
144{
145 // timer start value, it counts down from this
146 __IO uint32_t initial_value; // 0x00
147
148 // current countdown value
149 __IO uint32_t current_countdown_value; // 0x04
150
151 // timer control - enable, disable, mode, and set prescale value
152 __IO uint32_t control; // 0x08
153
154 // to clear the timer interrupt
155 __IO uint32_t clear_interrupt; // 0x0C
156
157 __IO uint32_t interrupt_repeat; // 0x10
158
159 // timer prescale value. if this is 0 then the prescale field in
160 // the control register is used.
161 __IO uint32_t prescalar; // 0x14
162
163 __IO uint32_t expire_value; // 0x18
164
166
167
168// *****************************************************************
169// these defines help when dealing with the CONTROL REGISTER (0x08)
170// bit 0 = count down (default) or up
171#define CR_COUNT_MODE_DOWN 0x00
172#define CR_COUNT_MODE_UP 0x01
173// bit 1 = one shot enable (1) or one shot disable(0)
174#define CR_ONE_SHOT_DISABLE 0x00
175#define CR_ONE_SHOT_ENABLE 0x10
176// bits 2-4 = prescalar
177#define CR_PRESCALER_MASK 0x1C
178// bit 5 = interrupt enable
179#define CR_INT_ENABLE_BIT 0x20
180// bit 6 = free running (0) or periodic(1)
181#define CR_MODE_BIT 0x40
182// bit 7 = timer running (1 = enabled) or not (0 = disabled)
183#define CR_TIMER_RUNNING_BIT 0x80
184// interrupt status bit
185#define CR_INT_STATUS_BIT 0x100
186// when we support PWM and input capture then define bits 9 - 21
187
188
189// *****************************************************************
190// this orients the TIMERx_REGISTERS struct with the correct addresses
191// so referencing a field will now read/write the correct timer
192// register chip address
193#define TIMER0_REGISTERS ((FAST_TIMER_REGISTERS_T *) CHIP_MEMORY_MAP_TIMER0_BASE)
194#define TIMER1_REGISTERS ((FAST_TIMER_REGISTERS_T *) CHIP_MEMORY_MAP_TIMER1_BASE)
195#define TIMER2_REGISTERS ((FAST_TIMER_REGISTERS_T *) CHIP_MEMORY_MAP_TIMER2_BASE)
196#define TIMER3_REGISTERS ((SLOW_TIMER_REGISTERS_T *) CHIP_MEMORY_MAP_TIMER3_BASE)
197#define TIMER4_REGISTERS ((SLOW_TIMER_REGISTERS_T *) CHIP_MEMORY_MAP_TIMER4_BASE)
198
199
206
208
209
210// prototype for callback from the Trident HAL to the app when a timer expires
211typedef void (*tr_hal_timer_callback_t) (tr_hal_timer_id_t expired_timer_id);
212
213
224typedef struct
225{
226 // timer value (counts down from this to 0)
227 uint32_t timer_start_value;
228 tr_hal_timer_prescalar_t prescalar;
229
230 // timer settings
231 bool timer_repeats;
232 bool timer_enabled;
233
234 // interrupt settings
235 bool interrupt_enabled;
236 tr_hal_int_pri_t interrupt_priority;
237
238 // function to call when we expire
239 tr_hal_timer_callback_t event_handler_fx;
240
241 // *** info that is passed back on tr_hal_timer_read: ***
242 bool interrupt_is_active;
243 uint32_t timer_current_countdown_value;
244
246
247
254#define DEFAULT_32MHZ_TIMER_CONFIG \
255 { \
256 .timer_start_value = (32000 * 10), \
257 .prescalar = TR_HAL_TIMER_PRESCALER_1024, \
258 .timer_repeats = true, \
259 .timer_enabled = false, \
260 .interrupt_enabled = true, \
261 .interrupt_priority = TR_HAL_INTERRUPT_PRIORITY_5, \
262 .event_handler_fx = NULL, \
263 }
264
265#define DEFAULT_32KHZ_TIMER_CONFIG \
266 { \
267 .timer_start_value = (32000 * 10), \
268 .prescalar = TR_HAL_TIMER_PRESCALER_1, \
269 .timer_repeats = true, \
270 .timer_enabled = false, \
271 .interrupt_enabled = true, \
272 .interrupt_priority = TR_HAL_INTERRUPT_PRIORITY_5, \
273 .event_handler_fx = NULL, \
274 }
275
276
280
281
282#endif // T32CZ20_TIMERS_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_timer_id_t
Definition T32CM11_timers.h:35
tr_hal_timer_prescalar_t
Definition T32CM11_timers.h:47
tr_hal_timer_id_t
Definition T32CZ20_timers.h:35
tr_hal_timer_prescalar_t
Definition T32CZ20_timers.h:47
SLOW_TIMER_REGISTERS_T * tr_hal_slow_timer_get_register_address(tr_hal_timer_id_t timer_id)
FAST_TIMER_REGISTERS_T * tr_hal_fast_timer_get_register_address(tr_hal_timer_id_t timer_id)
void(* tr_hal_timer_callback_t)(tr_hal_timer_id_t expired_timer_id)
Definition T32CZ20_timers.h:211
@ TIMER_1_ID
Definition T32CZ20_timers.h:37
@ SLOW_CLOCK_TIMER_0_ID
Definition T32CZ20_timers.h:39
@ TIMER_2_ID
Definition T32CZ20_timers.h:38
@ TIMER_0_ID
Definition T32CZ20_timers.h:36
@ SLOW_CLOCK_TIMER_1_ID
Definition T32CZ20_timers.h:40
@ TR_HAL_TIMER_PRESCALER_256
Definition T32CZ20_timers.h:50
@ TR_HAL_TIMER_PRESCALER_2
Definition T32CZ20_timers.h:51
@ TR_HAL_TIMER_PRESCALER_128
Definition T32CZ20_timers.h:54
@ TR_HAL_TIMER_PRESCALER_1
Definition T32CZ20_timers.h:48
@ TR_HAL_TIMER_PRESCALER_8
Definition T32CZ20_timers.h:52
@ TR_HAL_TIMER_PRESCALER_1024
Definition T32CZ20_timers.h:55
@ TR_HAL_TIMER_PRESCALER_16
Definition T32CZ20_timers.h:49
@ TR_HAL_TIMER_PRESCALER_32
Definition T32CZ20_timers.h:53
@ TR_HAL_TIMER_PRESCALER_MAX
Definition T32CZ20_timers.h:56
Definition T32CZ20_timers.h:107
__IO uint32_t capture_clear
Definition T32CZ20_timers.h:121
__IO uint32_t capture_ch_0
Definition T32CZ20_timers.h:122
__IO uint32_t initial_value
Definition T32CZ20_timers.h:109
__IO uint32_t PWM_phase
Definition T32CZ20_timers.h:134
__IO uint32_t capture_ch_1
Definition T32CZ20_timers.h:123
__IO uint32_t capture_IO_select
Definition T32CZ20_timers.h:132
__IO uint32_t prescalar
Definition T32CZ20_timers.h:127
__IO uint32_t current_countdown_value
Definition T32CZ20_timers.h:112
__IO uint32_t PWM_threshhold
Definition T32CZ20_timers.h:133
__IO uint32_t control
Definition T32CZ20_timers.h:115
__IO uint32_t clear_interrupt
Definition T32CZ20_timers.h:118
__IO uint32_t expire_value
Definition T32CZ20_timers.h:130
__IO uint32_t capture_enable
Definition T32CZ20_timers.h:131
Definition T32CZ20_timers.h:144
__IO uint32_t prescalar
Definition T32CZ20_timers.h:161
__IO uint32_t expire_value
Definition T32CZ20_timers.h:163
__IO uint32_t initial_value
Definition T32CZ20_timers.h:146
__IO uint32_t current_countdown_value
Definition T32CZ20_timers.h:149
__IO uint32_t clear_interrupt
Definition T32CZ20_timers.h:155
__IO uint32_t interrupt_repeat
Definition T32CZ20_timers.h:157
__IO uint32_t control
Definition T32CZ20_timers.h:152
Definition T32CM11_timers.h:149