From e3a4ae1370c21e93d471073e1b78e42b16e4fd8c Mon Sep 17 00:00:00 2001 From: aozima Date: Wed, 20 Feb 2013 10:15:09 +0800 Subject: [PATCH 1/6] update stm32f10x template. --- bsp/stm32f10x/project.Uv2 | 10 +++------- bsp/stm32f10x/template.Uv2 | 4 ++-- bsp/stm32f10x/template.uvproj | 4 ++-- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/bsp/stm32f10x/project.Uv2 b/bsp/stm32f10x/project.Uv2 index b7d07cbd3..19c1fcd32 100644 --- a/bsp/stm32f10x/project.Uv2 +++ b/bsp/stm32f10x/project.Uv2 @@ -24,7 +24,6 @@ File 2,1,<..\..\src\ipc.c> File 2,1,<..\..\src\irq.c> File 2,1,<..\..\src\kservice.c> File 2,1,<..\..\src\mem.c> -File 2,1,<..\..\src\memheap.c> File 2,1,<..\..\src\mempool.c> File 2,1,<..\..\src\object.c> File 2,1,<..\..\src\scheduler.c> @@ -48,7 +47,6 @@ File 4,1,<..\..\components\finsh\finsh_var.c> File 4,1,<..\..\components\finsh\finsh_vm.c> File 4,1,<..\..\components\finsh\shell.c> File 4,1,<..\..\components\finsh\symbol.c> -File 5,1, File 5,1, File 5,1, File 5,1, @@ -76,8 +74,6 @@ File 5,1, File 5,2, - - Options 1,0,0 // Target 'RT-Thread STM32' Device (STM32F103ZE) Vendor (STMicroelectronics) @@ -103,14 +99,14 @@ Options 1,0,0 // Target 'RT-Thread STM32' EnvReg (˙ST\STM32F10x\) OrgReg (˙ST\STM32F10x\) TgStat=16 - OutDir (.\obj\) + OutDir (.\build\) OutName (rtthread-stm32) GenApp=1 GenLib=0 GenHex=0 Debug=1 Browse=0 - LstDir (.\) + LstDir (.\build\) HexSel=1 MG32K=0 TGMORE=0 @@ -136,7 +132,7 @@ Options 1,0,0 // Target 'RT-Thread STM32' ADSCMISC () ADSCDEFN (STM32F10X_HD, USE_STDPERIPH_DRIVER) ADSCUDEF () - ADSCINCD (Libraries\STM32F10x_StdPeriph_Driver\inc;.;..\..\include;Libraries\CMSIS\CM3\CoreSupport;..\..\libcpu\arm\cortex-m3;..\..\libcpu\arm\common;..\..\components\finsh;Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x) + ADSCINCD (Libraries\STM32F10x_StdPeriph_Driver\inc;..\..\components\CMSIS\Include;.;..\..\include;..\..\libcpu\arm\cortex-m3;..\..\libcpu\arm\common;..\..\components\finsh;Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x) ADSASFLG { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } ADSAMISC () ADSADEFN () diff --git a/bsp/stm32f10x/template.Uv2 b/bsp/stm32f10x/template.Uv2 index 86d802dee..c72c12b7e 100644 --- a/bsp/stm32f10x/template.Uv2 +++ b/bsp/stm32f10x/template.Uv2 @@ -31,14 +31,14 @@ Options 1,0,0 // Target 'RT-Thread STM32' EnvReg (˙ST\STM32F10x\) OrgReg (˙ST\STM32F10x\) TgStat=16 - OutDir (.\obj\) + OutDir (.\build\) OutName (rtthread-stm32) GenApp=1 GenLib=0 GenHex=0 Debug=1 Browse=0 - LstDir (.\) + LstDir (.\build\) HexSel=1 MG32K=0 TGMORE=0 diff --git a/bsp/stm32f10x/template.uvproj b/bsp/stm32f10x/template.uvproj index e37f1f1c6..9ac75907f 100644 --- a/bsp/stm32f10x/template.uvproj +++ b/bsp/stm32f10x/template.uvproj @@ -43,14 +43,14 @@ 0 1 - .\obj\ + .\build\ rtthread-stm32 1 0 0 1 1 - .\obj\ + .\build\ 1 0 0 From fcf581ea3d1afa284b9ff06de619637fcbc0bdd4 Mon Sep 17 00:00:00 2001 From: aozima Date: Wed, 20 Feb 2013 10:20:40 +0800 Subject: [PATCH 2/6] remove old code. --- bsp/stm32f20x/applications/startup.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/bsp/stm32f20x/applications/startup.c b/bsp/stm32f20x/applications/startup.c index 15879299a..dd9969168 100644 --- a/bsp/stm32f20x/applications/startup.c +++ b/bsp/stm32f20x/applications/startup.c @@ -137,9 +137,6 @@ int main(void) /* disable interrupt first */ rt_hw_interrupt_disable(); - /* init system setting */ - SystemInit(); - /* startup RT-Thread RTOS */ rtthread_startup(); From eefb272cfdd782d57f106039eb1e10d08c387de6 Mon Sep 17 00:00:00 2001 From: aozima Date: Wed, 20 Feb 2013 10:29:21 +0800 Subject: [PATCH 3/6] update stm32f10x template. --- bsp/stm32f107/project.uvproj | 8 ++++---- bsp/stm32f107/template.uvproj | 8 ++++---- bsp/stm32f10x/project.Uv2 | 2 +- bsp/stm32f10x/template.Uv2 | 2 +- bsp/stm32f10x/template.uvproj | 4 ++-- bsp/stm32f20x/project.uvproj | 24 +++++------------------- bsp/stm32f20x/template.uvproj | 8 ++++---- bsp/stm32f40x/project.uvproj | 11 ++--------- bsp/stm32f40x/template.uvproj | 4 ++-- 9 files changed, 25 insertions(+), 46 deletions(-) diff --git a/bsp/stm32f107/project.uvproj b/bsp/stm32f107/project.uvproj index 2f84f1db0..4459183e7 100644 --- a/bsp/stm32f107/project.uvproj +++ b/bsp/stm32f107/project.uvproj @@ -40,14 +40,14 @@ 0 1 - .\obj\ + .\build\ rtthread-stm32 1 0 0 1 0 - .\ + .\build\ 1 0 0 @@ -68,9 +68,9 @@ 0 - 0 + 1 0 - + fromelf --bin !L --output rtthread.bin 0 0 diff --git a/bsp/stm32f107/template.uvproj b/bsp/stm32f107/template.uvproj index 30527feeb..c43b9e50c 100644 --- a/bsp/stm32f107/template.uvproj +++ b/bsp/stm32f107/template.uvproj @@ -43,14 +43,14 @@ 0 1 - .\obj\ + .\build\ rtthread-stm32 1 0 0 1 0 - .\ + .\build\ 1 0 0 @@ -71,9 +71,9 @@ 0 - 0 + 1 0 - + fromelf --bin !L --output rtthread.bin 0 0 diff --git a/bsp/stm32f10x/project.Uv2 b/bsp/stm32f10x/project.Uv2 index 19c1fcd32..6f9f30a43 100644 --- a/bsp/stm32f10x/project.Uv2 +++ b/bsp/stm32f10x/project.Uv2 @@ -110,7 +110,7 @@ Options 1,0,0 // Target 'RT-Thread STM32' HexSel=1 MG32K=0 TGMORE=0 - RunUsr 0 0 <> + RunUsr 0 1 RunUsr 1 0 <> BrunUsr 0 0 <> BrunUsr 1 0 <> diff --git a/bsp/stm32f10x/template.Uv2 b/bsp/stm32f10x/template.Uv2 index c72c12b7e..49db49165 100644 --- a/bsp/stm32f10x/template.Uv2 +++ b/bsp/stm32f10x/template.Uv2 @@ -42,7 +42,7 @@ Options 1,0,0 // Target 'RT-Thread STM32' HexSel=1 MG32K=0 TGMORE=0 - RunUsr 0 0 <> + RunUsr 0 1 RunUsr 1 0 <> BrunUsr 0 0 <> BrunUsr 1 0 <> diff --git a/bsp/stm32f10x/template.uvproj b/bsp/stm32f10x/template.uvproj index 9ac75907f..d92b75b40 100644 --- a/bsp/stm32f10x/template.uvproj +++ b/bsp/stm32f10x/template.uvproj @@ -71,9 +71,9 @@ 0 - 0 + 1 0 - + fromelf --bin !L --output rtthread.bin 0 0 diff --git a/bsp/stm32f20x/project.uvproj b/bsp/stm32f20x/project.uvproj index bbdc00119..96322bfc5 100644 --- a/bsp/stm32f20x/project.uvproj +++ b/bsp/stm32f20x/project.uvproj @@ -40,14 +40,14 @@ 0 1 - .\obj\ + .\build\ rtthread-stm32 1 0 0 1 0 - .\obj\ + .\build\ 1 0 0 @@ -68,9 +68,9 @@ 0 - 0 + 1 0 - + fromelf --bin !L --output rtthread.bin 0 0 @@ -343,7 +343,7 @@ USE_STDPERIPH_DRIVER - .;..\..\components\finsh;..\..\include;..\..\libcpu\arm\common;..\..\libcpu\arm\cortex-m3;Libraries\CMSIS\CM3\CoreSupport;Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F2xx;Libraries\STM32F2xx_StdPeriph_Driver\inc;applications;drivers + .;..\..\components\CMSIS\Include;..\..\components\finsh;..\..\include;..\..\libcpu\arm\common;..\..\libcpu\arm\cortex-m3;Drivers;Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F2xx;Libraries\STM32F2xx_StdPeriph_Driver\inc;applications @@ -458,13 +458,6 @@ STM32_StdPeriph - - - core_cm3.c - 1 - Libraries\CMSIS\CM3\CoreSupport\core_cm3.c - - system_stm32f2xx.c @@ -748,13 +741,6 @@ ..\..\src\mem.c - - - memheap.c - 1 - ..\..\src\memheap.c - - mempool.c diff --git a/bsp/stm32f20x/template.uvproj b/bsp/stm32f20x/template.uvproj index ce16bc94f..79c48c556 100644 --- a/bsp/stm32f20x/template.uvproj +++ b/bsp/stm32f20x/template.uvproj @@ -43,14 +43,14 @@ 0 1 - .\obj\ + .\build\ rtthread-stm32 1 0 0 1 0 - .\obj\ + .\build\ 1 0 0 @@ -71,9 +71,9 @@ 0 - 0 + 1 0 - + fromelf --bin !L --output rtthread.bin 0 0 diff --git a/bsp/stm32f40x/project.uvproj b/bsp/stm32f40x/project.uvproj index 40ea3f863..a2734d98a 100644 --- a/bsp/stm32f40x/project.uvproj +++ b/bsp/stm32f40x/project.uvproj @@ -68,9 +68,9 @@ 0 - 0 + 1 0 - + fromelf --bin !L --output rtthread.bin 0 0 @@ -713,13 +713,6 @@ ..\..\src\mem.c - - - memheap.c - 1 - ..\..\src\memheap.c - - mempool.c diff --git a/bsp/stm32f40x/template.uvproj b/bsp/stm32f40x/template.uvproj index 9d416799e..1cee2eecb 100644 --- a/bsp/stm32f40x/template.uvproj +++ b/bsp/stm32f40x/template.uvproj @@ -71,9 +71,9 @@ 0 - 0 + 1 0 - + fromelf --bin !L --output rtthread.bin 0 0 From 12f34b8c73b732cf5e695aca62618f4696d97f7a Mon Sep 17 00:00:00 2001 From: aozima Date: Wed, 20 Feb 2013 18:40:31 +0800 Subject: [PATCH 4/6] update bsp: stm32 family. --- bsp/stm32f107/project.uvproj | 8 ++++---- bsp/stm32f107/template.uvproj | 8 ++++---- bsp/stm32f10x/project.Uv2 | 12 ++++++++---- bsp/stm32f10x/template.Uv2 | 6 +++--- bsp/stm32f10x/template.uvproj | 8 ++++---- bsp/stm32f20x/applications/startup.c | 3 +++ bsp/stm32f20x/project.uvproj | 24 +++++++++++++++++++----- bsp/stm32f20x/template.uvproj | 8 ++++---- bsp/stm32f40x/project.uvproj | 11 +++++++++-- bsp/stm32f40x/template.uvproj | 4 ++-- 10 files changed, 60 insertions(+), 32 deletions(-) diff --git a/bsp/stm32f107/project.uvproj b/bsp/stm32f107/project.uvproj index 4459183e7..2f84f1db0 100644 --- a/bsp/stm32f107/project.uvproj +++ b/bsp/stm32f107/project.uvproj @@ -40,14 +40,14 @@ 0 1 - .\build\ + .\obj\ rtthread-stm32 1 0 0 1 0 - .\build\ + .\ 1 0 0 @@ -68,9 +68,9 @@ 0 - 1 + 0 0 - fromelf --bin !L --output rtthread.bin + 0 0 diff --git a/bsp/stm32f107/template.uvproj b/bsp/stm32f107/template.uvproj index c43b9e50c..30527feeb 100644 --- a/bsp/stm32f107/template.uvproj +++ b/bsp/stm32f107/template.uvproj @@ -43,14 +43,14 @@ 0 1 - .\build\ + .\obj\ rtthread-stm32 1 0 0 1 0 - .\build\ + .\ 1 0 0 @@ -71,9 +71,9 @@ 0 - 1 + 0 0 - fromelf --bin !L --output rtthread.bin + 0 0 diff --git a/bsp/stm32f10x/project.Uv2 b/bsp/stm32f10x/project.Uv2 index 6f9f30a43..b7d07cbd3 100644 --- a/bsp/stm32f10x/project.Uv2 +++ b/bsp/stm32f10x/project.Uv2 @@ -24,6 +24,7 @@ File 2,1,<..\..\src\ipc.c> File 2,1,<..\..\src\irq.c> File 2,1,<..\..\src\kservice.c> File 2,1,<..\..\src\mem.c> +File 2,1,<..\..\src\memheap.c> File 2,1,<..\..\src\mempool.c> File 2,1,<..\..\src\object.c> File 2,1,<..\..\src\scheduler.c> @@ -47,6 +48,7 @@ File 4,1,<..\..\components\finsh\finsh_var.c> File 4,1,<..\..\components\finsh\finsh_vm.c> File 4,1,<..\..\components\finsh\shell.c> File 4,1,<..\..\components\finsh\symbol.c> +File 5,1, File 5,1, File 5,1, File 5,1, @@ -74,6 +76,8 @@ File 5,1, File 5,2, + + Options 1,0,0 // Target 'RT-Thread STM32' Device (STM32F103ZE) Vendor (STMicroelectronics) @@ -99,18 +103,18 @@ Options 1,0,0 // Target 'RT-Thread STM32' EnvReg (˙ST\STM32F10x\) OrgReg (˙ST\STM32F10x\) TgStat=16 - OutDir (.\build\) + OutDir (.\obj\) OutName (rtthread-stm32) GenApp=1 GenLib=0 GenHex=0 Debug=1 Browse=0 - LstDir (.\build\) + LstDir (.\) HexSel=1 MG32K=0 TGMORE=0 - RunUsr 0 1 + RunUsr 0 0 <> RunUsr 1 0 <> BrunUsr 0 0 <> BrunUsr 1 0 <> @@ -132,7 +136,7 @@ Options 1,0,0 // Target 'RT-Thread STM32' ADSCMISC () ADSCDEFN (STM32F10X_HD, USE_STDPERIPH_DRIVER) ADSCUDEF () - ADSCINCD (Libraries\STM32F10x_StdPeriph_Driver\inc;..\..\components\CMSIS\Include;.;..\..\include;..\..\libcpu\arm\cortex-m3;..\..\libcpu\arm\common;..\..\components\finsh;Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x) + ADSCINCD (Libraries\STM32F10x_StdPeriph_Driver\inc;.;..\..\include;Libraries\CMSIS\CM3\CoreSupport;..\..\libcpu\arm\cortex-m3;..\..\libcpu\arm\common;..\..\components\finsh;Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x) ADSASFLG { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } ADSAMISC () ADSADEFN () diff --git a/bsp/stm32f10x/template.Uv2 b/bsp/stm32f10x/template.Uv2 index 49db49165..86d802dee 100644 --- a/bsp/stm32f10x/template.Uv2 +++ b/bsp/stm32f10x/template.Uv2 @@ -31,18 +31,18 @@ Options 1,0,0 // Target 'RT-Thread STM32' EnvReg (˙ST\STM32F10x\) OrgReg (˙ST\STM32F10x\) TgStat=16 - OutDir (.\build\) + OutDir (.\obj\) OutName (rtthread-stm32) GenApp=1 GenLib=0 GenHex=0 Debug=1 Browse=0 - LstDir (.\build\) + LstDir (.\) HexSel=1 MG32K=0 TGMORE=0 - RunUsr 0 1 + RunUsr 0 0 <> RunUsr 1 0 <> BrunUsr 0 0 <> BrunUsr 1 0 <> diff --git a/bsp/stm32f10x/template.uvproj b/bsp/stm32f10x/template.uvproj index d92b75b40..e37f1f1c6 100644 --- a/bsp/stm32f10x/template.uvproj +++ b/bsp/stm32f10x/template.uvproj @@ -43,14 +43,14 @@ 0 1 - .\build\ + .\obj\ rtthread-stm32 1 0 0 1 1 - .\build\ + .\obj\ 1 0 0 @@ -71,9 +71,9 @@ 0 - 1 + 0 0 - fromelf --bin !L --output rtthread.bin + 0 0 diff --git a/bsp/stm32f20x/applications/startup.c b/bsp/stm32f20x/applications/startup.c index dd9969168..15879299a 100644 --- a/bsp/stm32f20x/applications/startup.c +++ b/bsp/stm32f20x/applications/startup.c @@ -137,6 +137,9 @@ int main(void) /* disable interrupt first */ rt_hw_interrupt_disable(); + /* init system setting */ + SystemInit(); + /* startup RT-Thread RTOS */ rtthread_startup(); diff --git a/bsp/stm32f20x/project.uvproj b/bsp/stm32f20x/project.uvproj index 96322bfc5..bbdc00119 100644 --- a/bsp/stm32f20x/project.uvproj +++ b/bsp/stm32f20x/project.uvproj @@ -40,14 +40,14 @@ 0 1 - .\build\ + .\obj\ rtthread-stm32 1 0 0 1 0 - .\build\ + .\obj\ 1 0 0 @@ -68,9 +68,9 @@ 0 - 1 + 0 0 - fromelf --bin !L --output rtthread.bin + 0 0 @@ -343,7 +343,7 @@ USE_STDPERIPH_DRIVER - .;..\..\components\CMSIS\Include;..\..\components\finsh;..\..\include;..\..\libcpu\arm\common;..\..\libcpu\arm\cortex-m3;Drivers;Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F2xx;Libraries\STM32F2xx_StdPeriph_Driver\inc;applications + .;..\..\components\finsh;..\..\include;..\..\libcpu\arm\common;..\..\libcpu\arm\cortex-m3;Libraries\CMSIS\CM3\CoreSupport;Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F2xx;Libraries\STM32F2xx_StdPeriph_Driver\inc;applications;drivers @@ -458,6 +458,13 @@ STM32_StdPeriph + + + core_cm3.c + 1 + Libraries\CMSIS\CM3\CoreSupport\core_cm3.c + + system_stm32f2xx.c @@ -741,6 +748,13 @@ ..\..\src\mem.c + + + memheap.c + 1 + ..\..\src\memheap.c + + mempool.c diff --git a/bsp/stm32f20x/template.uvproj b/bsp/stm32f20x/template.uvproj index 79c48c556..ce16bc94f 100644 --- a/bsp/stm32f20x/template.uvproj +++ b/bsp/stm32f20x/template.uvproj @@ -43,14 +43,14 @@ 0 1 - .\build\ + .\obj\ rtthread-stm32 1 0 0 1 0 - .\build\ + .\obj\ 1 0 0 @@ -71,9 +71,9 @@ 0 - 1 + 0 0 - fromelf --bin !L --output rtthread.bin + 0 0 diff --git a/bsp/stm32f40x/project.uvproj b/bsp/stm32f40x/project.uvproj index a2734d98a..40ea3f863 100644 --- a/bsp/stm32f40x/project.uvproj +++ b/bsp/stm32f40x/project.uvproj @@ -68,9 +68,9 @@ 0 - 1 + 0 0 - fromelf --bin !L --output rtthread.bin + 0 0 @@ -713,6 +713,13 @@ ..\..\src\mem.c + + + memheap.c + 1 + ..\..\src\memheap.c + + mempool.c diff --git a/bsp/stm32f40x/template.uvproj b/bsp/stm32f40x/template.uvproj index 1cee2eecb..9d416799e 100644 --- a/bsp/stm32f40x/template.uvproj +++ b/bsp/stm32f40x/template.uvproj @@ -71,9 +71,9 @@ 0 - 1 + 0 0 - fromelf --bin !L --output rtthread.bin + 0 0 From 5fb028968b3629ac54a7fe7dc74245da05ec864f Mon Sep 17 00:00:00 2001 From: aozima Date: Wed, 20 Feb 2013 21:54:08 +0800 Subject: [PATCH 5/6] fix compile errors in bsp:stm32f0x. --- .../STM32F0xx/Source/Templates/gcc_ride7/startup_stm32f0xx.s | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bsp/stm32f0x/Libraries/CMSIS/ST/STM32F0xx/Source/Templates/gcc_ride7/startup_stm32f0xx.s b/bsp/stm32f0x/Libraries/CMSIS/ST/STM32F0xx/Source/Templates/gcc_ride7/startup_stm32f0xx.s index 63cd72b58..5fd2d5aff 100644 --- a/bsp/stm32f0x/Libraries/CMSIS/ST/STM32F0xx/Source/Templates/gcc_ride7/startup_stm32f0xx.s +++ b/bsp/stm32f0x/Libraries/CMSIS/ST/STM32F0xx/Source/Templates/gcc_ride7/startup_stm32f0xx.s @@ -89,7 +89,8 @@ LoopCopyDataInit: /* Zero fill the bss segment. */ FillZerobss: movs r3, #0 - str r3, [r2], #4 + str r3, [r2, #4] + adds r2, r2, #4 LoopFillZerobss: ldr r3, = _ebss From d80888a194ee2af7f00982ee9d6409566b7ab5a3 Mon Sep 17 00:00:00 2001 From: aozima Date: Wed, 20 Feb 2013 22:03:31 +0800 Subject: [PATCH 6/6] port stm32f0x to gcc. --- libcpu/arm/cortex-m0/context_gcc.S | 186 +++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 libcpu/arm/cortex-m0/context_gcc.S diff --git a/libcpu/arm/cortex-m0/context_gcc.S b/libcpu/arm/cortex-m0/context_gcc.S new file mode 100644 index 000000000..bd59a01e5 --- /dev/null +++ b/libcpu/arm/cortex-m0/context_gcc.S @@ -0,0 +1,186 @@ +/* + * File : context_gcc.S + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2009 - 2013, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2010-01-25 Bernard first version + * 2012-06-01 aozima set pendsv priority to 0xFF. + * 2012-08-17 aozima fixed bug: store r8 - r11. + * 2013-02-20 aozima port to gcc. + */ + + .cpu cortex-m3 + .fpu softvfp + .syntax unified + .thumb + .text + + .equ ICSR, 0xE000ED04 /* interrupt control state register */ + .equ PENDSVSET_BIT, 0x10000000 /* value to trigger PendSV exception */ + + .equ SHPR3, 0xE000ED20 /* system priority register (3) */ + .equ PENDSV_PRI_LOWEST, 0x00FF0000 /* PendSV priority value (lowest) */ + +/* + * rt_base_t rt_hw_interrupt_disable(); + */ + .global rt_hw_interrupt_disable + .type rt_hw_interrupt_disable, %function +rt_hw_interrupt_disable: + MRS R0, PRIMASK + CPSID I + BX LR + +/* + * void rt_hw_interrupt_enable(rt_base_t level); + */ + .global rt_hw_interrupt_enable + .type rt_hw_interrupt_enable, %function +rt_hw_interrupt_enable: + MSR PRIMASK, R0 + BX LR + +/* + * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to); + * R0 --> from + * R1 --> to + */ + .global rt_hw_context_switch_interrupt + .type rt_hw_context_switch_interrupt, %function + .global rt_hw_context_switch + .type rt_hw_context_switch, %function +rt_hw_context_switch_interrupt: +rt_hw_context_switch: + /* set rt_thread_switch_interrupt_flag to 1 */ + LDR R2, =rt_thread_switch_interrupt_flag + LDR R3, [R2] + CMP R3, #1 + BEQ _reswitch + MOV R3, #1 + STR R3, [R2] + + LDR R2, =rt_interrupt_from_thread /* set rt_interrupt_from_thread */ + STR R0, [R2] + +_reswitch: + LDR R2, =rt_interrupt_to_thread /* set rt_interrupt_to_thread */ + STR R1, [R2] + + LDR R0, =ICSR /* trigger the PendSV exception (causes context switch) */ + LDR R1, =PENDSVSET_BIT + STR R1, [R0] + BX LR + +/* R0 --> swith from thread stack + * R1 --> swith to thread stack + * psr, pc, LR, R12, R3, R2, R1, R0 are pushed into [from] stack + */ + .global PendSV_Handler + .type PendSV_Handler, %function +PendSV_Handler: + /* disable interrupt to protect context switch */ + MRS R2, PRIMASK + CPSID I + + /* get rt_thread_switch_interrupt_flag */ + LDR R0, =rt_thread_switch_interrupt_flag + LDR R1, [R0] + CBZ R1, pendsv_exit /* pendsv aLReady handled */ + + /* clear rt_thread_switch_interrupt_flag to 0 */ + MOV R1, #0 + STR R1, [R0] + + LDR R0, =rt_interrupt_from_thread + LDR R1, [R0] + CBZ R1, swtich_to_thread /* skip register save at the first time */ + + MRS R1, PSP /* get from thread stack pointer */ + STMFD R1!, {R4 - R11} /* push R4 - R11 register */ + LDR R0, [R0] + STR R1, [R0] /* update from thread stack pointer */ + +swtich_to_thread: + LDR R1, =rt_interrupt_to_thread + LDR R1, [R1] + LDR R1, [R1] /* load thread stack pointer */ + + LDMFD R1!, {R4 - R11} /* pop R4 - R11 register */ + MSR PSP, R1 /* update stack pointer */ + +pendsv_exit: + /* restore interrupt */ + MSR PRIMASK, R2 + + ORR LR, LR, #0x04 + BX LR + +/* + * void rt_hw_context_switch_to(rt_uint32 to); + * R0 --> to + */ + .global rt_hw_context_switch_to + .type rt_hw_context_switch_to, %function +rt_hw_context_switch_to: + LDR R1, =rt_interrupt_to_thread + STR R0, [R1] + + /* set from thread to 0 */ + LDR R1, =rt_interrupt_from_thread + MOV R0, #0 + STR R0, [R1] + + /* set interrupt flag to 1 */ + LDR R1, =rt_thread_switch_interrupt_flag + MOV R0, #1 + STR R0, [R1] + + /* set the PendSV exception priority */ + LDR R0, =SHPR3 + LDR R1, =PENDSV_PRI_LOWEST + LDR.W R2, [R0,#0] /* read */ + ORR R1, R1, R2 /* modify */ + STR R1, [R0] /* write-back */ + + LDR R0, =ICSR /* trigger the PendSV exception (causes context switch) */ + LDR R1, =PENDSVSET_BIT + STR R1, [R0] + + CPSIE I /* enable interrupts at processor level */ + + /* never reach here! */ + +/* compatible with old version */ + .global rt_hw_interrupt_thread_switch + .type rt_hw_interrupt_thread_switch, %function +rt_hw_interrupt_thread_switch: + BX LR + NOP + + .global HardFault_Handler + .type HardFault_Handler, %function +HardFault_Handler: + /* get current context */ + MRS R0, PSP /* get fault thread stack pointer */ + PUSH {LR} + BL rt_hw_hard_fault_exception + POP {LR} + + ORR LR, LR, #0x04 + BX LR + +/* + * rt_uint32_t rt_hw_interrupt_check(void); + * R0 --> state + */ + .global rt_hw_interrupt_check + .type rt_hw_interrupt_check, %function +rt_hw_interrupt_check: + MRS R0, IPSR + BX LR