PROGRAMMER'S GUIDETimer library
■ | Advance
Timer library

1. 1. guide


1.1 Purpose

This library mainly provides functional macros to get programmable WAIT and processing time.

1.2 Overview

The timer uses the free running timer (FRT) in the CPU and the timer interrupt in the SCU. We have prepared function-type macros for the following purposes for each device.

● SCU

● CPU

1.3 Detailed description

● SCU
<How to use>
See the timer interrupt in the SCU User's Manual for details on how to use it.

<Calling sequence>
The following shows a calling sequence that causes a timer 1 interrupt when drawing to the 10th bit of each line using timer 1, and inverts that line in the case of an odd line.

Uint32 time_flg; / * Interrupt flag * /
...
void vblankOut () / * V-BLANK OUT execution function * /
{
     Uint32 intr_count = 0; / * Interrupt counter * /
     ...
     TIM_T1_DISABLE (); / * Timer 1 interrupt disabled * /
     TIM_T1_SET_MODE (TIM_MD_LINE); / * Specify interrupt generation for each line * /
     TIM_T1_SET_DATA (10);                 
                  / * Specify the interrupt generation timing at the 10th bit of the line * /
     time_flg = OFF; / * Turn off the interrupt flag * /
     TIM_T1_ENABLE (); / * Timer 1 interrupt enabled * /
     ...
     for (intr_count <ALL_LINE_NUM) {
                                           / * Until the interrupt of all lines is executed * /
               changeLine (intr_count); / * Invert odd line * /
               intr_count ++; / * Line count * /
     }
}
void timeIntr () / * Interrupt execution function * /
{
     time_flg = ON; / * Turn on interrupt flag * /
}

● CPU
<Basic matters>
Counter value
The counter value is used to specify the time to FRT. This counter value is explained below.

The count-up cycle of the counter value changes depending on the frequency division specification and graphic mode specification. The count-up cycle can be calculated by the following calculation.

Count-up period (s) = frequency division x 1 / clock frequency (Hz)

It is convenient to use the following function-type macros for conversion from count value to microsecond and conversion from microsecond to count value.

 function
 Function format macro
 number
 Counter value-> microsecond conversion
 TIM_FRT_CNT_TO_MCR
 15
 Microsecond-> Counter value conversion
 TIM_FRT_MCR_TO_CNT
 16

<How to use>
Initialize
Execute the following function-form macro before getting the elapsed time and using the WAIT function.

 function
 Function format macro
 number
 FRT initialization
 TIM_FRT_INIT
 8

How to get the elapsed time
The following functions are prepared to obtain the elapsed time.

 function
 Function format macro
 number
 Counter value setting (16 bits)
 TIM_FRT_SET_16
 9
 Counter value acquisition (16 bits)
 TIM_FRT_GET_16
 Ten

void sysInit ()
{
     TIM_FRT_INIT (8); / * Set frequency division to 8 * /
     ...
}

 void writeFrameBuff ()
{
     Uint16 count; / * Acquisition count value storage area * /
     float micro_sec; / * Microsecond storage area * /
     TIM_FRT_SET_16 (0); / * Set the count value to 0 * /
     WriteAllVram (); / * Execution of the process you want to measure * /
     count = TIM_Frt_Get_16 (); / * Get the count value * /
                                           / * count indicates the execution time of WriteAllVram () * /
     micro_sec = TIM_FRT_CNT_TO_MCR (count); / * Convert counter value to microseconds * /
     printDisplay (micro_sec); / * Display the elapsed time on the screen * /
}


■ | Advance
PROGRAMMER'S GUIDETimer library
Copyright SEGA ENTERPRISES, LTD., 1997