IAR intrinsic functions

时间:2023-03-10 02:18:18
IAR intrinsic functions

You can insert asm code example asm("NOP") into the c or c++ source code to get a good performance. But it don’t have problem for the compatibility, and because there are no operands and clobbered resources, inline assembler statements have no interface with the surrounding C source code. IAR compiler provides a good solution is intrinsic functions. For example, the provided interrupt controlling intrinsic functions are __disable_interrupt() and __enable_interrupt().

Another example is that it is the first thing is to disable the watchdog in MSP430. The general method is to put the WDTCTL = WDTPW + WDTHOLD; at the first line of main(). But it may failure to disable the watchdog because it is too later to call it as there are lots of code to initialize global variables. The IAR compiler provides a __low_level_init() intrinsic function which makes sure it will be called firstly.

/* There is a possibility that there is a large memory need to be initialized.
* in that, it will cause the system reset if the watchdog is not initialized.
* using __low_level_init in IAR to make sure that this code will executed firstly
*/
#if defined(__IAR_SYSTEMS_ICC__)
__intrinsic int __low_level_init(void)
{
//Stop watchdog timer to prevent time out reset, shall be first line of main.
WDTCTL = WDTPW + WDTHOLD;
return ;
}
#endif