Skip to content

Commit

Permalink
save latest test code - all ports working...
Browse files Browse the repository at this point in the history
  • Loading branch information
ironsheep committed Dec 4, 2022
1 parent 7aab6c3 commit cb6cd11
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 56 deletions.
16 changes: 15 additions & 1 deletion P2-source/isp_octoport_serial.spin2
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,18 @@ PUB txPrefix(portHandle, pStr, prefixLen) | nChar
else
quit

PUB txBytesEmpty(portHandle) : nbrCharsAvail
'' Returns count of characters in backend COG Transceiver receive buffer waiting to be unloaded
if isValidPortHandle(portHandle)
nbrCharsAvail := 0
if (txTailIdx[portHandle] <> txHeadIdx[portHandle]) ' if BYTE(s) available
nbrCharsAvail := txHeadIdx[portHandle] - txTailIdx[portHandle] ' calculate count
if (nbrCharsAvail < 0)
nbrCharsAvail += BUF_SIZE ' fix if wrapped around
' and invert this value
nbrCharsAvail := BUF_SIZE - nbrCharsAvail
'debug("SP8: p", udec_(portHandle+1), " free=", udec_long_(nbrCharsAvail))

PUB txFlush(portHandle)
'' Wait until transmit buffer is empty
'' -- will delay one additional BYTE period after buffer is empty
Expand Down Expand Up @@ -512,7 +524,8 @@ PUB nextRxString(pUserBuf, nBufLen) : portHandle, pNextString | bStringComplete,
repeat nPortHandle from 0 to activPortCount - 1
' if this channel OVERRAN itself... tell this via debug
if bRxOverflow[nPortHandle] <> FALSE
debug("SP8: p", udec_(nPortHandle+1), uhex_long(bRxOverflow[nPortHandle]))
debug("SP8: p", udec_(nPortHandle+1), uhex_long_(bRxOverflow[nPortHandle]))
bRxOverflow[nPortHandle] := FALSE
' point to buffer for string
pString := @BYTE[@strBuffer][nPortHandle * BUF_SIZE]
' get char for this channel if one received
Expand Down Expand Up @@ -591,6 +604,7 @@ PRI initIfNotAlready()
if initialized <> INITIALIZED_FLAG
' zero our control variables
longfill(@activPortCount, 0, COPY_CNT_IN_LONGS)
longfill(@bRxOverflow, 0, MAX_PORTS)
' no queuing for now
bUseStringQueCog := FALSE ' set to TRUE to enable unload COG and use of string queue

Expand Down
42 changes: 24 additions & 18 deletions P2-source/test_octoExercise_recv.spin2
Original file line number Diff line number Diff line change
Expand Up @@ -59,32 +59,38 @@ PUB main()| portHandle, pNextString, bDidPass, portIndex, passIncr, failIncr, le
longfill(@msgTxCount, 0, utils.MAX_PORTS * 4) ' preload w/zero's

debug("* ----- RECEIVE end STARTED ----- *")

' testing P2 <-> P2 8 ports, 16 wires
'{
' Pair Blue/Green Long
portHndl[0] := serPorts.addPort(30, 31, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_15K) ' 1st open port

portHndl[0] := serPorts.addPort(30, 31, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_3K3) ' 1st open port
'}
'{
' Pair Yellow/Orange Long
portHndl[1] := serPorts.addPort(28, 29, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_3K3) ' 2nd open port
'}
'{
' Pair Yellow/Orange Long
portHndl[1] := serPorts.addPort(28, 29, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_15K) ' 2nd open port

' Pair Red/Brown Long
portHndl[2] := serPorts.addPort(26, 27, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_15K) ' 3rd open port

portHndl[2] := serPorts.addPort(26, 27, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_3K3) ' 3rd open port
'}
'{
' Pair Purple/Gray Long
portHndl[3] := serPorts.addPort(24, 25, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_15K) ' 4th open port

' Pair Orange/Yellow w/LA
portHndl[4] := serPorts.addPort(22, 23, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_15K) ' 5th open port

portHndl[3] := serPorts.addPort(24, 25, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_3K3) ' 4th open port
'}
'{
' Pair Orange/Yellow w/LA (OK)
portHndl[4] := serPorts.addPort(22, 23, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_3K3) ' 5th open port
'}
'{
' Pair Yellow/Green w/LA
portHndl[5] := serPorts.addPort(20, 21, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_15K) ' 6th open port

portHndl[5] := serPorts.addPort(20, 21, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_3K3) ' 6th open port
'}
'{
' Pair Blue/Purple
portHndl[6] := serPorts.addPort(18, 19, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_15K) ' 7th open port

