2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
6 #include <aros/asmcall.h>
7 #include <aros/libcall.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"
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
;
26 D(bug("!Received %d bytes on unit %d (%s)\n",length
,unitnum
,data
));
28 PU
= findUnit(pubParallelBase
, unitnum
);
32 if (0 != (PU
->pu_Status
& STATUS_READS_PENDING
))
34 struct IOStdReq
* ioreq
;
35 ioreq
= (struct IOStdReq
*)PU
->pu_ActiveRead
;
39 ioreq
= (struct IOStdReq
*)GetMsg(&PU
->pu_QReadCommandPort
);
40 PU
->pu_ActiveRead
= (struct Message
*)ioreq
;
41 D(bug("Something is wrong!"));
47 ** Copy the remaining data into a request buffer.
48 ** This loop woll possibly execute several times
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
];
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
;
86 if (index
== length
&& NULL
!= ioreq
)
88 ioreq
->io_Actual
= indexDestBuf
;
93 PU
->pu_Status
&= ~STATUS_READS_PENDING
;
96 } /* if (NULL != pu) */
99 ** Simply dropping the incoming data
107 * The write buffer empty interrupt handler
109 ULONG
WBE_InterruptHandler( ULONG unitnum
, APTR userdata
)
112 struct ParallelUnit
* PU
;
114 PU
= findUnit(pubParallelBase
, unitnum
);
118 * First get any active write
120 struct IOExtPar
* ioparreq
= (struct IOExtPar
*)PU
->pu_ActiveWrite
;
124 * Try to transmit the active write request
126 if (NULL
!= ioparreq
) {
128 writtenbytes
= HIDD_ParallelUnit_Write(PU
->pu_Unit
,
129 &((char *)ioparreq
->IOPar
.io_Data
)[PU
->pu_NextToWrite
],
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
);
140 * Not completed, yet.
142 PU
->pu_WriteLength
-= writtenbytes
;
143 PU
->pu_NextToWrite
+= writtenbytes
;
145 * Get out of the loop
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
;
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
);
170 PU
->pu_WriteLength
= ioparreq
->IOPar
.io_Length
;
173 * And repeat the loop with this request