2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: BeginIO - Start up a timer.device request.
10 #include <devices/newstyle.h>
11 #include <exec/errors.h>
12 #include <exec/initializers.h>
13 #include <proto/exec.h>
16 /****************************************************************************************/
18 #define NEWSTYLE_DEVICE 1
20 #define ioStd(x) ((struct IOStdReq *)x)
22 /****************************************************************************************/
26 static const UWORD SupportedCommands
[] =
37 /****************************************************************************************/
39 BOOL
timer_addToWaitList(struct TimerBase
*, struct MinList
*, struct timerequest
*);
41 /*****i***********************************************************************
44 #include <devices/timer.h>
45 #include <proto/timer.h>
46 AROS_LH1(void, BeginIO
,
49 AROS_LHA(struct timerequest
*, timereq
, A1
),
52 struct TimerBase
*, TimerBase
, 5, Timer
)
55 BeginIO() will perform a timer.device command. It is normally
56 called from within DoIO() and SendIO().
59 timereq - The request to process.
62 The requested message will be processed.
65 This function is safe to call from interrupts.
72 exec/Abort(), exec/SendIO(), exec/DoIO()
77 23-01-1998 iaint Implemented again.
79 ******************************************************************************/
86 outb((inb(0x61) & 0xfd) | 1, 0x61); /* Enable the timer (set GATE on) */
87 EClockUpdate(TimerBase
);
89 timereq
->tr_node
.io_Message
.mn_Node
.ln_Type
= NT_MESSAGE
;
90 timereq
->tr_node
.io_Error
= 0;
92 unitNum
= (ULONG
)timereq
->tr_node
.io_Unit
;
94 switch(timereq
->tr_node
.io_Command
)
97 case NSCMD_DEVICEQUERY
:
98 #warning In timer.device this is maybe a bit problematic, as the timerequest structure does not have io_Data and io_Length members
100 if (timereq
->tr_node
.io_Message
.mn_Length
< sizeof(struct IOStdReq
))
102 timereq
->tr_node
.io_Error
= IOERR_BADLENGTH
;
104 else if(ioStd(timereq
)->io_Length
< ((LONG
)OFFSET(NSDeviceQueryResult
, SupportedCommands
)) + sizeof(UWORD
*))
106 timereq
->tr_node
.io_Error
= IOERR_BADLENGTH
;
110 struct NSDeviceQueryResult
*d
;
112 d
= (struct NSDeviceQueryResult
*)ioStd(timereq
)->io_Data
;
114 d
->DevQueryFormat
= 0;
115 d
->SizeAvailable
= sizeof(struct NSDeviceQueryResult
);
116 d
->DeviceType
= NSDEVTYPE_TIMER
;
117 d
->DeviceSubType
= 0;
118 d
->SupportedCommands
= (UWORD
*)SupportedCommands
;
120 ioStd(timereq
)->io_Actual
= sizeof(struct NSDeviceQueryResult
);
126 GetSysTime(&timereq
->tr_time
);
128 if(!(timereq
->tr_node
.io_Flags
& IOF_QUICK
))
130 ReplyMsg((struct Message
*)timereq
);
132 replyit
= FALSE
; /* Because replyit will clear the timeval */
137 TimerBase
->tb_CurrentTime
.tv_secs
= timereq
->tr_time
.tv_secs
;
138 TimerBase
->tb_CurrentTime
.tv_micro
= timereq
->tr_time
.tv_micro
;
139 EClockSet(TimerBase
);
148 /* Firstly, check to see if request is for past */
150 if(CmpTime(&TimerBase
->tb_CurrentTime
, &timereq
->tr_time
) <= 0)
153 timereq
->tr_time
.tv_secs
= timereq
->tr_time
.tv_micro
= 0;
154 timereq
->tr_node
.io_Error
= 0;
159 /* Ok, we add this to the list */
160 if (timer_addToWaitList(TimerBase
, &TimerBase
->tb_Lists
[TL_WAITVBL
], timereq
))
162 outb((inb(0x61) & 0xfd) | 1, 0x61); /* Enable the timer (set GATE on) */
163 Timer0Setup(TimerBase
);
167 timereq
->tr_node
.io_Flags
&= ~IOF_QUICK
;
174 AddTime(&timereq
->tr_time
, &TimerBase
->tb_Elapsed
);
175 /* Slot it into the list */
176 if (timer_addToWaitList(TimerBase
, &TimerBase
->tb_Lists
[TL_VBLANK
], timereq
))
178 outb((inb(0x61) & 0xfd) | 1, 0x61); /* Enable the timer (set GATE on) */
179 Timer0Setup(TimerBase
);
182 timereq
->tr_node
.io_Flags
&= ~IOF_QUICK
;
187 case UNIT_WAITECLOCK
:
190 timereq
->tr_node
.io_Error
= IOERR_NOCMD
;
192 } /* switch(unitNum) */
206 timereq
->tr_node
.io_Error
= IOERR_NOCMD
;
208 } /* switch(command) */
212 timereq
->tr_time
.tv_secs
= 0;
213 timereq
->tr_time
.tv_micro
= 0;
214 if(!(timereq
->tr_node
.io_Flags
& IOF_QUICK
))
216 ReplyMsg((struct Message
*)timereq
);
224 timer_addToWaitList(struct TimerBase
*TimerBase
,
225 struct MinList
*list
,
226 struct timerequest
*iotr
)
228 /* We are disabled, so we should take as little time as possible. */
229 struct timerequest
*tr
;
232 ForeachNode(list
, tr
)
234 /* If the time in the new request is less than the next request */
235 if(CmpTime(&tr
->tr_time
, &iotr
->tr_time
) < 0)
237 /* Add the node before the next request */
241 tr
->tr_node
.io_Message
.mn_Node
.ln_Pred
249 This will catch the case of either an empty list, or request is
250 for after all other requests
254 AddTail((struct List
*)list
, (struct Node
*)iotr
);
256 /* Return TRUE if it ended up on head of list */
258 return ((struct timerequest
*)list
->mlh_Head
== iotr
) ? TRUE
: FALSE
;