' ' Test of cogserial - testecho: simple echo server 1 COG runs serial driver, one COG reads from rx1/2 and sends to tx1/2 continiously ' OBJ ser: "cogserial.spin2" 'this one takes care of communication with terminal/user interface VAR long cog 'cog id of this instance long echo_stack[20] ' '----------------------------------------------------------------------- 'stop cog if already running '----------------------------------------------------------------------- ' PUB stop if cog ser.stop cogstop(cog-1) cog := 0 ' '----------------------------------------------------------------------- 'start new cog to use serial driver and echo every byte from rx to tx '----------------------------------------------------------------------- ' PUB start(rxpin1, txpin1 , baudrate, rxpin2 = -1, txpin2 = -1 ) if rxpin2 == -1 ser.startExt(rxpin1, txpin1, baudrate, baudrate, ser#_rxmode+(%0111<<28), ser#_txmode,0, $FF, $100, $FF,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1) cog := cognew(echo_init1, @echo_stack) + 1 else ser.startExt(rxpin1, txpin1, baudrate, baudrate, ser#_rxmode+(%0111<<28), ser#_txmode,0, $7F, $80, $7F, rxpin2, txpin2, baudrate, baudrate, ser#_rxmode+(%0111<<28),ser#_txmode, $100, $7F, $180, $7F) cog := cognew(echo_init2, @echo_stack) + 1 ' '----------------------------------------------------------------------- 'new cog tests serial driver '----------------------------------------------------------------------- ' PUB echo_init1 | c 'echo one pair c := -1 repeat if ser.txcheck(0)> 0 if (c := ser.rxcheck(0))>-1 ser.tx(c,0) c := -1 PUB echo_init2 | c1, c2 'echo two pairs c1 := -1 c2 := -1 repeat if ser.txcheck(0)> 0 if c1 == -1 c1 := ser.rxcheck(0) if c1 > -1 ser.tx(c1,0) c1 := -1 if ser.txcheck(1)> 0 if c2 == -1 c2 := ser.rxcheck(1) if c2 > -1 ser.tx(c2,1) c2 := -1