Skip to content

Commit c4931af

Browse files
committed
Merge branch 'main' into 'main'
🐛 fix immature context switch optimization on ARMv6/ARMv7 See merge request library/M5P01_Prokaron!22
2 parents 8c93b87 + 121cd3d commit c4931af

File tree

8 files changed

+89
-75
lines changed

8 files changed

+89
-75
lines changed

Include/Platform/A6M/rmp_platform_a6m.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,9 @@ typedef rmp_s32_t rmp_ret_t;
8585
#define RMP_INT_MASK() RMP_Int_Disable()
8686
#define RMP_INT_UNMASK() RMP_Int_Enable()
8787
/* Yield operation */
88-
#define RMP_YIELD() (RMP_A6M_NVIC_INT_CTRL=RMP_A6M_NVIC_PENDSVSET)
88+
#define RMP_YIELD() _RMP_A6M_Yield()
8989
#define RMP_YIELD_ISR() RMP_YIELD()
9090
/* End System Macro **********************************************************/
91-
92-
/* ARMv6-M Macro *************************************************************/
93-
/* PendSV trigger */
94-
#define RMP_A6M_NVIC_INT_CTRL (*((volatile rmp_ptr_t*)0xE000ED04U))
95-
#define RMP_A6M_NVIC_PENDSVSET (0x10000000U)
96-
/* End ARMv6-M Macro *********************************************************/
9791
/*****************************************************************************/
9892
/* __RMP_PLATFORM_A6M_DEF__ */
9993
#endif
@@ -189,6 +183,8 @@ RMP_EXTERN void RMP_Int_Enable(void);
189183
RMP_EXTERN void _RMP_Start(rmp_ptr_t Entry,
190184
rmp_ptr_t Stack);
191185

