2 Copyright 2010, The AROS Development Team. All rights reserved.
9 * by Nexus Development 2003
10 * coded by Emanuele Cesaroni
15 #include "audio_intern.h"
17 #include <aros/debug.h>
19 #include <aros/symbolsets.h>
21 #include LC_LIBDEFS_FILE
23 /***********************************************************************/
25 AROS_LH1(void, beginio
,
26 AROS_LHA(struct IOAudio
*, ioreq
, A1
),
27 struct audiobase
*, AudioDevice
, 5, Audio
)
31 ioreq
->ioa_Request
.io_Error
= 0;
32 ioreq
->ioa_Request
.io_Message
.mn_Node
.ln_Type
= NT_MESSAGE
;
34 D(bug("BeginIO: Task 0x%lx\n", FindTask(NULL
)));
36 switch(ioreq
->ioa_Request
.io_Command
)
39 D(bug("CMD_CLEAR\n"));
44 D(bug("CMD_FLUSH\n"));
54 D(bug("CMD_RESET\n"));
59 D(bug("CMD_START\n"));
69 D(bug("CMD_UPDATE\n"));
74 D(bug("CMD_WRITE\n"));
79 audio_ALLOCATE(ioreq
);
83 D(bug("CMD_FINISH\n"));
96 D(bug("CMD_PERVOL\n"));
101 D(bug("CMD_SETPREC\n"));
102 audio_SETPREC(ioreq
);
105 case ADCMD_WAITCYCLE
:
106 D(bug("CMD_WAITCYCLE\n"));
107 audio_WAITCYCLE(ioreq
);
111 ((struct IOAudio
*) ioreq
)->ioa_Request
.io_Error
= IOERR_NOCMD
;
113 if((ioreq
->ioa_Request
.io_Flags
& IOF_QUICK
) == 0)
115 ReplyMsg(&ioreq
->ioa_Request
.io_Message
);
124 /***********************************************************************/
126 AROS_LH1(LONG
, abortio
,
127 AROS_LHA(struct IOAudio
*, ioreq
, A1
),
128 struct audiobase
*, AudioDevice
, 6, Audio
)
132 audio_ABORTIO(ioreq
,global_eta
);
139 /***********************************************************************/
140 static int GM_UNIQUENAME( Init
)
141 (LIBBASETYPEPTR AudiolDevice
)
143 memset(&emasys0
.es_devsem
,0,sizeof(struct SignalSemaphore
));
144 InitSemaphore(&emasys0
.es_devsem
);
149 /***********************************************************************/
150 static int DevClose(struct IOAudio
*MyIORequest
, LIBBASETYPEPTR MyDevBase
)
155 struct MsgPort
*Msgport
;
158 ObtainSemaphore(&emasys0
.es_devsem
);
160 D(bug("NEWD: CLOSEDEVICE called\n"));
162 Command
= MyIORequest
->ioa_Request
.io_Command
;
163 Flags
= MyIORequest
->ioa_Request
.io_Flags
;
164 Error
= MyIORequest
->ioa_Request
.io_Error
;
165 Msgport
= MyIORequest
->ioa_Request
.io_Message
.mn_ReplyPort
;
166 Unita
= MyIORequest
->ioa_Request
.io_Unit
;
168 MyIORequest
->ioa_Request
.io_Unit
= (struct Unit
*) 15;
169 MyIORequest
->ioa_Request
.io_Command
= ADCMD_FREE
;
170 //MyIORequest->ioa_Request.io_Message.mn_ReplyPort = NULL;
171 MyIORequest
->ioa_Request
.io_Flags
= IOF_QUICK
;
172 //MyIORequest->ioa_Request.io_Flags = 0;
173 BeginIO(&MyIORequest
->ioa_Request
);
174 WaitIO(&MyIORequest
->ioa_Request
);
176 //WaitPort(MyIOreuest->ioa_Request.io_Message->mn_ReplyPort);
178 //MyIORequest->ioa_Request.io_Flags = 0; // I try the waiting method.
179 //DoIO(&MyIORequest->ioa_Request);
180 //BeginIO(&MyIORequest->ioa_Request);
181 //WaitIO(&MyIORequest->ioa_Request);
183 MyIORequest
->ioa_Request
.io_Device
= (struct Device
*) -1;
184 MyIORequest
->ioa_Request
.io_Command
= Command
;
185 MyIORequest
->ioa_Request
.io_Flags
= Flags
;
186 MyIORequest
->ioa_Request
.io_Error
= Error
;
187 MyIORequest
->ioa_Request
.io_Message
.mn_ReplyPort
= Msgport
;
188 MyIORequest
->ioa_Request
.io_Unit
= Unita
;
190 // If this is the last client closing, free allocated resources
191 if (MyDevBase
->Dev
.dd_Library
.lib_OpenCnt
== 1)
193 FreeSLAVE(MyIORequest
); /* break Forbid() */// 24.9 Changed the order so actually never modify
this order
!!!!!!
197 ReleaseSemaphore(&emasys0
.es_devsem
);
201 /***********************************************************************/
202 static int GM_UNIQUENAME( Open
)
204 LIBBASETYPEPTR AudioDevice
,
205 struct IORequest
*ioreq
,
212 struct IOAudio
* audioio
= (struct IOAudio
*)ioreq
;
214 ObtainSemaphore(&emasys0
.es_devsem
);
216 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
217 // 24.9 Ok each time OpenDevice() is called do these: set no error.
219 audioio
->ioa_Request
.io_Error
= 0; // Ok, called for now no errors.
221 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
223 // It the device is opened for the first time it needs to have the ESYS ready to accepts new task arriving.
224 // So if this is the first time please inits the ESYS system before all the other.
226 if(AudioDevice
->Dev
.dd_Library
.lib_OpenCnt
== 0)
228 audioio
->ioa_Request
.io_Error
= IOERR_OPENFAIL
;
230 if(InitESYS() == OKEY
)
232 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
233 // 24.9 Well if no error i have the ESYS ready, and a task into the tasklist system.
234 // So please if the slave process isn't ready let
235 // it ready when the device is for the first time opened.
236 if(InitSLAVE(audioio
) == OKEY
)
238 audioio
->ioa_Request
.io_Error
= 0;
243 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
244 // 24.9 This a well know piece of code still valid.
246 audioio
->ioa_Request
.io_Device
= (struct Device
*) AudioDevice
;
248 if(audioio
->ioa_Request
.io_Error
== 0)
250 if(audioio
->ioa_Length
)
252 D(bug("NEWD: ADCMD_ALLOCATE during opendevice\n"));
254 tflags
= audioio
->ioa_Request
.io_Flags
;
255 oldcmd
= audioio
->ioa_Request
.io_Command
;
256 audioio
->ioa_Request
.io_Command
= ADCMD_ALLOCATE
;
257 audioio
->ioa_Request
.io_Flags
= (IOF_QUICK
| ADIOF_NOWAIT
);
258 //MyIORequest->ioa_Request.io_Flags = 0; // add.
259 BeginIO(&audioio
->ioa_Request
); // add
260 WaitIO(&audioio
->ioa_Request
); // add
262 D(bug("NEWD: ADCMD_ALLOCATE after the well know situation\n"));
264 //DoIO(&MyIORequest->ioa_Request); // prev
265 audioio
->ioa_Request
.io_Flags
= tflags
;
266 audioio
->ioa_Request
.io_Command
= oldcmd
;
270 if(audioio
->ioa_Request
.io_Error
== 0)
272 AudioDevice
->DevState
&= ~DEVF_DELEXP
;
276 DevClose(audioio
, AudioDevice
);
279 ReleaseSemaphore(&emasys0
.es_devsem
);
284 /***********************************************************************/
286 static int GM_UNIQUENAME( Close
)
288 LIBBASETYPEPTR AudioDevice
,
289 struct IORequest
*ioreq
292 return DevClose((struct IOAudio
*)ioreq
, AudioDevice
);
295 ADD2INITLIB(GM_UNIQUENAME(Init
), 0)
296 ADD2OPENDEV(GM_UNIQUENAME(Open
), 0)
297 ADD2CLOSEDEV(GM_UNIQUENAME(Close
), 0)