' ' Test of cogserial - user interface ' CON _XTALFREQ = 20_000_000 ' crystal frequency _XDIV = 4 '\ '\ crystal divider to give 5.0MHz _XMUL = 72'64 '| 180MHz '| crystal / div * mul to give 360MHz _XDIVP = 2 '/ '/ crystal / div * mul /divp to give 180MHz _XOSC = %01 '15pF ' %00=OFF, %01=OSC, %10=15pF, %11=30pF _XSEL = %11 'XI+PLL ' %00=rcfast(20+MHz), %01=rcslow(~20KHz), %10=XI(5ms), %11=XI+PLL(10ms) _XPPPP = ((_XDIVP>>1) + 15) & $F ' 1->15, 2->0, 4->1, 6->2...30->14 _clkfreq = _XTALFREQ / _XDIV * _XMUL / _XDIVP ' internal clock frequency _clkmode = 1<<24 + (_XDIV-1)<<18 + (_XMUL-1)<<8 + _XPPPP<<4 + _XOSC<<2 ' %0000_000e_dddddd_mmmmmmmmmm_pppp_cc_00 ' setup oscillator OBJ ser: "cogserial.spin2" 'this one takes care of communication with terminal/user interface echo: "testecho.spin2" 'simple echo server - 2 cogs - one echoing, one serial tst1: "testrunner.spin2" 'runs tests - 2 cogs - one running test, one serial PUB demo | c clkset(_clkmode, _clkfreq) ser.start(63,62,1,230_400) 'will start with start(rxpin = 63, txpin = 62, mode = -1, baudrate = 230_400 and 255 bytes buffers for rx and tx) ser.str(string(13,10,"_clkmode ")) ser.hex(_clkmode,8) ser.str(string(" _clkfreq ")) ser.dec(_clkfreq) ser.tx(13) ser.tx(10) repeat ser.str(@menu) c := ser.rx case c 49 : runTest1 50 : runTest2 51 : runTest3 other : ser.str(@entrynotvalid) ' start test1 serial at baud and transfer 16k of rom while receiving 16k from echo PRI runTest1 | a, b, c, count, baud, increment ser.str(STRING(13,10,"running Test 1 - any key to exit",13,10)) baud := 115200 '0* 40 increment := 115200 repeat 20 test(baud, $4000, 0, 3) baud += increment PRI runTest2 | a, b, c, count, baud, increment ser.str(STRING(13,10,"running Test 2 - any key to exit",13,10)) baud := 115200' * 20 increment := 115200 repeat 10 test(baud, $4000, 1, 3) baud += increment PRI runTest3 | a, b, c, count ser.str(STRING(13,10,"running Test 3 - any key to exit",13,10)) test(1_200_00, $4, 0) PRI test(baud, count, bothports, maxloops = -1) | a, b, c, d, e, timeout 'ed8978 80868c 8046c4 6401e4 497294 ser.str(STRING(13,10,"running at baud ")) ser.dec(baud) ser.tx(13) ser.tx(10) a := -1 b := -1 d := maxloops if bothports == 0 echo.start(1,2,baud) 'echo now checks sp1-1 (0) for input using sp1 and sends out on sp2 (2) tst1.start(@b,3,0,baud) 'tst1 now checks sp3-1 (2) for input using sp3 and sends out on sp0 (0) ' tst1.start(@b,3,2,baud) 'tst1 now checks sp3-1 (2) for input using sp3 and sends out on sp0 (0) else echo.start(1,2,baud,5,6) 'echo now checks sp1-1 (0) for input using sp1 and sends out on sp2 (2) 'and now checks sp5-1 (4) for input using sp5 and sends out on sp6 (6) tst1.start(@b,3,0,baud,7,4) 'tst1 now checks sp3-1 (2) for input using sp3 and sends out on sp0 (0) 'and now checks sp7-1 (6) for input using sp7 and sends out on sp4 (4) ' tst1.start(@b,3,2,baud,7,6) timeout := 1_000_000 c := 0 b := count repeat a := ser.rxcheck if b == -1 timeout := 1_000_000 'if c <> 0 if c > 0 e := c ser.dec(e,10) ser.str(STRING(" - PASS - ")) e :=(CLKFREQ*10) / ((e>>4)/1000) ' clk per bit? 'e:= e -(baud*CLKFREQ) ser.dec(e) ser.str(STRING(" - ")) e := (c - ($4000*((CLKFREQ*10)/baud)))/$4000 ser.dec(e) ser.str(string(" ",13,10)) ' c := 0 ' b := count if c < 1 e := -c ser.dec(e,10) ser.str(STRING(" - FAIL - ")) e :=(CLKFREQ*10) / ((e>>4)/1000) ' clk per bit? ser.dec(e) ser.str(STRING(" - ")) e := ((-c) - ($4000*((CLKFREQ*10)/baud)))/$4000 ser.dec(e) ser.str(string(" ",13,10)) c := 0 b := count if d > 0 d-- if d == 0 a := 0 else timeout-- until (a >-1) or (timeout < 0) if timeout<0 ser.str(STRING(" - timeout - ",13,10)) tst1.stop echo.stop DAT menu byte 13,10 byte "1 Test 1",13,10 byte "2 Test 2",13,10 byte "3 Test 3",13,10 byte 0 entrynotvalid byte 13,10 byte "Entry not valid, try 1-3",13,10 byte 0