Fork for fixes
Diff: utility/Enc28j60Eth.cpp
- Revision:
- 19:58e840279555
- Parent:
- 16:269f652b4d0b
--- a/utility/Enc28j60Eth.cpp Wed Jul 22 20:37:24 2020 +0000 +++ b/utility/Enc28j60Eth.cpp Thu Sep 24 21:14:56 2020 +0000 @@ -182,12 +182,12 @@ //if( !(readReg(EIR) & EIR_PKTIF) ){ // The above does not work. See Rev. B4 Silicon Errata point 6. if (readReg(EPKTCNT) != 0) { - uint16_t readPtr = nextPacketPtr + - 6 > RXEND_INIT ? nextPacketPtr + + uint16_t readPtr = (nextPacketPtr + + 6 > RXEND_INIT) ? (nextPacketPtr + 6 - RXEND_INIT + - RXSTART_INIT : nextPacketPtr + - 6; + RXSTART_INIT) : (nextPacketPtr + + 6); // Set the read pointer to the start of the received packet writeRegPair(ERDPTL, nextPacketPtr); @@ -204,16 +204,32 @@ //rxstat |= readOp(ENC28J60_READ_BUF_MEM, 0) << 8; #ifdef ENC28J60DEBUG + uint16_t start = readPtr; + uint16_t end = start + len -1; //todo: why -1 ? + printf ( - "receivePacket [%d-%d], next: %d, stat: %d, count: %d -> ", + "receivePacket [%d-%d] (%d) (%d), next: %d, stat: %d, count: %d -> ", readPtr, - (readPtr + len) % (RXEND_INIT + 1), + (readPtr + len), + len, + (readPtr + len) % (RXEND_INIT + 1), // todo: what is RXEND_INIT ? nextPacketPtr, rxstat, readReg(EPKTCNT) ); (rxstat & 0x80) != 0 ? printf("OK") : printf("failed"); + + printf("\r\n"); + + int j = 1; + for (uint16_t i = start; i < end; i++) { + printf("%02x ", readByte(i)); + if (j%8==0) printf(" "); + if (j%16==0) printf("\r\n"); + j++; + } + printf("\r\n"); #endif // decrement the packet counter indicate we are done with this packet @@ -245,7 +261,13 @@ */ void Enc28j60Eth::setERXRDPT() { - writeRegPair(ERXRDPTL, nextPacketPtr == RXSTART_INIT ? RXEND_INIT : nextPacketPtr - 1); + uint16_t tmp = (nextPacketPtr == RXSTART_INIT) ? RXEND_INIT : nextPacketPtr - 1; + + #ifdef ENC28J60DEBUG + printf("setERXRDPT set %d start %d end %d \r\n",tmp,RXSTART_INIT,RXEND_INIT); + #endif + + writeRegPair(ERXRDPTL, tmp); } /** @@ -278,9 +300,13 @@ writeByte(start, 0); #ifdef ENC28J60DEBUG - printf("sendPacket(%d) [%d-%d]: ", handle, start, end); - for (uint16_t i = start; i <= end; i++) { - printf("%d ", readByte(i)); + printf("sendPacket(%d) [%d-%d]\r\n", handle, start, end); + int j = 1; + for (uint16_t i = start+1; i <= end; i++) { + printf("%02x ", readByte(i)); + if (j%8==0) printf(" "); + if (j%16==0) printf("\r\n"); + j++; } printf("\r\n");