C166: PERFORMING A SOFTWARE RESET IN C

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:

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).

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: