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 support@ccsinfo.com

Use #INT_ADDRERR with PIC24 to locate code errors

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



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

Use #INT_ADDRERR with PIC24 to locate code errors
PostPosted: Wed Oct 22, 2008 2:40 am     Reply with quote

Hello,

PIC24 has an address error trap interrupt, that is triggered when accessing nonexisting memory or word data at an odd address. By default, the trap is unhandled, causing a reset with the TRAPR bit set in RCON.

The address error trap is usually indicating a user coding error (e. g. a bad pointer operation) or one of the various PCD bugs still present.

Installing a dummy #INT_ADDRERR avoids the reset on address error, but the code still behaves incorrect. By saving the return address in the trap interrupt, the existence and location of address errors can easily be monitored.

Code:
unsigned int32 trapaddr = 0;
#INT_ADDRERR
   void  ae_isr(void)
{
   #asm
   mov w15,w0   
   sub #36,w0
   mov [w0++],w1
   mov w1,trapaddr
   mov [w0],w1
   and #0x7f, w1
   mov w1,trapaddr+2
   #endasm
}


The 36 return address offset is empirically based on the default behaviour of PCD V4.081. Apparently, the compiler is always saving all WREGs in interrupt functions, thus the offset should be constant, but may be different with other compiler versions.

Regards,
Frank
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Thu Oct 15, 2009 1:52 am     Reply with quote

Hey FvM,

I've been using this while debugging the TCP/IP Stack and I'm finding stuff that looks legit causing traps...

Have you seen this? (I can post some code if you like)

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Oct 15, 2009 7:10 am     Reply with quote

Besides the said address error, also stack error and possibly arithmetic error (div zero) is likely to happen.
http://www.ccsinfo.com/forum/viewtopic.php?t=40083

Either accessing nonexisting memory addresses or word accesses to odd addresses can cause an address error trap. Programming errors in user code, particularly with pointers but also still existing PCD bugs are ways to produce them.

I didn't yet use the TCP/IP stack.
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Fri Oct 16, 2009 12:32 am     Reply with quote

I've been halting on some of the errors with my ICD3 and checking trapaddr as well as the interrupt register. And it's one right now has been a stick copying one WREG to another. (weird)

I haven't dug deep enough yet -- I found some other PCD bugs assigning INT8's (duh) -- which I'll report at some point...

But anyway... I can email you the stack if you'd like to see.

PM me your email if you'd like.

I don't know how many peeps have 16bit tcpip working yet... but I'm getting there...
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
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