Moved fat-handler sources to rom/filesys.
[AROS.git] / rom / filesys / fat / timer.c
blob40f4edcd2a32103915e46f946a5f1995007f4372
1 /*
2 * fat.handler - FAT12/16/32 filesystem handler
4 * Copyright 2008-2010 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(void)
24 LONG err = ERROR_NO_FREE_STORE;
26 glob->timerport = CreateMsgPort();
27 if (glob->timerport) {
28 glob->timereq = (struct timerequest *)CreateIORequest(glob->timerport,
29 sizeof(struct timerequest));
30 if (glob->timereq) {
31 if (OpenDevice("timer.device", UNIT_VBLANK, (struct IORequest *)glob->timereq, 0))
32 err = ERROR_DEVICE_NOT_MOUNTED;
33 else {
34 glob->timer_active = 0;
35 glob->restart_timer = 1;
36 D(bug("[fat] Timer ready\n"));
37 return 0;
39 DeleteIORequest((struct IORequest *)glob->timereq);
41 DeleteMsgPort(glob->timerport);
43 return err;
46 void CleanupTimer(void)
48 D(bug("[fat] Cleaning up timer\n"));
49 if (glob->timer_active) {
50 D(bug("[fat] Terminating active request\n"));
51 AbortIO((struct IORequest *)glob->timereq);
52 WaitIO((struct IORequest *)glob->timereq);
54 CloseDevice((struct IORequest *)glob->timereq);
55 DeleteIORequest((struct IORequest *)glob->timereq);
56 DeleteMsgPort(glob->timerport);
59 void RestartTimer(void)
61 if (glob->timer_active) {
62 D(bug("Queuing timer restart\n"));
63 glob->restart_timer = 1;
64 } else {
65 D(bug("Immediate timer restart\n"));
66 glob->timereq->tr_node.io_Command = TR_ADDREQUEST;
67 glob->timereq->tr_time.tv_secs = 1;
68 glob->timereq->tr_time.tv_micro = 0;
69 SendIO((struct IORequest *)glob->timereq);
70 glob->timer_active = 1;
74 void HandleTimer(void)
76 WaitIO((struct IORequest *)glob->timereq);
77 glob->timer_active = 0;
78 if (glob->restart_timer) {
79 D(bug("Timer restart queued\n"));
80 glob->restart_timer = 0;
81 RestartTimer();
82 } else {
83 D(bug("Updating disk\n"));
84 UpdateDisk();