add casts to zune macros to silence some warnings
[tangerine.git] / workbench / devs / serial / serial_support.c
blob0a938ff7b068273372113c9208d013f5a38ac8ca
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
4 */
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"
14 #define DEBUG 0
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
21 completely or not.
22 **************************************************************************/
24 BOOL copyInData(struct SerialUnit * SU, struct IOStdReq * ioreq)
26 UWORD count = 0;
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)
35 /* copy one byte */
36 Buffer[count] = SU->su_InputBuffer[index];
38 count++;
39 index++;
40 /*
41 ** The buffer is organized in a circular fashion with
42 ** length SU->su_InBufLength
44 if (index == SU->su_InBufLength)
45 index = 0;
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)
54 return TRUE;
56 /* The request could not be satisfied completely */
57 return FALSE;
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
64 completely or not.
65 **************************************************************************/
67 BOOL copyInDataUntilZero(struct SerialUnit * SU, struct IOStdReq * ioreq)
69 UWORD count = 0;
70 UWORD index = SU->su_InputFirst;
71 BYTE * Buffer = ioreq->io_Data;
72 BOOL end = FALSE;
74 while (SU->su_InputNextPos != index)
76 /* copy one byte */
77 Buffer[count] = SU->su_InputBuffer[index];
79 /* was that the terminating zero? */
80 if (0 == Buffer[count])
82 end = TRUE;
83 break;
86 count++;
87 index++;
88 /*
89 ** The buffer is organized in a circular fashion with
90 ** length SU->su_InBufLength
92 if (index == SU->su_InBufLength)
93 index = 0;
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) */
103 if (TRUE == end)
105 ioreq->io_Actual = count;
106 return TRUE;
109 /* make io_Actual point to the next index in the buffer */
110 ioreq->io_Actual = count+1;
111 return FALSE;
115 struct SerialUnit * findUnit(struct serialbase * SerialDevice,
116 ULONG unitnum)
118 struct SerialUnit * su;
119 ForeachNode(&SerialDevice->UnitList, su)
121 if (su->su_UnitNum == unitnum)
122 return su;
124 return NULL;