mirror of https://github.com/weiju/amiga-stuff
cleaned up and clarified behavior of the timer device and how to properly clean it up
This commit is contained in:
parent
b3fd30c95b
commit
35185e979a
|
@ -17,8 +17,6 @@ int main(int argc, char **argv)
|
|||
{
|
||||
struct MsgPort *timer_port = NULL;
|
||||
struct timerequest *timer_io = NULL;
|
||||
struct timeval time1;
|
||||
ULONG mics, secs;
|
||||
BYTE error = 0;
|
||||
|
||||
timer_port = CreatePort(NULL, 0);
|
||||
|
@ -33,24 +31,40 @@ int main(int argc, char **argv)
|
|||
DeletePort(timer_port);
|
||||
return 0;
|
||||
}
|
||||
error = OpenDevice(TIMERNAME, UNIT_MICROHZ, (struct IORequest *) timer_io, 0);
|
||||
error = OpenDevice(TIMERNAME, UNIT_MICROHZ,
|
||||
(struct IORequest *) timer_io, 0);
|
||||
if (error) {
|
||||
printf("could not open timer.device\n");
|
||||
} else {
|
||||
ULONG secs, mins, hours, days;
|
||||
|
||||
TimerBase = (struct Library *) timer_io->tr_node.io_Device;
|
||||
timer_io->tr_node.io_Command = TR_GETSYSTIME;
|
||||
DoIO((struct IORequest *) timer_io);
|
||||
mics = timer_io->tr_time.tv_micro;
|
||||
secs = timer_io->tr_time.tv_secs;
|
||||
|
||||
printf("micros: %lu secs: %lu\n", mics, secs);
|
||||
|
||||
mins = secs / 60;
|
||||
hours = mins / 60;
|
||||
days = hours / 24;
|
||||
secs %= 60;
|
||||
mins %= 60;
|
||||
hours %= 24;
|
||||
|
||||
printf("%lu days, %02lu:%02lu:%02lu\n",
|
||||
days, hours, mins, secs);
|
||||
|
||||
/*
|
||||
* clean close of device, note that this sequence will
|
||||
* either crash or hang indefinitely if no DoIO() was
|
||||
* sent to the device
|
||||
*/
|
||||
if (!CheckIO((struct IORequest *) timer_io)) {
|
||||
AbortIO((struct IORequest *) timer_io);
|
||||
}
|
||||
WaitIO((struct IORequest *) timer_io);
|
||||
TimerBase = NULL;
|
||||
}
|
||||
/* cleanup */
|
||||
if (!CheckIO((struct IORequest *) timer_io)) {
|
||||
AbortIO((struct IORequest *) timer_io);
|
||||
}
|
||||
WaitIO((struct IORequest *) timer_io);
|
||||
TimerBase = NULL;
|
||||
CloseDevice((struct IORequest *) timer_io);
|
||||
if (timer_io) DeleteExtIO((struct IORequest *) timer_io);
|
||||
if (timer_port) DeletePort(timer_port);
|
||||
|
|
Loading…
Reference in New Issue