portHndl[6] := serPorts.addPort(18, 19, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_3K3) ' 7th open port
'}
'{
' Pair Whaite/Gray
portHndl[7] := serPorts.addPort(16, 17, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_15K) ' 9th open port
portHndl[7] := serPorts.addPort(16, 17, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_3K3) ' 9th open port
'}
debug("* Handles: ", sdec_long_array_(@portHndl, utils.MAX_PORTS))

Expand Down
95 changes: 63 additions & 32 deletions P2-source/test_octoExercise_send.spin2
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ VAR
LONG passCt[utils.MAX_PORTS]
LONG failCt[utils.MAX_PORTS]

PUB main()| portIndex, portHandle, pNextString, bDidPass, bValidStatus, passIncr, failIncr
LONG currPortHandle
LONG currPortIndex

PUB main()| portHandle, pNextString, bDidPass, bValidStatus, passIncr, failIncr, lenNonCtrl, msgLen, freeSpaceBytes

longfill(@txState, SST_NEEDTX, utils.MAX_PORTS) ' preset "need a tx message"
longfill(@portHndl, serPorts.PORT_NOT_FOUND, utils.MAX_PORTS) ' empty handles
Expand All @@ -66,25 +69,37 @@ PUB main()| portIndex, portHandle, pNextString, bDidPass, bValidStatus, passIncr
debug("* ----- TRANSMIT end STARTED ----- *")

' testing setup only (rxp, txp, ....)
'{
' Pair Blue/Green Long
portHndl[0] := serPorts.addPort(16, 17, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_3K3) ' 1st open port

'}
'{
' Pair Yellow/Orange Long
portHndl[1] := serPorts.addPort(18, 19, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_3K3) ' 2nd open port

' orange, yellow pair
portHndl[2] := serPorts.addPort(20, 21, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_15K) ' 3rd open port

portHndl[3] := serPorts.addPort(22, 23, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_15K) ' 4th open port

' green, blue pair
portHndl[4] := serPorts.addPort(24, 25, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_15K) ' 5th open port

portHndl[5] := serPorts.addPort(26, 27, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_15K) ' 6th open port

' red, brown pair
portHndl[6] := serPorts.addPort(28, 29, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_15K) ' 7th open port

portHndl[7] := serPorts.addPort(30, 31, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_15K) ' 9th open port
'}
'{
' Pair Red/Brown Long
portHndl[2] := serPorts.addPort(20, 21, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_3K3) ' 3rd open port
'}
'{
' Pair Purple/Gray Long
portHndl[3] := serPorts.addPort(22, 23, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_3K3) ' 4th open port
'}
'{
' Pair Orange/Yellow w/LA (OK)
portHndl[4] := serPorts.addPort(24, 25, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_3K3) ' 5th open port
'}
'{
' Pair Yellow/Green w/LA Now Red/Orange w/LA
portHndl[5] := serPorts.addPort(26, 27, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_3K3) ' 6th open port
'}
'{
' Pair Blue/Purple
portHndl[6] := serPorts.addPort(28, 29, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_3K3) ' 7th open port
'}
'{
' Pair Whaite/Gray
portHndl[7] := serPorts.addPort(30, 31, serPorts.MODE_NONE, BAUD_OCTO_PORTS, serPorts.PU_3K3) ' 9th open port
'}
debug("* Handles: ", sdec_long_array_(@portHndl, utils.MAX_PORTS))

Expand All @@ -93,25 +108,41 @@ PUB main()| portIndex, portHandle, pNextString, bDidPass, bValidStatus, passIncr
' test each port once then quit!
' (we are checking hte wiring!)

repeat portIndex from 0 to utils.MAX_PORTS - 1
if portHndl[portIndex] <> serPorts.PORT_NOT_FOUND
if txState[portIndex] == SST_NEEDTX
msgTxCount[portIndex]++
utils.getMessageForCount(@valBuffer, portIndex, msgTxCount[portIndex], utils.MSG_RAW)
serPorts.txStr(portHndl[portIndex], @valBuffer)
txState[portIndex] := SST_NEEDRX
debug("Tx #", udec_(portIndex + 1), " msg=[", zstr(@valBuffer), "]")