186+
RMP_EXTERN void _RMP_A6M_Yield(void);
187+
192188
/* Initialization */
193189
__RMP_EXTERN__ rmp_ptr_t _RMP_Stack_Init(rmp_ptr_t Stack,
194190
rmp_ptr_t Size,

Include/Platform/A7M/rmp_platform_a7m.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ typedef rmp_s32_t rmp_ret_t;
8585
#define RMP_INT_MASK() RMP_Int_Mask(RMP_A7M_INT_MASK_LVL)
8686
#define RMP_INT_UNMASK() RMP_Int_Mask(0x00U)
8787
/* Yield operation */
88-
#define RMP_YIELD() (RMP_A7M_NVIC_INT_CTRL=RMP_A7M_NVIC_PENDSVSET)
88+
#define RMP_YIELD() _RMP_A7M_Yield()
8989
#define RMP_YIELD_ISR() RMP_YIELD()
9090
/* End System Macro **********************************************************/
9191

@@ -104,10 +104,6 @@ typedef rmp_s32_t rmp_ret_t;
104104
#define RMP_A7M_NVIC_GROUPING_P2S6 (5U)
105105
#define RMP_A7M_NVIC_GROUPING_P1S7 (6U)
106106
#define RMP_A7M_NVIC_GROUPING_P0S8 (7U)
107-
108-
/* PendSV trigger */
109-
#define RMP_A7M_NVIC_INT_CTRL (*((volatile rmp_ptr_t*)0xE000ED04U))
110-
#define RMP_A7M_NVIC_PENDSVSET (0x10000000U)
111107
/* End ARMv7-M Macro *********************************************************/
112108
/*****************************************************************************/
113109
/* __RMP_PLATFORM_A7M_DEF__ */
@@ -203,7 +199,9 @@ RMP_EXTERN void RMP_Int_Mask(rmp_ptr_t Level);
203199

204200
RMP_EXTERN rmp_ptr_t _RMP_A7M_MSB_Get(rmp_ptr_t Value);
205201
RMP_EXTERN rmp_ptr_t _RMP_A7M_LSB_Get(rmp_ptr_t Value);
206-
RMP_EXTERN void _RMP_Start(rmp_ptr_t Entry, rmp_ptr_t Stack);
202+
RMP_EXTERN void _RMP_Start(rmp_ptr_t Entry,
203+
rmp_ptr_t Stack);
204+
RMP_EXTERN void _RMP_A7M_Yield(void);
207205

208206
/* Initialization */
209207
__RMP_EXTERN__ rmp_ptr_t _RMP_Stack_Init(rmp_ptr_t Stack,

Project/RVMDK-STM32F767IGT6/RMP.uvprojx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
<TargetName>RMP</TargetName>
1111
<ToolsetNumber>0x4</ToolsetNumber>
1212
<ToolsetName>ARM-ADS</ToolsetName>
13-
<pCCUsed>6180000::V6.18::ARMCLANG</pCCUsed>
13+
<pCCUsed>6190000::V6.19::ARMCLANG</pCCUsed>
1414
<uAC6>1</uAC6>
1515
<TargetOption>
1616
<TargetCommonOption>
1717
<Device>STM32F767IGTx</Device>
1818
<Vendor>STMicroelectronics</Vendor>
19-
<PackID>Keil.STM32F7xx_DFP.2.16.0</PackID>
19+
<PackID>Keil.STM32F7xx_DFP.2.15.2</PackID>
2020
<PackURL>https://www.keil.com/pack/</PackURL>
2121
<Cpu>IRAM(0x20020000,0x60000) IRAM2(0x20000000,0x20000) IROM(0x08000000,0x100000) IROM2(0x00200000,0x100000) CPUTYPE("Cortex-M7") FPU3(DFPU) CLOCK(12000000) ELITTLE</Cpu>
2222
<FlashUtilSpec></FlashUtilSpec>
@@ -173,7 +173,7 @@
173173
<AdsLven>1</AdsLven>
174174
<AdsLsxf>1</AdsLsxf>
175175
<RvctClst>1</RvctClst>
176-
<GenPPlst>0</GenPPlst>
176+
<GenPPlst>1</GenPPlst>
177177
<AdsCpuType>"Cortex-M7"</AdsCpuType>
178178
<RvctDeviceName></RvctDeviceName>
179179
<mOS>0</mOS>

Project/RVMDK-STM32L071CBT6/RMP.uvprojx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
<TargetName>RMP</TargetName>
1111
<ToolsetNumber>0x4</ToolsetNumber>
1212
<ToolsetName>ARM-ADS</ToolsetName>
13-
<pCCUsed>6180000::V6.18::ARMCLANG</pCCUsed>
13+
<pCCUsed>6190000::V6.19::ARMCLANG</pCCUsed>
1414
<uAC6>1</uAC6>
1515
<TargetOption>
1616
<TargetCommonOption>
1717
<Device>STM32L071CBTx</Device>
1818
<Vendor>STMicroelectronics</Vendor>
19-
<PackID>Keil.STM32L0xx_DFP.2.3.0</PackID>
20-
<PackURL>https://www.keil.com/pack/</PackURL>
19+
<PackID>Keil.STM32L0xx_DFP.2.2.0</PackID>
20+
<PackURL>http://www.keil.com/pack/</PackURL>
2121
<Cpu>IRAM(0x20000000,0x00005000) IROM(0x08000000,0x00020000) CPUTYPE("Cortex-M0+") CLOCK(12000000) ELITTLE</Cpu>
2222
<FlashUtilSpec></FlashUtilSpec>
2323
<StartupFile></StartupFile>

Source/Platform/A6M/rmp_platform_a6m_armcc.s

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
EXPORT RMP_Int_Enable
3636
;Start the first thread
3737
EXPORT _RMP_Start
38+
;Yield to another thread
39+
EXPORT _RMP_A6M_Yield
3840
;The system pending service routine
3941
EXPORT PendSV_Handler
4042
;The systick timer routine
@@ -87,14 +89,23 @@ _RMP_Start PROC
8789
ENDP
8890
;/* End Function:_RMP_Start **************************************************/
8991

92+
;/* Function:_RMP_A6M_Yield ***************************************************
93+
;Description : Trigger a yield to another thread.
94+
;Input : None.
95+
;Output : None.
96+
;Return : None.
97+
;*****************************************************************************/
98+
_RMP_A6M_Yield PROC
99+
LDR R0,=0xE000ED04 ;The NVIC_INT_CTRL register
100+
LDR R1,=0x10000000 ;Trigger the PendSV
101+
STR R1,[R0]
102+
DSB
103+
BX LR
104+
ENDP
105+
;/* End Function:_RMP_A6M_Yield **********************************************/
106+
90107
;/* Function:PendSV_Handler ***************************************************
91-
;Description : The PendSV interrupt routine. In fact, it will call a C function
92-
; directly. The reason why the interrupt routine must be an assembly
93-
; function is that the compiler may deal with the stack in a different
94-
; way when different optimization level is chosen. An assembly function
95-
; can make way around this problem.
96-
; However, if your compiler support inline assembly functions, this
97-
; can also be written in C.
108+
;Description : The PendSV interrupt handler.
98109
; ARMv6-M only have STMIA, will have to live with it.
99110
;Input : None.
100111
;Output : None.
@@ -134,13 +145,7 @@ PendSV_Handler PROC
134145
;/* End Function:PendSV_Handler **********************************************/
135146

136147
;/* Function:SysTick_Handler **************************************************
137-
;Description : The SysTick interrupt routine. In fact, it will call a C function
138-
; directly. The reason why the interrupt routine must be an assembly
139-
; function is that the compiler may deal with the stack in a different
140-
; way when different optimization level is chosen. An assembly function
141-
; can make way around this problem.
142-
; However, if your compiler support inline assembly functions, this
143-
; can also be written in C.
148+
;Description : The SysTick interrupt handler.
144149
;Input : None.
145150
;Output : None.
146151
;Return : None.

Source/Platform/A6M/rmp_platform_a6m_gcc.s

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ The above 3 registers are saved into the stack in combination(xPSR).
3737
.global RMP_Int_Mask
3838
/* Start the first thread */
3939
.global _RMP_Start
40+
/* Yield to another thread */
41+
.global _RMP_A6M_Yield
4042
/* The system pending service routine */
4143
.global PendSV_Handler
4244
/* The systick timer routine */
@@ -89,14 +91,23 @@ _RMP_Start:
8991
BLX R0 /* Branch to our target */
9092
/* End Function:_RMP_Start ***************************************************/
9193

94+
/* Function:_RMP_A6M_Yield ****************************************************
95+
Description : Trigger a yield to another thread.
96+
Input : None.
97+
Output : None.
98+
Return : None.
99+
******************************************************************************/
100+
.thumb_func
101+
_RMP_A6M_Yield:
102+
LDR R0,=0xE000ED04 /* The NVIC_INT_CTRL register */
103+
LDR R1,=0x10000000 /* Trigger the PendSV */
104+
STR R1,[R0]
105+
DSB
106+
BX LR
107+
/* End Function:_RMP_A6M_Yield ***********************************************/
108+
92109
/* Function:PendSV_Handler ****************************************************
93-
Description : The PendSV interrupt routine. In fact, it will call a C function
94-
directly. The reason why the interrupt routine must be an assembly
95-
function is that the compiler may deal with the stack in a different
96-
way when different optimization level is chosen. An assembly function
97-
can make way around this problem.
98-
However, if your compiler support inline assembly functions, this
99-
can also be written in C.
110+
Description : The PendSV interrupt handler.
100111
ARMv6-M only have STMIA, will have to live with it.
101112
Input : None.
102113
Output : None.
@@ -136,13 +147,7 @@ PendSV_Handler:
136147
/* End Function:PendSV_Handler ***********************************************/
137148

138149
/* Function:SysTick_Handler ***************************************************
139-
Description : The SysTick interrupt routine. In fact, it will call a C function
140-
directly. The reason why the interrupt routine must be an assembly
141-
function is that the compiler may deal with the stack in a different
142-
way when different optimization level is chosen. An assembly function
143-
can make way around this problem.
144-
However, if your compiler support inline assembly functions, this
145-
can also be written in C.
150+
Description : The SysTick interrupt handler.
146151
Input : None.
147152
Output : None.
148153
Return : None.

Source/Platform/A7M/rmp_platform_a7m_armcc.s

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
EXPORT _RMP_A7M_LSB_Get
4343
;Start the first thread
4444
EXPORT _RMP_Start
45+
;Yield to another thread
46+
EXPORT _RMP_A7M_Yield
4547
;The system pending service routine
4648
EXPORT PendSV_Handler
4749
;The systick timer routine
@@ -135,14 +137,23 @@ _RMP_Start PROC
135137
ENDP
136138
;/* End Function:_RMP_Start **************************************************/
137139

140+
;/* Function:_RMP_A7M_Yield ***************************************************
141+
;Description : Trigger a yield to another thread.
142+
;Input : None.
143+
;Output : None.
144+
;Return : None.
145+
;*****************************************************************************/
146+
_RMP_A7M_Yield PROC
147+
LDR R0,=0xE000ED04 ;The NVIC_INT_CTRL register
148+
LDR R1,=0x10000000 ;Trigger the PendSV
149+
STR R1,[R0]
150+
DSB
151+
BX LR
152+
ENDP
153+
;/* End Function:_RMP_A7M_Yield **********************************************/
154+
138155
;/* Function:PendSV_Handler ***************************************************
139-
;Description : The PendSV interrupt routine. In fact, it will call a C function
140-
; directly. The reason why the interrupt routine must be an assembly
141-
; function is that the compiler may deal with the stack in a different
142-
; way when different optimization level is chosen. An assembly function
143-
; can make way around this problem.
144-
; However, if your compiler support inline assembly functions, this
145-
; can also be written in C.
156+
;Description : The PendSV interrupt handler.
146157
;Input : None.
147158
;Output : None.
148159
;Return : None.
@@ -175,13 +186,7 @@ PendSV_Handler PROC
175186
;/* End Function:PendSV_Handler **********************************************/
176187

177188
;/* Function:SysTick_Handler **************************************************
178-
;Description : The SysTick interrupt routine. In fact, it will call a C function
179-
; directly. The reason why the interrupt routine must be an assembly
180-
; function is that the compiler may deal with the stack in a different
181-
; way when different optimization level is chosen. An assembly function
182-
; can make way around this problem.
183-
; However, if your compiler support inline assembly functions, this
184-
; can also be written in C.
189+
;Description : The SysTick interrupt handler.
185190
;Input : None.
186191
;Output : None.
187192
;Return : None.

Source/Platform/A7M/rmp_platform_a7m_gcc.s

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ The ARM Cortex-M4/7 also include a FPU.
4242
.global _RMP_A7M_LSB_Get
4343
/* Start the first thread */
4444
.global _RMP_Start
45+
/* Yield to another thread */
46+
.global _RMP_A7M_Yield
4547
/* The system pending service routine */
4648
.global PendSV_Handler
4749
/* The systick timer routine */
@@ -135,14 +137,23 @@ _RMP_Start:
135137
BLX R0 /* Branch to our target */
136138
/* End Function:_RMP_Start ***************************************************/
137139

140+
/* Function:_RMP_A7M_Yield ****************************************************
141+
Description : Trigger a yield to another thread.
142+
Input : None.
143+
Output : None.
144+
Return : None.
145+
******************************************************************************/
146+
.thumb_func
147+
_RMP_A7M_Yield:
148+
LDR R0,=0xE000ED04 /* The NVIC_INT_CTRL register */
149+
LDR R1,=0x10000000 /* Trigger the PendSV */
150+
STR R1,[R0]
151+
DSB
152+
BX LR
153+
/* End Function:_RMP_A7M_Yield ***********************************************/
154+
138155
/* Function:PendSV_Handler ****************************************************
139-
Description : The PendSV interrupt routine. In fact, it will call a C function
140-
directly. The reason why the interrupt routine must be an assembly
141-
function is that the compiler may deal with the stack in a different
142-
way when different optimization level is chosen. An assembly function
143-
can make way around this problem.
144-
However, if your compiler support inline assembly functions, this
145-
can also be written in C.
156+
Description : The PendSV interrupt handler.
146157
Input : None.
147158
Output : None.
148159
Return : None.
@@ -175,13 +186,7 @@ PendSV_Handler:
175186
/* End Function:PendSV_Handler ***********************************************/
176187

177188
/* Function:SysTick_Handler ***************************************************
178-
Description : The SysTick interrupt routine. In fact, it will call a C function
179-
directly. The reason why the interrupt routine must be an assembly
180-
function is that the compiler may deal with the stack in a different
181-
way when different optimization level is chosen. An assembly function
182-
can make way around this problem.
183-
However, if your compiler support inline assembly functions, this
184-
can also be written in C.
189+
Description : The SysTick interrupt handler.
185190
Input : None.
186191
Output : None.
187192
Return : None.

0 commit comments

Comments
 (0)