From 196ea509176fbb4f1341b9f7f1fbaed2ee286047 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 13 Mar 2009 20:53:08 +0000 Subject: [PATCH] Space optimization for Cortex-M3 port. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@844 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- ports/ARMCM3/chcore.c | 12 ++++++++++++ ports/ARMCM3/chcore.h | 16 ++++++++++++++++ readme.txt | 4 +++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/ports/ARMCM3/chcore.c b/ports/ARMCM3/chcore.c index b075ec27c..0159ee71f 100644 --- a/ports/ARMCM3/chcore.c +++ b/ports/ARMCM3/chcore.c @@ -42,6 +42,18 @@ void port_halt(void) { } } +#if !CH_OPTIMIZE_SPEED +void _port_lock(void) { + register uint32_t tmp asm ("r3") = BASEPRI_KERNEL; + asm volatile ("msr BASEPRI, %0" : : "r" (tmp)); +} + +void _port_unlock(void) { + register uint32_t tmp asm ("r3") = BASEPRI_USER; + asm volatile ("msr BASEPRI, %0" : : "r" (tmp)); +} +#endif + /** * System Timer vector. * This interrupt is used as system tick. diff --git a/ports/ARMCM3/chcore.h b/ports/ARMCM3/chcore.h index 477e2fede..5ef44a09f 100644 --- a/ports/ARMCM3/chcore.h +++ b/ports/ARMCM3/chcore.h @@ -221,18 +221,30 @@ struct context { /** * Raises the base priority to kernel level. */ +#if CH_OPTIMIZE_SPEED #define port_lock() { \ register uint32_t tmp asm ("r3") = BASEPRI_KERNEL; \ asm volatile ("msr BASEPRI, %0" : : "r" (tmp)); \ } +#else +#define port_lock() { \ + asm volatile ("bl _port_lock" : : : "r3", "lr"); \ +} +#endif /** * Lowers the base priority to user level. */ +#if CH_OPTIMIZE_SPEED #define port_unlock() { \ register uint32_t tmp asm ("r3") = BASEPRI_USER; \ asm volatile ("msr BASEPRI, %0" : : "r" (tmp)); \ } +#else +#define port_unlock() { \ + asm volatile ("bl _port_unlock" : : : "r3", "lr"); \ +} +#endif /** * Same as @p port_lock() in this port. @@ -303,6 +315,10 @@ struct context { extern "C" { #endif void port_halt(void); +#if !CH_OPTIMIZE_SPEED + void _port_lock(void); + void _port_unlock(void); +#endif #ifdef __cplusplus } #endif diff --git a/readme.txt b/readme.txt index 73d28de7e..19db5e968 100644 --- a/readme.txt +++ b/readme.txt @@ -87,8 +87,10 @@ Win32-MinGW - ChibiOS/RT simulator and demo into a WIN32 process, the macro chSysGetTime() in chTimeNow(), the old names are still recognized but marked as deprecated (fixes the bug 2678953 but goes a bit further by introducing a new API category "Time"). -- OPT: Small optimization to the Cortex-M3 port code, improved thread +- OPT: Small optimization to the Cortex-M3 thread startup code, improved thread related performance scores and smaller code. +- OPT: Alternative implementations for port_lock() and port_unlock() when + CH_OPTIMIZE_SPEED is FALSE, huge space savings. - OPT: Improved ready list and priority ordered lists code, saved some tens of bytes here and there in the kernel. - Modified the test thread function to return the global test result flag.