' ' 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 serport = 0 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.start2(-1,-1,-1,-1,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.start2(63,62,-1,230_400,1,0,-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.start2(1,0,-1,230_400,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.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 "), serport) ser.hex(_clkmode,8,0,serport) ser.str(string(" _clkfreq "), serport) ser.dec(_clkfreq, 10, 0, serport) ser.tx(13, serport) ser.tx(10, serport) repeat ser.str(@menu, serport) c := ser.rx(serport) case c 49 : runTest1 50 : runTest2 51 : runTest3 52 : runTest4 other : ser.str(@entrynotvalid, serport) ' 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), serport) baud := 115200 * 700 increment := 115200 repeat until test(baud, $4000, 0, 3, 0) < 0 baud += increment PRI runTest2 | a, b, c, count, baud, increment ser.str(STRING(13,10,"running Test 2 - any key to exit",13,10), serport) baud := 115200 * 700 increment := 115200 repeat until test(baud, $4000, 1, 3, 0) < 0 baud += increment PRI runTest3 | a, b, c, count, baud, increment ser.str(STRING(13,10,"running Test 3 - any key to exit",13,10), serport) baud := 115200'0* 60 increment := 115200 repeat until test(baud, $4000, 0, 3, 1) < 0 baud += increment PRI runTest4 | a, b, c, count, baud, increment ser.str(STRING(13,10,"running Test 4 - any key to exit",13,10), serport) baud := 115200'0*60 increment := 115200 repeat until test(baud, $4000, 1, 3, 1) < 0 baud += increment PRI test(baud, count, bothports, maxloops, useechoserver) | a, b, c, d, e, timeout 'ed8978 80868c 8046c4 6401e4 497294 ser.str(STRING(13,10,"running at baud "), serport) ser.dec(baud, 0, 0, serport) if bothports ser.str(STRING(" - two ports"), serport) else ser.str(STRING(" - one port"), serport) if useechoserver ser.str(STRING(" - using echo server"), serport) ser.tx(13, serport) ser.tx(10, serport) a := -1 b := -1 d := maxloops if bothports == 0 if useechoserver 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) else tst1.start(@b,3,2,baud) 'tst1 now checks sp3-1 (2) for input using sp3 and sends out on sp0 (0) else if useechoserver 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) else '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(serport) if b < 0 ' -1 pass, -2 fail timeout := 1_000_000 if b == -1 e := c ser.dec(e,10, 0, serport) ser.str(STRING(" - PASS - "), serport) e :=(CLKFREQ*10) / ((e>>4)/1000) ' clk per bit? ser.dec(e, 0, 0, serport) ser.str(STRING(" - "), serport) e := (c - ($4000*((CLKFREQ*10)/baud)))/$4000 ser.dec(e, 0, 0, serport) ser.str(string(" ",13), serport) if b < -1 RESULT := -2 e := -c ser.dec(e,10, 0, serport) ser.str(STRING(" - FAIL - "), serport) e :=(CLKFREQ*10) / ((e>>4)/1000) ' clk per bit? ser.dec(e, 0, 0, serport) ser.str(STRING(" - "), serport) e := ((-c) - ($4000*((CLKFREQ*10)/baud)))/$4000 ser.dec(e, 0, 0, serport) ser.str(STRING(" - "), serport) case b -2: ser.str(string("timeout rx1"), serport) -3: ser.str(string("timeout rx2"), serport) -4: ser.str(string("buffer 1 does not check"), serport) -5: ser.str(string("buffer 2 does not check"), serport) ser.str(string(" ",13,10), serport) c := 0 b := count if d > 0 d-- if d == 0 a := 0 else timeout-- until (a >-1) or (timeout < 0) or (RESULT < 0) if timeout<0 ser.str(STRING(" - timeout - ",13,10), serport) RESULT := -1 tst1.stop echo.stop DAT menu byte 13,10 byte "1 Test 1 - one port talking to itself",13,10 byte "2 Test 2 - two port talking to themself",13,10 byte "3 Test 3 - one port talking to one port echo server",13,10 byte "4 Test 4 - two port talking to two port echo server",13,10 byte 0 entrynotvalid byte 13,10 byte "Entry not valid, try 1-3",13,10 byte 0