initial commit
[gba_blender] / src / timer.h
1 /*
2 blender for the Gameboy Advance
3 Copyright (C) 2021  John Tsiombikas <nuclear@member.fsf.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 */
18 #ifndef _TIMER_H_
19 #define _TIMER_H_
20
21 #include "gbaregs.h"
22
23 #define enable_timer(x) \
24         do { REG_TMCNT_H(x) |= TMCNT_EN; } while(0)
25
26 #define disable_timer(x) \
27         do { REG_TMCNT_H(x) &= ~TMCNT_EN; } while(0)
28
29 volatile unsigned long timer_msec;
30
31 void init_timer(int tm, unsigned long rate_hz, void (*intr)(void));
32
33 void reset_msec_timer(void);
34
35 void delay(unsigned long ms);
36
37 #ifdef __thumb__
38 #define udelay(x)  asm volatile ( \
39         "0: sub %0, %0, #1\n\t" \
40         "bne 0b\n\t" \
41         :: "r"(x) : "cc")
42 #else
43 #define udelay(x)  asm volatile ( \
44         "0: subs %0, %0, #1\n\t" \
45         "bne 0b\n\t" \
46         :: "r"(x) : "cc")
47 #endif
48
49 #endif  /* _TIMER_H_ */