From 1a2e19d5d6161df4c7b385bc03ed761e0e27e825 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 13 Sep 2013 11:24:38 +0000 Subject: [PATCH] git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6299 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- demos/rt/RT-STM32F051-DISCOVERY/main.c | 4 +- demos/rt/RT-STM32F303-DISCOVERY/main.c | 52 +++++++++++--------- demos/rt/RT-STM32F407-DISCOVERY/main.c | 2 +- os/nil/ports/ARMCMx/compilers/GCC/niltypes.h | 2 +- os/rt/include/chthreads.h | 11 +++++ os/rt/ports/ARMCMx/compilers/GCC/chtypes.h | 5 ++ 6 files changed, 50 insertions(+), 26 deletions(-) diff --git a/demos/rt/RT-STM32F051-DISCOVERY/main.c b/demos/rt/RT-STM32F051-DISCOVERY/main.c index ea6ed9f39..cc7753756 100644 --- a/demos/rt/RT-STM32F051-DISCOVERY/main.c +++ b/demos/rt/RT-STM32F051-DISCOVERY/main.c @@ -22,7 +22,7 @@ * Blue LED blinker thread, times are in milliseconds. */ static THD_WORKING_AREA(waThread1, 128); -static msg_t Thread1(void *arg) { +static THD_FUNCTION(Thread1, arg) { (void)arg; chRegSetThreadName("blinker1"); @@ -38,7 +38,7 @@ static msg_t Thread1(void *arg) { * Green LED blinker thread, times are in milliseconds. */ static THD_WORKING_AREA(waThread2, 128); -static msg_t Thread2(void *arg) { +static THD_FUNCTION(Thread2, arg) { (void)arg; chRegSetThreadName("blinker2"); diff --git a/demos/rt/RT-STM32F303-DISCOVERY/main.c b/demos/rt/RT-STM32F303-DISCOVERY/main.c index 72b3994bc..b3e7c37f6 100644 --- a/demos/rt/RT-STM32F303-DISCOVERY/main.c +++ b/demos/rt/RT-STM32F303-DISCOVERY/main.c @@ -18,12 +18,11 @@ #include "hal.h" #include "test.h" -#if 0 /* - * This is a periodic thread that does absolutely nothing except flashing LEDs. + * Flasher thread #1. */ -static WORKING_AREA(waThread1, 128); -static msg_t Thread1(void *arg) { +static THD_WORKING_AREA(waThread1, 128); +static THD_FUNCTION(Thread1, arg) { (void)arg; chRegSetThreadName("blinker"); @@ -54,31 +53,40 @@ static msg_t Thread1(void *arg) { palClearPad(GPIOE, GPIOE_LED4_BLUE); } } -#endif -static THD_WORKING_AREA(waThread1, 128); -static msg_t Thread1(void *arg) { +/* + * Flasher thread #2. + */ +static THD_WORKING_AREA(waThread2, 128); +static THD_FUNCTION(Thread2, arg) { (void)arg; - chRegSetThreadName("blinker1"); + chRegSetThreadName("blinker"); while (true) { palSetPad(GPIOE, GPIOE_LED3_RED); - chThdSleepMilliseconds(250); + chThdSleepMilliseconds(125); palClearPad(GPIOE, GPIOE_LED3_RED); - chThdSleepMilliseconds(250); - } -} - -static THD_WORKING_AREA(waThread2, 128); -static msg_t Thread2(void *arg) { - - (void)arg; - chRegSetThreadName("blinker2"); - while (true) { + palSetPad(GPIOE, GPIOE_LED5_ORANGE); + chThdSleepMilliseconds(125); + palClearPad(GPIOE, GPIOE_LED5_ORANGE); + palSetPad(GPIOE, GPIOE_LED7_GREEN); + chThdSleepMilliseconds(125); + palClearPad(GPIOE, GPIOE_LED7_GREEN); + palSetPad(GPIOE, GPIOE_LED9_BLUE); + chThdSleepMilliseconds(125); + palClearPad(GPIOE, GPIOE_LED9_BLUE); + palSetPad(GPIOE, GPIOE_LED10_RED); + chThdSleepMilliseconds(125); + palClearPad(GPIOE, GPIOE_LED10_RED); + palSetPad(GPIOE, GPIOE_LED8_ORANGE); + chThdSleepMilliseconds(125); + palClearPad(GPIOE, GPIOE_LED8_ORANGE); + palSetPad(GPIOE, GPIOE_LED6_GREEN); + chThdSleepMilliseconds(125); + palClearPad(GPIOE, GPIOE_LED6_GREEN); palSetPad(GPIOE, GPIOE_LED4_BLUE); - chThdSleepMilliseconds(500); + chThdSleepMilliseconds(125); palClearPad(GPIOE, GPIOE_LED4_BLUE); - chThdSleepMilliseconds(500); } } @@ -109,7 +117,7 @@ int main(void) { * Creates the example thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO+1, Thread1, NULL); - chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO+2, Thread2, NULL); + chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO+1, Thread2, NULL); /* * Normal main() thread activity, in this demo it does nothing except diff --git a/demos/rt/RT-STM32F407-DISCOVERY/main.c b/demos/rt/RT-STM32F407-DISCOVERY/main.c index be7c848c2..ceb144e98 100644 --- a/demos/rt/RT-STM32F407-DISCOVERY/main.c +++ b/demos/rt/RT-STM32F407-DISCOVERY/main.c @@ -23,7 +23,7 @@ * a LED. */ static THD_WORKING_AREA(waThread1, 128); -static msg_t Thread1(void *arg) { +static THD_FUNCTION(Thread1, arg) { (void)arg; chRegSetThreadName("blinker"); diff --git a/os/nil/ports/ARMCMx/compilers/GCC/niltypes.h b/os/nil/ports/ARMCMx/compilers/GCC/niltypes.h index 8aa7bf7a6..8b206cb1d 100644 --- a/os/nil/ports/ARMCMx/compilers/GCC/niltypes.h +++ b/os/nil/ports/ARMCMx/compilers/GCC/niltypes.h @@ -72,7 +72,7 @@ typedef uint32_t ucnt_t; /**< Generic unsigned counter. */ #define NOINLINE __attribute__((noinline)) /** - * @brief Thread function declaration macro optimized for GCC. + * @brief Optimized thread function declaration macro. */ #define PORT_THD_FUNCTION(tname, arg) \ __attribute__((noreturn)) void tname(void *arg) diff --git a/os/rt/include/chthreads.h b/os/rt/include/chthreads.h index 6da6b6518..1dcad9b48 100644 --- a/os/rt/include/chthreads.h +++ b/os/rt/include/chthreads.h @@ -147,6 +147,17 @@ typedef msg_t (*tfunc_t)(void *); stkalign_t s[THD_WORKING_AREA_SIZE(n) / sizeof(stkalign_t)] /** @} */ +/** + * @name Threads abstraction macros + */ +/** + * @brief Thread declaration macro. + * @note Thread declarations should be performed using this macro because + * the port layer could define optimizations for thread functions. + */ +#define THD_FUNCTION(tname, arg) PORT_THD_FUNCTION(tname, arg) +/** @} */ + /** * @name Macro Functions * @{ diff --git a/os/rt/ports/ARMCMx/compilers/GCC/chtypes.h b/os/rt/ports/ARMCMx/compilers/GCC/chtypes.h index 1cf45c99b..61052a46d 100644 --- a/os/rt/ports/ARMCMx/compilers/GCC/chtypes.h +++ b/os/rt/ports/ARMCMx/compilers/GCC/chtypes.h @@ -79,6 +79,11 @@ typedef uint32_t ucnt_t; /**< Generic unsigned counter. */ */ #define NOINLINE __attribute__((noinline)) +/** + * @brief Optimized thread function declaration macro. + */ +#define PORT_THD_FUNCTION(tname, arg) msg_t tname(void *arg) + #endif /* _CHTYPES_H_ */ /** @} */