best way to initiate a reset from software

Hi,

What's the best/preferred way to initiate a reset from software?

The folowing options could work:

- The BRK instruction can trigger a software interrupt. From there a illegal memory acces can be triggered, but this sounds a bit dodgy.

- Set the SP to 0 in a ASM reset function. Very ugly

I assume there must be better ways to do this.

Thanks,

Sjoerd

  • Hi,

    I know 2 ways:

    1. setup watchdog for reset and go to infinite loop

    2. execute 0xFF opcode (this is the only non-valid opcode and it will initiate reset).

    Maxim.

  • There are five reasons for a HW-RESET listed register RESF, but two of them ( LVD and RAM parity) are controlled

    by harwdare and not by the application. Beside the two possibilities listed by Maxim you can alternatively

    execute an illegal memory access to force a HW-reset.

  • I would recommend the watchdog timeout method. It should be quite close in effect to a hardware reset.

  • Thanks for all the suggestions.

    I'd like to keep the watchdog timeout and illegal memory acces for real software problems.

    A reset handler at bootup can check the RESF flag to see what caused the reset and

    save SP, stack data and special registers if they are still valid.

    For the software reset i'll go for the illegal instruction:

    void reset()

    {

        static const unsigned char illegalInstruction = 0xFF;

        void (*dummy) (void) = (void (*)(void))&illegalInstruction;

        dummy();

    }

    shorter but i'm not sure if there's always 0xFF at location 0xFFFF

    void (*reset) (void) = (void (*)(void)) (0xFFFF);

    I still need to check if the SP and General-purpose registers contain valid data from the point where the software reset was triggered.

    With that information it's possible to log the problem and analyse it later.

    According to the datasheet the content of that registers are 'Undefined'...

    -sjoerd

  • May be something simplier:

    void reset(void)

    {

      asm ("db FFh");

    }


  • That's what I was looking for  happy

    thanks,

    Sjoerd

  • In reply to Sjoerd Brandsma:

    Hi, I used asm("db 0xFF") to implement the reset function though it works in normal/ run mode, it doesn't work in debug mode..

    Can anyone tell me what could be the reason? I use IAR workbench..

  • In reply to vasu819:

    This is a limitation of the RL78 and it is described in the device UM  (-> chapter RESET Function, description of register RESF):

    Note 2. The illegal instruction is generated when instruction code FFH is executed. Reset by the illegal instruction execution not issued by emulation with the in-circuit emulator or on-chip debug emulator.

    To force a RESET please either create an illegal memory access or write a wrong value to watchdog trigger register WDTE (if watch is enabled) .

  • Hi!
    For me the following code works fine. It does not need a watchdog, no external port and works with IAR Workbanch in debug mode.

    void SYS_vDoReset(void)
    {
      int8_t __far* a;            // Create a far-Pointer
      IAWCTL|=0x80;               // switch IAWEN on (defalut off)
      a=(int8_t __far*) 0x00000;  // Point to 0x000000 (Flash-ROM area)
      *a=0;                       // write something into ROM-Area -> Illegal -> Reset
    }