w.i.p sdcard device driver for raspi. detects cards but isnt able to send commands...
[AROS.git] / arch / arm-raspi / devs / sdcard / timer.c
blob180cfbecfc4111a2778ca269ea8c98db6cd06ff5
1 /*
2 Copyright © 2013, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 1
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_intern.h"
19 struct IORequest *sdcard_OpenTimer(struct SDCardBase *SDCardBase)
21 struct MsgPort *p = CreateMsgPort();
22 if (NULL != p)
24 struct IORequest *io = CreateIORequest(p, sizeof(struct timerequest));
26 if (NULL != io)
29 * ok. ECLOCK does not have too great resolution, either.
30 * we will have to sacrifice our performance a little bit, meaning, the 400ns will turn into (worst case) 2us.
31 * hopefully we won't have to call that TOO often...
33 if (0 == OpenDevice("timer.device", UNIT_MICROHZ, io, 0))
35 if (NULL == SDCardBase->sdcard_TimerBase)
37 SDCardBase->sdcard_TimerBase = io->io_Device;
39 return io;
41 else
43 bug("[SDCard ] Failed to open timer.device, unit MICROHZ\n");
45 DeleteIORequest(io);
47 else
49 bug("[SDCard ] Failed to create timerequest\n");
51 DeleteMsgPort(p);
53 else
55 bug("[SDCard ] Failed to create timer port\n");
58 return NULL;
61 void sdcard_CloseTimer(struct IORequest *tmr)
63 if (NULL != tmr)
65 struct MsgPort *p = tmr->io_Message.mn_ReplyPort;
66 CloseDevice(tmr);
67 DeleteIORequest(tmr);
68 DeleteMsgPort(p);
72 void sdcard_WaitNano(register ULONG ns, struct SDCardBase *SDCardBase)
74 volatile register ULONG t = 1;
75 while (ns > 0)
77 asm volatile("mov r0, r0\n");
78 --ns;
82 ULONG sdcard_WaitTO(struct IORequest* tmr, ULONG secs, ULONG micro, ULONG sigs)
84 ULONG sig = 1 << tmr->io_Message.mn_ReplyPort->mp_SigBit;
86 //D(bug("[SDCard--] Timed wait %lds %ldu\n", secs, micro));
88 tmr->io_Command = TR_ADDREQUEST;
89 ((struct timerequest*)tmr)->tr_time.tv_secs = secs;
90 ((struct timerequest*)tmr)->tr_time.tv_micro = micro;
92 SendIO(tmr);
93 sigs = Wait(sigs | sig);
94 if (0 == (sigs & sig))
96 if (!CheckIO(tmr))
97 AbortIO(tmr);
99 WaitIO(tmr);
101 SetSignal(0, sig);
103 return sigs &~ sig;