CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

IPstack with DSPIC

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Markdem



Joined: 24 Jun 2005
Posts: 206

View user's profile Send private message Send e-mail

IPstack with DSPIC
PostPosted: Sun Aug 09, 2020 3:06 am     Reply with quote

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: 19513

View user's profile Send private message

PostPosted: Sun Aug 09, 2020 9:55 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Sun Aug 09, 2020 2:34 pm     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Mon Aug 10, 2020 4:23 am     Reply with quote

OK, changing that fixed the issue and a new one has come up.. Now the FTP server only half works. Rolling Eyes Time for more debugging..

One quick question, I found this in the manual

Code:

#TYPE = unsigned


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: 19513

View user's profile Send private message

PostPosted: Mon Aug 10, 2020 5:35 am     Reply with quote

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.
Very Happy
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group