Put pciehci.device in DEVS:USBHardware, like the other host-controller
[AROS.git] / workbench / devs / parallel / parallel_interrupthandlers.c
blob0c347ec392aba6102d879a97fa14a378545c19b1
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/asmcall.h>
7 #include <aros/libcall.h>
8 #include <stdio.h>
9 #include <proto/exec.h>
10 #include <proto/dos.h>
11 #include <exec/types.h>
12 #include <exec/interrupts.h>
13 #include <hidd/parallel.h>
14 #include "parallel_intern.h"
16 #define DEBUG 0
17 #include <aros/debug.h>
19 extern struct parallelbase * pubParallelBase;
21 ULONG RBF_InterruptHandler(UBYTE * data, ULONG length, ULONG unitnum, APTR userdata)
23 struct ParallelUnit * PU = NULL;
24 ULONG index = 0;
26 D(bug("!Received %d bytes on unit %d (%s)\n",length,unitnum,data));
28 PU = findUnit(pubParallelBase, unitnum);
30 if (NULL != PU)
32 if (0 != (PU->pu_Status & STATUS_READS_PENDING))
34 struct IOStdReq * ioreq;
35 ioreq = (struct IOStdReq *)PU->pu_ActiveRead;
37 if (NULL == ioreq)
39 ioreq = (struct IOStdReq *)GetMsg(&PU->pu_QReadCommandPort);
40 PU->pu_ActiveRead = (struct Message *)ioreq;
41 D(bug("Something is wrong!"));
44 while (NULL != ioreq)
47 ** Copy the remaining data into a request buffer.
48 ** This loop woll possibly execute several times
50 UBYTE * destBuf;
51 UWORD indexDestBuf;
52 D(bug("Have a IORequest for Parallel device!\n"));
54 destBuf = ioreq->io_Data;
55 indexDestBuf = ioreq->io_Actual;
57 ** I copy as many bytes as I can into this request
59 while (index < length)
61 destBuf[indexDestBuf] = data[index];
63 index++;
64 indexDestBuf++;
66 D(bug("io_Length %d: io_Actual: %d\n",ioreq->io_Length,indexDestBuf));
68 if ((-1 == ioreq->io_Length && 0 == destBuf[indexDestBuf-1]) ||
69 (indexDestBuf == ioreq->io_Length))
72 ** this request is done, I answer the message
74 ioreq->io_Actual = indexDestBuf;
75 ReplyMsg((struct Message *)ioreq);
78 ** Get the next request ...
80 ioreq = (struct IOStdReq *)GetMsg(&PU->pu_QReadCommandPort);
81 PU->pu_ActiveRead = (struct Message *)ioreq;
82 break;
86 if (index == length && NULL != ioreq)
88 ioreq->io_Actual = indexDestBuf;
89 break;
92 if (NULL == ioreq)
93 PU->pu_Status &= ~STATUS_READS_PENDING;
96 } /* if (NULL != pu) */
99 ** Simply dropping the incoming data
102 return length;
107 * The write buffer empty interrupt handler
109 ULONG WBE_InterruptHandler( ULONG unitnum, APTR userdata)
111 ULONG total = 0;
112 struct ParallelUnit * PU;
114 PU = findUnit(pubParallelBase, unitnum);
116 if (NULL != PU) {
118 * First get any active write
120 struct IOExtPar * ioparreq = (struct IOExtPar *)PU->pu_ActiveWrite;
122 while (1) {
124 * Try to transmit the active write request
126 if (NULL != ioparreq) {
127 ULONG writtenbytes;
128 writtenbytes = HIDD_ParallelUnit_Write(PU->pu_Unit,
129 &((char *)ioparreq->IOPar.io_Data)[PU->pu_NextToWrite],
130 PU->pu_WriteLength);
132 * Check whether this was written completely.
134 total += writtenbytes;
135 if (writtenbytes >= PU->pu_WriteLength) {
136 /* This one is done */
137 ReplyMsg(&ioparreq->IOPar.io_Message);
138 } else {
140 * Not completed, yet.
142 PU->pu_WriteLength -= writtenbytes;
143 PU->pu_NextToWrite += writtenbytes;
145 * Get out of the loop
147 break;
151 * Get the next request from the queue.
153 ioparreq = (struct IOExtPar *)GetMsg(&PU->pu_QWriteCommandPort);
154 PU->pu_ActiveWrite = (struct Message *)ioparreq;
155 if (NULL == ioparreq) {
157 * No more request left. Done.
159 PU->pu_Status &= ~STATUS_WRITES_PENDING;
160 break;
164 * There is a new request.
166 PU->pu_NextToWrite = 0;
167 if (-1 == ioparreq->IOPar.io_Length) {
168 PU->pu_WriteLength = strlen(ioparreq->IOPar.io_Data);
169 } else {
170 PU->pu_WriteLength = ioparreq->IOPar.io_Length;
173 * And repeat the loop with this request
177 return total;