if txState[portIndex] == SST_NEEDRX
repeat currPortIndex from 0 to utils.MAX_PORTS - 1
currPortHandle := portHndl[currPortIndex]
if currPortHandle <> serPorts.PORT_NOT_FOUND
if txState[currPortIndex] == SST_NEEDTX
' incre count of sent messages
msgTxCount[currPortIndex]++
utils.getMessageForCount(@valBuffer, currPortIndex, msgTxCount[currPortIndex], utils.MSG_RAW)
' wait for tx bufffer to have room for entire message
msgLen := strsize(@valBuffer)
repeat
freeSpaceBytes := serPorts.txBytesEmpty(currPortHandle)
if freeSpaceBytes < msgLen
debug("* wr chk ", udec(msgLen), udec(freeSpaceBytes))
waitms(1) ' let some time pass to tx more of bytes already in buffer
else
quit
' send it (place it into buffer quickly)
serPorts.txStr(currPortHandle, @valBuffer)
txState[currPortIndex] := SST_NEEDRX
lenNonCtrl := utils.lenExcludingCtrl(@valBuffer) - 1 ' no display of CRC
debug("Tx #", udec_(currPortIndex + 1), " msg=[", lstr_(@valBuffer, lenNonCtrl), "]")

if txState[currPortIndex] == SST_NEEDRX
repeat
portHandle, pNextString := serPorts.nextRxString(@rxBuffer,utils.CHAR_BUFFER_SIZE)
if portHandle <> portHndl[portIndex]
if portHandle == currPortHandle
lenNonCtrl := utils.lenExcludingCtrl(@valBuffer) - 1 ' no display of CRC
' validate message
msgRxCount[portIndex]++
bValidStatus, passIncr, failincr := utils.validateAckedString(portIndex, msgRxCount[portIndex], pNextString)
debug("Rx #", udec_(portIndex + 1), " msg=[", zstr(pNextString), "] cts [good=(", udec_(passCt[portIndex]), "), bad=(", udec_(failCt[portIndex]), ")]")
msgRxCount[currPortIndex]++
bValidStatus, passIncr, failIncr := utils.validateAckedString(currPortIndex, msgRxCount[currPortIndex], pNextString)
passCt[currPortIndex] += passIncr
failCt[currPortIndex] += failIncr
debug("Rx #", udec_(currPortIndex + 1), " msg=[", lstr_(pNextString, lenNonCtrl), "] cts [good=(", udec_(passCt[currPortIndex]), "), bad=(", udec_(failCt[currPortIndex]), ")]")
' mark port as needing a TX
txState[portIndex] := SST_NEEDTX
txState[currPortIndex] := SST_NEEDTX
quit ' we received one, go send more


Expand Down
10 changes: 5 additions & 5 deletions P2-source/test_utils.spin2
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ PUB validateStringFrom(portHandleRcvr, pString, pDesiredString) : bFailStatus, p
pResult := (bDidPass) ? @" " : @"FAIL"
nCount := (bDidPass) ? passCt[portHandleRcvr] : failCt[portHandleRcvr]
lenNonCtrl := lenExcludingCtrl(pString) - 1 ' don't show CRC
debug("* RX p#", udec_(portHandleRcvr), " (", udec_(lenNonCtrl), "/", udec_(strsize(pString)), ")[", lstr_(pString, lenNonCtrl), "]: ", zstr_(pResult), " seq#", udec_(nCount))
'debug("* RX p#", udec_(portHandleRcvr+1), " [", lstr_(pString, lenNonCtrl), "]: ", zstr_(pResult), " seq#", udec_(nCount))


PUB getMessageForCount(pBuffer, portIndex, nCount, eMsgState)
Expand Down Expand Up @@ -94,8 +94,8 @@ PRI replaceMarkerWithCRC(pStr, pMarkerChar) : bPlacedStatus | strLen, byteIdx, b
if bFoundMarker
calcCrc := crc8(pStr, crcIdx)
' don't appear to be one of our critical chars!
if calcCrc == $0a or calcCrc == $0d or calcCrc == $00
calcCrc++
if calcCrc < $20
calcCrc += $80
BYTE[pStr][crcIdx] := calcCrc
bPlacedStatus := bFoundMarker

Expand All @@ -106,8 +106,8 @@ PRI isValidCRC(pStr) : bValidStatus | strLen, crcIdx, calcCRC
crcIdx := strLen - 3
calcCRC := crc8(pStr, crcIdx)
' don't appear to be one of our critical chars!
if calcCrc == $0a or calcCrc == $0d or calcCrc == $00
calcCrc++
if calcCrc < $20
calcCrc += $80
if BYTE[pStr][crcIdx] == calcCRC
bValidStatus := TRUE

Expand Down

0 comments on commit cb6cd11

Please sign in to comment.