View previous topic :: View next topic |
Author |
Message |
Markdem
Joined: 24 Jun 2005 Posts: 206
|
IPstack with DSPIC |
Posted: Sun Aug 09, 2020 3:06 am |
|
|
Hello,
I am trying to use the IP stack with a DSPIC30F6015. I have the same stack working fine with a 18F67K22. No changes (except for 3 pins for the ENC chip) are made. CCS version 5.025.
I can still ping the DSPIC so I know my hardware is good, but no TCP connections can be made.
I have debugged it down to where the checksum is worked out.
This is the code from tcp.c
Code: |
BOOL TCPProcess(NODE_INFO *remote, IP_ADDR *localIP, WORD len)
{
TCP_HEADER TCPHeader;
PSEUDO_HEADER pseudoHeader;
TCP_SOCKET socket;
WORD_VAL checksum1;
WORD_VAL checksum2;
BYTE optionsSize;
// Calculate IP pseudoheader checksum.
pseudoHeader.SourceAddress = remote->IPAddr;
pseudoHeader.DestAddress = *localIP;
pseudoHeader.Zero = 0x0;
pseudoHeader.Protocol = IP_PROT_TCP;
pseudoHeader.TCPLength = len;
SwapPseudoTCPHeader(pseudoHeader);
checksum1.Val = ~CalcIPChecksum((BYTE*)&pseudoHeader,
sizeof(pseudoHeader));
// Now calculate TCP packet checksum in NIC RAM - should match
// pesudo header checksum
checksum2.Val = CalcIPBufferChecksum(len);
// Compare checksums. Note that the endianness is different.
if(checksum1.v[0] != checksum2.v[1] || checksum1.v[1] != checksum2.v[0])
{
//We fail here!
MACDiscardRx();
return TRUE;
}
|
The function for CalcIPChecksum is;
Code: |
WORD CalcIPChecksum(BYTE* buffer, WORD count)
{
WORD i;
WORD *val;
union
{
DWORD Val;
struct
{
WORD_VAL LSB;
WORD_VAL MSB;
} words;
} tempSum, sum;
sum.Val = 0;
i = count >> 1;
val = (WORD *)buffer;
while( i-- )
sum.Val += *val++;
if ( count & 1 )
sum.Val += *(BYTE *)val;
tempSum.Val = sum.Val;
while( (i = tempSum.words.MSB.Val) != 0u )
{
sum.words.MSB.Val = 0;
sum.Val = (DWORD)sum.words.LSB.Val + (DWORD)i;
tempSum.Val = sum.Val;
}
return (~sum.words.LSB.Val);
}
|
When I have the PIC18 on the debugger, I get the following into the checksums:
Code: |
buffer = 0xA8C0
//stack checksum
checksum1.v[0] = 127
checksum1.v[1] = 18
//bnuffer checksum
checksum2.v[0] = 18
checksum2.v[1] = 127
|
Perfect.
However with the DSPIC I get:
Code: |
buffer = 0xA8C0
//stack checksum
checksum1.v[0] = 127
checksum1.v[1] = 15 <<This is no good
//bnuffer checksum
checksum2.v[0] = 18
checksum2.v[1] = 127
|
Not so good. So something about how CalcIPChecksum() is working.
Before I start to single step though the code (hard for me as I only have 1 set of hardware), can anyone see why I would be having issues? I am guessing it has something to do with the 8 to 16 bit change, but I can't workout what.
Thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19512
|
|
Posted: Sun Aug 09, 2020 9:55 am |
|
|
Show your definitions for 'WORD' and 'DWORD'. Remember that on the 16bit
PIC's variables default to 'signed', while on the PIC16/18, they default to
unsigned. The definitions need to explicitly be selecting unsigned.
There are potential 'issues'. A pointer to a 16bit value, must be to an
even memory address. The compiler will by default align 'buffer' to an
evenly defined address, but if you did any form of offsetting of this value
there will be problems. Caveat... |
|
|
Markdem
Joined: 24 Jun 2005 Posts: 206
|
|
Posted: Sun Aug 09, 2020 2:34 pm |
|
|
Thanks Ttelmah,
Code: |
typedef int16 WORD;
typedef int32 DWORD;
|
So I should change to?
Code: |
typedef unsigned int16 WORD;
typedef unsigned int32 DWORD;
|
This is CCS code, that is just a port of the Microchip stack. I did not write it, but I cant see anywhere they are adding a offset to the memory.
I will try the unsigned fix later today and see how I go.
Thanks |
|
|
Markdem
Joined: 24 Jun 2005 Posts: 206
|
|
Posted: Mon Aug 10, 2020 4:23 am |
|
|
OK, changing that fixed the issue and a new one has come up.. Now the FTP server only half works. Time for more debugging..
One quick question, I found this in the manual
From what I can tell it makes the default unsigned. Perfect. Is there anything "undocumented" I should know about using this?
Thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19512
|
|
Posted: Mon Aug 10, 2020 5:35 am |
|
|
Yes. Problem is quite a few of the CCS libraries don't work right when this
is used.
Set is before including this library, and set it back to the default afterwards.
|
|
|
|