2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
5 Desc: Parallel Unit hidd class implementation.
9 #define __OOP_NOATTRBASES__
11 /* Some POSIX includes */
17 /* the rest are Amiga includes */
18 #define timeval aros_timeval
20 #include <proto/exec.h>
21 #include <proto/utility.h>
22 #include <proto/oop.h>
23 #include <proto/alib.h>
24 #include <exec/libraries.h>
25 #include <exec/ports.h>
26 #include <exec/memory.h>
27 #include <exec/interrupts.h>
28 #include <exec/lists.h>
29 #include <utility/tagitem.h>
30 #include <hidd/parallel.h>
31 #include <hidd/unixio.h>
33 #include <aros/symbolsets.h>
35 #include "parallel_intern.h"
38 #include LC_LIBDEFS_FILE
44 #include <aros/debug.h>
46 void parallelunit_io(int fd
, int mode
, void *ptr
);
48 static char * unitname
[] =
55 /*************************** Classes *****************************/
57 static OOP_AttrBase HiddParallelUnitAB
;
58 static OOP_AttrBase HiddUnixIOAttrBase
;
60 static struct OOP_ABDescr attrbases
[] =
62 { IID_Hidd_ParallelUnit
, &HiddParallelUnitAB
},
63 { IID_Hidd_UnixIO
, &HiddUnixIOAttrBase
},
67 /******* ParallelUnit::New() ***********************************/
68 OOP_Object
*UXParUnit__Root__New(OOP_Class
*cl
, OOP_Object
*obj
, struct pRoot_New
*msg
)
70 struct HIDDParallelUnitData
* data
;
71 const struct TagItem tags
[] = {
72 {aHidd_UnixIO_Opener
, (IPTR
)"parallel.hidd"},
73 {aHidd_UnixIO_Architecture
, (IPTR
)AROS_ARCHITECTURE
},
76 struct TagItem
*tag
, *tstate
;
79 EnterFunc(bug("ParallelUnit::New()\n"));
81 tstate
= msg
->attrList
;
82 while ((tag
= NextTagItem(&tstate
))) {
85 if (IS_HIDDPARALLELUNIT_ATTR(tag
->ti_Tag
, idx
)) {
87 case aoHidd_ParallelUnit_Unit
:
88 unitnum
= (ULONG
)tag
->ti_Data
;
93 } /* while (tags to process) */
95 D(bug("!!!!Request for unit number %d\n",unitnum
));
97 obj
= (OOP_Object
*)OOP_DoSuperMethod(cl
, obj
, (OOP_Msg
)msg
);
101 data
= OOP_INST_DATA(cl
, obj
);
103 data
->unitnum
= unitnum
;
105 data
->unixio
= OOP_NewObject(NULL
, CLID_Hidd_UnixIO
, (struct TagItem
*)tags
);
106 if (NULL
!= data
->unixio
)
108 D(bug("Opening %s.\n",unitname
[data
->unitnum
]));
110 data
->unixio_int
.fd
= Hidd_UnixIO_OpenFile(data
->unixio
, unitname
[data
->unitnum
], O_NONBLOCK
|O_RDWR
, 0, NULL
);
112 D(bug("Opened %s on handle %d\n",unitname
[data
->unitnum
], data
->unixio_int
.fd
));
114 if (-1 != data
->unixio_int
.fd
)
118 data
->unixio_int
.mode
= vHidd_UnixIO_RW
;
119 data
->unixio_int
.handler
= parallelunit_io
;
120 data
->unixio_int
.handlerData
= data
;
122 D(bug("Adding UnixIO AsyncIO interrupt!\n"));
123 error
= Hidd_UnixIO_AddInterrupt(data
->unixio
, &data
->unixio_int
);
126 ReturnPtr("ParallelUnit::New()", OOP_Object
*, obj
);
128 Hidd_UnixIO_CloseFile(data
->unixio
, data
->unixio_int
.fd
, NULL
);
130 /* There's no need to dispose UnixIO object */
133 OOP_DisposeObject(obj
);
136 ReturnPtr("ParallelUnit::New()", OOP_Object
*, NULL
);
139 /******* ParallelUnit::Dispose() ***********************************/
140 OOP_Object
*UXParUnit__Root__Dispose(OOP_Class
*cl
, OOP_Object
*obj
, OOP_Msg msg
)
142 struct HIDDParallelUnitData
* data
;
143 EnterFunc(bug("ParallelUnit::Dispose()\n"));
145 data
= OOP_INST_DATA(cl
, obj
);
146 D(bug("Freeing filedescriptor (%d)!\n",data
->unixio_int
.fd
));
148 if (-1 != data
->unixio_int
.fd
)
150 Hidd_UnixIO_RemInterrupt(data
->unixio
, &data
->unixio_int
);
151 Hidd_UnixIO_CloseFile(data
->unixio
, data
->unixio_int
.fd
, NULL
);
153 OOP_DoSuperMethod(cl
, obj
, (OOP_Msg
)msg
);
154 ReturnPtr("ParallelUnit::Dispose()", OOP_Object
*, obj
);
157 /******* ParallelUnit::Init() **********************************/
158 BOOL
UXParUnit__Hidd_ParallelUnit__Init(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_ParallelUnit_Init
*msg
)
160 struct HIDDParallelUnitData
* data
= OOP_INST_DATA(cl
, o
);
162 EnterFunc(bug("ParallelUnit::Init()\n"));
163 data
->DataReceivedCallBack
= msg
->DataReceived
;
164 data
->DataReceivedUserData
= msg
->DataReceivedUserData
;
165 data
->DataWriteCallBack
= msg
->WriteData
;
166 data
->DataWriteUserData
= msg
->WriteDataUserData
;
168 ReturnBool("ParallelUnit::Init()", TRUE
);
171 /******* ParallelUnit::Write() **********************************/
172 ULONG
UXParUnit__Hidd_ParallelUnit__Write(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_ParallelUnit_Write
*msg
)
174 struct HIDDParallelUnitData
* data
= OOP_INST_DATA(cl
, o
);
177 EnterFunc(bug("ParallelUnit::Write()\n"));
179 if (TRUE
== data
->stopped
)
182 D(bug("Writing %d bytes to fd %d (stream: %s)\n",
187 len
= Hidd_UnixIO_WriteFile(data
->unixio
, data
->unixio_int
.fd
, msg
->Outbuffer
, msg
->Length
, NULL
);
189 ReturnInt("ParallelUnit::Write()",ULONG
, len
);
192 /******* ParallelUnit::Start() **********************************/
193 VOID
UXParUnit__Hidd_ParallelUnit__Start(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_ParallelUnit_Start
*msg
)
195 struct HIDDParallelUnitData
* data
= OOP_INST_DATA(cl
, o
);
198 * Allow or start feeding the UART with data. Get the data
201 if (TRUE
== data
->stopped
) {
202 if (NULL
!= data
->DataWriteCallBack
)
203 data
->DataWriteCallBack(data
->unitnum
, data
->DataWriteUserData
);
205 * Also mark the stopped flag as FALSE.
207 data
->stopped
= FALSE
;
211 /******* ParallelUnit::Stop() **********************************/
212 VOID
UXParUnit__Hidd_ParallelUnit__Stop(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_ParallelUnit_Stop
*msg
)
214 struct HIDDParallelUnitData
* data
= OOP_INST_DATA(cl
, o
);
217 * The next time the interrupt comes along and asks for
218 * more data we just don't do anything...
220 data
->stopped
= TRUE
;
223 /****** ParallelUnit::GetStatus ********************************/
224 UWORD
UXParUnit__Hidd_ParallelUnit__GetStatus(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_ParallelUnit_GetStatus
*msg
)
227 struct HIDDParallelUnitData
* data
= OOP_INST_DATA(cl
, o
);
234 /************* The software interrupt handler that gets data from PORT *****/
237 #define READBUFFER_SIZE 513
239 void parallelunit_io(int fd
, int mode
, void *ptr
)
241 struct HIDDParallelUnitData
*data
= ptr
;
243 if (mode
& vHidd_UnixIO_Read
)
246 UBYTE buffer
[READBUFFER_SIZE
];
249 ** Read the data from the port ...
251 len
= Hidd_UnixIO_ReadFile(data
->unixio
, fd
, buffer
, READBUFFER_SIZE
, NULL
);
254 ** ... and deliver them to whoever is interested.
256 if (NULL
!= data
->DataReceivedCallBack
)
257 data
->DataReceivedCallBack(buffer
, len
, data
->unitnum
, data
->DataReceivedUserData
);
261 if (mode
& vHidd_UnixIO_Write
)
263 if (NULL
!= data
->DataWriteCallBack
)
264 data
->DataWriteCallBack(data
->unitnum
, data
->DataWriteUserData
);
268 /******* init_parallelunitclass ********************************/
270 static int UXParUnit_InitAttrBases(LIBBASETYPEPTR LIBBASE
)
272 return OOP_ObtainAttrBases(attrbases
);
276 static int UXParUnit_ExpungeAttrBases(LIBBASETYPEPTR LIBBASE
)
278 OOP_ReleaseAttrBases(attrbases
);
282 ADD2INITLIB(UXParUnit_InitAttrBases
, 0)
283 ADD2EXPUNGELIB(UXParUnit_ExpungeAttrBases
, 0)