summaryrefslogtreecommitdiff
path: root/packages/libndsfpc/src/nds/timers.inc
blob: 2a601812d1e059849c94140d1be218d233ee48e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
(*
  $Id: timers.inc 25 2007-12-10 21:06:46Z p4p3r0 $
  ------------------------------------------------------------------------------
  	Copyright (C) 2005
  		Jason Rogers (dovoto)
  		Dave Murphy (WinterMute)
  	
  	This software is provided 'as-is', without any express or implied
  	warranty.  In no event will the authors be held liable for any
  	damages arising from the use of this software.
  	
  	Permission is granted to anyone to use this software for any
  	purpose, including commercial applications, and to alter it and
  	redistribute it freely, subject to the following restrictions:
  	
  	1.	The origin of this software must not be misrepresented; you
  		must not claim that you wrote the original software. If you use
  		this software in a product, an acknowledgment in the product
  		documentation would be appreciated but is not required.
  	
  	2.	Altered source versions must be plainly marked as such, and
  		must not be misrepresented as being the original software.
  	
  	3.	This notice may not be removed or altered from any source
  		distribution.
  ------------------------------------------------------------------------------
    
    
  Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
  (http://www.freepascal.org)
   
  Copyright (C) 2006  Francesco Lombardi
  Check http://sourceforge.net/projects/libndsfpc for updates
   
  ------------------------------------------------------------------------------

  $Log$

*)

{$ifdef NDS_IMPLEMENTATION}
function TIMER_FREQ(n: cint): cint; inline;
begin
  TIMER_FREQ := cint(-$2000000 div (n));
end;
	
function TIMER_FREQ_64(n: cint): cint; inline;
begin
  TIMER_FREQ_64 := cint(-($2000000 shr 6) div (n));
end;
	
function TIMER_FREQ_256(n: cint): cint; inline;
begin
  TIMER_FREQ_256 := cint(-($2000000 shr 8) div (n));
end;

function TIMER_FREQ_1024(n: cint): cint; inline; 
begin
  TIMER_FREQ_1024 := cint(-($2000000 shr 10) div (n));
end;
{$endif NDS_IMPLEMENTATION}

{$ifdef NDS_INTERFACE}
const
  //!	Same as %TIMER_DATA(0).
  TIMER0_DATA    : pcuint16 = pointer($04000100);
  //!	Same as %TIMER_DATA(1).
  TIMER1_DATA    : pcuint16 = pointer($04000104);
  //!	Same as %TIMER_DATA(2).
  TIMER2_DATA    : pcuint16 = pointer($04000108);
  //!	Same as %TIMER_DATA(3).
  TIMER3_DATA    : pcuint16 = pointer($0400010C);
{$endif NDS_INTERFACE}

{$ifdef NDS_IMPLEMENTATION}
function TIMER_DATA(n: cuint): pcuint16; inline;
begin
  TIMER_DATA := pcuint16($04000100 + (n shl 2));
end;
{$endif NDS_IMPLEMENTATION}

{$ifdef NDS_INTERFACE}
const
// Timer control registers
  //!	Same as %TIMER_CR(0).
  TIMER0_CR   : pcuint16 = pointer($04000102);
  //!	Same as %TIMER_CR(1).
  TIMER1_CR   : pcuint16 = pointer($04000106);
  //!	Same as %TIMER_CR(2).
  TIMER2_CR   : pcuint16 = pointer($0400010A);
  //!	Same as %TIMER_CR(3).
  TIMER3_CR   : pcuint16 = pointer($0400010E);
{$endif NDS_INTERFACE}

{$ifdef NDS_IMPLEMENTATION}
function TIMER_CR(n: cint): pcuint16; inline;
begin
  TIMER_CR := pcuint16($04000102 + (n shl 2));
end;
{$endif NDS_IMPLEMENTATION}

{$ifdef NDS_INTERFACE}
const
  //!	Enables the timer.
  TIMER_ENABLE  = (1 shl 7);

  //!	Causes the timer to request an Interupt on overflow.
  TIMER_IRQ_REQ = (1 shl 6);

  //!	When set will cause the timer to count when the timer below overflows (unavailable for timer 0).
  TIMER_CASCADE = (1 shl 2);
  
  //!	Causes the timer to count at 33.514Mhz.
  TIMER_DIV_1   =  (0);
  //!	Causes the timer to count at (33.514 / 64) Mhz.
  TIMER_DIV_64  = (1);
  //!	Causes the timer to count at (33.514 / 256) Mhz.
  TIMER_DIV_256 = (2);
  //!	Causes the timer to count at (33.514 / 1024)Mhz.
  TIMER_DIV_1024  = (3);
{$endif NDS_INTERFACE}

{$ifdef NDS_INTERFACE}
function TIMER_FREQ(n: cint): cint; inline;
function TIMER_FREQ_64(n: cint): cint; inline;
function TIMER_FREQ_256(n: cint): cint; inline;
function TIMER_FREQ_1024(n: cint): cint; inline; 
function TIMER_DATA(n: cuint): pcuint16; inline;
function TIMER_CR(n: cint): pcuint16; inline;
{$endif NDS_INTERFACE}