Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / fs / fat / timer.c
blob58d8855b672e9f67cd6ec9f51a9075fb3ce8b255
1 #define DEBUG 0
3 #include <devices/timer.h>
4 #include <dos/dos.h>
5 #include <proto/exec.h>
7 #include "debug.h"
8 #include "fat_fs.h"
9 #include "fat_protos.h"
10 #include "timer.h"
12 LONG InitTimer(void)
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));
20 if (glob->timereq) {
21 if (OpenDevice("timer.device", UNIT_VBLANK, (struct IORequest *)glob->timereq, 0))
22 err = ERROR_DEVICE_NOT_MOUNTED;
23 else {
24 glob->timer_active = 0;
25 glob->restart_timer = 1;
26 D(bug("[fat] Timer ready\n"));
27 return 0;
29 DeleteIORequest((struct IORequest *)glob->timereq);
31 DeleteMsgPort(glob->timerport);
33 return err;
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;
54 } else {
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;
71 RestartTimer();
72 } else {
73 D(bug("Updating disk\n"));
74 UpdateDisk();