新手上路
- 积分
- 33
- 金钱
- 33
- 注册时间
- 2018-1-18
- 在线时间
- 4 小时
|
楼主 |
发表于 2018-4-20 12:09:25
|
显示全部楼层
本帖最后由 风离蓝 于 2018-4-20 12:24 编辑
谢谢左老师,通过在调试查看进入中断后的SP和当前MSP的关系了解了是这样,
但我在网上找了一个人在STM8S上移植的FreeRTOS例程,通过IAR在线调试查看Memery发现,中断服务函数使用的栈是当前被中断的任务的栈(基本上是idletask的栈),,,若要在STM8中移植FreeRTOS的话,是否只能这样做呢???下面是我找的例程移植的汇编部分。
SECTION `.far_func.text`:CODE
portSAVE_CONTEXT MACRO
push ?b8 ; Now store the rest of the registers. Dont store the ...
push ?b9 ; ... the stack pointer register here
push ?b10 ; stack pointer and will get saved into the TCB.
push ?b11 ; Note: These are not the actual registers of STM8 core
push ?b12 ; These are vertual registers used by IAR compiler
push ?b13
push ?b14
push ?b15
ld a, uxCriticalNesting ; Store the critical nesting counter. You may have to use ldf
push a
ldw x, pxCurrentTCB ; Finally save the stack pointer register
ldw y, sp ; into the TCB.
ldw (x), y
ENDM
;-------------------------------------------------------------------------------
portRESTORE_CONTEXT MACRO
ldw x, pxCurrentTCB ; Restore the software stack pointer from ...
ldw x, (x) ; the TCB into the stack pointer register
ldw sp, x
pop a
ld uxCriticalNesting, a ; Store the critical nesting counter.
pop ?b15
pop ?b14
pop ?b13
pop ?b12
pop ?b11
pop ?b10
pop ?b9
pop ?b8
iret ; ... scheduler decided should run.
ENDM
; vPortYield() and vPortYieldFromTick()
; -------------------------------------
;
; Manual and preemptive context switch functions respectively.
; The IAR compiler does not fully support inline assembler,
; so these are implemented here rather than the more usually
; place of within port.c.
;-------------------------------------------------------------------------------
vPortYield:
push #$0
pushw y
pushw x
push a
push cc
sim ;Disable interrupts
portSAVE_CONTEXT ; Save the context of the current task.
call vTaskSwitchContext ; Call the scheduler.
portRESTORE_CONTEXT ; Restore the context of whichever task the ...
;----------------------
vPortYieldFromTick:
LD A, #$1 ; Clear the Timer 1 IT pending Bit
CPL A ; TIM1->SR1 = (uint8_t)(~(uint8_t)TIM1_IT);
LD L:0x52b6,A
sim ;Disable interrupts
portSAVE_CONTEXT ; Save the context of the current task.
call xTaskIncrementTick ; Call the timer tick function.
tnz a
jreq SkipTaskSwitch
call vTaskSwitchContext ; Call the scheduler.
SkipTaskSwitch:
portRESTORE_CONTEXT ; Restore the context of whichever task the ...
;-------------------------------------------------------------------------------
; vPortStart()
; ------------
;
; Again due to the lack of inline assembler, this is required
; to get access to the portRESTORE_CONTEXT macro.
vPortStart:
portRESTORE_CONTEXT
|
|