' ' 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.startExt(63,62,230_400,230_400, ser#_rxmode, ser#_txmode,0, $FF, $100, $FF,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 100) '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.txwrite(@menu, 60, serport) ser.str(string(">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