Software Reset on mega128

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a mega128 (in an ethernut) and are looking for ways of having a software-only method of resetting the processor. Has anbody tried a software-generated reset not using the watchdog or hardware?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

The only true reset will be a watchdog or pulling the reset pin low. What is wrong with using the watchdog?

But if you want a semi-reset in software, jump to address 0. This won't re-initilize the hardware though...

-Colin

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was hoping there was a way of getting the reset through a software-called interrupt (like the HC12 "swi"), which the mega128 doesn't have (or at least I didn't find it in the instruction set). In this case, the you're probably right - running the watchdog and allowing it to time out is the best way of getting a software-generated reset.

I was hoping to avoid plugging the watchdog because I'm having to use the Nut/OS that comes with the Ethernut, and that means a new task thread in the OS to ensure proper timing, and my available memory isn't going to take too many more threads...

Thanks for the response!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why would you need another thread to let the watchdog timeout? To issue a software reset via the watchdog timer, you simply sit in a tight loop after enabling the watchdog timer (if it was not already enabled). Disabling interrupts before the loop would ensure that no other code gets executed while you wait for reset.

/* John Butera */

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You need a place to reset the watchdog on a regular basis isn'it?
In the case of NutOs this place may be the main thread, another
special thread or in every other threads.

Cosmin

Oh I see, pepsi's method is to enable->enter loop->reset, not
enabling the watchdog somwhere at program start.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

this is what i use on AVR GCC :
u will have to include avr/wdt.h

wdt_enable(0); //enabling wdt with shortest time out
delay(200); // a loop...u can use a while(1); also

hope it helped..
good luck
Shadab

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ronut wrote:

Oh I see, pepsi's method is to enable->enter loop->reset, not
enabling the watchdog somwhere at program start.

Exactly.

shadaba wrote:

wdt_enable(0); //enabling wdt with shortest time out
delay(200); // a loop...u can use a while(1); also

Even that is overkill. Just do (with AVR GCC):

#include 
...
wdt_enable(0);
// Sit in infinite loop until proccessor resets.
for(;;)
{
}

You can even make a macro out of the thing:

#include 

#define software_reset()  \
do{  \
    wdt_enable(0); \
    for(;;){} \
} while(0)

//...

void task(void)
{
    //...

    software_reset();
}