Page 1 of 1

Can't get smarttrap to fire...

Posted: Wed Aug 21, 2013 1:17 pm
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?

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

Posted: Wed Aug 21, 2013 1:58 pm
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.

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

Posted: Thu Aug 22, 2013 5:34 am
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?

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

Posted: Fri Aug 23, 2013 11:54 am
by pbreed
Any C++ global objects setting things up on construction... ie trapping before UserMain even runs?

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

Posted: Fri Aug 23, 2013 12:39 pm
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.

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

Posted: Mon Aug 26, 2013 5:41 am
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?

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

Posted: Mon Aug 26, 2013 11:17 am
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);
    }
}