关注+星标公众号,不错过精彩内容
作者 | strongerHuang
微信公众号 | 嵌入式专栏
概述
有认真研究,或者说细心一点的读者应该都知道:C中定义汇编代码与编译器有关。
; Assembler Code Here
C中嵌套汇编代码
常见两种定义:
1.在C函数中定义一段汇编代码;
2.在C文件中定义一个汇编函数;
__ASM uint32_t __get_PSP(void)
{
mrs r0, psp
bx lr
}
uint32_t __get_PSP(void)
{
__ASM("mrs r0, psp");
__ASM("bx lr");
}
举例
下面举一些常见例子。
static portFORCE_INLINE void vPortRaiseBASEPRI( void )
{
uint32_t ulNewBASEPRI = configMAX_SYSCALL_INTERRUPT_PRIORITY;
__asm
{
/* Set BASEPRI to the max syscall priority to effect a critical section. */
msr basepri, ulNewBASEPRI
dsb
isb
}
}
__asm void xPortPendSVHandler( void )
{
extern uxCriticalNesting;
extern pxCurrentTCB;
extern vTaskSwitchContext;
PRESERVE8
mrs r0, psp
isb
ldr r3, =pxCurrentTCB /* Get the location of the current TCB. */
ldr r2, [r3]
stmdb r0!, {r4-r11} /* Save the remaining registers. */
str r0, [r2] /* Save the new top of stack into the first member of the TCB. */
stmdb sp!, {r3, r14}
mov r0,
msr basepri, r0
dsb
isb
bl vTaskSwitchContext
mov r0,
msr basepri, r0
ldmia sp!, {r3, r14}
ldr r1, [r3]
ldr r0, [r1] /* The first item in pxCurrentTCB is the task top of stack. */
ldmia r0!, {r4-r11} /* Pop the registers and the critical nesting count. */
msr psp, r0
isb
bx r14
nop
}
__asm void NVIC_CoreReset_a(void)
{
LDR R0, =0xE000ED0C
LDR R1, =0x05FA0001
STR R1, [R0]
deadloop_Core
B deadloop_Core
}
------------ END ------------
●专栏《嵌入式工具》
●专栏《嵌入式开发》
●专栏《Keil教程》
●嵌入式专栏精选教程
点击“阅读原文”查看更多分享。