2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
7 #include <proto/exec.h>
8 #include <exec/tasks.h>
9 #include <exec/lists.h>
10 #include <exec/memory.h>
12 #include "serial_intern.h"
15 #include <aros/debug.h>
17 /**************************************************************************
18 Copy data from the buffer where it is collected to the destination buffer
19 in the IORequest structure
20 The return value indicates whether the request could be satisfied
22 **************************************************************************/
24 BOOL
copyInData(struct SerialUnit
* SU
, struct IOStdReq
* ioreq
)
27 UWORD index
= SU
->su_InputFirst
;
28 UBYTE
* Buffer
= ioreq
->io_Data
;
30 D(bug("su_InputNextPos: %d su_InputFirst: %d\n",SU
->su_InputNextPos
, index
));
32 while (count
< ioreq
->io_Length
&&
33 SU
->su_InputNextPos
!= index
)
36 Buffer
[count
] = SU
->su_InputBuffer
[index
];
41 ** The buffer is organized in a circular fashion with
42 ** length SU->su_InBufLength
44 if (index
== SU
->su_InBufLength
)
47 /* move the index of the first valid byte for the next read */
48 SU
->su_InputFirst
= index
;
49 ioreq
->io_Actual
= count
;
51 SU
->su_Status
&= ~STATUS_BUFFEROVERFLOW
;
53 if (count
== ioreq
->io_Length
)
56 /* The request could not be satisfied completely */
60 /**************************************************************************
61 Copy data from the buffer where it is collected to the destination buffer
62 in the IORequest structure
63 The return value indicates whether the request could be satisfied
65 **************************************************************************/
67 BOOL
copyInDataUntilZero(struct SerialUnit
* SU
, struct IOStdReq
* ioreq
)
70 UWORD index
= SU
->su_InputFirst
;
71 BYTE
* Buffer
= ioreq
->io_Data
;
74 while (SU
->su_InputNextPos
!= index
)
77 Buffer
[count
] = SU
->su_InputBuffer
[index
];
79 /* was that the terminating zero? */
80 if (0 == Buffer
[count
])
89 ** The buffer is organized in a circular fashion with
90 ** length SU->su_InBufLength
92 if (index
== SU
->su_InBufLength
)
95 /* move the index of the first valid byte for the next read */
96 SU
->su_InputFirst
= index
;
98 SU
->su_Status
&= ~STATUS_BUFFEROVERFLOW
;
100 /* whatever is in end represents "satisfied request"(TRUE) or
101 "unsatisfied request" (FALSE) */
105 ioreq
->io_Actual
= count
;
109 /* make io_Actual point to the next index in the buffer */
110 ioreq
->io_Actual
= count
+1;
115 struct SerialUnit
* findUnit(struct serialbase
* SerialDevice
,
118 struct SerialUnit
* su
;
119 ForeachNode(&SerialDevice
->UnitList
, su
)
121 if (su
->su_UnitNum
== unitnum
)