comparison src/timer/nds/SDL_systimer.c @ 2696:0b395a60deff gsoc2008_nds

Timers work now.
author Darren Alton <dalton@stevens.edu>
date Mon, 18 Aug 2008 07:29:52 +0000
parents e858ac8868b6
children e1da92da346c
comparison
equal deleted inserted replaced
2695:c04a266c277a 2696:0b395a60deff
26 #include <nds.h> 26 #include <nds.h>
27 #include <nds/timers.h> 27 #include <nds/timers.h>
28 28
29 #include "SDL_timer.h" 29 #include "SDL_timer.h"
30 #include "../SDL_timer_c.h" 30 #include "../SDL_timer_c.h"
31 #include "../SDL_systimer.h"
31 32
33 /* Data to handle a single periodic alarm */
34 static int timer_alive = 0;
32 static Uint32 timer_ticks; 35 static Uint32 timer_ticks;
33 36
34 void 37 void
35 SDL_StartTicks(void) 38 SDL_StartTicks(void)
36 { 39 {
55 while(timer_alive) { 58 while(timer_alive) {
56 if((SDL_GetTicks() - start) >= ms) break; 59 if((SDL_GetTicks() - start) >= ms) break;
57 } 60 }
58 } 61 }
59 62
60 /* Data to handle a single periodic alarm */
61 static int timer_alive = 0;
62 static int timer_ticks = 0;
63
64 static int 63 static int
65 RunTimer(void *unused) 64 RunTimer(void *unused)
66 { 65 {
67 while (timer_alive) { 66 while (timer_alive) {
68 if (SDL_timer_running) { 67 if (SDL_timer_running) {
70 SDL_Delay(1); 69 SDL_Delay(1);
71 } 70 }
72 return (0); 71 return (0);
73 } 72 }
74 73
75 void NDS_TimerInterrupt() { 74 void NDS_TimerInterrupt(void) {
76 printf("timer irq\n"); 75 timer_ticks++;
77 } 76 }
78 77
79 /* This is only called if the event thread is not running */ 78 /* This is only called if the event thread is not running */
80 int 79 int
81 SDL_SYS_TimerInit(void) 80 SDL_SYS_TimerInit(void)
82 { 81 {
83 timer_alive = 1; 82 timer_alive = 1;
84 timer_ticks = 0; 83 timer_ticks = 0;
85 TIMER_CR(0) = TIMER_DIV_1024 | TIMER_IRQ_REQ; 84 TIMER_CR(3) = TIMER_DIV_1024 | TIMER_IRQ_REQ;
86 TIMER_DATA(0) = TIMER_FREQ_1024(1000); 85 TIMER_DATA(3) = TIMER_FREQ_1024(1000);
87 irqSet(IRQ_TIMER1, NDS_TimerInterrupt); 86 irqSet(IRQ_TIMER3, NDS_TimerInterrupt);
87 irqEnable(IRQ_TIMER3);
88 return 0; 88 return 0;
89 } 89 }
90 90
91 void 91 void
92 SDL_SYS_TimerQuit(void) 92 SDL_SYS_TimerQuit(void)
93 { 93 {
94 if (timer_alive) { 94 if (timer_alive) {
95 TIMER_CR(0) = 0; 95 TIMER_CR(3) = 0;
96 } 96 }
97 timer_alive = 0; 97 timer_alive = 0;
98 irqDisable(IRQ_TIMER3);
98 } 99 }
99 100
100 int 101 int
101 SDL_SYS_StartTimer(void) 102 SDL_SYS_StartTimer(void)
102 { 103 {
103 TIMER_CR(0) |= TIMER_ENABLE; 104 TIMER_CR(3) |= TIMER_ENABLE;
104 return 0; 105 return 0;
105 } 106 }
106 107
107 void 108 void
108 SDL_SYS_StopTimer(void) 109 SDL_SYS_StopTimer(void)
109 { 110 {
110 TIMER_CR(0) &= ~TIMER_ENABLE; 111 TIMER_CR(3) &= ~TIMER_ENABLE;
111 return; 112 return;
112 } 113 }
113 114
114 115
115 #endif /* SDL_TIMER_NDS */ 116 #endif /* SDL_TIMER_NDS */