Trident IoT SDK
 
Loading...
Searching...
No Matches
T32CM11_timers.h
Go to the documentation of this file.
1
17
18#ifndef T32CM11_TIMERS_H_
19#define T32CM11_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#define CHIP_MEMORY_MAP_TIMER0_BASE (0xA0700000UL)
71#define CHIP_MEMORY_MAP_TIMER1_BASE (0xA0800000UL)
72#define CHIP_MEMORY_MAP_TIMER2_BASE (0xA0F00000UL)
73#define CHIP_MEMORY_MAP_TIMER3_BASE (0xA0F40000UL)
74#define CHIP_MEMORY_MAP_TIMER4_BASE (0xA0F80000UL)
75
76
80typedef struct
81{
82 // timer start value, it counts down from this
83 __IO uint32_t initial_value; // 0x00
84
85 // current countdown value
86 __IO uint32_t current_countdown_value; // 0x04
87
88 // timer control - enable, disable, mode, and set prescale value
89 __IO uint32_t control; // 0x08
90
91 // to clear the timer interrupt
92 __IO uint32_t clear_interrupt; // 0x0C
93
94 // only valid for timer 3 and timer 4 when sleep is enabled
95 __IO uint32_t repeat_delay; // 0x10
96
98
99
100// *****************************************************************
101// these defines help when dealing with the CONTROL REGISTER (0x08)
102
103// bits 2-4 = prescalar
104#define CR_PRESCALER_MASK 0x1C
105// bit 5 = interrupt enable
106#define CR_INT_ENABLE_BIT 0x20
107// bit 6 = free running (0) or periodic(1)
108#define CR_MODE_BIT 0x40
109// bit 7 = timer running (1 = enabled) or not (0 = disabled)
110#define CR_TIMER_RUNNING_BIT 0x80
111// interrupt status bit
112#define CR_INT_STATUS_BIT 0x100
113
114
115// *****************************************************************
116// this orients the TIMERx_REGISTERS struct with the correct addresses
117// so referencing a field will now read/write the correct timer
118// register chip address
119#define TIMER0_REGISTERS ((TIMER_REGISTERS_T *) CHIP_MEMORY_MAP_TIMER0_BASE)
120#define TIMER1_REGISTERS ((TIMER_REGISTERS_T *) CHIP_MEMORY_MAP_TIMER1_BASE)
121#define TIMER2_REGISTERS ((TIMER_REGISTERS_T *) CHIP_MEMORY_MAP_TIMER2_BASE)
122#define TIMER3_REGISTERS ((TIMER_REGISTERS_T *) CHIP_MEMORY_MAP_TIMER3_BASE)
123#define TIMER4_REGISTERS ((TIMER_REGISTERS_T *) CHIP_MEMORY_MAP_TIMER4_BASE)
124
125
132
133
134// prototype for callback from the Trident HAL to the app when a timer expires
135typedef void (*tr_hal_timer_callback_t) (tr_hal_timer_id_t expired_timer_id);
136
137
148typedef struct
149{
150 // timer value (counts down from this to 0)
153
154 // timer settings
157
158 // interrupt settings
161
162 // function to call when we expire
164
165 // *** info that is passed back on tr_hal_timer_read: ***
168
170
171
178#define DEFAULT_32MHZ_TIMER_CONFIG \
179 { \
180 .timer_start_value = (32000 * 10), \
181 .prescalar = TR_HAL_TIMER_PRESCALER_1024, \
182 .timer_repeats = true, \
183 .timer_enabled = false, \
184 .interrupt_enabled = true, \
185 .interrupt_priority = TR_HAL_INTERRUPT_PRIORITY_5, \
186 .event_handler_fx = NULL, \
187 }
188
189#define DEFAULT_32KHZ_TIMER_CONFIG \
190 { \
191 .timer_start_value = (32000 * 10), \
192 .prescalar = TR_HAL_TIMER_PRESCALER_1, \
193 .timer_repeats = true, \
194 .timer_enabled = false, \
195 .interrupt_enabled = true, \
196 .interrupt_priority = TR_HAL_INTERRUPT_PRIORITY_5, \
197 .event_handler_fx = NULL, \
198 }
199
200
204
205
206#endif // T32CM11_TIMERS_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
TIMER_REGISTERS_T * tr_hal_timer_get_register_address(tr_hal_timer_id_t timer_id)
tr_hal_timer_id_t
Definition T32CM11_timers.h:35
tr_hal_timer_prescalar_t
Definition T32CM11_timers.h:47
void(* tr_hal_timer_callback_t)(tr_hal_timer_id_t expired_timer_id)
Definition T32CM11_timers.h:135
@ TIMER_1_ID
Definition T32CM11_timers.h:37
@ TIMER_2_ID
Definition T32CM11_timers.h:38
@ TIMER_4_ID
Definition T32CM11_timers.h:40
@ TIMER_0_ID
Definition T32CM11_timers.h:36
@ TIMER_3_ID
Definition T32CM11_timers.h:39
@ TR_HAL_TIMER_PRESCALER_256
Definition T32CM11_timers.h:50
@ TR_HAL_TIMER_PRESCALER_2
Definition T32CM11_timers.h:51
@ TR_HAL_TIMER_PRESCALER_128
Definition T32CM11_timers.h:54
@ TR_HAL_TIMER_PRESCALER_1
Definition T32CM11_timers.h:48
@ TR_HAL_TIMER_PRESCALER_8
Definition T32CM11_timers.h:52
@ TR_HAL_TIMER_PRESCALER_1024
Definition T32CM11_timers.h:55
@ TR_HAL_TIMER_PRESCALER_16
Definition T32CM11_timers.h:49
@ TR_HAL_TIMER_PRESCALER_32
Definition T32CM11_timers.h:53
@ TR_HAL_TIMER_PRESCALER_MAX
Definition T32CM11_timers.h:56
tr_hal_timer_prescalar_t
Definition T32CZ20_timers.h:47
Definition T32CM11_timers.h:81
__IO uint32_t clear_interrupt
Definition T32CM11_timers.h:92
__IO uint32_t repeat_delay
Definition T32CM11_timers.h:95
__IO uint32_t initial_value
Definition T32CM11_timers.h:83
__IO uint32_t control
Definition T32CM11_timers.h:89
__IO uint32_t current_countdown_value
Definition T32CM11_timers.h:86
Definition T32CM11_timers.h:149
bool interrupt_is_active
Definition T32CM11_timers.h:166
bool timer_repeats
Definition T32CM11_timers.h:155
tr_hal_int_pri_t interrupt_priority
Definition T32CM11_timers.h:160
bool interrupt_enabled
Definition T32CM11_timers.h:159
bool timer_enabled
Definition T32CM11_timers.h:156
tr_hal_timer_callback_t event_handler_fx
Definition T32CM11_timers.h:163
uint32_t timer_start_value
Definition T32CM11_timers.h:151
tr_hal_timer_prescalar_t prescalar
Definition T32CM11_timers.h:152
uint32_t timer_current_countdown_value
Definition T32CM11_timers.h:167