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"
16 #include <aros/debug.h>
18 extern struct parallelbase
* pubParallelBase
;
20 ULONG
RBF_InterruptHandler(UBYTE
* data
, ULONG length
, ULONG unitnum
, APTR userdata
)
22 struct ParallelUnit
* PU
= NULL
;
25 D(bug("!Received %d bytes on unit %d (%s)\n",length
,unitnum
,data
));
27 PU
= findUnit(pubParallelBase
, unitnum
);
31 if (0 != (PU
->pu_Status
& STATUS_READS_PENDING
))
33 struct IOStdReq
* ioreq
;
34 ioreq
= (struct IOStdReq
*)PU
->pu_ActiveRead
;
38 ioreq
= (struct IOStdReq
*)GetMsg(&PU
->pu_QReadCommandPort
);
39 PU
->pu_ActiveRead
= (struct Message
*)ioreq
;
40 D(bug("Something is wrong!"));
46 ** Copy the remaining data into a request buffer.
47 ** This loop woll possibly execute several times
51 D(bug("Have a IORequest for Parallel device!\n"));
53 destBuf
= ioreq
->io_Data
;
54 indexDestBuf
= ioreq
->io_Actual
;
56 ** I copy as many bytes as I can into this request
58 while (index
< length
)
60 destBuf
[indexDestBuf
] = data
[index
];
65 D(bug("io_Length %d: io_Actual: %d\n",ioreq
->io_Length
,indexDestBuf
));
67 if ((-1 == ioreq
->io_Length
&& 0 == destBuf
[indexDestBuf
-1]) ||
68 (indexDestBuf
== ioreq
->io_Length
))
71 ** this request is done, I answer the message
73 ioreq
->io_Actual
= indexDestBuf
;
74 ReplyMsg((struct Message
*)ioreq
);
77 ** Get the next request ...
79 ioreq
= (struct IOStdReq
*)GetMsg(&PU
->pu_QReadCommandPort
);
80 PU
->pu_ActiveRead
= (struct Message
*)ioreq
;
85 if (index
== length
&& NULL
!= ioreq
)
87 ioreq
->io_Actual
= indexDestBuf
;
92 PU
->pu_Status
&= ~STATUS_READS_PENDING
;
95 } /* if (NULL != pu) */
98 ** Simply dropping the incoming data
106 * The write buffer empty interrupt handler
108 ULONG
WBE_InterruptHandler( ULONG unitnum
, APTR userdata
)
111 struct ParallelUnit
* PU
;
113 PU
= findUnit(pubParallelBase
, unitnum
);
117 * First get any active write
119 struct IOExtPar
* ioparreq
= (struct IOExtPar
*)PU
->pu_ActiveWrite
;
123 * Try to transmit the active write request
125 if (NULL
!= ioparreq
) {
127 writtenbytes
= HIDD_ParallelUnit_Write(PU
->pu_Unit
,
128 &((char *)ioparreq
->IOPar
.io_Data
)[PU
->pu_NextToWrite
],
131 * Check whether this was written completely.
133 total
+= writtenbytes
;
134 if (writtenbytes
>= PU
->pu_WriteLength
) {
135 /* This one is done */
136 ReplyMsg(&ioparreq
->IOPar
.io_Message
);
139 * Not completed, yet.
141 PU
->pu_WriteLength
-= writtenbytes
;
142 PU
->pu_NextToWrite
+= writtenbytes
;
144 * Get out of the loop
150 * Get the next request from the queue.
152 ioparreq
= (struct IOExtPar
*)GetMsg(&PU
->pu_QWriteCommandPort
);
153 PU
->pu_ActiveWrite
= (struct Message
*)ioparreq
;
154 if (NULL
== ioparreq
) {
156 * No more request left. Done.
158 PU
->pu_Status
&= ~STATUS_WRITES_PENDING
;
163 * There is a new request.
165 PU
->pu_NextToWrite
= 0;
166 if (-1 == ioparreq
->IOPar
.io_Length
) {
167 PU
->pu_WriteLength
= strlen(ioparreq
->IOPar
.io_Data
);
169 PU
->pu_WriteLength
= ioparreq
->IOPar
.io_Length
;
172 * And repeat the loop with this request