Timer (Overview)


Introduction

There are four 16-bit hardware timers in the Nintendo DS. Each can be used independently, or they can be combined to make 32-bit, 48-bit, or 64-bit timers.

However, the user must abide by certain conditions when using these timers. When using a timer inside the NitroSDK OS, the user cannot directly use that timer.

Inside the NitroSDK, there are two features that use the timer: the tick system and the alarm system. By default, the tick system uses timer 0, while the alarm system uses timer 1. Also, the tick system is required when using the alarm system. These gives rise to the following restrictions:

  • When using the tick system but not the alarm system, timer 0 cannot be used.
  • When using the alarm system (and in such a case, the tick system must be used), neither timers 0 and 1 can be used.

  • (both restrictions apply to the default configuration)

    When performing a DEBUG build with the NitroSDK, when trying to access the timer being used by the system by using the timer function, a warning appears and processing halts.


    Timer Operations

    By setting a value in the timer count register and setting the enable flag of the timer control register, a regular-interval count begins. It is possible to configure and choose a multiple of the system clock (1x, 16x, 64x, or 1024x) for the increment interval.

    A timer interrupt occurs when the counter ranges from 0xFFFF to 0x0000. If the timer interrupt handler is set in advance with OS_SetIrqFunction(), that handler will be called.

    According to the hardware specifications, as long as the timer does not stop, the count up and interrupt will repeat any number of times. However, if the interrupt occurs inside the OS, the timer will be disabled. In other words, only one interrupt occurs per configuration.


    Timer Configuration and Startup

    The functions below set appropriate values to the timer count register and the timer control register, then start the timer.

    OS_StartTimer()
    OS_StartTimer32()
    OS_StartTimer48()
    OS_StartTimer64()


    Stopping the Timer

    The functions below clear the enable flag of the timer control register and stop the timer.

    OS_StopTimer()
    OS_StopTimer32()
    OS_StopTimer48()
    OS_StopTimer64()

    See Also

    An Overview of OS Functions (Timer), An Overview of OS Functions (Time), An Overview of OS Functions (Alarm)

    Revision History

    11/16/2004 Initial version