revert between 56095 -> 55830 in arch
[AROS.git] / arch / ppc-sam440 / serial.hidd / SerialClass.c
blob3739543ed83973f425c281ea7a5199337e798684
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Serial hidd class implementation.
6 Lang: english
7 */
9 #include <proto/exec.h>
10 #include <proto/utility.h>
11 #include <proto/oop.h>
12 #include <aros/config.h>
13 #include <aros/symbolsets.h>
14 #include <exec/libraries.h>
16 #include <utility/tagitem.h>
17 #include <hidd/serial.h>
20 #include "serial_intern.h"
22 #include LC_LIBDEFS_FILE
24 #undef SDEBUG
25 #undef DEBUG
26 #define SDEBUG 0
27 #define DEBUG 0
28 #include <aros/debug.h>
30 /*** HIDDSerial::NewUnit() *********************************************************/
32 OOP_Object *PPC4xxSer__Hidd_Serial__NewUnit(OOP_Class *cl, OOP_Object *obj, struct pHidd_Serial_NewUnit *msg)
34 OOP_Object *su = NULL;
35 struct HIDDSerialData * data = OOP_INST_DATA(cl, obj);
36 ULONG unitnum = -1;
38 EnterFunc(bug("HIDDSerial::NewSerial()\n"));
40 D(bug("Request for unit number %d\n",msg->unitnum));
42 #if (AROS_SERIAL_DEBUG > 0)
43 if (msg->unitnum == (AROS_SERIAL_DEBUG-1))
44 ReturnPtr("HIDDSerial::NewSerial", Object *, su);
45 #endif
47 switch (msg->unitnum)
49 case 0:
50 case 1:
51 case 2:
52 case 3:
53 unitnum = msg->unitnum;
54 if (0 != (data->sd_UsedMask & (1 << unitnum)))
55 unitnum = -1;
56 break;
58 case -1: /* search for the next available unit */
60 unitnum = 0;
61 while (unitnum < SER_MAX_UNITS)
63 if (0 == (data->sd_UsedMask & (1 << unitnum)))
64 break;
65 unitnum++;
68 break;
73 if (unitnum >= 0 && unitnum < SER_MAX_UNITS)
75 struct TagItem tags[] =
77 #define csd CSD(cl->UserData)
78 {aHidd_SerialUnit_Unit, unitnum},
79 #undef csd
80 {TAG_DONE }
83 su = OOP_NewObject(NULL, CLID_Hidd_SerialUnit, tags);
84 data->sd_Unit[unitnum] = su;
86 ** Mark it as used
88 data->sd_UsedMask |= (1 << unitnum);
91 ReturnPtr("HIDDSerial::NewSerial", Object *, su);
95 /*** HIDDSerial::DisposeUnit() ****************************************************/
97 VOID PPC4xxSer__Hidd_Serial__DisposeUnit(OOP_Class *cl, OOP_Object *obj, struct pHidd_Serial_DisposeUnit *msg)
99 OOP_Object * su = msg->unit;
100 struct HIDDSerialData * data = OOP_INST_DATA(cl, obj);
101 EnterFunc(bug("HIDDSerial::DisposeUnit()\n"));
103 if(su)
105 ULONG unitnum = 0;
106 while (unitnum < SER_MAX_UNITS)
108 if (data->sd_Unit[unitnum] == su)
110 D(bug("Disposing SerialUnit!\n"));
111 OOP_DisposeObject(su);
112 data->sd_Unit[unitnum] = NULL;
113 data->sd_UsedMask &= ~(1 << unitnum);
114 break;
116 unitnum++;
120 ReturnVoid("HIDDSerial::DisposeUnit");
125 /*************************** Classes *****************************/
127 #define csd (&(LIBBASE->hdg_csd))
129 static int PPC4xxSer_InitAttrs(LIBBASETYPEPTR LIBBASE)
131 EnterFunc(bug("PPC4xxSer_InitAttrs\n"));
133 __IHidd_SerialUnitAB = OOP_ObtainAttrBase(IID_Hidd_SerialUnit);
135 ReturnInt("PPC4xxSer_InitAttrs", ULONG, __IHidd_SerialUnitAB != 0);
139 static int PPC4xxSer_ExpungeAttrs(LIBBASETYPEPTR LIBBASE)
141 EnterFunc(bug("PPC4xxSer_ExpungeAttrs\n"));
143 OOP_ReleaseAttrBase(IID_Hidd_SerialUnit);
145 ReturnInt("PPC4xxSer_ExpungeAttrs", int, TRUE);
148 ADD2INITLIB(PPC4xxSer_InitAttrs, 0)
149 ADD2EXPUNGELIB(PPC4xxSer_ExpungeAttrs, 0)