3 #include <devices/timer.h>
5 #include <proto/exec.h>
9 #include "fat_protos.h"
14 LONG err
= ERROR_NO_FREE_STORE
;
16 glob
->timerport
= CreateMsgPort();
17 if (glob
->timerport
) {
18 glob
->timereq
= (struct timerequest
*)CreateIORequest(glob
->timerport
,
19 sizeof(struct timerequest
));
21 if (OpenDevice("timer.device", UNIT_VBLANK
, (struct IORequest
*)glob
->timereq
, 0))
22 err
= ERROR_DEVICE_NOT_MOUNTED
;
24 glob
->timer_active
= 0;
25 glob
->restart_timer
= 1;
26 D(bug("[fat] Timer ready\n"));
29 DeleteIORequest((struct IORequest
*)glob
->timereq
);
31 DeleteMsgPort(glob
->timerport
);
36 void CleanupTimer(void)
38 D(bug("[fat] Cleaning up timer\n"));
39 if (glob
->timer_active
) {
40 D(bug("[fat] Terminating active request\n"));
41 AbortIO((struct IORequest
*)glob
->timereq
);
42 WaitIO((struct IORequest
*)glob
->timereq
);
44 CloseDevice((struct IORequest
*)glob
->timereq
);
45 DeleteIORequest((struct IORequest
*)glob
->timereq
);
46 DeleteMsgPort(glob
->timerport
);
49 void RestartTimer(void)
51 if (glob
->timer_active
) {
52 D(bug("Queuing timer restart\n"));
53 glob
->restart_timer
= 1;
55 D(bug("Immediate timer restart\n"));
56 glob
->timereq
->tr_node
.io_Command
= TR_ADDREQUEST
;
57 glob
->timereq
->tr_time
.tv_secs
= 2;
58 glob
->timereq
->tr_time
.tv_micro
= 0;
59 SendIO((struct IORequest
*)glob
->timereq
);
60 glob
->timer_active
= 1;
64 void HandleTimer(void)
66 WaitIO((struct IORequest
*)glob
->timereq
);
67 glob
->timer_active
= 0;
68 if (glob
->restart_timer
) {
69 D(bug("Timer restart queued\n"));
70 glob
->restart_timer
= 0;
73 D(bug("Updating disk\n"));