2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
5 Desc: Parallel Unit hidd class implementation.
9 #define __OOP_NOATTRBASES__
11 /* the rest are Amiga includes */
12 #include <proto/exec.h>
13 #include <proto/utility.h>
14 #include <proto/oop.h>
15 #include <proto/alib.h>
16 #include <proto/cia.h>
18 #include <exec/libraries.h>
19 #include <exec/ports.h>
20 #include <exec/memory.h>
21 #include <exec/interrupts.h>
22 #include <exec/lists.h>
23 #include <aros/symbolsets.h>
25 #include <utility/tagitem.h>
26 #include <hidd/parallel.h>
28 #include <hardware/cia.h>
30 #include "parallel_intern.h"
32 #include LC_LIBDEFS_FILE
34 #include <aros/debug.h>
36 void parallelunit_receive_data();
37 void parallelunit_write_more_data();
39 /*************************** Classes *****************************/
41 static OOP_AttrBase HiddParallelUnitAB
;
43 static struct OOP_ABDescr attrbases
[] =
45 { IID_Hidd_ParallelUnit
, &HiddParallelUnitAB
},
49 /******* ParallelUnit::New() ***********************************/
50 OOP_Object
*AmigaParUnit__Root__New(OOP_Class
*cl
, OOP_Object
*obj
, struct pRoot_New
*msg
)
52 struct TagItem
*tag
, *tstate
;
55 EnterFunc(bug("ParallelUnit::New()\n"));
57 tstate
= msg
->attrList
;
58 while ((tag
= NextTagItem(&tstate
))) {
61 if (IS_HIDDPARALLELUNIT_ATTR(tag
->ti_Tag
, idx
)) {
63 case aoHidd_ParallelUnit_Unit
:
64 unitnum
= (ULONG
)tag
->ti_Data
;
69 } /* while (tags to process) */
72 ReturnPtr("ParallelUnit::New()", OOP_Object
*, NULL
);
74 D(bug("!!!!Request for unit number %d\n",unitnum
));
76 obj
= (OOP_Object
*)OOP_DoSuperMethod(cl
, obj
, (OOP_Msg
)msg
);
79 D(bug("%s - an error occurred!\n",__FUNCTION__
));
82 ReturnPtr("ParallelUnit::New()", OOP_Object
*, obj
);
85 /******* ParallelUnit::Dispose() ***********************************/
86 OOP_Object
*AmigaParUnit__Root__Dispose(OOP_Class
*cl
, OOP_Object
*obj
, OOP_Msg msg
)
88 struct HIDDParallelUnitData
* data
= OOP_INST_DATA(cl
, obj
);
89 struct Interrupt
*irq
= &data
->parint
;
91 EnterFunc(bug("ParallelUnit::Dispose()\n"));
93 /* stop all interrupts */
95 RemICRVector(data
->ciares
, 4, irq
);
97 OOP_DoSuperMethod(cl
, obj
, (OOP_Msg
)msg
);
98 ReturnPtr("ParallelUnit::Dispose()", OOP_Object
*, obj
);
101 static AROS_INTH1(parallel_interrupt
, struct HIDDParallelUnitData
*, data
)
105 data
->DataWriteCallBack(0, data
->DataWriteUserData
);
112 /******* ParallelUnit::Init() **********************************/
113 BOOL
AmigaParUnit__Hidd_ParallelUnit__Init(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_ParallelUnit_Init
*msg
)
115 struct HIDDParallelUnitData
* data
= OOP_INST_DATA(cl
, o
);
116 struct Interrupt
*irq
= &data
->parint
;
118 EnterFunc(bug("ParallelUnit::Init()\n"));
119 data
->ciares
= OpenResource("ciaa.resource");
121 ReturnBool("ParallelUnit::Init()", FALSE
);
123 data
->DataReceivedCallBack
= msg
->DataReceived
;
124 data
->DataReceivedUserData
= msg
->DataReceivedUserData
;
125 data
->DataWriteCallBack
= msg
->WriteData
;
126 data
->DataWriteUserData
= msg
->WriteDataUserData
;
129 irq
->is_Node
.ln_Pri
= 0;
130 irq
->is_Node
.ln_Type
= NT_INTERRUPT
;
131 irq
->is_Node
.ln_Name
= "par";
132 irq
->is_Code
= (APTR
)parallel_interrupt
;
135 if (AddICRVector(data
->ciares
, 4, irq
))
136 Alert(AT_DeadEnd
| AG_NoMemory
| AN_Unknown
);
138 ReturnBool("ParallelUnit::Init()", TRUE
);
141 /******* ParallelUnit::Write() **********************************/
142 ULONG
AmigaParUnit__Hidd_ParallelUnit__Write(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_ParallelUnit_Write
*msg
)
144 struct HIDDParallelUnitData
* data
= OOP_INST_DATA(cl
, o
);
145 volatile struct CIA
*ciaa
= (struct CIA
*)0xbfe001;
146 ULONG len
= msg
->Length
;
148 EnterFunc(bug("ParallelUnit::Write()\n"));
150 * If the output is currently stopped just don't do anything here.
152 if (TRUE
== data
->stopped
|| len
< 1)
155 ciaa
->ciaprb
= msg
->Outbuffer
[0];
157 ReturnInt("ParallelUnit::Write()",ULONG
, 1);
160 /******* ParallelUnit::Start() **********************************/
161 VOID
AmigaParUnit__Hidd_ParallelUnit__Start(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_ParallelUnit_Start
*msg
)
163 struct HIDDParallelUnitData
* data
= OOP_INST_DATA(cl
, o
);
164 volatile struct CIA
*ciaa
= (struct CIA
*)0xbfe001;
166 /* Ensure that the parallel port is in output mode */
167 ciaa
->ciaddrb
= 0xff;
170 * Allow or start feeding the CIA with data. Get the data
173 if (TRUE
== data
->stopped
) {
174 if (NULL
!= data
->DataWriteCallBack
)
175 data
->DataWriteCallBack(0, data
->DataWriteUserData
);
177 * Also mark the stopped flag as FALSE.
179 data
->stopped
= FALSE
;
183 /******* ParallelUnit::Stop() **********************************/
184 VOID
AmigaParUnit__Hidd_ParallelUnit__Stop(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_ParallelUnit_Stop
*msg
)
186 struct HIDDParallelUnitData
* data
= OOP_INST_DATA(cl
, o
);
189 * The next time the interrupt comes along and asks for
190 * more data we just don't do anything...
192 data
->stopped
= TRUE
;
195 /****** ParallelUnit::GetStatus ********************************/
196 UWORD
AmigaParUnit__Hidd_ParallelUnit__GetStatus(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_ParallelUnit_GetStatus
*msg
)
198 volatile struct CIA
*ciab
= (struct CIA
*)0xbfd000;
200 return ciab
->ciapra
& 7;
204 /******* init_parallelunitclass ********************************/
206 static int AmigaParUnit_Init(LIBBASETYPEPTR LIBBASE
)
208 ReturnInt("AmigaParUnit_Init", ULONG
, OOP_ObtainAttrBases(attrbases
));
212 static int AmigaParUnit_Expunge(LIBBASETYPEPTR LIBBASE
)
214 OOP_ReleaseAttrBases(attrbases
);
215 ReturnInt("AmigaParUnit_Expunge", int, TRUE
);
218 ADD2INITLIB(AmigaParUnit_Init
, 0)
219 ADD2EXPUNGELIB(AmigaParUnit_Expunge
, 0)