timers.inc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. (*
  2. $Id: timers.inc 25 2007-12-10 21:06:46Z p4p3r0 $
  3. ------------------------------------------------------------------------------
  4. Copyright (C) 2005
  5. Jason Rogers (dovoto)
  6. Dave Murphy (WinterMute)
  7. This software is provided 'as-is', without any express or implied
  8. warranty. In no event will the authors be held liable for any
  9. damages arising from the use of this software.
  10. Permission is granted to anyone to use this software for any
  11. purpose, including commercial applications, and to alter it and
  12. redistribute it freely, subject to the following restrictions:
  13. 1. The origin of this software must not be misrepresented; you
  14. must not claim that you wrote the original software. If you use
  15. this software in a product, an acknowledgment in the product
  16. documentation would be appreciated but is not required.
  17. 2. Altered source versions must be plainly marked as such, and
  18. must not be misrepresented as being the original software.
  19. 3. This notice may not be removed or altered from any source
  20. distribution.
  21. ------------------------------------------------------------------------------
  22. Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
  23. (http://www.freepascal.org)
  24. Copyright (C) 2006 Francesco Lombardi
  25. Check http://sourceforge.net/projects/libndsfpc for updates
  26. ------------------------------------------------------------------------------
  27. $Log$
  28. *)
  29. {$ifdef NDS_IMPLEMENTATION}
  30. function TIMER_FREQ(n: cint): cint; inline;
  31. begin
  32. TIMER_FREQ := cint(-$2000000 div (n));
  33. end;
  34. function TIMER_FREQ_64(n: cint): cint; inline;
  35. begin
  36. TIMER_FREQ_64 := cint(-($2000000 shr 6) div (n));
  37. end;
  38. function TIMER_FREQ_256(n: cint): cint; inline;
  39. begin
  40. TIMER_FREQ_256 := cint(-($2000000 shr 8) div (n));
  41. end;
  42. function TIMER_FREQ_1024(n: cint): cint; inline;
  43. begin
  44. TIMER_FREQ_1024 := cint(-($2000000 shr 10) div (n));
  45. end;
  46. {$endif NDS_IMPLEMENTATION}
  47. {$ifdef NDS_INTERFACE}
  48. const
  49. //! Same as %TIMER_DATA(0).
  50. TIMER0_DATA : pcuint16 = pointer($04000100);
  51. //! Same as %TIMER_DATA(1).
  52. TIMER1_DATA : pcuint16 = pointer($04000104);
  53. //! Same as %TIMER_DATA(2).
  54. TIMER2_DATA : pcuint16 = pointer($04000108);
  55. //! Same as %TIMER_DATA(3).
  56. TIMER3_DATA : pcuint16 = pointer($0400010C);
  57. {$endif NDS_INTERFACE}
  58. {$ifdef NDS_IMPLEMENTATION}
  59. function TIMER_DATA(n: cuint): pcuint16; inline;
  60. begin
  61. TIMER_DATA := pcuint16($04000100 + (n shl 2));
  62. end;
  63. {$endif NDS_IMPLEMENTATION}
  64. {$ifdef NDS_INTERFACE}
  65. const
  66. // Timer control registers
  67. //! Same as %TIMER_CR(0).
  68. TIMER0_CR : pcuint16 = pointer($04000102);
  69. //! Same as %TIMER_CR(1).
  70. TIMER1_CR : pcuint16 = pointer($04000106);
  71. //! Same as %TIMER_CR(2).
  72. TIMER2_CR : pcuint16 = pointer($0400010A);
  73. //! Same as %TIMER_CR(3).
  74. TIMER3_CR : pcuint16 = pointer($0400010E);
  75. {$endif NDS_INTERFACE}
  76. {$ifdef NDS_IMPLEMENTATION}
  77. function TIMER_CR(n: cint): pcuint16; inline;
  78. begin
  79. TIMER_CR := pcuint16($04000102 + (n shl 2));
  80. end;
  81. {$endif NDS_IMPLEMENTATION}
  82. {$ifdef NDS_INTERFACE}
  83. const
  84. //! Enables the timer.
  85. TIMER_ENABLE = (1 shl 7);
  86. //! Causes the timer to request an Interupt on overflow.
  87. TIMER_IRQ_REQ = (1 shl 6);
  88. //! When set will cause the timer to count when the timer below overflows (unavailable for timer 0).
  89. TIMER_CASCADE = (1 shl 2);
  90. //! Causes the timer to count at 33.514Mhz.
  91. TIMER_DIV_1 = (0);
  92. //! Causes the timer to count at (33.514 / 64) Mhz.
  93. TIMER_DIV_64 = (1);
  94. //! Causes the timer to count at (33.514 / 256) Mhz.
  95. TIMER_DIV_256 = (2);
  96. //! Causes the timer to count at (33.514 / 1024)Mhz.
  97. TIMER_DIV_1024 = (3);
  98. {$endif NDS_INTERFACE}
  99. {$ifdef NDS_INTERFACE}
  100. function TIMER_FREQ(n: cint): cint; inline;
  101. function TIMER_FREQ_64(n: cint): cint; inline;
  102. function TIMER_FREQ_256(n: cint): cint; inline;
  103. function TIMER_FREQ_1024(n: cint): cint; inline;
  104. function TIMER_DATA(n: cuint): pcuint16; inline;
  105. function TIMER_CR(n: cint): pcuint16; inline;
  106. {$endif NDS_INTERFACE}