Timers

From Amiga Development Wiki
Jump to: navigation, search

On Amiga timers are operated through timer.device interface.

Timer units

Type Description
UNIT_VBLANK This unit has low overhead, but resolution is limited to 1/50 or 1/60 seconds.
UNIT_MICROHZ This unit has microsecond accuracy with more overhead. Recommended for short waits.
UNIT_CPUCLOCK This unit has the best possible accuracy, but has relatively more overhead thank VBLANK unit. Recommended for short waits. Not available on all systems.
UNIT_ECLOCK This unit has good accuracy with more overhead.
UNIT_WAITUNTIL An alarm clock unit with the resolution of 1/50 or 1/60 seconds.
UNIT_WAITECLOCK An alarm clock unit with the resolution of Amiga E-clock.
UNIT_WAITCPUCLOCK An alarm clock unit with the best possible resolution. Not available on all systems.

Example

#include <devices/timer.h>
#include <proto/dos.h>
#include <proto/exec.h>
 
int main()
{
   struct MsgPort *port = CreateMsgPort();
 
   if (port)
   {
      struct timerequest req;
      req.mn_ReplyPort = port;
 
      if (OpenDevice("timer.device", UNIT_VBLANK, &req.tr_node, 0) == 0)
      {
         req.tr_node.io_Command = TR_ADDREQUEST;
         req.tr_time.tv_secs = 10; // 10 seconds
         req.tr_time.tv_micro = 0;
         SendIO(&req.tr_node);
 
         PutStr("Waiting...\n");
         WaitPort(port);
         GetMsg(port);
 
         PutStr("Done!\n");
         CloseDevice(&req.tr_node);
      }
   }
 
   DeleteMsgPort(port);
 
   return 0;
}