home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AmigActive 6
/
AACD06.ISO
/
AACD
/
Utilities
/
Resources
/
ProNET
/
src
/
drivers
/
serial.s
< prev
Wrap
Text File
|
1996-11-30
|
6KB
|
310 lines
*
* serial (ProNET driver)
*
** This driver does not work correctly with 8n1.device 37.13
; Format of one packet
; 2bytes "R!" for packet recognization
; 2bytes Length in Bytes of pure data without next two words
; 2bytes Destination Port
; 2bytes source Port
; xbytes Data
include "A:OSmacros.i"
include "exec/exec.i"
include "devices/serial.i"
include "P:include/devices/pronet.i"
include "exec_lib.i"
Init
movem.l d2-d7/a2-a6,-(sp)
move.l a0,a4
move.l a1,a5
cmp.l #"RST!",d0 ;compare ID
bne .ende
cmp.l #2,d1 ;0 was the error condition
bne.s .ende ;in ProNET V2/V3
bsr StartDevice
tst.w d0
beq.s .ende
move.l serialio(pc),a0
move.l MN_REPLYPORT(a0),a0
move.b MP_SIGBIT(a0),pndd_ReadSignalBit(a4)
move.l #ReadQuery,pndd_ReadQuery(a4)
move.l #ReadFlush,pndd_ReadFlush(a4)
move.l #Read,pndd_Read(a4)
move.l #Write,pndd_Write(a4)
move.l #Exit,pndd_Exit(a4)
clr.l RC
.ende movem.l (sp)+,d2-d7/a2-a6
move.l RC(pc),d0
rts
RC dc.l 0
dc.b "$VER: serial 37.0 (30.11.96)",13,10,0
even
Exit movem.l d2-d7/a2-a6,-(sp)
bsr StopDevice
movem.l (sp)+,d2-d7/a2-a6
rts
; -- Start the right `serial.device'
StartDevice move.l 4.w,a6
move.l #PNDRVERR_NO_MEMORY,RC
moveq #IOEXTSER_SIZE,d0
bsr GetIORequest
move.l d0,serialio
beq noiorequest
moveq #IOEXTSER_SIZE,d0
bsr GetIORequest
move.l d0,serialiow
beq noiorequest2
move.l serialio(pc),a2
move.b #SERF_7WIRE,IO_SERFLAGS(a2)
move.l a5,a0 ;device name
.0 move.b (a0)+,d0
cmp.b #" ",d0
bhi.s .0
clr.b -1(a0)
bsr dec2long
move.l d1,d5 ;unit
bsr dec2long
move.l d1,d6 ;baudrate
move.b #SERF_XDISABLED^SERF_RAD_BOOGIE^SERF_7WIRE,d7
lea threeweestring(pc),a1
tst.b -1(a0)
beq.s .7wire ;3 or 7 wire??
moveq #4,d0
.test3wire move.b (a0)+,d1
cmp.b #"A",d1
bcs.s .nochar
bclr #5,d1
.nochar cmp.b (a1)+,d1
dbne d0,.test3wire
bne.s .7wire
bclr #SERB_7WIRE,d7
bclr #SERB_7WIRE,IO_SERFLAGS(a2)
.7wire
move.l a5,a0
move.l d5,d0
move.l a2,a1
moveq #0,d1
LIBCALL OpenDevice
move.l #err1,RC
tst.b d0
bne nodevice
move.l a2,a0
move.l serialiow(pc),a1
move.l a1,a2
move.l MN_REPLYPORT(a2),d2
moveq #IOEXTSER_SIZE,d0
LIBCALL CopyMem
move.l d2,MN_REPLYPORT(a2)
move.w #CMD_WRITE,IO_COMMAND(a2)
move.l serialio(pc),a1
move.w #SDCMD_SETPARAMS,IO_COMMAND(a1)
move.b d7,IO_SERFLAGS(a1)
move.l d6,IO_BAUD(a1)
move.l #16384,IO_RBUFLEN(a1)
clr.l IO_EXTFLAGS(a1)
move.b #8,IO_READLEN(a1)
move.b #8,IO_WRITELEN(a1)
move.b #1,IO_STOPBITS(a1)
clr.b IO_FLAGS(a1)
LIBCALL DoIO
move.l #err2,RC
tst.b d0
bne.s noparams
bsr.s IssueReadCMD
moveq #-1,d0
rts
err1 dc.b "Can't open specified serial.device.",0
err2 dc.b "Couldn't set serial parameters.",0
even
StopDevice move.l 4.w,a6
move.l serialio(pc),a1
LIBCALL AbortIO
move.l serialio(pc),a1
LIBCALL WaitIO
noparams move.l serialio(pc),a1
LIBCALL CloseDevice
nodevice move.l serialiow(pc),a0
bsr FreeIORequest
noiorequest2 move.l serialio(pc),a0
bsr FreeIORequest
noiorequest moveq #0,d0
rts
threeweestring dc.b "3WIRE"
even
; -- Put Out An 8 Bytes Read Command
IssueReadCMD move.l serialio(pc),a0
move.l MN_REPLYPORT(a0),a0
move.b MP_SIGBIT(a0),d2
moveq #0,d0
moveq #0,d1
bset d2,d1
LIBCALL SetSignal
move.l serialio(pc),a1
move.w #CMD_READ,IO_COMMAND(a1)
clr.b IO_FLAGS(a1)
move.l #buffer,IO_DATA(a1)
move.l #8,IO_LENGTH(a1)
move.l 4.w,a6
LIBJMP SendIO
ReadQuery
movem.l d3-d7/a2-a6,-(sp)
move.l serialio(pc),a0
move.l MN_REPLYPORT(a0),a0
move.l 4.w,a6
LIBCALL GetMsg
tst.l d0
beq.s .nope
move.w buffer(pc),d0
cmp.w #"R!",d0
beq.s .ok0
bsr ReadEmpty
bsr IssueReadCMD
.nope moveq #0,d0
bra.s .ende
.ok0 movem.w buffer+2(pc),d0-d2
.ende movem.l (sp)+,d3-d7/a2-a6
rts
ReadFlush
movem.l d2-d7/a2-a6,-(sp)
move.l 4.w,a6
moveq #0,d2
move.w buffer+2(pc),d2
.1 move.l d2,d0
cmp.l #64,d0
bls.s .0
moveq #64,d0
.0 sub.l d0,d2
move.l serialio(pc),a1
move.l #clrbuffer,IO_DATA(a1)
move.l d0,IO_LENGTH(a1)
move.w #CMD_READ,IO_COMMAND(a2)
clr.b IO_FLAGS(a1)
LIBCALL DoIO
tst.l d2
bne.s .1
bra.s read_entry
Read
movem.l d2-d7/a2-a6,-(sp)
move.l 4.w,a6
move.l serialio(pc),a1
move.l a0,IO_DATA(a1)
moveq #0,d0
move.w buffer+2(pc),d0
move.l d0,IO_LENGTH(a1)
move.w #CMD_READ,IO_COMMAND(a1)
clr.b IO_FLAGS(a1)
LIBCALL DoIO
read_entry bsr IssueReadCMD
movem.l (sp)+,d2-d7/a2-a6
rts
Write
movem.l d2-d7/a2-a6,-(sp)
move.l serialiow(pc),a2
move.l 4.w,a6
move.l a0,a3
move.l d0,d3
lea sendbuffer(pc),a5
move.w d0,2(a5)
move.w d1,4(a5)
move.w d2,6(a5)
move.l a5,IO_DATA(a2)
move.l #8,IO_LENGTH(a2)
clr.b IO_FLAGS(a2)
move.l a2,a1
LIBCALL DoIO
move.l a3,IO_DATA(a2)
move.l d3,IO_LENGTH(a2)
clr.b IO_FLAGS(a2)
move.l a2,a1
LIBCALL DoIO
moveq #0,d0
movem.l (sp)+,d2-d7/a2-a6
rts
buffer ds.b 8
sendbuffer dc.b "R!"
dc.w 0,0,0
; -- A received message did not contain the "R!" string (probably
; -- the BaudBandit.device startup message), so clear it!
ReadEmpty move.l serialio(pc),a2 * CMD_CLEAR
move.l 4.w,a6 * does not help!
.loop move.w #SDCMD_QUERY,IO_COMMAND(a2) * so we have to read
move.l a2,a1 * it out!
clr.b IO_FLAGS(a1)
LIBCALL DoIO
move.l IO_ACTUAL(a2),d0
beq.s .ende
cmp.l #64,d0
bcs.s .ok0
moveq #64,d0
.ok0 move.l d0,IO_LENGTH(a2)
move.l #clrbuffer,IO_DATA(a2)
move.w #CMD_READ,IO_COMMAND(a2)
move.l a2,a1
clr.b IO_FLAGS(a1)
LIBCALL DoIO
bra.s .loop
.ende rts
dec2long ; konvertiert Dezimalstring ab (a0) zu Longword in D1 !!
moveq #0,d1
.loop moveq #0,d0
move.b (a0)+,d0
sub.b #"0",d0
cmp.b #9,d0
bhi.s .oki
move.l d1,d2
lsl.l #3,d1
add.l d2,d1
add.l d2,d1
add.l d0,d1
bra.s .loop
.oki rts
serialio dc.l 0
serialiow dc.l 0
include "P:include/devio.s"
section b,bss
clrbuffer ds.b 64