Can't get smarttrap to fire...

Discussion to talk about software related topics only.
Post Reply
User avatar
terry_opie
Posts: 27
Joined: Tue Jul 30, 2013 8:33 am

Can't get smarttrap to fire...

Post by terry_opie »

I have a trap being hit. I assume since I can't track the PC back to any code listed in my map file that I'm going off into the weeds. But I'm not sure where. With no smarttraps enabled, I get this output in the MTTY:

Code: Select all

Trap occured

 Vector=Access Error FMT =03 SR =2004 FS =0C

 Faulted PC = 0201317E

D0:00000000 00000000 00000023 0000024F 00000001 021A9480 021A9478 00000024

A0:00000003 40000204 021A9504 0201CED0 021A944E 021A94B0 001A940C 021A93F4
                                                                     
When I enable smarttraps Using the following include and calls in my main.cpp, I get absolutely no indication in the MTTY that we crashed besides the fact that the unit rebooted.

Code: Select all

...
#ifdef _DEBUG
#include <NetworkDebug.h>
#else
#include <smarttrap.h>
#endif


void UserMain( void *pd )
{
    InitializeStack();

    if ( EthernetIP == 0 )
    {
        iprintf( "Trying DHCP\n" );
        GetDHCPAddress(); 
        iprintf( "DHCP assigned the IP address of :" );
        ShowIP( EthernetIP );
        iprintf( "\n" );
    }
    else
    {
        iprintf( "Static IP set to:" );
        ShowIP( EthernetIP );
        iprintf( "\n" );
    }

#ifdef _DEBUG
    InitializeNetworkGDB();
#else
    EnableSmartTraps();
#endif

...
}
Any ideas what I may be doing wrong with the traps?
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: Can't get smarttrap to fire...

Post by rnixon »

Look up the status register values you see. I believe 2004 means you are in irq 4. Access Error means your program is off in the weeds and is trying to access a memory address that is not mapped to any chip select.
User avatar
terry_opie
Posts: 27
Joined: Tue Jul 30, 2013 8:33 am

Re: Can't get smarttrap to fire...

Post by terry_opie »

I'm not so much worried about the trap... That I'm sure I can track down. I'm more worried that the smarttrap stuff isn't working as I would expect, or that the documentation shows. Since I only added a small chunk of code, I know that is the root of my issue. But I figured I'd use this to try out the smarttrap stuff.

So, I'm more worried about why, when the smarttrap code is enabled, why there is no indication that a trap occurred?
User avatar
pbreed
Posts: 1091
Joined: Thu Apr 24, 2008 3:58 pm

Re: Can't get smarttrap to fire...

Post by pbreed »

Any C++ global objects setting things up on construction... ie trapping before UserMain even runs?
User avatar
tod
Posts: 587
Joined: Sat Apr 26, 2008 8:27 am
Location: Southern California
Contact:

Re: Can't get smarttrap to fire...

Post by tod »

Adding to Paul's idea, if you're a C++ guy you also have to be careful about non-local static objects (NLSOs). They're really just another form of a global but it's easy not to think of them that way, plus I was surprised (because I hadn't really thought about it) when I learned their constructors get called before UserMain. I described the issue in a little more detail on the wiki a while back.
User avatar
terry_opie
Posts: 27
Joined: Tue Jul 30, 2013 8:33 am

Re: Can't get smarttrap to fire...

Post by terry_opie »

No, based on the messages printing out in the MTTY, I can tell that UserMain runs, my tasks get started and we run for at least a minimal amount of time before the trap.

So, is there some magic order that things have to be done in for the smartrap code to work?
User avatar
Forrest
Posts: 289
Joined: Wed Apr 23, 2008 10:05 am

Re: Can't get smarttrap to fire...

Post by Forrest »

This works for me:

Code: Select all

void UserMain(void * pd) {
    InitializeStack();
    if (EthernetIP == 0) GetDHCPAddress();
    OSChangePrio(MAIN_PRIO);
    EnableAutoUpdate();
    StartHTTP();
    EnableTaskMonitor();

    #ifndef _DEBUG
    EnableSmartTraps();
    #endif

    #ifdef _DEBUG
    InitializeNetworkGDB_and_Wait();
    #endif

    iprintf("Application started\n");
    while (1) {
    	for(int i = 10;i>=0;i--) {
    		iprintf("Trapping in %2d seconds\r",i);
        	OSTimeDly(TICKS_PER_SECOND);
    	}
        iprintf("%d",5/0);
    }
}
Forrest Stanley
Project Engineer
NetBurner, Inc

NetBurner Learn Articles: http://www.netburner.com/learn
Post Reply