parallel.device: Clean up DEBUG
[AROS.git] / workbench / devs / parallel / parallel_interrupthandlers.c
blobd2d54304747359ee2ba40fab4ae06542f2474eff
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 #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;
23 ULONG index = 0;
25 D(bug("!Received %d bytes on unit %d (%s)\n",length,unitnum,data));
27 PU = findUnit(pubParallelBase, unitnum);
29 if (NULL != PU)
31 if (0 != (PU->pu_Status & STATUS_READS_PENDING))
33 struct IOStdReq * ioreq;
34 ioreq = (struct IOStdReq *)PU->pu_ActiveRead;
36 if (NULL == ioreq)
38 ioreq = (struct IOStdReq *)GetMsg(&PU->pu_QReadCommandPort);
39 PU->pu_ActiveRead = (struct Message *)ioreq;
40 D(bug("Something is wrong!"));
43 while (NULL != ioreq)
46 ** Copy the remaining data into a request buffer.
47 ** This loop woll possibly execute several times
49 UBYTE * destBuf;
50 UWORD indexDestBuf;
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];
62 index++;
63 indexDestBuf++;
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;
81 break;
85 if (index == length && NULL != ioreq)
87 ioreq->io_Actual = indexDestBuf;
88 break;
91 if (NULL == ioreq)
92 PU->pu_Status &= ~STATUS_READS_PENDING;
95 } /* if (NULL != pu) */
98 ** Simply dropping the incoming data
101 return length;
106 * The write buffer empty interrupt handler
108 ULONG WBE_InterruptHandler( ULONG unitnum, APTR userdata)
110 ULONG total = 0;
111 struct ParallelUnit * PU;
113 PU = findUnit(pubParallelBase, unitnum);
115 if (NULL != PU) {
117 * First get any active write
119 struct IOExtPar * ioparreq = (struct IOExtPar *)PU->pu_ActiveWrite;
121 while (1) {
123 * Try to transmit the active write request
125 if (NULL != ioparreq) {
126 ULONG writtenbytes;
127 writtenbytes = HIDD_ParallelUnit_Write(PU->pu_Unit,
128 &((char *)ioparreq->IOPar.io_Data)[PU->pu_NextToWrite],
129 PU->pu_WriteLength);
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);
137 } else {
139 * Not completed, yet.
141 PU->pu_WriteLength -= writtenbytes;
142 PU->pu_NextToWrite += writtenbytes;
144 * Get out of the loop
146 break;
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;
159 break;
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);
168 } else {
169 PU->pu_WriteLength = ioparreq->IOPar.io_Length;
172 * And repeat the loop with this request
176 return total;