73 lines
1.6 KiB
C
73 lines
1.6 KiB
C
//--------------------------------------------------------------------------//
|
|
// This file is in the public domain. //
|
|
//--------------------------------------------------------------------------//
|
|
|
|
/*
|
|
* Written by Carsten Larsen.
|
|
* Public domain.
|
|
*/
|
|
|
|
#include <clib/exec_protos.h>
|
|
#include <clib/timer_protos.h>
|
|
#include <devices/timer.h>
|
|
|
|
struct Device* TimerBase;
|
|
struct MsgPort* TimerPort;
|
|
struct timerequest* TimeRequest;
|
|
|
|
int CreateTimer()
|
|
{
|
|
int error;
|
|
|
|
TimerPort = CreateMsgPort();
|
|
if (TimerPort == NULL) {
|
|
return 1;
|
|
}
|
|
|
|
TimeRequest = (struct timerequest*)CreateIORequest(
|
|
TimerPort,
|
|
sizeof(struct timerequest)
|
|
);
|
|
|
|
if (TimeRequest == NULL) {
|
|
DeleteMsgPort(TimerPort);
|
|
return 2;
|
|
}
|
|
|
|
error = OpenDevice(
|
|
(STRPTR)TIMERNAME,
|
|
UNIT_MICROHZ,
|
|
(struct IORequest*)TimeRequest,
|
|
0
|
|
);
|
|
|
|
if (error != 0)
|
|
{
|
|
DeleteIORequest((struct IORequest*)TimeRequest);
|
|
DeleteMsgPort(TimerPort);
|
|
return 3;
|
|
}
|
|
|
|
TimerBase = (struct Device*)TimeRequest->tr_node.io_Device;
|
|
return 0;
|
|
}
|
|
|
|
void DeleteTimer()
|
|
{
|
|
if (TimeRequest != NULL) {
|
|
if (!CheckIO((struct IORequest*)TimeRequest)) {
|
|
WaitIO((struct IORequest*)TimeRequest);
|
|
}
|
|
|
|
CloseDevice((struct IORequest*)TimeRequest);
|
|
DeleteIORequest((struct IORequest*)TimeRequest);
|
|
|
|
TimeRequest = NULL;
|
|
}
|
|
|
|
if (TimerPort != NULL) {
|
|
DeleteMsgPort(TimerPort);
|
|
TimerPort = NULL;
|
|
}
|
|
}
|