2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
7 #include <proto/exec.h>
8 #include <dos/dostags.h>
10 #include "camd_intern.h"
14 # include AROS_DEBUG_H_FILE
17 struct SignalSemaphore camdwaitsemaphore
={{0}};
18 struct SignalSemaphore camdwaitsemaphore2
={{0}};
20 struct Task
*camdwaittask
;
24 ULONG camdwaitprocstatus
=0; //0=not alive or not initialized, 1=alive and fine, 2=failed, 3=dead.
27 SAVEDS
void CamdTimerProc(void){
28 struct timerequest
*TimerIO
;
29 struct MsgPort
*TimerMP
;
33 camdwaitsig
=AllocSignal(-1);
38 camdwaitsig2
=AllocSignal(-1);
40 FreeSignal(1L<<camdwaitsig
);
45 TimerMP
=CreateMsgPort();
47 FreeSignal(1L<<camdwaitsig2
);
48 FreeSignal(1L<<camdwaitsig
);
53 TimerIO
=(struct timerequest
*)AllocMem(sizeof(struct timerequest
),MEMF_ANY
|MEMF_CLEAR
|MEMF_PUBLIC
);
56 FreeSignal(1L<<camdwaitsig2
);
57 FreeSignal(1L<<camdwaitsig
);
58 DeleteMsgPort(TimerMP
);
63 TimerIO
->tr_node
.io_Message
.mn_Node
.ln_Type
=NT_MESSAGE
;
64 TimerIO
->tr_node
.io_Message
.mn_ReplyPort
=TimerMP
;
65 TimerIO
->tr_node
.io_Message
.mn_Length
=sizeof(struct timerequest
);
67 /* No support for eclock in AROS. */
70 TIMERNAME
,UNIT_ECLOCK
,(struct IORequest
*)TimerIO
,0L
74 TIMERNAME
,UNIT_VBLANK
,(struct IORequest
*)TimerIO
,0L
78 FreeSignal(1L<<camdwaitsig2
);
79 FreeSignal(1L<<camdwaitsig
);
80 TimerIO
->tr_node
.io_Message
.mn_Node
.ln_Type
=(UBYTE
)-1;
81 TimerIO
->tr_node
.io_Device
=(struct Device
*)-1L;
82 TimerIO
->tr_node
.io_Unit
=(struct Unit
*)-1L;
83 FreeMem(TimerIO
,sizeof(struct timerequest
));
84 DeleteMsgPort(TimerMP
);
89 ObtainSemaphore(&camdwaitsemaphore
);
91 camdwaittask
=FindTask(0L);
100 if(sig
&SIGBREAKF_CTRL_C
) break;
102 if(sig
& 1L<<camdwaitsig
){ // Someone wants to obtain the semaphore?
103 TimerIO
->tr_node
.io_Command
=TR_ADDREQUEST
;
104 TimerIO
->tr_time
.tv_secs
=0;
105 TimerIO
->tr_time
.tv_micro
=10;
106 DoIO((struct IORequest
*)TimerIO
); // ..Better let them wait.
108 ReleaseSemaphore(&camdwaitsemaphore
); // Well, okey then.
110 Wait(1L<<camdwaitsig2
); // Finished soon?
112 ObtainSemaphore(&camdwaitsemaphore
); // But I want it back!
117 ReleaseSemaphore(&camdwaitsemaphore
);
119 FreeSignal(1L<<camdwaitsig2
);
120 FreeSignal(1L<<camdwaitsig
);
121 CloseDevice((struct IORequest
*)TimerIO
);
122 TimerIO
->tr_node
.io_Message
.mn_Node
.ln_Type
=(UBYTE
)-1;
123 TimerIO
->tr_node
.io_Device
=(struct Device
*)-1L;
124 TimerIO
->tr_node
.io_Unit
=(struct Unit
*)-1L;
125 FreeMem(TimerIO
,sizeof(struct timerequest
));
127 DeleteMsgPort(TimerMP
);
129 camdwaitprocstatus
=3;
134 BOOL
InitCamdTimer(void){
135 struct Process
*process
;
137 InitSemaphore(&camdwaitsemaphore
);
138 InitSemaphore(&camdwaitsemaphore2
);
140 process
=CreateNewProcTags(
141 NP_Entry
, (IPTR
) CamdTimerProc
,
142 NP_Name
, (IPTR
) "Camd Wait Proc",
146 if(process
==NULL
) return FALSE
;
148 while(camdwaitprocstatus
==0) Delay(1);
150 if(camdwaitprocstatus
==2) return FALSE
;
155 void UninitCamdTimer(void){
157 if(camdwaitprocstatus
==2) return;
159 Signal(camdwaittask
,SIGBREAKF_CTRL_C
);
160 while(camdwaitprocstatus
!=3) Delay(1);
166 * When a hardware-sender buffer is full, or we are sending a sysex-message
167 * to hardware, we need to wait for small amounts of time. That is what
168 * this function tries to do.
174 static BOOL iswaiting
=FALSE
;
175 BOOL imjustgoingtoreturnsoon
=iswaiting
;
177 ObtainSemaphore(&camdwaitsemaphore2
);
179 if(imjustgoingtoreturnsoon
==TRUE
){ // No big point having more than one visitor to wait.
180 ReleaseSemaphore(&camdwaitsemaphore2
);
186 Signal(camdwaittask
,1L<<camdwaitsig
); // Give me the semaphore!
187 ObtainSemaphore(&camdwaitsemaphore
); // This should take some time.
188 Signal(camdwaittask
,1L<<camdwaitsig2
); // Okey, I've got it.
189 ReleaseSemaphore(&camdwaitsemaphore
); // You're welcome.
193 ReleaseSemaphore(&camdwaitsemaphore2
);