config/make.tmpl: pass -nix flag also to LDFLAGS of configure
[AROS.git] / rom / filesys / fat / timer.c
blob266499f80f99486eb50172bdfc5fc4809ff9e7b6
1 /*
2 * fat-handler - FAT12/16/32 filesystem handler
4 * Copyright © 2008-2015 The AROS Development Team
6 * This program is free software; you can redistribute it and/or modify it
7 * under the same terms as AROS itself.
9 * $Id$
12 #define DEBUG 0
14 #include <devices/timer.h>
15 #include <dos/dos.h>
16 #include <proto/exec.h>
18 #include "debug.h"
19 #include "fat_fs.h"
20 #include "fat_protos.h"
22 LONG InitTimer(struct Globals *glob)
24 LONG err = ERROR_NO_FREE_STORE;
26 glob->timerport = CreateMsgPort();
27 if (glob->timerport)
29 glob->timereq =
30 (struct timerequest *)CreateIORequest(glob->timerport,
31 sizeof(struct timerequest));
32 if (glob->timereq)
34 if (OpenDevice("timer.device", UNIT_VBLANK,
35 (struct IORequest *)glob->timereq, 0))
36 err = ERROR_DEVICE_NOT_MOUNTED;
37 else
39 glob->timer_active = FALSE;
40 glob->restart_timer = TRUE;
41 glob->gl_TimerBase = glob->timereq->tr_node.io_Device;
42 D(bug("[fat] Timer ready\n"));
43 return 0;
45 DeleteIORequest((struct IORequest *)glob->timereq);
47 DeleteMsgPort(glob->timerport);
49 return err;
52 void CleanupTimer(struct Globals *glob)
54 D(bug("[fat] Cleaning up timer\n"));
55 if (glob->timer_active)
57 D(bug("[fat] Terminating active request\n"));
58 AbortIO((struct IORequest *)glob->timereq);
59 WaitIO((struct IORequest *)glob->timereq);
61 CloseDevice((struct IORequest *)glob->timereq);
62 DeleteIORequest((struct IORequest *)glob->timereq);
63 DeleteMsgPort(glob->timerport);
66 void RestartTimer(struct Globals *glob)
68 if (glob->timer_active)
70 D(bug("Queuing timer restart\n"));
71 glob->restart_timer = TRUE;
73 else
75 D(bug("Immediate timer restart\n"));
76 glob->timereq->tr_node.io_Command = TR_ADDREQUEST;
77 glob->timereq->tr_time.tv_secs = 1;
78 glob->timereq->tr_time.tv_micro = 0;
79 SendIO((struct IORequest *)glob->timereq);
80 glob->timer_active = TRUE;
84 void HandleTimer(struct Globals *glob)
86 WaitIO((struct IORequest *)glob->timereq);
87 glob->timer_active = 0;
88 if (glob->restart_timer)
90 D(bug("Timer restart queued\n"));
91 glob->restart_timer = FALSE;
92 RestartTimer(glob);
94 else
96 D(bug("Updating disk\n"));
97 UpdateDisk(glob);