42 #define TMR_OFFSET (0x20)
43 #define TMR_BASE (0x80007000)
44 #define TMR0_BASE (TMR_BASE)
45 #define TMR1_BASE (TMR_BASE + TMR_OFFSET*1)
46 #define TMR2_BASE (TMR_BASE + TMR_OFFSET*2)
47 #define TMR3_BASE (TMR_BASE + TMR_OFFSET*3)
69 uint16_t OUTPUT_MODE:3;
74 uint16_t SECONDARY_CNT_SOURCE:2;
75 uint16_t PRIMARY_CNT_SOURCE:4;
76 uint16_t COUNT_MODE:3;
88 uint16_t CAPTURE_MODE:2;
116 uint16_t reserved[4];
137 static volatile struct TMR_struct *
const TMR0 = (
void *) (TMR0_BASE);
138 static volatile struct TMR_struct *
const TMR1 = (
void *) (TMR1_BASE);
139 static volatile struct TMR_struct *
const TMR2 = (
void *) (TMR2_BASE);
140 static volatile struct TMR_struct *
const TMR3 = (
void *) (TMR3_BASE);
143 #define TMR_ADDR(x) ((volatile struct TMR_struct *)(((uint32_t)(x) * TMR_OFFSET) + TMR_BASE))
146 #define TMR_NUM(x) (((uint32_t)(x) - TMR_BASE) / TMR_OFFSET)
152 #define TMR_ENABLE_BIT(x) (1 << TMR_NUM(x))
154 #define TMR0_PIN GPIO_08
155 #define TMR1_PIN GPIO_09
156 #define TMR2_PIN GPIO_10
157 #define TMR3_PIN GPIO_11
160 #ifndef REG_NO_COMPAT
162 #define TMR_REGOFF_COMP1 (0x0)
163 #define TMR_REGOFF_COMP2 (0x2)
164 #define TMR_REGOFF_CAPT (0x4)
165 #define TMR_REGOFF_LOAD (0x6)
166 #define TMR_REGOFF_HOLD (0x8)
167 #define TMR_REGOFF_CNTR (0xa)
168 #define TMR_REGOFF_CTRL (0xc)
169 #define TMR_REGOFF_SCTRL (0xe)
170 #define TMR_REGOFF_CMPLD1 (0x10)
171 #define TMR_REGOFF_CMPLD2 (0x12)
172 #define TMR_REGOFF_CSCTRL (0x14)
173 #define TMR_REGOFF_ENBL (0x1e)
176 #define TMR_ENBL ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_ENBL))
179 #define TMR0_COMP1 ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_COMP1))
180 #define TMR0_COMP_UP TMR0_COMP1
181 #define TMR0_COMP2 ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_COMP2))
182 #define TMR0_COMP_DOWN TMR0_COMP2
183 #define TMR0_CAPT ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_CAPT))
184 #define TMR0_LOAD ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_LOAD))
185 #define TMR0_HOLD ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_HOLD))
186 #define TMR0_CNTR ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_CNTR))
187 #define TMR0_CTRL ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_CTRL))
188 #define TMR0_SCTRL ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_SCTRL))
189 #define TMR0_CMPLD1 ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_CMPLD1))
190 #define TMR0_CMPLD2 ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_CMPLD2))
191 #define TMR0_CSCTRL ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_CSCTRL))
194 #define TMR1_COMP1 ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_COMP1))
195 #define TMR1_COMP_UP TMR1_COMP1
196 #define TMR1_COMP2 ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_COMP2))
197 #define TMR1_COMP_DOWN TMR1_COMP2
198 #define TMR1_CAPT ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_CAPT))
199 #define TMR1_LOAD ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_LOAD))
200 #define TMR1_HOLD ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_HOLD))
201 #define TMR1_CNTR ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_CNTR))
202 #define TMR1_CTRL ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_CTRL))
203 #define TMR1_SCTRL ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_SCTRL))
204 #define TMR1_CMPLD1 ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_CMPLD1))
205 #define TMR1_CMPLD2 ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_CMPLD2))
206 #define TMR1_CSCTRL ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_CSCTRL))
209 #define TMR2_COMP1 ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_COMP1))
210 #define TMR2_COMP_UP TMR2_COMP1
211 #define TMR2_COMP2 ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_COMP2))
212 #define TMR2_COMP_DOWN TMR2_COMP2
213 #define TMR2_CAPT ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_CAPT))
214 #define TMR2_LOAD ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_LOAD))
215 #define TMR2_HOLD ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_HOLD))
216 #define TMR2_CNTR ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_CNTR))
217 #define TMR2_CTRL ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_CTRL))
218 #define TMR2_SCTRL ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_SCTRL))
219 #define TMR2_CMPLD1 ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_CMPLD1))
220 #define TMR2_CMPLD2 ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_CMPLD2))
221 #define TMR2_CSCTRL ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_CSCTRL))
224 #define TMR3_COMP1 ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_COMP1))
225 #define TMR3_COMP_UP TMR3_COMP1
226 #define TMR3_COMP2 ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_COMP2))
227 #define TMR3_COMP_DOWN TMR3_COMP2
228 #define TMR3_CAPT ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_CAPT))
229 #define TMR3_LOAD ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_LOAD))
230 #define TMR3_HOLD ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_HOLD))
231 #define TMR3_CNTR ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_CNTR))
232 #define TMR3_CTRL ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_CTRL))
233 #define TMR3_SCTRL ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_SCTRL))
234 #define TMR3_CMPLD1 ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_CMPLD1))
235 #define TMR3_CMPLD2 ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_CMPLD2))
236 #define TMR3_CSCTRL ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_CSCTRL))
238 #define TMR(num, reg) CAT2(TMR,num,_##reg)
247 uint32_t timer_setup_ex(
int timer_num, uint32_t rate,
int enable_int);
254 #define timer_setup(timer,rate,enable_int) timer_setup_ex(TMR_NUM(timer), rate, enable_int)