' ' 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[200] long buf1[$100] long buf2[$100] ' '----------------------------------------------------------------------- '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, 100) 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, 100) cog := cognew(echo_init2, @echo_stack) + 1 ' '----------------------------------------------------------------------- 'new cog tests serial driver '----------------------------------------------------------------------- ' PUB echo_init1 | a, b, c 'echo one pair c := -1 repeat if ser.check_txready(0) == -1 if ser.check_rxready(0) == -1 a := ser.txcount(0) 'bytes free in tx buffer if a > 0 b := ser.rxcount(0) 'bytes available tn rx buffer if b > 0 if b < a a := b ' a now min(a,b) ser.rxread(@buf1, a, 0) ser.txwrite_async(@buf1, a ,0) PUB echo_init2 | a, b, c 'echo two pairs repeat if ser.check_txready(0) == -1 if ser.check_rxready(0) == -1 a := ser.txcount(0) 'bytes free in tx buffer if a > 0 b := ser.rxcount(0) 'bytes available tn rx buffer if b > 0 if b < a a := b ' a now min(a,b) ser.rxread(@buf1, a, 0) ser.txwrite_async(@buf1, a ,0) if ser.check_txready(1) == -1 if ser.check_rxready(1) == -1 a := ser.txcount(1) 'bytes free in tx buffer if a > 0 b := ser.rxcount(1) 'bytes available tn rx buffer if b > 0 if b < a a := b ' a now min(a,b) ser.rxread(@buf2, a, 1) ser.txwrite_async(@buf2, a ,1)