5 #include <exec/types.h>
6 #include <exec/resident.h>
8 #include <exec/ports.h>
9 #include <exec/errors.h>
10 #include <exec/lists.h>
13 #include <aros/libcall.h>
14 #include <aros/symbolsets.h>
16 #include <devices/sana2.h>
17 #include <devices/sana2specialstats.h>
18 #include <devices/newstyle.h>
19 #include <devices/timer.h>
20 #include <devices/serial.h>
21 #include <devices/timer.h>
23 #include <utility/utility.h>
24 #include <utility/tagitem.h>
25 #include <utility/hooks.h>
27 #include <proto/exec.h>
28 #include <proto/dos.h>
29 #include <proto/oop.h>
30 #include <proto/timer.h>
31 #include <proto/utility.h>
42 #include <devices/serial.h>
43 #include <devices/timer.h>
46 #include "device_protos.h"
47 #include LC_LIBDEFS_FILE
50 void SetTimer(struct EasyTimer
* t
,const ULONG s
){
54 AbortIO((struct IORequest
*)t
->TimeReq
);
55 WaitIO((struct IORequest
*)t
->TimeReq
);
56 while(GetMsg(t
->TimeMsg
));
60 t
->TimeReq
->tr_time
.tv_secs
= s
;
61 t
->TimeReq
->tr_time
.tv_micro
= 0;
62 ((struct IORequest
*)t
->TimeReq
)->io_Command
= TR_ADDREQUEST
;
63 SendIO( (struct IORequest
*)t
->TimeReq
);
64 //bug("setTimer ok\n");
70 void CloseTimer(struct EasyTimer
* t
){
72 //bug("closeTimer\n");
74 AbortIO((struct IORequest
*)t
->TimeReq
);
75 WaitIO((struct IORequest
*)t
->TimeReq
);
76 while(GetMsg(t
->TimeMsg
));
77 CloseDevice((struct IORequest
*)t
->TimeReq
);
78 DeleteIORequest(t
->TimeReq
);
80 if(t
->TimeMsg
) DeleteMsgPort(t
->TimeMsg
);
81 FreeMem( t
, sizeof(struct EasyTimer
) );
82 //bug("closeTimer ok\n");
86 struct EasyTimer
* OpenTimer(){
89 if( t
= AllocMem( sizeof(struct EasyTimer
),MEMF_CLEAR
|MEMF_PUBLIC
) ){
90 if( t
->TimeMsg
= CreateMsgPort() ){
91 if( t
->TimeReq
= CreateIORequest((struct MsgPort
*)t
->TimeMsg
, sizeof(struct timerequest
))){
92 if(!OpenDevice("timer.device", UNIT_VBLANK
,(struct IORequest
*)t
->TimeReq
, 0)){
93 t
->TimeReq
->tr_time
.tv_secs
= 0;
94 t
->TimeReq
->tr_time
.tv_micro
= 1;
95 ((struct IORequest
*)t
->TimeReq
)->io_Command
= TR_ADDREQUEST
;
96 DoIO( (struct IORequest
*)t
->TimeReq
);
98 //bug("OpenTimer ok!\n");
104 //bug("OpenTimer FAIL!\n");
110 VOID
DoStr(struct EasySerial
*s
,const STRPTR str
){
111 DoBYTES(s
,str
,strlen((char*) str
));
114 void DoBYTES(struct EasySerial
*s
, BYTE
*p
,ULONG len
){
117 if( ! s
->Ok
) return;
119 WaitIO((struct IORequest
*)s
->SerTx
);
121 s
->SerTx
->IOSer
.io_Length
= len
;
122 s
->SerTx
->IOSer
.io_Data
= p
;
123 s
->SerTx
->IOSer
.io_Command
= CMD_WRITE
;
124 DoIO((struct IORequest
*)s
->SerTx
);
127 void SendBYTES(struct EasySerial
*s
, BYTE
*p
, ULONG len
){
130 if( ! s
->Ok
) return;
132 WaitIO((struct IORequest
*)s
->SerTx
);
134 s
->SerTx
->IOSer
.io_Length
= len
;
135 s
->SerTx
->IOSer
.io_Data
= p
;
136 s
->SerTx
->IOSer
.io_Command
= CMD_WRITE
;
137 SendIO((struct IORequest
*)s
->SerTx
);
141 struct EasySerial
*OpenSerial(BYTE
*name
,ULONG unit
){
142 struct EasySerial
*s
= NULL
;
143 D(bug("OpenSerial\n"));
147 if( ! (s
= AllocMem( sizeof(struct EasySerial
),MEMF_CLEAR
|MEMF_PUBLIC
))) break;
148 if( ! (s
->TxBuff
= AllocMem( SERIAL_BUFSIZE
,MEMF_CLEAR
|MEMF_PUBLIC
))) break;
149 if( ! (s
->RxBuff
= AllocMem( SERIAL_BUFSIZE
,MEMF_CLEAR
|MEMF_PUBLIC
))) break;
150 if( ! (s
->TxPort
= CreateMsgPort())) break;
151 if( ! (s
->SerTx
= CreateIORequest(s
->TxPort
,sizeof(struct IOExtSer
)))) break;
154 D(bug("OpenDevice: \"%s\" unit %d\n",name
,unit
));
155 if( OpenDevice( name
, unit
, (struct IORequest
*)s
->SerTx
,0)){
156 DeleteIORequest(s
->SerTx
);
161 bug("Test CMD_WRITE\n");
162 s
->SerTx
->IOSer
.io_Length
= 0;
163 s
->SerTx
->IOSer
.io_Data
= " ";
164 s
->SerTx
->IOSer
.io_Command
= CMD_WRITE
;
165 if( DoIO((struct IORequest
*)s
->SerTx
)){
169 if( ! (s
->RxPort
= CreateMsgPort()) ) break;
170 if( ! (s
->SerRx
= CreateIORequest(s
->RxPort
,sizeof(struct IOExtSer
)))) break;
172 bug("Test SDCMD_QUERY\n");
173 s
->SerRx
->IOSer
.io_Device
= s
->SerTx
->IOSer
.io_Device
;
174 s
->SerRx
->IOSer
.io_Unit
= s
->SerTx
->IOSer
.io_Unit
;
175 s
->SerRx
->IOSer
.io_Command
= SDCMD_QUERY
;
176 if( DoIO((struct IORequest
*)s
->SerRx
)){
180 D(bug("OpenSerial OK\n"));
190 VOID
_CloseSerial(struct EasySerial
*s
){
196 AbortIO((struct IORequest
*)s
->SerRx
);
197 WaitIO((struct IORequest
*)s
->SerRx
);
198 while(GetMsg(s
->RxPort
));
202 AbortIO((struct IORequest
*)s
->SerTx
);
203 WaitIO((struct IORequest
*)s
->SerTx
);
204 while(GetMsg(s
->TxPort
));
207 if(s
->SerTx
) CloseDevice((struct IORequest
*)s
->SerTx
);
209 if(s
->SerTx
) DeleteIORequest(s
->SerTx
);
210 if(s
->TxPort
) DeleteMsgPort(s
->TxPort
);
212 if(s
->SerRx
) DeleteIORequest(s
->SerRx
);
213 if(s
->RxPort
) DeleteMsgPort(s
->RxPort
);
215 if( s
->TxBuff
) FreeMem( s
->TxBuff
, SERIAL_BUFSIZE
);
216 if( s
->RxBuff
) FreeMem( s
->RxBuff
, SERIAL_BUFSIZE
);
217 FreeMem( s
, sizeof(struct EasySerial
) );
220 VOID
QueueSerRequest(struct EasySerial
*s
, LONG maxlength
){
223 if( ! s
->Ok
) return;
224 if( maxlength
< 1 ) return;
226 if( maxlength
> SERIAL_BUFSIZE
) maxlength
= SERIAL_BUFSIZE
;
227 s
->SerRx
->IOSer
.io_Command
= SDCMD_QUERY
;
228 DoIO((struct IORequest
*)s
->SerRx
);
230 if( s
->SerRx
->IOSer
.io_Error
){
231 bug("QueueSerRequest() OOOOPS lost device!\n");
236 s
->SerRx
->IOSer
.io_Command
= CMD_READ
;
237 s
->SerRx
->IOSer
.io_Data
= s
->RxBuff
;
238 s
->SerRx
->IOSer
.io_Length
= s
->SerRx
->IOSer
.io_Actual
;
240 if( s
->SerRx
->IOSer
.io_Length
> maxlength
)
241 s
->SerRx
->IOSer
.io_Length
= maxlength
;
242 /* If the number of bytes available is zero, queue a request
244 if(!s
->SerRx
->IOSer
.io_Length
)
245 s
->SerRx
->IOSer
.io_Length
= 1;
247 SendIO((struct IORequest
*)s
->SerRx
);
248 if( s
->SerRx
->IOSer
.io_Error
){
249 bug("QueueSerRequest() SendIO -> CMD_READ error!");