SuperH-based fx calculators
fx legacy timer

Software Timer


The system provides for 10 software-timers (accessed by the ID 1..10).
The system uses timer slots 1..5. The SDK functions (SetTimer/KillTimer) use the timer slots 6..10 only. Two of the timer slots 1..5 are installed permanently (2 and 4). They are stopped most of the time. Timer slot 2 is active a short time when hitting a key. Its handler is syscall 0x0251. On the slim the software-timer 1 is installed permanently for backlight timing.
On the non-slim the software-timer 1 seems to be used sometimes by the system.
Timer 4 serves the USB communication and uses syscall 0x04AE as handler.
Obviously the timer slots 1..5 are not automatically destroyed when changing an application, possibly giving the opportunity to install system resident handlers. Such handlers cannot be positioned inside an application's code.
Timer slots 3 and 5 seem to be available, at present.

The timers are served by some extra TMU.

0x0118: int Timer_Install( int InternalTimerID, void*handler, int elapse ); (SDK name Bcre_cychdr())

InternalTimerID may be 1..10, the ID of one of the 10 software-timer slots located at 88004654 (OS 1.03) or zero. InternalTimerID = 0 instructs the installation routine to search the next free timer slot. Any other allowed value tries to use exactly that timer slot.
handler and elapse are equivalent to the SDK SetTimer parameters (except for the order swap).
returns a valid TimerID (1..10) or a negative number when failing.

A timer slot consists of four int parameters.
slot.parameter[0]: -1 when free, 0 when stopped, 1 when running.
slot.parameter[1]: handler address or 0 when free.
slot.parameter[2]: maxcount; elapse/25 or 1 if elapse/25 yields zero. Is -1 when free.
slot.parameter[3]: counter; permanently counts down to zero from the value in slot.parameter[2] when running. Equals slot.parameter[2] when stopped. Is -1 when free.

0x0119: int Timer_Deinstall( int InternalTimerID ); (SDK name Bdel_cychdr())

sets slot.parameter[0] to -1, slot.parameter[1] to 0, slot.parameter[2] to -1 and slot.parameter[3] to -1.

0x011A: int Timer_Start( int InternalTimerID ); (SDK name Bsta_cychdr())

starts a timer by setting slot.parameter[0] to 1.
resets the counter, t. i. sets slot.parameter[3] = slot.parameter[2].

0x011B: int Timer_Stop( int InternalTimerID ); (SDK name Bstp_cychdr())

stops a timer by setting slot.parameter[0] to 0.
resets the counter, t. i. sets slot.parameter[3] = slot.parameter[2].

The corresponding SDK functions are implemented as follows:

int SetTimer( int ID, int elapse, void (*handler)(void) ){
int result=Timer_Install( ID+5, handler, elapse );
  if (result==ID+5){ result = Timer_Start( ID+5 );};
return result;
}



int KillTimer( int ID ){
int result=Timer_Stop( ID+5 );
  if (result==ID+5){ result = Timer_Deinstall( ID+5 );};
return result;
}

 

 

 

(13.10.2012 12:06:12)