RT1050 Saving and Restoring C registers

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

RT1050 Saving and Restoring C registers

ソリューションへジャンプ
1,425件の閲覧回数
kamal1
Contributor III

Hello,

 

I need help figuring out how to record the current state of the processor registers so they can later be restored at the specific location in code. This will act like a warm reset but starting after initializing all my devices. Below are the functions used on the ARM9 processor. I need to do the same with the Cortext M7 processor. I am using Keilv5 with RTX5 RTOS in my project. Any examples or tips would be appreciated. 

 

Will I also need to clear the stack?

 

//Record current state of processor registers. These registers can be restored at any

//time using the popcregs routine and should cause the program to the spot in code that

//the pushcregs was called.

__asm void pushcregs(PROC_STATE *regs)

{

STMIA R0!,{R0-R15} //save register values in data structure

STMDB SP!,{R0-R1} //Save R0 & R1 on stack

MRS R1,CPSR //move contents of CPSR to R1

STMIA R0!,{R1} //save PSR in data structure

MRS R1,SPSR //Move contents of saved PSR to R1

STMIA R0!,{R1} //save contents in data structure

LDMIA SP!,{R0-R1} //restore registers R0 & R1

BX LR //return

}

 

 

__asm void popcregs(PROC_STATE *regs)

{

LDR R1,[R0,#(17*4)] //point to end of data structure

MSR SPSR_c,R1 //restore SPSR

LDR R1,[R0,#(16*4)] //load CPSR into R1

MSR CPSR_c,R1 //restore CPSR

ADD R0,R0,#4 //do not restore PC

LDMIA R0!,{R1-R14} //restore R1 thru R14

BX LR //return to top of program

}

ラベル(1)
0 件の賞賛
返信
1 解決策
1,400件の閲覧回数
kamal1
Contributor III

Update:

I found these two functions which is what I needed for my project. Using setjmp and longjmp, I can branch back in my code.

#include "setjmp.h"

setjmp(jmp_buf);

longjmp(jmp_buf, return);

元の投稿で解決策を見る

0 件の賞賛
返信
4 返答(返信)
1,401件の閲覧回数
kamal1
Contributor III

Update:

I found these two functions which is what I needed for my project. Using setjmp and longjmp, I can branch back in my code.

#include "setjmp.h"

setjmp(jmp_buf);

longjmp(jmp_buf, return);

0 件の賞賛
返信
1,416件の閲覧回数
jeremyzhou
NXP Employee
NXP Employee

Hi,
Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.
1) Will I also need to clear the stack?
-- No, I'm afraid not. Regarding the Cortex-M core-based MCU, the compiler can manage the stack during the function context operation via utilizing the registers in the cores (as below shows). When the MCU runs the RTOS which provides the stack management for the created task, in addition to the above stack management.

jeremyzhou_0-1628653484548.png

 


Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 件の賞賛
返信
1,412件の閲覧回数
kamal1
Contributor III

Hi @jeremyzhou,

Thank you for the helpful information. Are there any examples of saving and restoring the stack pointer and all the registers?

 

 

0 件の賞賛
返信
1,406件の閲覧回数
jeremyzhou
NXP Employee
NXP Employee

Hi,
Thanks for your reply.
1) Are there any examples of saving and restoring the stack pointer and all the registers?
-- No, however, you can learn stack management via reviewing the assembly code of the related C language code function.
Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 件の賞賛
返信