Three primary steps are required to open the timer device:
struct MsgPort *TimerMP; // Message port pointer
struct Timerequest *TimerIO; // I/O structure pointer
// Create port for timer device communications
if (!(TimerMP = IExec->AllocSysObjectTags(ASOT_PORT, TAG_END)))
cleanexit(" Error: Can't create port\n", RETURN_FAIL);// Create message block for device IO
TimerIO = IExec->AllocSysObjectTags(ASOT_IOREQUEST,
ASOIOR_Size, sizeof(struct TimeRequest),
ASOIOR_ReplyPort, TimerMP,
TAG_END);// Open the timer device with UNIT_MICROHZ
if (error = IExec->OpenDevice(TIMERNAME, UNIT_MICROHZ, TimerIO, 0))
cleanexit(" Error: Can't open Timer.device\n", RETURN_FAIL);The procedure for applications which only use the timer device functions is slightly different:
struct TimerIFace *ITimer /* global interface pointer */
/* Allocate memory for TimeRequest and TimeVal structures */
struct TimeRequest *TimerIO = IExec->AllocVecTags(sizeof(struct TimeRequest),
AVT_ClearWithValue, 0,
TAG_END);
if (TimerIO == NULL)
cleanexit(" Error: Can't allocate memory for I/O structures\n", RETURN_FAIL);
if (error = IExec->OpenDevice(TIMERNAME, UNIT_MICROHZ, TimerIO, 0))
cleanexit(" Error: Can't open Timer.device\n", RETURN_FAIL);
/* Set up pointers for timer functions */
struct Library *TimerBase = (struct Library *)TimerIO->Request.io_Device;
ITimer = IExec->GetInterface(TimerBase, "main", 1, NULL);@peceha, post #1