2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Serial hidd initialization code.
9 #include <exec/types.h>
10 #include <exec/alerts.h>
12 #include <aros/system.h>
13 #include <aros/asmcall.h>
17 #include <proto/oop.h>
18 #include <proto/exec.h>
20 #include "serial_intern.h"
25 /* Customize libheader.c */
26 #define LC_SYSBASE_FIELD(lib) (((LIBBASETYPEPTR )(lib))->hdg_SysBase)
27 #define LC_SEGLIST_FIELD(lib) (((LIBBASETYPEPTR )(lib))->hdg_SegList)
28 #define LC_RESIDENTNAME hiddserial_resident
29 #define LC_RESIDENTFLAGS RTF_AUTOINIT | RTF_COLDSTART
30 #define LC_RESIDENTPRI 9
31 #define LC_LIBBASESIZE sizeof(LIBBASETYPE)
32 #define LC_LIBHEADERTYPEPTR LIBBASETYPEPTR
33 #define LC_LIB_FIELD(lib) (((LIBBASETYPEPTR)(lib))->hdg_LibNode)
36 #define LC_NO_CLOSELIB
38 /* to avoid removing the serialhiddclass from memory add #define NOEXPUNGE */
40 #include <libcore/libheader.c>
45 #include <aros/debug.h>
47 #define SysBase (LC_SYSBASE_FIELD(lh))
49 void serial_int_uart1(HIDDT_IRQ_Handler
*, HIDDT_IRQ_HwInfo
*);
50 void serial_int_uart2(HIDDT_IRQ_Handler
*, HIDDT_IRQ_HwInfo
*);
53 #define OOPBase (csd->oopbase)
55 ULONG SAVEDS STDARGS
LC_BUILDNAME(L_InitLib
) (LC_LIBHEADERTYPEPTR lh
)
57 struct class_static_data
*csd
; /* SerialHidd static data */
59 EnterFunc(bug("SerialHIDD_Init()\n"));
62 We map the memory into the shared memory space, because it is
63 to be accessed by many processes, eg searching for a HIDD etc.
65 Well, maybe once we've got MP this might help...:-)
67 csd
= AllocVec(sizeof(struct class_static_data
), MEMF_CLEAR
|MEMF_PUBLIC
);
70 csd
->sysbase
= SysBase
;
74 csd
->oopbase
= OpenLibrary(AROSOOP_NAME
, 0);
76 D(bug(" Got OOPBase\n"));
77 csd
->utilitybase
= OpenLibrary("utility.library", 37);
78 if (csd
->utilitybase
) {
79 D(bug(" Got UtilityBase\n"));
81 csd
->serialhiddclass
= init_serialhiddclass(csd
);
83 D(bug(" SerialHiddClass: %p\n", csd
->serialhiddclass
));
85 if(csd
->serialhiddclass
) {
86 D(bug(" Got SerialHIDDClass\n"));
88 csd
->irqhidd
= OOP_NewObject(NULL
, CLID_Hidd_IRQ
, NULL
);
91 HIDDT_IRQ_Handler
*irq
;
93 /* Install COM1 and COM3 interrupt */
94 irq
= AllocMem(sizeof(HIDDT_IRQ_Handler
), MEMF_CLEAR
|MEMF_PUBLIC
);
96 kprintf(" ERROR: Cannot install Serial\n");
97 Alert( AT_DeadEnd
| AN_IntrMem
);
99 irq
->h_Node
.ln_Pri
=127; /* Set the highest pri */
100 irq
->h_Code
= serial_int_uart1
;
101 irq
->h_Data
= (APTR
)csd
;
102 HIDD_IRQ_AddHandler(csd
->irqhidd
, irq
, vHidd_IRQ_Serial1
);
104 /* Install UART1 and UART2 interrupt */
105 irq
= AllocMem(sizeof(HIDDT_IRQ_Handler
), MEMF_CLEAR
|MEMF_PUBLIC
);
107 kprintf(" ERROR: Cannot install Serial\n");
108 Alert( AT_DeadEnd
| AN_IntrMem
);
110 irq
->h_Node
.ln_Pri
=127; /* Set the highest pri */
111 irq
->h_Code
= serial_int_uart2
;
112 irq
->h_Data
= (APTR
)csd
;
113 HIDD_IRQ_AddHandler(csd
->irqhidd
, irq
, vHidd_IRQ_Serial2
);
115 D(bug(" Got Interrupts\n"));
116 ReturnInt("SerialHIDD_Init", ULONG
, TRUE
);
120 CloseLibrary(csd
->utilitybase
);
122 CloseLibrary(csd
->oopbase
);
130 ReturnInt("SerialHIDD_Init", ULONG
, FALSE
);
134 void SAVEDS STDARGS
LC_BUILDNAME(L_ExpungeLib
) (LC_LIBHEADERTYPEPTR lh
)
136 EnterFunc(bug("SerialHIDD_Expunge()\n"));
139 free_serialhiddclass(lh
->hdg_csd
);
141 CloseLibrary(lh
->hdg_csd
->utilitybase
);
142 CloseLibrary(lh
->hdg_csd
->oopbase
);
144 FreeVec(lh
->hdg_csd
);
147 ReturnVoid("SerialHIDD_Expunge");