ARM Technical Support Knowledge Articles

PERFORMING A SOFTWARE RESET IN C

Applies to: C166 C Compiler

Answer


Information in this article applies to:


QUESTION

I need to perform a software reset in C without using inline assembly. How can I do that?

ANSWER

There are 2 ways to accomplish this depending on what you want to achieve:

  1. The following reset function jumps to 0 and starts executing code from there. Note that since this is only jumping to the reset vector, the chip is not actually being reset. The startup code (executed before EINIT) will have no effect.
    void reset (void)
    {
    ((void (far *) (void)) 0x000000) ();
    }
    

    The following code is generated for the reset function. The ?C_SCALLI routine calls the address stored in R4 and R5 (which is 0x000000).

    0000 E004          MOV       R4,#00H
    0002 E005          MOV       R5,#00H
    0004 DA000000 E    CALLS     SEG (?C_SCALLI),?C_SCALLI
    0008 CB00          RET
    
  2. The Keil compiler supports a number of "intrinsic library functions". These are not really functions. When you use one of them, the compiler inserts a C16x architecture specific instruction inline. You do not need to use the "asm" pragma and you don't need to insert assembly mnemonics yourself.

    To perform a software reset, use intrinsic library function _trap_ with a parameter of 0. For example:

    #include <intrins.h>
    main()
    {
    // ...............................
    //.............................
      _trap_ (0);
    }
    

    If you look at the listing file, you will see that main function has an SRST assembly instruction in place of _trap_(0).

MORE INFORMATION

SEE ALSO

Article last edited on: 2005-07-15 13:15:54

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential