tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / rom / devs / sdcard / timer.c
blobb10edc7d9fef05836e198307807300ce83470b7b
1 /*
2 Copyright © 2013, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 0
7 #include <aros/debug.h>
9 #include <exec/types.h>
10 #include <devices/timer.h>
11 #include <exec/io.h>
12 #include <proto/exec.h>
13 #include <aros/debug.h>
14 #include <proto/timer.h>
16 #include "timer.h"
17 #include "sdcard_base.h"
19 #include LC_LIBDEFS_FILE
21 struct IORequest *sdcard_OpenTimer(LIBBASETYPEPTR LIBBASE)
23 struct MsgPort *p = CreateMsgPort();
24 if (NULL != p)
26 struct IORequest *io = CreateIORequest(p, sizeof(struct timerequest));
28 if (NULL != io)
31 * ok. ECLOCK does not have too great resolution, either.
32 * we will have to sacrifice our performance a little bit, meaning, the 400ns will turn into (worst case) 2us.
33 * hopefully we won't have to call that TOO often...
35 if (0 == OpenDevice("timer.device", UNIT_MICROHZ, io, 0))
37 if (NULL == LIBBASE->sdcard_TimerBase)
39 LIBBASE->sdcard_TimerBase = io->io_Device;
41 return io;
43 else
45 bug("[SDCard ] Failed to open timer.device, unit MICROHZ\n");
47 DeleteIORequest(io);
49 else
51 bug("[SDCard ] Failed to create timerequest\n");
53 DeleteMsgPort(p);
55 else
57 bug("[SDCard ] Failed to create timer port\n");
60 return NULL;
63 void sdcard_CloseTimer(struct IORequest *tmr)
65 if (NULL != tmr)
67 struct MsgPort *p = tmr->io_Message.mn_ReplyPort;
68 CloseDevice(tmr);
69 DeleteIORequest(tmr);
70 DeleteMsgPort(p);
74 ULONG sdcard_WaitTO(struct IORequest* tmr, ULONG secs, ULONG micro, ULONG sigs)
76 ULONG sig = 1 << tmr->io_Message.mn_ReplyPort->mp_SigBit;
78 tmr->io_Command = TR_ADDREQUEST;
79 ((struct timerequest*)tmr)->tr_time.tv_secs = secs;
80 ((struct timerequest*)tmr)->tr_time.tv_micro = micro;
82 SendIO(tmr);
83 sigs = Wait(sigs | sig);
84 if (0 == (sigs & sig))
86 if (!CheckIO(tmr))
87 AbortIO(tmr);
89 WaitIO(tmr);
91 SetSignal(0, sig);
93 return sigs &~ sig;