revert between 56095 -> 55830 in arch
[AROS.git] / workbench / devs / audio / libfunctions.c
blob93c107f3c757d3e3ed80ca6c24cc7e5bc96f9040
1 /*
2 Copyright 2010, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /*
7 * audio.device
9 * by Nexus Development 2003
10 * coded by Emanuele Cesaroni
12 * $Id$
15 #include "audio_intern.h"
16 #define DEBUG 0
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)
29 AROS_LIBFUNC_INIT
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)
38 case CMD_CLEAR:
39 D(bug("CMD_CLEAR\n"));
40 audio_CLEAR(ioreq);
41 break;
43 case CMD_FLUSH:
44 D(bug("CMD_FLUSH\n"));
45 audio_FLUSH(ioreq);
46 break;
48 case CMD_READ:
49 D(bug("CMD_READ\n"));
50 audio_READ(ioreq);
51 break;
53 case CMD_RESET:
54 D(bug("CMD_RESET\n"));
55 audio_RESET(ioreq);
56 break;
58 case CMD_START:
59 D(bug("CMD_START\n"));
60 audio_START(ioreq);
61 break;
63 case CMD_STOP:
64 D(bug("CMD_STOP\n"));
65 audio_STOP(ioreq);
66 break;
68 case CMD_UPDATE:
69 D(bug("CMD_UPDATE\n"));
70 audio_UPDATE(ioreq);
71 break;
73 case CMD_WRITE:
74 D(bug("CMD_WRITE\n"));
75 audio_WRITE(ioreq);
76 break;
78 case ADCMD_ALLOCATE:
79 audio_ALLOCATE(ioreq);
80 break;
82 case ADCMD_FINISH:
83 D(bug("CMD_FINISH\n"));
84 audio_FINISH(ioreq);
85 break;
87 case ADCMD_FREE:
88 audio_FREE(ioreq);
89 break;
91 case ADCMD_LOCK:
92 audio_LOCK(ioreq);
93 break;
95 case ADCMD_PERVOL:
96 D(bug("CMD_PERVOL\n"));
97 audio_PERVOL(ioreq);
98 break;
100 case ADCMD_SETPREC:
101 D(bug("CMD_SETPREC\n"));
102 audio_SETPREC(ioreq);
103 break;
105 case ADCMD_WAITCYCLE:
106 D(bug("CMD_WAITCYCLE\n"));
107 audio_WAITCYCLE(ioreq);
108 break;
110 default:
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);
118 break;
121 AROS_LIBFUNC_EXIT
124 /***********************************************************************/
126 AROS_LH1(LONG, abortio,
127 AROS_LHA(struct IOAudio *, ioreq, A1),
128 struct audiobase *, AudioDevice, 6, Audio)
130 AROS_LIBFUNC_INIT
132 audio_ABORTIO(ioreq,global_eta);
134 return 0;
136 AROS_LIBFUNC_EXIT
139 /***********************************************************************/
140 static int GM_UNIQUENAME( Init)
141 (LIBBASETYPEPTR AudiolDevice)
143 memset(&emasys0.es_devsem,0,sizeof(struct SignalSemaphore));
144 InitSemaphore(&emasys0.es_devsem);
146 return TRUE;
149 /***********************************************************************/
150 static int DevClose(struct IOAudio *MyIORequest, LIBBASETYPEPTR MyDevBase)
152 UWORD Command;
153 UBYTE Flags;
154 BYTE Error;
155 struct MsgPort *Msgport;
156 struct Unit *Unita;
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!!!!!!
194 FreeESYS(); // ok
197 ReleaseSemaphore(&emasys0.es_devsem);
198 return TRUE;
201 /***********************************************************************/
202 static int GM_UNIQUENAME( Open)
204 LIBBASETYPEPTR AudioDevice,
205 struct IORequest *ioreq,
206 ULONG unitnum,
207 ULONG flags
210 UBYTE tflags;
211 UWORD oldcmd;
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 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
222 // 24.9 First thing.
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;
274 else
276 DevClose(audioio, AudioDevice);
279 ReleaseSemaphore(&emasys0.es_devsem);
281 return TRUE;
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)