src/timer/nds/SDL_systimer.c
author Darren Alton <dalton@stevens.edu>
Mon, 18 Aug 2008 07:29:52 +0000
branchgsoc2008_nds
changeset 2696 0b395a60deff
parent 2683 e858ac8868b6
child 2698 e1da92da346c
permissions -rw-r--r--
Timers work now.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2006 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library 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 GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 #include "SDL_config.h"
    23 
    24 #ifdef SDL_TIMER_NDS
    25 
    26 #include <nds.h>
    27 #include <nds/timers.h>
    28 
    29 #include "SDL_timer.h"
    30 #include "../SDL_timer_c.h"
    31 #include "../SDL_systimer.h"
    32 
    33 /* Data to handle a single periodic alarm */
    34 static int timer_alive = 0;
    35 static Uint32 timer_ticks;
    36 
    37 void
    38 SDL_StartTicks(void)
    39 {
    40     if(!timer_alive) {
    41         SDL_SYS_TimerInit();
    42         SDL_SYS_StartTimer();
    43     }
    44 
    45     timer_ticks = 0;
    46 }
    47 
    48 Uint32
    49 SDL_GetTicks(void)
    50 {
    51     return timer_ticks;
    52 }
    53 
    54 void
    55 SDL_Delay(Uint32 ms)
    56 {
    57     Uint32 start = SDL_GetTicks();
    58     while(timer_alive) {
    59         if((SDL_GetTicks() - start) >= ms) break;
    60     }
    61 }
    62 
    63 static int
    64 RunTimer(void *unused)
    65 {
    66     while (timer_alive) {
    67         if (SDL_timer_running) {
    68         }
    69         SDL_Delay(1);
    70     }
    71     return (0);
    72 }
    73 
    74 void NDS_TimerInterrupt(void) {
    75 	timer_ticks++;
    76 }
    77 
    78 /* This is only called if the event thread is not running */
    79 int
    80 SDL_SYS_TimerInit(void)
    81 {
    82     timer_alive = 1;
    83     timer_ticks = 0;
    84     TIMER_CR(3) = TIMER_DIV_1024 | TIMER_IRQ_REQ;
    85     TIMER_DATA(3) = TIMER_FREQ_1024(1000);
    86     irqSet(IRQ_TIMER3, NDS_TimerInterrupt);
    87     irqEnable(IRQ_TIMER3);
    88     return 0;
    89 }
    90 
    91 void
    92 SDL_SYS_TimerQuit(void)
    93 {
    94     if (timer_alive) {
    95         TIMER_CR(3) = 0;
    96     }
    97     timer_alive = 0;
    98     irqDisable(IRQ_TIMER3);
    99 }
   100 
   101 int
   102 SDL_SYS_StartTimer(void)
   103 {
   104     TIMER_CR(3) |= TIMER_ENABLE;
   105     return 0;
   106 }
   107 
   108 void
   109 SDL_SYS_StopTimer(void)
   110 {
   111     TIMER_CR(3) &= ~TIMER_ENABLE;
   112     return;
   113 }
   114 
   115 
   116 #endif /* SDL_TIMER_NDS */
   117 /* vi: set ts=4 sw=4 expandtab: */