This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2640R2F: Hwi_dispatcher function related

Part Number: CC2640R2F
Other Parts Discussed in Thread: SYSBIOS

Hi, I'm newbie and currently testing rfPacketRx, a rtos based example.

I have some questions. In Hwi_dispatcher asm function (redefine as ti_sysbios_family_arm_m3_Hwi_dispatch__I) :

;
; Here when no other interrupt is pending
; perform a dummy EXC_RETURN to return to thread mode before
; running the Swi and Task schedulers
;
$2
pop {r2} ; restore old basepri
tst lr, #4 ; context on PSP?
ite NE
mrsne r1, psp ; if yes, then use PSP
moveq r1, sp ; else use MSP
sub r1, #(8*4) ; make room for dummy

 

Q1: What does "make room for dummy" mean here? In my understanding, before jumping to this dispatcher function, all the requested registers have been pushed into PSP. Then what are the "room" for?

bx lr ; EXC_RETURN to $1 below

;
; Now we're back in thread mode and could be running on the task stack
; or the ISR stack.
;
; If an ISR hit while a Swi posted from an ISR was running, we'll be on the ISR stack.
; Otherwise we'll be on the pre-empted Task stack.
;
; r0 = swiTaskKey
; r1 = old basepri
;
; Call Swi and Task schedulers
;
$1  ...

Q2: Here, the bx insn will jump to 0xfffffffd (in my case). And the previous pushed registers based on PSP will be restored. So why the $1 marked part will be called (to continue calling Swi and Task schedulers)?  

Also, Because the PSP is deducted by 32, the restored PC value is wrong and will cause fault. Really confused about this.

The file I use is simplelink_cc2640r2_sdk_4_20_00_04/kernel/tirtos/packages/ti/sysbios/family/arm/m3/Hwi_asm.sv7M, so as my sdk version.

Thanks for your help.

  • Hi Yihang,

    "Dummy" is in the comment:

    "; perform a dummy EXC_RETURN to return to thread mode before
    ; running the Swi and Task schedulers"


    So making room for dummy is accounting for this EXC_RETURN.

    As for your LR being way off, the answer is likely "stack corruption". Could you share what you are doing to put yourself into this exception state with this example? Which modification have you (potentially) done to the project etc?