Skip to content

Commit d0d2f6c

Browse files
Add macros for controlling timers
1 parent 0190ebf commit d0d2f6c

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/ce/tice.h

+31
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,37 @@ uint32_t atomic_load_decreasing_32(volatile uint32_t *p);
225225
#define timer_IntAcknowledge (*(volatile uint16_t*)0xF20034) /**< Timer Interrupt Acknowledge register. */
226226
#define timer_EnableInt (*(volatile uint16_t*)0xF20038) /**< Timer Interrupt Enable register. */
227227

228+
#define TIMER_32K 1 /**< Use the 32K clock for timer */
229+
#define TIMER_CPU 0 /**< Use the CPU clock rate for timer */
230+
#define TIMER_0INT 1 /**< Enable an interrupt when 0 is reached for the timer */
231+
#define TIMER_NOINT 0 /**< Disable interrupts for the timer */
232+
#define TIMER_UP 1 /**< Timer counts up */
233+
#define TIMER_DOWN 0 /**< Timer counts down */
234+
235+
#define TIMER_MATCH1 (1<<0) /**< Timer hit the first match value */
236+
#define TIMER_MATCH2 (1<<1) /**< Timer hit the second match value */
237+
#define TIMER_RELOADED (1<<2) /**< Timer was reloaded (Needs TIMER_0INT enabled) */
238+
239+
/**
240+
* Enables timer \p n with the specified settings
241+
*/
242+
#define timer_Enable(n, rate, int, dir) (timer_Control = timer_Control & ~(0x7 << 3 * ((n) - 1) | 1 << ((n) + 8)) | (1 | (rate) << 1 | (int) << 2) << 3 * ((n) - 1) | (dir) << ((n) + 8))
243+
244+
/**
245+
* Disables timer \p n
246+
*/
247+
#define timer_Disable(n) (timer_Control &= ~(1 << 3 * ((n) - 1)))
248+
249+
/**
250+
* Acknowledges an interrupt for timer \p n of type \p type.
251+
*/
252+
#define timer_AckInterrupt(n, type) (timer_IntAcknowledge = (type) << 3 * ((n) - 1))
253+
254+
/**
255+
* Checks if an interrupt for timer \p n of type \p type has occurred.
256+
*/
257+
#define timer_CheckInterrupt(n, type) ((timer_IntStatus >> 3 * ((n) - 1)) & (type))
258+
228259
/* LCD defines */
229260
#define lcd_Ram ((volatile uint16_t*)0xD40000) /**< Base address of memory-mapped RAM for the LCD */
230261
/* @cond */

0 commit comments

Comments
 (0)