diff --git a/demos/AVR/NIL-ARDUINO-MEGA/chconf.h b/demos/AVR/NIL-ARDUINO-MEGA/chconf.h index d523c3de2..ac9186bda 100644 --- a/demos/AVR/NIL-ARDUINO-MEGA/chconf.h +++ b/demos/AVR/NIL-ARDUINO-MEGA/chconf.h @@ -29,7 +29,7 @@ #define CHCONF_H #define _CHIBIOS_NIL_CONF_ -#define _CHIBIOS_NIL_CONF_VER_3_2_ +#define _CHIBIOS_NIL_CONF_VER_4_0_ /*===========================================================================*/ /** @@ -39,11 +39,20 @@ /*===========================================================================*/ /** - * @brief Number of user threads in the application. + * @brief Maximum number of user threads in the application. * @note This number is not inclusive of the idle thread which is - * Implicitly handled. + * implicitly handled. + * @note Set this value to be exactly equal to the number of threads you + * will use or you would be wasting RAM and cycles. + * @note This values also defines the number of available priorities + * (0..CH_CFG_MAX_THREADS-1). */ -#define CH_CFG_NUM_THREADS 2 +#define CH_CFG_MAX_THREADS 4 + +/** + * @brief Auto starts threads when @p chSysInit() is invoked. + */ +#define CH_CFG_AUTOSTART_THREADS TRUE /** @} */ @@ -87,6 +96,15 @@ */ /*===========================================================================*/ +/** + * @brief Threads synchronization APIs. + * @details If enabled then the @p chThdWait() function is included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_WAITEXIT TRUE + /** * @brief Semaphores APIs. * @details If enabled then the Semaphores APIs are included in the kernel. @@ -292,10 +310,8 @@ /** * @brief System initialization hook. */ -#if !defined(CH_CFG_SYSTEM_INIT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_INIT_HOOK() { \ } -#endif /** * @brief Threads descriptor structure extension. @@ -311,6 +327,12 @@ /* Add custom threads initialization code here.*/ \ } +/** + * @brief Threads finalization hook. + * @details User finalization code added to the @p chThdExit() API. + */ +#define CH_CFG_THREAD_EXIT_HOOK(tp) {} + /** * @brief Idle thread enter hook. * @note This hook is invoked within a critical zone, no OS functions @@ -332,10 +354,8 @@ /** * @brief System halt hook. */ -#if !defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_HALT_HOOK(reason) { \ } -#endif /** @} */ diff --git a/demos/AVR/NIL-ARDUINO-MINI/chconf.h b/demos/AVR/NIL-ARDUINO-MINI/chconf.h index 91ba353a8..29787a167 100644 --- a/demos/AVR/NIL-ARDUINO-MINI/chconf.h +++ b/demos/AVR/NIL-ARDUINO-MINI/chconf.h @@ -29,7 +29,7 @@ #define CHCONF_H #define _CHIBIOS_NIL_CONF_ -#define _CHIBIOS_NIL_CONF_VER_3_2_ +#define _CHIBIOS_NIL_CONF_VER_4_0_ /*===========================================================================*/ /** @@ -39,11 +39,20 @@ /*===========================================================================*/ /** - * @brief Number of user threads in the application. + * @brief Maximum number of user threads in the application. * @note This number is not inclusive of the idle thread which is - * Implicitly handled. + * implicitly handled. + * @note Set this value to be exactly equal to the number of threads you + * will use or you would be wasting RAM and cycles. + * @note This values also defines the number of available priorities + * (0..CH_CFG_MAX_THREADS-1). */ -#define CH_CFG_NUM_THREADS 2 +#define CH_CFG_MAX_THREADS 4 + +/** + * @brief Auto starts threads when @p chSysInit() is invoked. + */ +#define CH_CFG_AUTOSTART_THREADS TRUE /** @} */ @@ -87,6 +96,15 @@ */ /*===========================================================================*/ +/** + * @brief Threads synchronization APIs. + * @details If enabled then the @p chThdWait() function is included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_WAITEXIT TRUE + /** * @brief Semaphores APIs. * @details If enabled then the Semaphores APIs are included in the kernel. @@ -292,10 +310,8 @@ /** * @brief System initialization hook. */ -#if !defined(CH_CFG_SYSTEM_INIT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_INIT_HOOK() { \ } -#endif /** * @brief Threads descriptor structure extension. @@ -311,6 +327,12 @@ /* Add custom threads initialization code here.*/ \ } +/** + * @brief Threads finalization hook. + * @details User finalization code added to the @p chThdExit() API. + */ +#define CH_CFG_THREAD_EXIT_HOOK(tp) {} + /** * @brief Idle thread enter hook. * @note This hook is invoked within a critical zone, no OS functions @@ -332,10 +354,8 @@ /** * @brief System halt hook. */ -#if !defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_HALT_HOOK(reason) { \ } -#endif /** @} */ diff --git a/demos/AVR/NIL-ARDUINO-NANO/chconf.h b/demos/AVR/NIL-ARDUINO-NANO/chconf.h index d523c3de2..ac9186bda 100644 --- a/demos/AVR/NIL-ARDUINO-NANO/chconf.h +++ b/demos/AVR/NIL-ARDUINO-NANO/chconf.h @@ -29,7 +29,7 @@ #define CHCONF_H #define _CHIBIOS_NIL_CONF_ -#define _CHIBIOS_NIL_CONF_VER_3_2_ +#define _CHIBIOS_NIL_CONF_VER_4_0_ /*===========================================================================*/ /** @@ -39,11 +39,20 @@ /*===========================================================================*/ /** - * @brief Number of user threads in the application. + * @brief Maximum number of user threads in the application. * @note This number is not inclusive of the idle thread which is - * Implicitly handled. + * implicitly handled. + * @note Set this value to be exactly equal to the number of threads you + * will use or you would be wasting RAM and cycles. + * @note This values also defines the number of available priorities + * (0..CH_CFG_MAX_THREADS-1). */ -#define CH_CFG_NUM_THREADS 2 +#define CH_CFG_MAX_THREADS 4 + +/** + * @brief Auto starts threads when @p chSysInit() is invoked. + */ +#define CH_CFG_AUTOSTART_THREADS TRUE /** @} */ @@ -87,6 +96,15 @@ */ /*===========================================================================*/ +/** + * @brief Threads synchronization APIs. + * @details If enabled then the @p chThdWait() function is included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_WAITEXIT TRUE + /** * @brief Semaphores APIs. * @details If enabled then the Semaphores APIs are included in the kernel. @@ -292,10 +310,8 @@ /** * @brief System initialization hook. */ -#if !defined(CH_CFG_SYSTEM_INIT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_INIT_HOOK() { \ } -#endif /** * @brief Threads descriptor structure extension. @@ -311,6 +327,12 @@ /* Add custom threads initialization code here.*/ \ } +/** + * @brief Threads finalization hook. + * @details User finalization code added to the @p chThdExit() API. + */ +#define CH_CFG_THREAD_EXIT_HOOK(tp) {} + /** * @brief Idle thread enter hook. * @note This hook is invoked within a critical zone, no OS functions @@ -332,10 +354,8 @@ /** * @brief System halt hook. */ -#if !defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_HALT_HOOK(reason) { \ } -#endif /** @} */ diff --git a/demos/AVR/NIL-ARDUINO-UNO/chconf.h b/demos/AVR/NIL-ARDUINO-UNO/chconf.h index d523c3de2..ac9186bda 100644 --- a/demos/AVR/NIL-ARDUINO-UNO/chconf.h +++ b/demos/AVR/NIL-ARDUINO-UNO/chconf.h @@ -29,7 +29,7 @@ #define CHCONF_H #define _CHIBIOS_NIL_CONF_ -#define _CHIBIOS_NIL_CONF_VER_3_2_ +#define _CHIBIOS_NIL_CONF_VER_4_0_ /*===========================================================================*/ /** @@ -39,11 +39,20 @@ /*===========================================================================*/ /** - * @brief Number of user threads in the application. + * @brief Maximum number of user threads in the application. * @note This number is not inclusive of the idle thread which is - * Implicitly handled. + * implicitly handled. + * @note Set this value to be exactly equal to the number of threads you + * will use or you would be wasting RAM and cycles. + * @note This values also defines the number of available priorities + * (0..CH_CFG_MAX_THREADS-1). */ -#define CH_CFG_NUM_THREADS 2 +#define CH_CFG_MAX_THREADS 4 + +/** + * @brief Auto starts threads when @p chSysInit() is invoked. + */ +#define CH_CFG_AUTOSTART_THREADS TRUE /** @} */ @@ -87,6 +96,15 @@ */ /*===========================================================================*/ +/** + * @brief Threads synchronization APIs. + * @details If enabled then the @p chThdWait() function is included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_WAITEXIT TRUE + /** * @brief Semaphores APIs. * @details If enabled then the Semaphores APIs are included in the kernel. @@ -292,10 +310,8 @@ /** * @brief System initialization hook. */ -#if !defined(CH_CFG_SYSTEM_INIT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_INIT_HOOK() { \ } -#endif /** * @brief Threads descriptor structure extension. @@ -311,6 +327,12 @@ /* Add custom threads initialization code here.*/ \ } +/** + * @brief Threads finalization hook. + * @details User finalization code added to the @p chThdExit() API. + */ +#define CH_CFG_THREAD_EXIT_HOOK(tp) {} + /** * @brief Idle thread enter hook. * @note This hook is invoked within a critical zone, no OS functions @@ -332,10 +354,8 @@ /** * @brief System halt hook. */ -#if !defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_HALT_HOOK(reason) { \ } -#endif /** @} */ diff --git a/demos/AVR/NIL-DIGISPARK-ATTINY-167/chconf.h b/demos/AVR/NIL-DIGISPARK-ATTINY-167/chconf.h index dfd77b7ce..ac9186bda 100644 --- a/demos/AVR/NIL-DIGISPARK-ATTINY-167/chconf.h +++ b/demos/AVR/NIL-DIGISPARK-ATTINY-167/chconf.h @@ -29,7 +29,7 @@ #define CHCONF_H #define _CHIBIOS_NIL_CONF_ -#define _CHIBIOS_NIL_CONF_VER_3_2_ +#define _CHIBIOS_NIL_CONF_VER_4_0_ /*===========================================================================*/ /** @@ -39,11 +39,20 @@ /*===========================================================================*/ /** - * @brief Number of user threads in the application. + * @brief Maximum number of user threads in the application. * @note This number is not inclusive of the idle thread which is - * Implicitly handled. + * implicitly handled. + * @note Set this value to be exactly equal to the number of threads you + * will use or you would be wasting RAM and cycles. + * @note This values also defines the number of available priorities + * (0..CH_CFG_MAX_THREADS-1). */ -#define CH_CFG_NUM_THREADS 1 +#define CH_CFG_MAX_THREADS 4 + +/** + * @brief Auto starts threads when @p chSysInit() is invoked. + */ +#define CH_CFG_AUTOSTART_THREADS TRUE /** @} */ @@ -87,6 +96,15 @@ */ /*===========================================================================*/ +/** + * @brief Threads synchronization APIs. + * @details If enabled then the @p chThdWait() function is included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_WAITEXIT TRUE + /** * @brief Semaphores APIs. * @details If enabled then the Semaphores APIs are included in the kernel. @@ -292,10 +310,8 @@ /** * @brief System initialization hook. */ -#if !defined(CH_CFG_SYSTEM_INIT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_INIT_HOOK() { \ } -#endif /** * @brief Threads descriptor structure extension. @@ -311,6 +327,12 @@ /* Add custom threads initialization code here.*/ \ } +/** + * @brief Threads finalization hook. + * @details User finalization code added to the @p chThdExit() API. + */ +#define CH_CFG_THREAD_EXIT_HOOK(tp) {} + /** * @brief Idle thread enter hook. * @note This hook is invoked within a critical zone, no OS functions @@ -332,10 +354,8 @@ /** * @brief System halt hook. */ -#if !defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_HALT_HOOK(reason) { \ } -#endif /** @} */ diff --git a/demos/AVR/NIL-MT-DB-X4/chconf.h b/demos/AVR/NIL-MT-DB-X4/chconf.h index 6328fe918..09aa59129 100644 --- a/demos/AVR/NIL-MT-DB-X4/chconf.h +++ b/demos/AVR/NIL-MT-DB-X4/chconf.h @@ -29,7 +29,7 @@ #define CHCONF_H #define _CHIBIOS_NIL_CONF_ -#define _CHIBIOS_NIL_CONF_VER_3_2_ +#define _CHIBIOS_NIL_CONF_VER_4_0_ /*===========================================================================*/ /** @@ -39,11 +39,20 @@ /*===========================================================================*/ /** - * @brief Number of user threads in the application. + * @brief Maximum number of user threads in the application. * @note This number is not inclusive of the idle thread which is - * Implicitly handled. + * implicitly handled. + * @note Set this value to be exactly equal to the number of threads you + * will use or you would be wasting RAM and cycles. + * @note This values also defines the number of available priorities + * (0..CH_CFG_MAX_THREADS-1). */ -#define CH_CFG_NUM_THREADS 1 +#define CH_CFG_MAX_THREADS 4 + +/** + * @brief Auto starts threads when @p chSysInit() is invoked. + */ +#define CH_CFG_AUTOSTART_THREADS TRUE /** @} */ @@ -87,6 +96,15 @@ */ /*===========================================================================*/ +/** + * @brief Threads synchronization APIs. + * @details If enabled then the @p chThdWait() function is included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_WAITEXIT TRUE + /** * @brief Semaphores APIs. * @details If enabled then the Semaphores APIs are included in the kernel. @@ -292,10 +310,8 @@ /** * @brief System initialization hook. */ -#if !defined(CH_CFG_SYSTEM_INIT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_INIT_HOOK() { \ } -#endif /** * @brief Threads descriptor structure extension. @@ -311,6 +327,12 @@ /* Add custom threads initialization code here.*/ \ } +/** + * @brief Threads finalization hook. + * @details User finalization code added to the @p chThdExit() API. + */ +#define CH_CFG_THREAD_EXIT_HOOK(tp) {} + /** * @brief Idle thread enter hook. * @note This hook is invoked within a critical zone, no OS functions @@ -332,10 +354,8 @@ /** * @brief System halt hook. */ -#if !defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_HALT_HOOK(reason) { \ } -#endif /** @} */ diff --git a/demos/AVR/TEST-SUITE-NIL/chconf.h b/demos/AVR/TEST-SUITE-NIL/chconf.h index 68d27b78c..7047da7aa 100644 --- a/demos/AVR/TEST-SUITE-NIL/chconf.h +++ b/demos/AVR/TEST-SUITE-NIL/chconf.h @@ -29,7 +29,7 @@ #define CHCONF_H #define _CHIBIOS_NIL_CONF_ -#define _CHIBIOS_NIL_CONF_VER_3_2_ +#define _CHIBIOS_NIL_CONF_VER_4_0_ /*===========================================================================*/ /** @@ -39,11 +39,20 @@ /*===========================================================================*/ /** - * @brief Number of user threads in the application. + * @brief Maximum number of user threads in the application. * @note This number is not inclusive of the idle thread which is - * Implicitly handled. + * implicitly handled. + * @note Set this value to be exactly equal to the number of threads you + * will use or you would be wasting RAM and cycles. + * @note This values also defines the number of available priorities + * (0..CH_CFG_MAX_THREADS-1). */ -#define CH_CFG_NUM_THREADS 3 +#define CH_CFG_MAX_THREADS 4 + +/** + * @brief Auto starts threads when @p chSysInit() is invoked. + */ +#define CH_CFG_AUTOSTART_THREADS TRUE /** @} */ @@ -87,6 +96,15 @@ */ /*===========================================================================*/ +/** + * @brief Threads synchronization APIs. + * @details If enabled then the @p chThdWait() function is included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_WAITEXIT TRUE + /** * @brief Semaphores APIs. * @details If enabled then the Semaphores APIs are included in the kernel. @@ -292,10 +310,8 @@ /** * @brief System initialization hook. */ -#if !defined(CH_CFG_SYSTEM_INIT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_INIT_HOOK() { \ } -#endif /** * @brief Threads descriptor structure extension. @@ -311,6 +327,12 @@ /* Add custom threads initialization code here.*/ \ } +/** + * @brief Threads finalization hook. + * @details User finalization code added to the @p chThdExit() API. + */ +#define CH_CFG_THREAD_EXIT_HOOK(tp) {} + /** * @brief Idle thread enter hook. * @note This hook is invoked within a critical zone, no OS functions @@ -332,10 +354,8 @@ /** * @brief System halt hook. */ -#if !defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_HALT_HOOK(reason) { \ } -#endif /** @} */ diff --git a/demos/SPC5/NIL-SPC560D-EVB/chconf.h b/demos/SPC5/NIL-SPC560D-EVB/chconf.h index 7efabe727..fc1d98a74 100644 --- a/demos/SPC5/NIL-SPC560D-EVB/chconf.h +++ b/demos/SPC5/NIL-SPC560D-EVB/chconf.h @@ -29,7 +29,7 @@ #define CHCONF_H #define _CHIBIOS_NIL_CONF_ -#define _CHIBIOS_NIL_CONF_VER_3_2_ +#define _CHIBIOS_NIL_CONF_VER_4_0_ /*===========================================================================*/ /** @@ -39,11 +39,20 @@ /*===========================================================================*/ /** - * @brief Number of user threads in the application. + * @brief Maximum number of user threads in the application. * @note This number is not inclusive of the idle thread which is - * Implicitly handled. + * implicitly handled. + * @note Set this value to be exactly equal to the number of threads you + * will use or you would be wasting RAM and cycles. + * @note This values also defines the number of available priorities + * (0..CH_CFG_MAX_THREADS-1). */ -#define CH_CFG_NUM_THREADS 3 +#define CH_CFG_MAX_THREADS 4 + +/** + * @brief Auto starts threads when @p chSysInit() is invoked. + */ +#define CH_CFG_AUTOSTART_THREADS TRUE /** @} */ @@ -87,6 +96,15 @@ */ /*===========================================================================*/ +/** + * @brief Threads synchronization APIs. + * @details If enabled then the @p chThdWait() function is included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_WAITEXIT TRUE + /** * @brief Semaphores APIs. * @details If enabled then the Semaphores APIs are included in the kernel. @@ -292,10 +310,8 @@ /** * @brief System initialization hook. */ -#if !defined(CH_CFG_SYSTEM_INIT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_INIT_HOOK() { \ } -#endif /** * @brief Threads descriptor structure extension. @@ -311,6 +327,12 @@ /* Add custom threads initialization code here.*/ \ } +/** + * @brief Threads finalization hook. + * @details User finalization code added to the @p chThdExit() API. + */ +#define CH_CFG_THREAD_EXIT_HOOK(tp) {} + /** * @brief Idle thread enter hook. * @note This hook is invoked within a critical zone, no OS functions @@ -332,10 +354,8 @@ /** * @brief System halt hook. */ -#if !defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_HALT_HOOK(reason) { \ } -#endif /** @} */ diff --git a/demos/SPC5/NIL-SPC560D-EVB/main.c b/demos/SPC5/NIL-SPC560D-EVB/main.c index 47b4a8169..52e216f27 100644 --- a/demos/SPC5/NIL-SPC560D-EVB/main.c +++ b/demos/SPC5/NIL-SPC560D-EVB/main.c @@ -119,13 +119,12 @@ THD_FUNCTION(Thread2, arg) { } /* - * Threads static table, one entry per thread. The number of entries must - * match NIL_CFG_NUM_THREADS. + * Threads creation table, one entry per thread. */ THD_TABLE_BEGIN -THD_TABLE_ENTRY(waThread1, "blinker", Thread1, NULL) -THD_TABLE_ENTRY(wa_test_support, "test_support", test_support, (void *)&nil.threads[2]) -THD_TABLE_ENTRY(waThread2, "tester", Thread2, NULL) + THD_TABLE_THREAD(0, "blinker", waThread1, Thread1, NULL) + THD_TABLE_THREAD(1, "test_support", wa_test_support, test_support, (void *)&nil.threads[2]) + THD_TABLE_THREAD(2, "tester", waThread2, Thread2, NULL) THD_TABLE_END /* diff --git a/demos/STM32/NIL-STM32F051-DISCOVERY/cfg/chconf.h b/demos/STM32/NIL-STM32F051-DISCOVERY/cfg/chconf.h index 593dbb296..40ab75365 100644 --- a/demos/STM32/NIL-STM32F051-DISCOVERY/cfg/chconf.h +++ b/demos/STM32/NIL-STM32F051-DISCOVERY/cfg/chconf.h @@ -29,7 +29,7 @@ #define CHCONF_H #define _CHIBIOS_NIL_CONF_ -#define _CHIBIOS_NIL_CONF_VER_3_2_ +#define _CHIBIOS_NIL_CONF_VER_4_0_ /*===========================================================================*/ /** @@ -39,11 +39,20 @@ /*===========================================================================*/ /** - * @brief Number of user threads in the application. + * @brief Maximum number of user threads in the application. * @note This number is not inclusive of the idle thread which is - * Implicitly handled. + * implicitly handled. + * @note Set this value to be exactly equal to the number of threads you + * will use or you would be wasting RAM and cycles. + * @note This values also defines the number of available priorities + * (0..CH_CFG_MAX_THREADS-1). */ -#define CH_CFG_NUM_THREADS 4 +#define CH_CFG_MAX_THREADS 4 + +/** + * @brief Auto starts threads when @p chSysInit() is invoked. + */ +#define CH_CFG_AUTOSTART_THREADS TRUE /** @} */ @@ -87,6 +96,15 @@ */ /*===========================================================================*/ +/** + * @brief Threads synchronization APIs. + * @details If enabled then the @p chThdWait() function is included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_WAITEXIT TRUE + /** * @brief Semaphores APIs. * @details If enabled then the Semaphores APIs are included in the kernel. @@ -292,10 +310,8 @@ /** * @brief System initialization hook. */ -#if !defined(CH_CFG_SYSTEM_INIT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_INIT_HOOK() { \ } -#endif /** * @brief Threads descriptor structure extension. @@ -311,6 +327,12 @@ /* Add custom threads initialization code here.*/ \ } +/** + * @brief Threads finalization hook. + * @details User finalization code added to the @p chThdExit() API. + */ +#define CH_CFG_THREAD_EXIT_HOOK(tp) {} + /** * @brief Idle thread enter hook. * @note This hook is invoked within a critical zone, no OS functions @@ -332,10 +354,8 @@ /** * @brief System halt hook. */ -#if !defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_HALT_HOOK(reason) { \ } -#endif /** @} */ diff --git a/demos/STM32/NIL-STM32F051-DISCOVERY/main.c b/demos/STM32/NIL-STM32F051-DISCOVERY/main.c index 3c69dafc3..81becd95d 100644 --- a/demos/STM32/NIL-STM32F051-DISCOVERY/main.c +++ b/demos/STM32/NIL-STM32F051-DISCOVERY/main.c @@ -81,14 +81,13 @@ THD_FUNCTION(Thread3, arg) { } /* - * Threads static table, one entry per thread. The number of entries must - * match NIL_CFG_NUM_THREADS. + * Threads creation table, one entry per thread. */ THD_TABLE_BEGIN - THD_TABLE_ENTRY(waThread1, "blinker1", Thread1, NULL) - THD_TABLE_ENTRY(waThread2, "blinker2", Thread2, NULL) - THD_TABLE_ENTRY(wa_test_support, "test_support", test_support, (void *)&nil.threads[3]) - THD_TABLE_ENTRY(waThread3, "tester", Thread3, NULL) + THD_TABLE_THREAD(0, "blinker1", waThread1, Thread1, NULL) + THD_TABLE_THREAD(1, "blinker2", waThread2, Thread2, NULL) + THD_TABLE_THREAD(2, "test_support", wa_test_support, test_support, (void *)&nil.threads[3]) + THD_TABLE_THREAD(3, "tester", waThread3, Thread3, NULL) THD_TABLE_END /* diff --git a/demos/STM32/NIL-STM32F100-DISCOVERY/cfg/chconf.h b/demos/STM32/NIL-STM32F100-DISCOVERY/cfg/chconf.h index bfe1f8841..080b196cb 100644 --- a/demos/STM32/NIL-STM32F100-DISCOVERY/cfg/chconf.h +++ b/demos/STM32/NIL-STM32F100-DISCOVERY/cfg/chconf.h @@ -29,7 +29,7 @@ #define CHCONF_H #define _CHIBIOS_NIL_CONF_ -#define _CHIBIOS_NIL_CONF_VER_3_2_ +#define _CHIBIOS_NIL_CONF_VER_4_0_ /*===========================================================================*/ /** @@ -39,11 +39,20 @@ /*===========================================================================*/ /** - * @brief Number of user threads in the application. + * @brief Maximum number of user threads in the application. * @note This number is not inclusive of the idle thread which is - * Implicitly handled. + * implicitly handled. + * @note Set this value to be exactly equal to the number of threads you + * will use or you would be wasting RAM and cycles. + * @note This values also defines the number of available priorities + * (0..CH_CFG_MAX_THREADS-1). */ -#define CH_CFG_NUM_THREADS 3 +#define CH_CFG_MAX_THREADS 3 + +/** + * @brief Auto starts threads when @p chSysInit() is invoked. + */ +#define CH_CFG_AUTOSTART_THREADS TRUE /** @} */ @@ -87,6 +96,15 @@ */ /*===========================================================================*/ +/** + * @brief Threads synchronization APIs. + * @details If enabled then the @p chThdWait() function is included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_WAITEXIT TRUE + /** * @brief Semaphores APIs. * @details If enabled then the Semaphores APIs are included in the kernel. @@ -292,10 +310,8 @@ /** * @brief System initialization hook. */ -#if !defined(CH_CFG_SYSTEM_INIT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_INIT_HOOK() { \ } -#endif /** * @brief Threads descriptor structure extension. @@ -311,6 +327,12 @@ /* Add custom threads initialization code here.*/ \ } +/** + * @brief Threads finalization hook. + * @details User finalization code added to the @p chThdExit() API. + */ +#define CH_CFG_THREAD_EXIT_HOOK(tp) {} + /** * @brief Idle thread enter hook. * @note This hook is invoked within a critical zone, no OS functions @@ -332,10 +354,8 @@ /** * @brief System halt hook. */ -#if !defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_HALT_HOOK(reason) { \ } -#endif /** @} */ diff --git a/demos/STM32/NIL-STM32F100-DISCOVERY/main.c b/demos/STM32/NIL-STM32F100-DISCOVERY/main.c index af71d0eea..34b623c89 100644 --- a/demos/STM32/NIL-STM32F100-DISCOVERY/main.c +++ b/demos/STM32/NIL-STM32F100-DISCOVERY/main.c @@ -69,13 +69,12 @@ THD_FUNCTION(Thread3, arg) { } /* - * Threads static table, one entry per thread. The number of entries must - * match NIL_CFG_NUM_THREADS. + * Threads creation table, one entry per thread. */ THD_TABLE_BEGIN - THD_TABLE_ENTRY(waThread1, "blinker1", Thread1, NULL) - THD_TABLE_ENTRY(waThread2, "blinker2", Thread2, NULL) - THD_TABLE_ENTRY(waThread3, "hello", Thread3, NULL) + THD_TABLE_THREAD(0, "blinker1", waThread1, Thread1, NULL) + THD_TABLE_THREAD(1, "blinker2", waThread2, Thread2, NULL) + THD_TABLE_THREAD(2, "hello", waThread3, Thread3, NULL) THD_TABLE_END /* diff --git a/demos/STM32/NIL-STM32F303-DISCOVERY/Makefile b/demos/STM32/NIL-STM32F303-DISCOVERY/Makefile index bca2377d7..631095137 100644 --- a/demos/STM32/NIL-STM32F303-DISCOVERY/Makefile +++ b/demos/STM32/NIL-STM32F303-DISCOVERY/Makefile @@ -5,7 +5,7 @@ # Compiler options here. ifeq ($(USE_OPT),) - USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16 + USE_OPT = -O0 -ggdb -fomit-frame-pointer -falign-functions=16 endif # C specific options here (added to USE_OPT). diff --git a/demos/STM32/NIL-STM32F303-DISCOVERY/cfg/chconf.h b/demos/STM32/NIL-STM32F303-DISCOVERY/cfg/chconf.h index 980648eed..e0dca22c5 100644 --- a/demos/STM32/NIL-STM32F303-DISCOVERY/cfg/chconf.h +++ b/demos/STM32/NIL-STM32F303-DISCOVERY/cfg/chconf.h @@ -29,7 +29,7 @@ #define CHCONF_H #define _CHIBIOS_NIL_CONF_ -#define _CHIBIOS_NIL_CONF_VER_3_2_ +#define _CHIBIOS_NIL_CONF_VER_4_0_ /*===========================================================================*/ /** @@ -39,11 +39,20 @@ /*===========================================================================*/ /** - * @brief Number of user threads in the application. + * @brief Maximum number of user threads in the application. * @note This number is not inclusive of the idle thread which is - * Implicitly handled. + * implicitly handled. + * @note Set this value to be exactly equal to the number of threads you + * will use or you would be wasting RAM and cycles. + * @note This values also defines the number of available priorities + * (0..CH_CFG_MAX_THREADS-1). */ -#define CH_CFG_NUM_THREADS 4 +#define CH_CFG_MAX_THREADS 4 + +/** + * @brief Auto starts threads when @p chSysInit() is invoked. + */ +#define CH_CFG_AUTOSTART_THREADS TRUE /** @} */ @@ -87,6 +96,15 @@ */ /*===========================================================================*/ +/** + * @brief Threads synchronization APIs. + * @details If enabled then the @p chThdWait() function is included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_WAITEXIT TRUE + /** * @brief Semaphores APIs. * @details If enabled then the Semaphores APIs are included in the kernel. @@ -257,21 +275,21 @@ * * @note The default is @p FALSE. */ -#define CH_DBG_SYSTEM_STATE_CHECK FALSE +#define CH_DBG_SYSTEM_STATE_CHECK TRUE /** * @brief Debug option, parameters checks. * * @note The default is @p FALSE. */ -#define CH_DBG_ENABLE_CHECKS FALSE +#define CH_DBG_ENABLE_CHECKS TRUE /** * @brief System assertions. * * @note The default is @p FALSE. */ -#define CH_DBG_ENABLE_ASSERTS FALSE +#define CH_DBG_ENABLE_ASSERTS TRUE /** * @brief Stack check. @@ -292,10 +310,8 @@ /** * @brief System initialization hook. */ -#if !defined(CH_CFG_SYSTEM_INIT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_INIT_HOOK() { \ } -#endif /** * @brief Threads descriptor structure extension. @@ -311,6 +327,12 @@ /* Add custom threads initialization code here.*/ \ } +/** + * @brief Threads finalization hook. + * @details User finalization code added to the @p chThdExit() API. + */ +#define CH_CFG_THREAD_EXIT_HOOK(tp) {} + /** * @brief Idle thread enter hook. * @note This hook is invoked within a critical zone, no OS functions @@ -332,10 +354,8 @@ /** * @brief System halt hook. */ -#if !defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_HALT_HOOK(reason) { \ } -#endif /** @} */ diff --git a/demos/STM32/NIL-STM32F303-DISCOVERY/main.c b/demos/STM32/NIL-STM32F303-DISCOVERY/main.c index 8bc501303..00f151f19 100644 --- a/demos/STM32/NIL-STM32F303-DISCOVERY/main.c +++ b/demos/STM32/NIL-STM32F303-DISCOVERY/main.c @@ -105,14 +105,13 @@ THD_FUNCTION(Thread3, arg) { } /* - * Threads static table, one entry per thread. The number of entries must - * match NIL_CFG_NUM_THREADS. + * Threads creation table, one entry per thread. */ THD_TABLE_BEGIN - THD_TABLE_ENTRY(waThread1, "blinker1", Thread1, NULL) - THD_TABLE_ENTRY(waThread2, "blinker2", Thread2, NULL) - THD_TABLE_ENTRY(wa_test_support, "test_support", test_support, (void *)&nil.threads[3]) - THD_TABLE_ENTRY(waThread3, "tester", Thread3, NULL) + THD_TABLE_THREAD(0, "blinker1", waThread1, Thread1, NULL) + THD_TABLE_THREAD(1, "blinker2", waThread2, Thread2, NULL) + THD_TABLE_THREAD(2, "test_support", wa_test_support, test_support, (void *)&nil.threads[3]) + THD_TABLE_THREAD(3, "tester", waThread3, Thread3, NULL) THD_TABLE_END /* diff --git a/demos/STM32/NIL-STM32F373-STM32373C_EVAL/cfg/chconf.h b/demos/STM32/NIL-STM32F373-STM32373C_EVAL/cfg/chconf.h index 5a9f9864e..05c357d36 100644 --- a/demos/STM32/NIL-STM32F373-STM32373C_EVAL/cfg/chconf.h +++ b/demos/STM32/NIL-STM32F373-STM32373C_EVAL/cfg/chconf.h @@ -29,7 +29,7 @@ #define CHCONF_H #define _CHIBIOS_NIL_CONF_ -#define _CHIBIOS_NIL_CONF_VER_3_2_ +#define _CHIBIOS_NIL_CONF_VER_4_0_ /*===========================================================================*/ /** @@ -39,11 +39,20 @@ /*===========================================================================*/ /** - * @brief Number of user threads in the application. + * @brief Maximum number of user threads in the application. * @note This number is not inclusive of the idle thread which is - * Implicitly handled. + * implicitly handled. + * @note Set this value to be exactly equal to the number of threads you + * will use or you would be wasting RAM and cycles. + * @note This values also defines the number of available priorities + * (0..CH_CFG_MAX_THREADS-1). */ -#define CH_CFG_NUM_THREADS 3 +#define CH_CFG_MAX_THREADS 3 + +/** + * @brief Auto starts threads when @p chSysInit() is invoked. + */ +#define CH_CFG_AUTOSTART_THREADS TRUE /** @} */ @@ -87,6 +96,15 @@ */ /*===========================================================================*/ +/** + * @brief Threads synchronization APIs. + * @details If enabled then the @p chThdWait() function is included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_WAITEXIT TRUE + /** * @brief Semaphores APIs. * @details If enabled then the Semaphores APIs are included in the kernel. @@ -292,10 +310,8 @@ /** * @brief System initialization hook. */ -#if !defined(CH_CFG_SYSTEM_INIT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_INIT_HOOK() { \ } -#endif /** * @brief Threads descriptor structure extension. @@ -311,6 +327,12 @@ /* Add custom threads initialization code here.*/ \ } +/** + * @brief Threads finalization hook. + * @details User finalization code added to the @p chThdExit() API. + */ +#define CH_CFG_THREAD_EXIT_HOOK(tp) {} + /** * @brief Idle thread enter hook. * @note This hook is invoked within a critical zone, no OS functions @@ -332,10 +354,8 @@ /** * @brief System halt hook. */ -#if !defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_HALT_HOOK(reason) { \ } -#endif /** @} */ diff --git a/demos/STM32/NIL-STM32F373-STM32373C_EVAL/main.c b/demos/STM32/NIL-STM32F373-STM32373C_EVAL/main.c index 97aa17258..33281f2f6 100644 --- a/demos/STM32/NIL-STM32F373-STM32373C_EVAL/main.c +++ b/demos/STM32/NIL-STM32F373-STM32373C_EVAL/main.c @@ -72,13 +72,12 @@ THD_FUNCTION(Thread3, arg) { } /* - * Threads static table, one entry per thread. The number of entries must - * match NIL_CFG_NUM_THREADS. + * Threads creation table, one entry per thread. */ THD_TABLE_BEGIN - THD_TABLE_ENTRY(waThread1, "blinker1", Thread1, NULL) - THD_TABLE_ENTRY(waThread2, "blinker2", Thread2, NULL) - THD_TABLE_ENTRY(waThread3, "hello", Thread3, NULL) + THD_TABLE_THREAD(0, "blinker1", waThread1, Thread1, NULL) + THD_TABLE_THREAD(1, "blinker2", waThread2, Thread2, NULL) + THD_TABLE_THREAD(2, "hello", waThread3, Thread3, NULL) THD_TABLE_END /* diff --git a/demos/STM32/NIL-STM32F746G-DISCOVERY/cfg/chconf.h b/demos/STM32/NIL-STM32F746G-DISCOVERY/cfg/chconf.h index ae3504075..6023b0458 100644 --- a/demos/STM32/NIL-STM32F746G-DISCOVERY/cfg/chconf.h +++ b/demos/STM32/NIL-STM32F746G-DISCOVERY/cfg/chconf.h @@ -29,7 +29,7 @@ #define CHCONF_H #define _CHIBIOS_NIL_CONF_ -#define _CHIBIOS_NIL_CONF_VER_3_2_ +#define _CHIBIOS_NIL_CONF_VER_4_0_ /*===========================================================================*/ /** @@ -39,11 +39,20 @@ /*===========================================================================*/ /** - * @brief Number of user threads in the application. + * @brief Maximum number of user threads in the application. * @note This number is not inclusive of the idle thread which is - * Implicitly handled. + * implicitly handled. + * @note Set this value to be exactly equal to the number of threads you + * will use or you would be wasting RAM and cycles. + * @note This values also defines the number of available priorities + * (0..CH_CFG_MAX_THREADS-1). */ -#define CH_CFG_NUM_THREADS 3 +#define CH_CFG_MAX_THREADS 3 + +/** + * @brief Auto starts threads when @p chSysInit() is invoked. + */ +#define CH_CFG_AUTOSTART_THREADS TRUE /** @} */ @@ -87,6 +96,15 @@ */ /*===========================================================================*/ +/** + * @brief Threads synchronization APIs. + * @details If enabled then the @p chThdWait() function is included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_WAITEXIT TRUE + /** * @brief Semaphores APIs. * @details If enabled then the Semaphores APIs are included in the kernel. @@ -292,10 +310,8 @@ /** * @brief System initialization hook. */ -#if !defined(CH_CFG_SYSTEM_INIT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_INIT_HOOK() { \ } -#endif /** * @brief Threads descriptor structure extension. @@ -311,6 +327,12 @@ /* Add custom threads initialization code here.*/ \ } +/** + * @brief Threads finalization hook. + * @details User finalization code added to the @p chThdExit() API. + */ +#define CH_CFG_THREAD_EXIT_HOOK(tp) {} + /** * @brief Idle thread enter hook. * @note This hook is invoked within a critical zone, no OS functions @@ -332,10 +354,8 @@ /** * @brief System halt hook. */ -#if !defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_HALT_HOOK(reason) { \ } -#endif /** @} */ diff --git a/demos/STM32/NIL-STM32F746G-DISCOVERY/main.c b/demos/STM32/NIL-STM32F746G-DISCOVERY/main.c index 4af9b94a5..68295e948 100644 --- a/demos/STM32/NIL-STM32F746G-DISCOVERY/main.c +++ b/demos/STM32/NIL-STM32F746G-DISCOVERY/main.c @@ -68,13 +68,12 @@ THD_FUNCTION(Thread2, arg) { } /* - * Threads static table, one entry per thread. The number of entries must - * match CH_CFG_NUM_THREADS. + * Threads creation table, one entry per thread. */ THD_TABLE_BEGIN - THD_TABLE_ENTRY(waThread1, "blinker1", Thread1, NULL) - THD_TABLE_ENTRY(wa_test_support, "test_support", test_support, (void *)&nil.threads[2]) - THD_TABLE_ENTRY(waThread2, "tester", Thread2, NULL) + THD_TABLE_THREAD(0, "blinker1", waThread1, Thread1, NULL) + THD_TABLE_THREAD(1, "test_support", wa_test_support, test_support, (void *)&nil.threads[2]) + THD_TABLE_THREAD(2, "tester", waThread2, Thread2, NULL) THD_TABLE_END /* diff --git a/demos/STM32/NIL-STM32L011K4-NUCLEO32/cfg/chconf.h b/demos/STM32/NIL-STM32L011K4-NUCLEO32/cfg/chconf.h index 30bb03926..e2632018d 100644 --- a/demos/STM32/NIL-STM32L011K4-NUCLEO32/cfg/chconf.h +++ b/demos/STM32/NIL-STM32L011K4-NUCLEO32/cfg/chconf.h @@ -29,7 +29,7 @@ #define CHCONF_H #define _CHIBIOS_NIL_CONF_ -#define _CHIBIOS_NIL_CONF_VER_3_2_ +#define _CHIBIOS_NIL_CONF_VER_4_0_ /*===========================================================================*/ /** @@ -39,11 +39,20 @@ /*===========================================================================*/ /** - * @brief Number of user threads in the application. + * @brief Maximum number of user threads in the application. * @note This number is not inclusive of the idle thread which is - * Implicitly handled. + * implicitly handled. + * @note Set this value to be exactly equal to the number of threads you + * will use or you would be wasting RAM and cycles. + * @note This values also defines the number of available priorities + * (0..CH_CFG_MAX_THREADS-1). */ -#define CH_CFG_NUM_THREADS 2 +#define CH_CFG_MAX_THREADS 2 + +/** + * @brief Auto starts threads when @p chSysInit() is invoked. + */ +#define CH_CFG_AUTOSTART_THREADS TRUE /** @} */ @@ -87,6 +96,15 @@ */ /*===========================================================================*/ +/** + * @brief Threads synchronization APIs. + * @details If enabled then the @p chThdWait() function is included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_WAITEXIT TRUE + /** * @brief Semaphores APIs. * @details If enabled then the Semaphores APIs are included in the kernel. @@ -292,10 +310,8 @@ /** * @brief System initialization hook. */ -#if !defined(CH_CFG_SYSTEM_INIT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_INIT_HOOK() { \ } -#endif /** * @brief Threads descriptor structure extension. @@ -311,6 +327,12 @@ /* Add custom threads initialization code here.*/ \ } +/** + * @brief Threads finalization hook. + * @details User finalization code added to the @p chThdExit() API. + */ +#define CH_CFG_THREAD_EXIT_HOOK(tp) {} + /** * @brief Idle thread enter hook. * @note This hook is invoked within a critical zone, no OS functions @@ -332,10 +354,8 @@ /** * @brief System halt hook. */ -#if !defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_HALT_HOOK(reason) { \ } -#endif /** @} */ diff --git a/demos/STM32/NIL-STM32L011K4-NUCLEO32/main.c b/demos/STM32/NIL-STM32L011K4-NUCLEO32/main.c index 5eba0e1d1..d7b6ff836 100644 --- a/demos/STM32/NIL-STM32L011K4-NUCLEO32/main.c +++ b/demos/STM32/NIL-STM32L011K4-NUCLEO32/main.c @@ -51,12 +51,11 @@ THD_FUNCTION(Thread2, arg) { /* - * Threads static table, one entry per thread. The number of entries must - * match NIL_CFG_NUM_THREADS. + * Threads creation table, one entry per thread. */ THD_TABLE_BEGIN - THD_TABLE_ENTRY(waThread1, "blinker", Thread1, NULL) - THD_TABLE_ENTRY(waThread2, "hello", Thread2, NULL) + THD_TABLE_THREAD(0, "blinker", waThread1, Thread1, NULL) + THD_TABLE_THREAD(1, "hello", waThread2, Thread2, NULL) THD_TABLE_END /* diff --git a/demos/STM32/NIL-STM32L152-DISCOVERY/cfg/chconf.h b/demos/STM32/NIL-STM32L152-DISCOVERY/cfg/chconf.h index bfe1f8841..080b196cb 100644 --- a/demos/STM32/NIL-STM32L152-DISCOVERY/cfg/chconf.h +++ b/demos/STM32/NIL-STM32L152-DISCOVERY/cfg/chconf.h @@ -29,7 +29,7 @@ #define CHCONF_H #define _CHIBIOS_NIL_CONF_ -#define _CHIBIOS_NIL_CONF_VER_3_2_ +#define _CHIBIOS_NIL_CONF_VER_4_0_ /*===========================================================================*/ /** @@ -39,11 +39,20 @@ /*===========================================================================*/ /** - * @brief Number of user threads in the application. + * @brief Maximum number of user threads in the application. * @note This number is not inclusive of the idle thread which is - * Implicitly handled. + * implicitly handled. + * @note Set this value to be exactly equal to the number of threads you + * will use or you would be wasting RAM and cycles. + * @note This values also defines the number of available priorities + * (0..CH_CFG_MAX_THREADS-1). */ -#define CH_CFG_NUM_THREADS 3 +#define CH_CFG_MAX_THREADS 3 + +/** + * @brief Auto starts threads when @p chSysInit() is invoked. + */ +#define CH_CFG_AUTOSTART_THREADS TRUE /** @} */ @@ -87,6 +96,15 @@ */ /*===========================================================================*/ +/** + * @brief Threads synchronization APIs. + * @details If enabled then the @p chThdWait() function is included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_WAITEXIT TRUE + /** * @brief Semaphores APIs. * @details If enabled then the Semaphores APIs are included in the kernel. @@ -292,10 +310,8 @@ /** * @brief System initialization hook. */ -#if !defined(CH_CFG_SYSTEM_INIT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_INIT_HOOK() { \ } -#endif /** * @brief Threads descriptor structure extension. @@ -311,6 +327,12 @@ /* Add custom threads initialization code here.*/ \ } +/** + * @brief Threads finalization hook. + * @details User finalization code added to the @p chThdExit() API. + */ +#define CH_CFG_THREAD_EXIT_HOOK(tp) {} + /** * @brief Idle thread enter hook. * @note This hook is invoked within a critical zone, no OS functions @@ -332,10 +354,8 @@ /** * @brief System halt hook. */ -#if !defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_HALT_HOOK(reason) { \ } -#endif /** @} */ diff --git a/demos/STM32/NIL-STM32L152-DISCOVERY/main.c b/demos/STM32/NIL-STM32L152-DISCOVERY/main.c index 1703fdbcf..a8336f5fa 100644 --- a/demos/STM32/NIL-STM32L152-DISCOVERY/main.c +++ b/demos/STM32/NIL-STM32L152-DISCOVERY/main.c @@ -72,13 +72,12 @@ THD_FUNCTION(Thread3, arg) { } /* - * Threads static table, one entry per thread. The number of entries must - * match NIL_CFG_NUM_THREADS. + * Threads creation table, one entry per thread. */ THD_TABLE_BEGIN - THD_TABLE_ENTRY(waThread1, "blinker1", Thread1, NULL) - THD_TABLE_ENTRY(waThread2, "blinker2", Thread2, NULL) - THD_TABLE_ENTRY(waThread3, "hello", Thread3, NULL) + THD_TABLE_THREAD(0, "blinker1", waThread1, Thread1, NULL) + THD_TABLE_THREAD(1, "blinker2", waThread2, Thread2, NULL) + THD_TABLE_THREAD(2, "hello", waThread3, Thread3, NULL) THD_TABLE_END /* diff --git a/demos/various/NIL-ARMCM0-GENERIC/cfg/chconf.h b/demos/various/NIL-ARMCM0-GENERIC/cfg/chconf.h index a9f28f1ad..f2634e84d 100644 --- a/demos/various/NIL-ARMCM0-GENERIC/cfg/chconf.h +++ b/demos/various/NIL-ARMCM0-GENERIC/cfg/chconf.h @@ -29,7 +29,7 @@ #define CHCONF_H #define _CHIBIOS_NIL_CONF_ -#define _CHIBIOS_NIL_CONF_VER_3_2_ +#define _CHIBIOS_NIL_CONF_VER_4_0_ /*===========================================================================*/ /** @@ -39,11 +39,20 @@ /*===========================================================================*/ /** - * @brief Number of user threads in the application. + * @brief Maximum number of user threads in the application. * @note This number is not inclusive of the idle thread which is - * Implicitly handled. + * implicitly handled. + * @note Set this value to be exactly equal to the number of threads you + * will use or you would be wasting RAM and cycles. + * @note This values also defines the number of available priorities + * (0..CH_CFG_MAX_THREADS-1). */ -#define CH_CFG_NUM_THREADS 2 +#define CH_CFG_MAX_THREADS 4 + +/** + * @brief Auto starts threads when @p chSysInit() is invoked. + */ +#define CH_CFG_AUTOSTART_THREADS TRUE /** @} */ @@ -87,6 +96,15 @@ */ /*===========================================================================*/ +/** + * @brief Threads synchronization APIs. + * @details If enabled then the @p chThdWait() function is included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_WAITEXIT TRUE + /** * @brief Semaphores APIs. * @details If enabled then the Semaphores APIs are included in the kernel. @@ -292,10 +310,8 @@ /** * @brief System initialization hook. */ -#if !defined(CH_CFG_SYSTEM_INIT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_INIT_HOOK() { \ } -#endif /** * @brief Threads descriptor structure extension. @@ -311,6 +327,12 @@ /* Add custom threads initialization code here.*/ \ } +/** + * @brief Threads finalization hook. + * @details User finalization code added to the @p chThdExit() API. + */ +#define CH_CFG_THREAD_EXIT_HOOK(tp) {} + /** * @brief Idle thread enter hook. * @note This hook is invoked within a critical zone, no OS functions @@ -332,10 +354,8 @@ /** * @brief System halt hook. */ -#if !defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_HALT_HOOK(reason) { \ } -#endif /** @} */ diff --git a/demos/various/NIL-ARMCM0-GENERIC/main.c b/demos/various/NIL-ARMCM0-GENERIC/main.c index 1f27d36a7..9eb3a5de2 100644 --- a/demos/various/NIL-ARMCM0-GENERIC/main.c +++ b/demos/various/NIL-ARMCM0-GENERIC/main.c @@ -66,12 +66,11 @@ static THD_FUNCTION(Thread2, arg) { } /* - * Threads static table, one entry per thread. The number of entries must - * match NIL_CFG_NUM_THREADS. + * Threads creation table, one entry per thread. */ THD_TABLE_BEGIN -THD_TABLE_ENTRY(waThread1, "counter1", Thread1, NULL) -THD_TABLE_ENTRY(waThread2, "counter2", Thread2, NULL) + THD_TABLE_THREAD(0, "counter1", waThread1, Thread1, NULL) + THD_TABLE_THREAD(1, "counter2", waThread2, Thread2, NULL) THD_TABLE_END /* diff --git a/demos/various/NIL-ARMCM4-GENERIC/cfg/chconf.h b/demos/various/NIL-ARMCM4-GENERIC/cfg/chconf.h index a9f28f1ad..f2634e84d 100644 --- a/demos/various/NIL-ARMCM4-GENERIC/cfg/chconf.h +++ b/demos/various/NIL-ARMCM4-GENERIC/cfg/chconf.h @@ -29,7 +29,7 @@ #define CHCONF_H #define _CHIBIOS_NIL_CONF_ -#define _CHIBIOS_NIL_CONF_VER_3_2_ +#define _CHIBIOS_NIL_CONF_VER_4_0_ /*===========================================================================*/ /** @@ -39,11 +39,20 @@ /*===========================================================================*/ /** - * @brief Number of user threads in the application. + * @brief Maximum number of user threads in the application. * @note This number is not inclusive of the idle thread which is - * Implicitly handled. + * implicitly handled. + * @note Set this value to be exactly equal to the number of threads you + * will use or you would be wasting RAM and cycles. + * @note This values also defines the number of available priorities + * (0..CH_CFG_MAX_THREADS-1). */ -#define CH_CFG_NUM_THREADS 2 +#define CH_CFG_MAX_THREADS 4 + +/** + * @brief Auto starts threads when @p chSysInit() is invoked. + */ +#define CH_CFG_AUTOSTART_THREADS TRUE /** @} */ @@ -87,6 +96,15 @@ */ /*===========================================================================*/ +/** + * @brief Threads synchronization APIs. + * @details If enabled then the @p chThdWait() function is included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_WAITEXIT TRUE + /** * @brief Semaphores APIs. * @details If enabled then the Semaphores APIs are included in the kernel. @@ -292,10 +310,8 @@ /** * @brief System initialization hook. */ -#if !defined(CH_CFG_SYSTEM_INIT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_INIT_HOOK() { \ } -#endif /** * @brief Threads descriptor structure extension. @@ -311,6 +327,12 @@ /* Add custom threads initialization code here.*/ \ } +/** + * @brief Threads finalization hook. + * @details User finalization code added to the @p chThdExit() API. + */ +#define CH_CFG_THREAD_EXIT_HOOK(tp) {} + /** * @brief Idle thread enter hook. * @note This hook is invoked within a critical zone, no OS functions @@ -332,10 +354,8 @@ /** * @brief System halt hook. */ -#if !defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_HALT_HOOK(reason) { \ } -#endif /** @} */ diff --git a/demos/various/NIL-ARMCM4-GENERIC/main.c b/demos/various/NIL-ARMCM4-GENERIC/main.c index 1f27d36a7..9eb3a5de2 100644 --- a/demos/various/NIL-ARMCM4-GENERIC/main.c +++ b/demos/various/NIL-ARMCM4-GENERIC/main.c @@ -66,12 +66,11 @@ static THD_FUNCTION(Thread2, arg) { } /* - * Threads static table, one entry per thread. The number of entries must - * match NIL_CFG_NUM_THREADS. + * Threads creation table, one entry per thread. */ THD_TABLE_BEGIN -THD_TABLE_ENTRY(waThread1, "counter1", Thread1, NULL) -THD_TABLE_ENTRY(waThread2, "counter2", Thread2, NULL) + THD_TABLE_THREAD(0, "counter1", waThread1, Thread1, NULL) + THD_TABLE_THREAD(1, "counter2", waThread2, Thread2, NULL) THD_TABLE_END /* diff --git a/os/common/ports/ARM/compilers/GCC/chcoreasm.S b/os/common/ports/ARM/compilers/GCC/chcoreasm.S index 6e9a849da..f4f435dbc 100644 --- a/os/common/ports/ARM/compilers/GCC/chcoreasm.S +++ b/os/common/ports/ARM/compilers/GCC/chcoreasm.S @@ -158,15 +158,9 @@ _port_thread_start: mov r0, r5 mov lr, pc bx r4 -#if defined(_CHIBIOS_RT_CONF_) mov r0, #0 /* MSG_OK */ bl chThdExit _zombies: b _zombies -#endif -#if defined(_CHIBIOS_NIL_CONF_) - mov r0, #0 - bl chSysHalt -#endif #endif /* !defined(__DOXYGEN__) */ diff --git a/os/common/ports/ARMCAx-TZ/compilers/GCC/chcoreasm.S b/os/common/ports/ARMCAx-TZ/compilers/GCC/chcoreasm.S index e79b791ad..91b019400 100644 --- a/os/common/ports/ARMCAx-TZ/compilers/GCC/chcoreasm.S +++ b/os/common/ports/ARMCAx-TZ/compilers/GCC/chcoreasm.S @@ -160,15 +160,9 @@ _port_thread_start: mov r0, r5 mov lr, pc bx r4 -#if defined(_CHIBIOS_RT_CONF_) mov r0, #0 /* MSG_OK */ bl chThdExit _zombies: b _zombies -#endif -#if defined(_CHIBIOS_NIL_CONF_) - mov r0, #0 - bl chSysHalt -#endif #endif /* !defined(__DOXYGEN__) */ diff --git a/os/common/ports/ARMCMx/compilers/GCC/chcoreasm_v6m.S b/os/common/ports/ARMCMx/compilers/GCC/chcoreasm_v6m.S index 23c421680..115559e70 100644 --- a/os/common/ports/ARMCMx/compilers/GCC/chcoreasm_v6m.S +++ b/os/common/ports/ARMCMx/compilers/GCC/chcoreasm_v6m.S @@ -106,14 +106,9 @@ _port_thread_start: cpsie i mov r0, r5 blx r4 -#if defined(_CHIBIOS_RT_CONF_) movs r0, #0 /* MSG_OK */ bl chThdExit -#endif -#if defined(_CHIBIOS_NIL_CONF_) - mov r3, #0 - bl chSysHalt -#endif +_zombies: b _zombies /*--------------------------------------------------------------------------* * Post-IRQ switch code. diff --git a/os/common/ports/ARMCMx/compilers/GCC/chcoreasm_v7m.S b/os/common/ports/ARMCMx/compilers/GCC/chcoreasm_v7m.S index db3f675ea..e67e10c05 100644 --- a/os/common/ports/ARMCMx/compilers/GCC/chcoreasm_v7m.S +++ b/os/common/ports/ARMCMx/compilers/GCC/chcoreasm_v7m.S @@ -117,14 +117,9 @@ _port_thread_start: #endif mov r0, r5 blx r4 -#if defined(_CHIBIOS_RT_CONF_) movs r0, #0 /* MSG_OK */ bl chThdExit -#endif -#if defined(_CHIBIOS_NIL_CONF_) - mov r3, #0 - bl chSysHalt -#endif +_zombies: b _zombies /*--------------------------------------------------------------------------* * Post-IRQ switch code. diff --git a/os/common/ports/ARMCMx/compilers/IAR/chcoreasm_v6m.s b/os/common/ports/ARMCMx/compilers/IAR/chcoreasm_v6m.s index ff22fdb94..ff9c59179 100644 --- a/os/common/ports/ARMCMx/compilers/IAR/chcoreasm_v6m.s +++ b/os/common/ports/ARMCMx/compilers/IAR/chcoreasm_v6m.s @@ -111,14 +111,9 @@ _port_thread_start: cpsie i mov r0, r5 blx r4 -#if defined(_CHIBIOS_RT_CONF_) movs r0, #0 /* MSG_OK */ bl chThdExit -#endif -#if defined(_CHIBIOS_NIL_CONF_) - mov r3, #0 - bl chSysHalt -#endif +_zombies: b _zombies /* * Post-IRQ switch code. diff --git a/os/common/ports/ARMCMx/compilers/IAR/chcoreasm_v7m.s b/os/common/ports/ARMCMx/compilers/IAR/chcoreasm_v7m.s index 0b330e8d3..d01b91350 100644 --- a/os/common/ports/ARMCMx/compilers/IAR/chcoreasm_v7m.s +++ b/os/common/ports/ARMCMx/compilers/IAR/chcoreasm_v7m.s @@ -121,14 +121,9 @@ _port_thread_start: #endif mov r0, r5 blx r4 -#if defined(_CHIBIOS_RT_CONF_) movs r0, #0 /* MSG_OK */ bl chThdExit -#endif -#if defined(_CHIBIOS_NIL_CONF_) - mov r3, #0 - bl chSysHalt -#endif +_zombies: b _zombies /* * Post-IRQ switch code. diff --git a/os/common/ports/ARMCMx/compilers/RVCT/chcoreasm_v6m.s b/os/common/ports/ARMCMx/compilers/RVCT/chcoreasm_v6m.s index f0daef294..578493507 100644 --- a/os/common/ports/ARMCMx/compilers/RVCT/chcoreasm_v6m.s +++ b/os/common/ports/ARMCMx/compilers/RVCT/chcoreasm_v6m.s @@ -106,14 +106,9 @@ _port_thread_start PROC cpsie i mov r0, r5 blx r4 -#if defined(_CHIBIOS_RT_CONF_) movs r0, #0 /* MSG_OK */ bl chThdExit -#endif -#if defined(_CHIBIOS_NIL_CONF_) - mov r3, #0 - bl chSysHalt -#endif +_zombies b _zombies ENDP /* diff --git a/os/common/ports/ARMCMx/compilers/RVCT/chcoreasm_v7m.s b/os/common/ports/ARMCMx/compilers/RVCT/chcoreasm_v7m.s index 6f536c2c2..905c5fa0b 100644 --- a/os/common/ports/ARMCMx/compilers/RVCT/chcoreasm_v7m.s +++ b/os/common/ports/ARMCMx/compilers/RVCT/chcoreasm_v7m.s @@ -116,14 +116,9 @@ _port_thread_start PROC #endif mov r0, r5 blx r4 -#if defined(_CHIBIOS_RT_CONF_) movs r0, #0 /* MSG_OK */ bl chThdExit -#endif -#if defined(_CHIBIOS_NIL_CONF_) - mov r3, #0 - bl chSysHalt -#endif +_zombies b _zombies ENDP /* diff --git a/os/common/ports/AVR/chcore.c b/os/common/ports/AVR/chcore.c index 9a62b6b67..f75b12e63 100644 --- a/os/common/ports/AVR/chcore.c +++ b/os/common/ports/AVR/chcore.c @@ -153,12 +153,7 @@ void _port_thread_start(void) { asm volatile ("movw r24, r4"); asm volatile ("movw r30, r2"); asm volatile ("icall"); -#if defined(_CHIBIOS_RT_) asm volatile ("call chThdExit"); /* Used for avr5 Architecture. */ -#endif -#if defined(_CHIBIOS_NIL_) - asm volatile ("call chSysHalt"); /* Used for avr5 Architecture. */ -#endif } /** @} */ diff --git a/os/common/ports/e200/compilers/CW/chcoreasm.s b/os/common/ports/e200/compilers/CW/chcoreasm.s index e39646a5e..5e5528110 100644 --- a/os/common/ports/e200/compilers/CW/chcoreasm.s +++ b/os/common/ports/e200/compilers/CW/chcoreasm.s @@ -105,14 +105,8 @@ _port_thread_start: mr r3, r31 mtctr r30 se_bctrl -#if defined(_CHIBIOS_RT_CONF_) se_li r0, 0 e_bl chThdExit -#endif -#if defined(_CHIBIOS_NIL_CONF_) - se_li r0, 0 - e_bl chSysHalt -#endif #else /* PPC_USE_VLE == FALSE */ diff --git a/os/common/ports/e200/compilers/GCC/chcoreasm.S b/os/common/ports/e200/compilers/GCC/chcoreasm.S index a0e527266..4b312382d 100644 --- a/os/common/ports/e200/compilers/GCC/chcoreasm.S +++ b/os/common/ports/e200/compilers/GCC/chcoreasm.S @@ -105,14 +105,8 @@ _port_thread_start: mr r3, r31 mtctr r30 se_bctrl -#if defined(_CHIBIOS_RT_CONF_) e_li r0, 0 e_bl chThdExit -#endif -#if defined(_CHIBIOS_NIL_CONF_) - se_li r0, 0 - e_bl chSysHalt -#endif #endif /* !defined(__DOXYGEN__) */ diff --git a/os/common/ports/e200/compilers/GHS/chcoreasm.s b/os/common/ports/e200/compilers/GHS/chcoreasm.s index 1f4cc05a6..9d49a7de2 100644 --- a/os/common/ports/e200/compilers/GHS/chcoreasm.s +++ b/os/common/ports/e200/compilers/GHS/chcoreasm.s @@ -99,14 +99,8 @@ _port_thread_start: mr r3, r31 mtctr r30 se_bctrl -#if defined(_CHIBIOS_RT_CONF_) e_li r0, 0 e_bl chThdExit -#endif -#if defined(_CHIBIOS_NIL_CONF_) - se_li r0, 0 - e_bl chSysHalt -#endif #endif /* !defined(__DOXYGEN__) */ diff --git a/os/nil/include/ch.h b/os/nil/include/ch.h index b50158260..75a89766f 100644 --- a/os/nil/include/ch.h +++ b/os/nil/include/ch.h @@ -55,17 +55,17 @@ /** * @brief Kernel version string. */ -#define CH_KERNEL_VERSION "3.2.0" +#define CH_KERNEL_VERSION "4.0.0" /** * @brief Kernel version major number. */ -#define CH_KERNEL_MAJOR 3 +#define CH_KERNEL_MAJOR 4 /** * @brief Kernel version minor number. */ -#define CH_KERNEL_MINOR 2 +#define CH_KERNEL_MINOR 0 /** * @brief Kernel version patch number. @@ -81,7 +81,7 @@ * @note It is meant to be used in configuration files as switch. */ #if !defined(FALSE) || defined(__DOXYGEN__) -#define FALSE 0 +#define FALSE 0 #endif /** @@ -89,7 +89,7 @@ * @note It is meant to be used in configuration files as switch. */ #if !defined(TRUE) || defined(__DOXYGEN__) -#define TRUE 1 +#define TRUE 1 #endif /** @} */ @@ -137,17 +137,31 @@ * @name Thread state related macros * @{ */ -#define NIL_STATE_READY (tstate_t)0 /**< @brief Thread ready or +#define NIL_STATE_WTSTART (tstate_t)0 /**< @brief Thread not yet + started or terminated. */ +#define NIL_STATE_READY (tstate_t)1 /**< @brief Thread ready or executing. */ -#define NIL_STATE_SLEEPING (tstate_t)1 /**< @brief Thread sleeping. */ -#define NIL_STATE_SUSP (tstate_t)2 /**< @brief Thread suspended. */ -#define NIL_STATE_WTQUEUE (tstate_t)3 /**< @brief On queue or semaph. */ -#define NIL_STATE_WTOREVT (tstate_t)4 /**< @brief Waiting for events. */ -#define NIL_THD_IS_READY(tp) ((tp)->state == NIL_STATE_READY) -#define NIL_THD_IS_SLEEPING(tp) ((tp)->state == NIL_STATE_SLEEPING) -#define NIL_THD_IS_SUSP(tp) ((tp)->state == NIL_STATE_SUSP) -#define NIL_THD_IS_WTQUEUE(tp) ((tp)->state == NIL_STATE_WTQUEUE) -#define NIL_THD_IS_WTOREVT(tp) ((tp)->state == NIL_STATE_WTOREVT) +#define NIL_STATE_SLEEPING (tstate_t)2 /**< @brief Thread sleeping. */ +#define NIL_STATE_SUSPENDED (tstate_t)3 /**< @brief Thread suspended. */ +#define NIL_STATE_WTEXIT (tstate_t)4 /**< @brief Waiting a thread. */ +#define NIL_STATE_WTQUEUE (tstate_t)5 /**< @brief On queue or semaph. */ +#define NIL_STATE_WTOREVT (tstate_t)6 /**< @brief Waiting for events. */ +#define NIL_STATE_WTANDEVT (tstate_t)7 /**< @brief Waiting for events. */ +#define NIL_STATE_FINAL (tstate_t)8 /**< @brief Thread terminated. */ + +#define NIL_THD_IS_WTSTART(tp) ((tp)->state == NIL_STATE_WTSTART) +#define NIL_THD_IS_READY(tp) ((tp)->state == NIL_STATE_READY) +#define NIL_THD_IS_SLEEPING(tp) ((tp)->state == NIL_STATE_SLEEPING) +#define NIL_THD_IS_SUSPENDED(tp) ((tp)->state == NIL_STATE_SUSPENDED) +#define NIL_THD_IS_WTEXIT(tp) ((tp)->state == NIL_STATE_WTEXIT) +#define NIL_THD_IS_WTQUEUE(tp) ((tp)->state == NIL_STATE_WTQUEUE) +#define NIL_THD_IS_WTOREVT(tp) ((tp)->state == NIL_STATE_WTOREVT) +#define NIL_THD_IS_WTANDEVT(tp) ((tp)->state == NIL_STATE_WTANDEVT) +#define NIL_THD_IS_FINAL(tp) ((tp)->state == NIL_STATE_FINAL) + +#define CH_STATE_NAMES \ + "WTSTART", "READY", "SLEEPING", "SUSPENDED", "WTEXIT", "WTQUEUE", \ + "WTOREVT", "WTANDEVT", "FINAL" /** @} */ /** @@ -170,12 +184,23 @@ /*===========================================================================*/ /*-* - * @brief Number of user threads in the application. + * @brief Maximum number of user threads in the application. * @note This number is not inclusive of the idle thread which is * implicitly handled. + * @note Set this value to be exactly equal to the number of threads you + * will use or you would be wasting RAM and cycles. + * @note This values also defines the number of available priorities + * (0..CH_CFG_MAX_THREADS-1). */ -#if !defined(CH_CFG_NUM_THREADS) || defined(__DOXYGEN__) -#define CH_CFG_NUM_THREADS 2 +#if !defined(CH_CFG_MAX_THREADS) || defined(__DOXYGEN__) +#define CH_CFG_MAX_THREADS 2 +#endif + +/*-* + * @brief Auto starts threads when @p chSysInit() is invoked. + */ +#if !defined(CH_CFG_AUTOSTART_THREADS) || defined(__DOXYGEN__) +#define CH_CFG_AUTOSTART_THREADS TRUE #endif /*-* @@ -208,6 +233,17 @@ #define CH_CFG_ST_TIMEDELTA 0 #endif +/*-* + * @brief Threads synchronization APIs. + * @details If enabled then the @p chThdWait() function is included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#if !defined(CH_CFG_USE_WAITEXIT) +#define CH_CFG_USE_WAITEXIT TRUE +#endif + /*-* * @brief Semaphores APIs. * @details If enabled then the Semaphores APIs are included in the kernel. @@ -283,7 +319,8 @@ #if !defined(CH_CFG_USE_MEMPOOLS) || defined(__DOXYGEN__) #define CH_CFG_USE_MEMPOOLS TRUE #endif -/** + +/*-* * @brief Objects Factory APIs. * @details If enabled then the objects factory APIs are included in the * kernel. @@ -294,7 +331,7 @@ #define CH_CFG_USE_FACTORY TRUE #endif -/** +/*-* * @brief Maximum length for object names. * @details If the specified length is zero then the name is stored by * pointer but this could have unintended side effects. @@ -303,41 +340,52 @@ #define CH_CFG_FACTORY_MAX_NAMES_LENGTH 8 #endif -/** +/*-* * @brief Enables the registry of generic objects. */ #if !defined(CH_CFG_FACTORY_OBJECTS_REGISTRY) || defined(__DOXYGEN__) #define CH_CFG_FACTORY_OBJECTS_REGISTRY TRUE #endif -/** +/*-* * @brief Enables factory for generic buffers. */ #if !defined(CH_CFG_FACTORY_GENERIC_BUFFERS) || defined(__DOXYGEN__) #define CH_CFG_FACTORY_GENERIC_BUFFERS TRUE #endif -/** +/*-* * @brief Enables factory for semaphores. */ #if !defined(CH_CFG_FACTORY_SEMAPHORES) || defined(__DOXYGEN__) #define CH_CFG_FACTORY_SEMAPHORES TRUE #endif -/** +/*-* * @brief Enables factory for mailboxes. */ #if !defined(CH_CFG_FACTORY_MAILBOXES) || defined(__DOXYGEN__) #define CH_CFG_FACTORY_MAILBOXES TRUE #endif -/** +/*-* * @brief Enables factory for objects FIFOs. */ #if !defined(CH_CFG_FACTORY_OBJ_FIFOS) || defined(__DOXYGEN__) #define CH_CFG_FACTORY_OBJ_FIFOS TRUE #endif +/*-* + * @brief Pipes APIs. + * @details If enabled then the pipes APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + */ +#if !defined(CH_CFG_USE_PIPES) || defined(__DOXYGEN__) +#define CH_CFG_USE_PIPES TRUE +#endif + /*-* * @brief Debug option, kernel statistics. * @@ -407,6 +455,14 @@ #define CH_CFG_THREAD_EXT_INIT_HOOK(tp) {} #endif +/*-* + * @brief Threads finalization hook. + * @details User finalization code added to the @p chThdExit() API. + */ +#if !defined(CH_CFG_THREAD_EXIT_HOOK) || defined(__DOXYGEN__) +#define CH_CFG_THREAD_EXIT_HOOK(tp) {} +#endif + /*-* * @brief Idle thread enter hook. * @note This hook is invoked within a critical zone, no OS functions @@ -479,15 +535,15 @@ #error "missing or wrong configuration file" #endif -#if !defined(_CHIBIOS_NIL_CONF_VER_3_2_) +#if !defined(_CHIBIOS_NIL_CONF_VER_4_0_) #error "obsolete or unknown configuration file" #endif -#if CH_CFG_NUM_THREADS < 1 +#if CH_CFG_MAX_THREADS < 1 #error "at least one thread must be defined" #endif -#if CH_CFG_NUM_THREADS > 16 +#if CH_CFG_MAX_THREADS > 16 #error "ChibiOS/NIL is not recommended for thread-intensive applications," \ "consider ChibiOS/RT instead" #endif @@ -562,20 +618,31 @@ typedef uint16_t sysinterval_t; typedef uint32_t time_conv_t; #endif +/** + * @brief Type of a structure representing the system. + */ +typedef struct nil_system nil_system_t; + +/** + * @brief Thread function. + */ +typedef void (*tfunc_t)(void *p); + +/** + * @brief Type of a structure representing a thread static configuration. + */ +typedef struct nil_thread_cfg thread_config_t; + /** * @brief Type of a structure representing a thread. * @note It is required as an early definition. */ typedef struct nil_thread thread_t; -#include "chcore.h" - /** - * @brief Structure representing a queue of threads. + * @brief Type of a thread reference. */ -struct nil_threads_queue { - volatile cnt_t cnt; /**< @brief Threads Queue counter. */ -}; +typedef thread_t * thread_reference_t; /** * @brief Type of a queue of threads. @@ -591,45 +658,43 @@ typedef struct nil_threads_queue threads_queue_t; typedef threads_queue_t semaphore_t; #endif /* CH_CFG_USE_SEMAPHORES == TRUE */ -/** - * @brief Thread function. - */ -typedef void (*tfunc_t)(void *p); +/* Late inclusion of port core layer.*/ +#include "chcore.h" /** - * @brief Type of a structure representing a thread static configuration. + * @brief Structure representing a queue of threads. */ -typedef struct nil_thread_cfg thread_config_t; +struct nil_threads_queue { + volatile cnt_t cnt; /**< @brief Threads Queue counter. */ +}; /** * @brief Structure representing a thread static configuration. */ struct nil_thread_cfg { + tprio_t prio; /**< @brief Thread priority slot. */ + const char *namep; /**< @brief Thread name, for debugging. */ stkalign_t *wbase; /**< @brief Thread working area base. */ stkalign_t *wend; /**< @brief Thread working area end. */ - const char *namep; /**< @brief Thread name, for debugging. */ tfunc_t funcp; /**< @brief Thread function. */ void *arg; /**< @brief Thread function argument. */ }; -/** - * @brief Type of a thread reference. - */ -typedef thread_t * thread_reference_t; - /** * @brief Structure representing a thread. */ struct nil_thread { struct port_context ctx; /**< @brief Processor context. */ tstate_t state; /**< @brief Thread state. */ - /* Note, the following union contains a pointer while the thread is in a - sleeping state (!NIL_THD_IS_READY()) else contains the wake-up message.*/ + /* Note, the following union contains a pointer/value while the thread is + in a sleeping state or a wake-up message when the thread is made ready.*/ union { msg_t msg; /**< @brief Wake-up message. */ void *p; /**< @brief Generic pointer. */ + nil_system_t *nsp; /**< @brief Pointer to nil base struct. */ thread_reference_t *trp; /**< @brief Pointer to thread reference.*/ threads_queue_t *tqp; /**< @brief Pointer to thread queue. */ + thread_t *tp; /**< @brief Pointer to thread. */ #if (CH_CFG_USE_SEMAPHORES == TRUE) || defined(__DOXYGEN__) semaphore_t *semp; /**< @brief Pointer to semaphore. */ #endif @@ -649,11 +714,6 @@ struct nil_thread { CH_CFG_THREAD_EXT_FIELDS }; -/** - * @brief Type of a structure representing the system. - */ -typedef struct nil_system nil_system_t; - /** * @brief System data structure. * @note This structure contain all the data areas used by the OS except @@ -709,7 +769,7 @@ struct nil_system { /** * @brief Thread structures for all the defined threads. */ - thread_t threads[CH_CFG_NUM_THREADS + 1]; + thread_t threads[CH_CFG_MAX_THREADS + 1]; }; /*===========================================================================*/ @@ -734,20 +794,21 @@ struct nil_system { * @brief Start of user threads table. */ #define THD_TABLE_BEGIN \ - const thread_config_t nil_thd_configs[CH_CFG_NUM_THREADS + 1] = { + const thread_config_t nil_thd_configs[] = { /** * @brief Entry of user threads table */ -#define THD_TABLE_ENTRY(wap, name, funcp, arg) \ - {wap, ((stkalign_t *)(wap)) + (sizeof (wap) / sizeof(stkalign_t)), \ - name, funcp, arg}, +#define THD_TABLE_THREAD(prio, name, wap, funcp, arg) \ + {prio, name, \ + wap, ((stkalign_t *)(wap)) + (sizeof (wap) / sizeof(stkalign_t)), \ + funcp, arg}, /** * @brief End of user threads table. */ #define THD_TABLE_END \ - {THD_IDLE_BASE, THD_IDLE_END, "idle", NULL, NULL} \ + {CH_CFG_MAX_THREADS, "idle", THD_IDLE_BASE, THD_IDLE_END, NULL, NULL} \ }; /** @} */ @@ -1304,7 +1365,7 @@ struct nil_system { * * @init */ -#define chSemObjectInit(sp, n) ((sp)->cnt = (n)) +#define chSemObjectInit(sp, n) ((sp)->cnt = n) /** * @brief Performs a wait operation on a semaphore. @@ -1509,7 +1570,7 @@ struct nil_system { extern stkalign_t __main_thread_stack_base__, __main_thread_stack_end__; #endif extern nil_system_t nil; -extern const thread_config_t nil_thd_configs[CH_CFG_NUM_THREADS + 1]; +extern const thread_config_t nil_thd_configs[]; #endif #ifdef __cplusplus @@ -1529,6 +1590,12 @@ extern "C" { void chSchDoReschedule(void); void chSchRescheduleS(void); msg_t chSchGoSleepTimeoutS(tstate_t newstate, sysinterval_t timeout); + thread_t *chThdCreateI(const thread_config_t *tcp); + thread_t *chThdCreate(const thread_config_t *tcp); + void chThdExit(msg_t msg); +#if CH_CFG_USE_WAITEXIT == TRUE + msg_t chThdWait(thread_t *tp); +#endif msg_t chThdSuspendTimeoutS(thread_reference_t *trp, sysinterval_t timeout); void chThdResumeI(thread_reference_t *trp, msg_t msg); void chThdResume(thread_reference_t *trp, msg_t msg); @@ -1550,6 +1617,7 @@ extern "C" { void chEvtSignal(thread_t *tp, eventmask_t mask); void chEvtSignalI(thread_t *tp, eventmask_t mask); eventmask_t chEvtWaitAnyTimeout(eventmask_t mask, sysinterval_t timeout); + eventmask_t chEvtWaitAllTimeout(eventmask_t mask, sysinterval_t timeout); #endif #if CH_DBG_SYSTEM_STATE_CHECK == TRUE void _dbg_check_disable(void); diff --git a/os/nil/src/ch.c b/os/nil/src/ch.c index 0777c3d10..233a3f4ae 100644 --- a/os/nil/src/ch.c +++ b/os/nil/src/ch.c @@ -55,7 +55,6 @@ nil_system_t nil; * * @param[in] state thread state * @param[in] p object pointer - * @return Pointer to the thread. */ static thread_t *nil_find_thread(tstate_t state, void * p) { thread_t *tp = nil.threads; @@ -67,7 +66,7 @@ static thread_t *nil_find_thread(tstate_t state, void * p) { } tp++; - chDbgAssert(tp < &nil.threads[CH_CFG_NUM_THREADS], + chDbgAssert(tp < &nil.threads[CH_CFG_MAX_THREADS], "pointer out of range"); } } @@ -80,14 +79,15 @@ static thread_t *nil_find_thread(tstate_t state, void * p) { * @param[in] cnt number of threads to be readied as a negative number, * non negative numbers are ignored * @param[in] msg the wakeup message - * @return Always zero. + * + * @iclass */ static cnt_t nil_ready_all(void * p, cnt_t cnt, msg_t msg) { thread_t *tp = nil.threads;; while (cnt < (cnt_t)0) { - chDbgAssert(tp < &nil.threads[CH_CFG_NUM_THREADS], + chDbgAssert(tp < &nil.threads[CH_CFG_MAX_THREADS], "pointer out of range"); /* Is this thread waiting on this queue?*/ @@ -271,47 +271,10 @@ void chDbgCheckClassS(void) { * @special */ void chSysInit(void) { - thread_t *tp; const thread_config_t *tcp; -#if CH_DBG_SYSTEM_STATE_CHECK == TRUE - nil.isr_cnt = (cnt_t)0; - nil.lock_cnt = (cnt_t)0; -#endif - - /* System initialization hook.*/ - CH_CFG_SYSTEM_INIT_HOOK(); - - /* Iterates through the list of defined threads.*/ - tp = &nil.threads[0]; - tcp = nil_thd_configs; - while (tp < &nil.threads[CH_CFG_NUM_THREADS]) { -#if CH_DBG_ENABLE_STACK_CHECK - tp->wabase = (stkalign_t *)tcp->wbase; -#endif - - /* Port dependent thread initialization.*/ - PORT_SETUP_CONTEXT(tp, tcp->wbase, tcp->wend, tcp->funcp, tcp->arg); - - /* Initialization hook.*/ - CH_CFG_THREAD_EXT_INIT_HOOK(tp); - - tp++; - tcp++; - } - -#if CH_DBG_ENABLE_STACK_CHECK - /* The idle thread is a special case because its stack is set up by the - runtime environment.*/ - tp->wabase = THD_IDLE_BASE; -#endif - - /* Interrupts partially enabled. It is equivalent to entering the - kernel critical zone.*/ - chSysSuspend(); -#if CH_DBG_SYSTEM_STATE_CHECK == TRUE - nil.lock_cnt = (cnt_t)1; -#endif + /* Architecture layer initialization.*/ + port_init(); /* Memory core initialization, if enabled.*/ #if CH_CFG_USE_MEMCORE == TRUE @@ -328,14 +291,37 @@ void chSysInit(void) { _factory_init(); #endif - /* Port layer initialization last because it depend on some of the - initializations performed before.*/ - port_init(); + /* System initialization hook.*/ + CH_CFG_SYSTEM_INIT_HOOK(); - /* Runs the highest priority thread, the current one becomes the idle - thread.*/ - nil.current = nil.next = nil.threads; - port_switch(nil.current, tp); + /* Making idle the current thread, this may change after rescheduling.*/ + nil.next = nil.current = &nil.threads[CH_CFG_MAX_THREADS]; + nil.current->state = NIL_STATE_READY; + +#if CH_DBG_ENABLE_STACK_CHECK == TRUE + /* The idle thread is a special case because its stack is set up by the + runtime environment.*/ + nil.threads[CH_CFG_MAX_THREADS].wabase = THD_IDLE_BASE; +#endif + + /* Interrupts partially enabled. It is equivalent to entering the + kernel critical zone.*/ + chSysSuspend(); +#if CH_DBG_SYSTEM_STATE_CHECK == TRUE + nil.lock_cnt = (cnt_t)1; +#endif + +#if CH_CFG_AUTOSTART_THREADS == TRUE + /* Iterates through the list of threads to be auto-started.*/ + tcp = nil_thd_configs; + do { + chThdCreateI(tcp); + tcp++; + } while (tcp->funcp != NULL); +#endif + + /* Starting the dance.*/ + chSchRescheduleS(); chSysUnlock(); } @@ -397,7 +383,7 @@ void chSysTimerHandlerI(void) { if (NIL_THD_IS_WTQUEUE(tp)) { tp->u1.semp->cnt++; } - else if (NIL_THD_IS_SUSP(tp)) { + else if (NIL_THD_IS_SUSPENDED(tp)) { *tp->u1.trp = NULL; } /*lint -restore*/ @@ -409,7 +395,7 @@ void chSysTimerHandlerI(void) { chSysUnlockFromISR(); tp++; chSysLockFromISR(); - } while (tp < &nil.threads[CH_CFG_NUM_THREADS]); + } while (tp < &nil.threads[CH_CFG_MAX_THREADS]); #else thread_t *tp = &nil.threads[0]; sysinterval_t next = (sysinterval_t)0; @@ -437,7 +423,7 @@ void chSysTimerHandlerI(void) { tp->u1.tqp->cnt++; } else { - if (NIL_THD_IS_SUSP(tp)) { + if (NIL_THD_IS_SUSPENDED(tp)) { *tp->u1.trp = NULL; } } @@ -455,7 +441,7 @@ void chSysTimerHandlerI(void) { chSysUnlockFromISR(); tp++; chSysLockFromISR(); - } while (tp < &nil.threads[CH_CFG_NUM_THREADS]); + } while (tp < &nil.threads[CH_CFG_MAX_THREADS]); nil.lasttime = nil.nexttime; if (next > (sysinterval_t)0) { @@ -601,7 +587,7 @@ void chSysPolledDelayX(rtcnt_t cycles) { thread_t *chSchReadyI(thread_t *tp, msg_t msg) { chDbgCheckClassI(); - chDbgCheck((tp >= nil.threads) && (tp < &nil.threads[CH_CFG_NUM_THREADS])); + chDbgCheck((tp >= nil.threads) && (tp < &nil.threads[CH_CFG_MAX_THREADS])); chDbgAssert(!NIL_THD_IS_READY(tp), "already ready"); chDbgAssert(nil.next <= nil.current, "priority ordering"); @@ -643,7 +629,7 @@ void chSchDoReschedule(void) { thread_t *otp = nil.current; nil.current = nil.next; - if (otp == &nil.threads[CH_CFG_NUM_THREADS]) { + if (otp == &nil.threads[CH_CFG_MAX_THREADS]) { CH_CFG_IDLE_LEAVE_HOOK(); } port_switch(nil.next, otp); @@ -685,7 +671,7 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, sysinterval_t timeout) { chDbgCheckClassS(); - chDbgAssert(otp != &nil.threads[CH_CFG_NUM_THREADS], + chDbgAssert(otp != &nil.threads[CH_CFG_MAX_THREADS], "idle cannot sleep"); /* Storing the wait object for the current thread.*/ @@ -733,7 +719,7 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, sysinterval_t timeout) { /* Is this thread ready to execute?*/ if (NIL_THD_IS_READY(ntp)) { nil.current = nil.next = ntp; - if (ntp == &nil.threads[CH_CFG_NUM_THREADS]) { + if (ntp == &nil.threads[CH_CFG_MAX_THREADS]) { CH_CFG_IDLE_ENTER_HOOK(); } port_switch(ntp, otp); @@ -742,11 +728,142 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, sysinterval_t timeout) { /* Points to the next thread in lowering priority order.*/ ntp++; - chDbgAssert(ntp <= &nil.threads[CH_CFG_NUM_THREADS], + chDbgAssert(ntp <= &nil.threads[CH_CFG_MAX_THREADS], "pointer out of range"); } } +/** + * @brief Creates a new thread into a static memory area. + * @details The new thread is initialized and make ready to execute. + * @note A thread can terminate by calling @p chThdExit() or by simply + * returning from its main function. + * + * @param[out] tcp pointer to the thread configuration structure + * @return The pointer to the @p thread_t structure allocated for + * the thread. + * + * @iclass + */ +thread_t *chThdCreateI(const thread_config_t *tcp) { + thread_t *tp; + + chDbgCheck(tcp->prio < CH_CFG_MAX_THREADS); + chDbgCheckClassI(); + + /* Pointer to the thread slot to be used.*/ + tp = &nil.threads[tcp->prio]; + chDbgAssert(NIL_THD_IS_WTSTART(tp) || NIL_THD_IS_FINAL(tp), + "priority slot taken"); + +#if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || defined(__DOXYGEN__) + tp->wabase = (stkalign_t *)tcp->wbase; +#endif + + /* Port dependent thread initialization.*/ + PORT_SETUP_CONTEXT(tp, tcp->wbase, tcp->wend, tcp->funcp, tcp->arg); + + /* Initialization hook.*/ + CH_CFG_THREAD_EXT_INIT_HOOK(tp); + + /* Readying up thread.*/ + return chSchReadyI(tp, MSG_OK); +} + + +/** + * @brief Creates a new thread into a static memory area. + * @details The new thread is initialized and make ready to execute. + * @note A thread can terminate by calling @p chThdExit() or by simply + * returning from its main function. + * + * @param[out] tcp pointer to the thread configuration structure + * @return The pointer to the @p thread_t structure allocated for + * the thread. + * + * @api + */ +thread_t *chThdCreate(const thread_config_t *tcp) { + thread_t *tp; + + chSysLock(); + tp = chThdCreateI(tcp); + chSchRescheduleS(); + chSysUnlock(); + + return tp; +} + +/** + * @brief Terminates the current thread. + * @details The thread goes in the @p CH_STATE_FINAL state holding the + * specified exit status code, other threads can retrieve the + * exit status code by invoking the function @p chThdWait(). + * @post Exiting a non-static thread that does not have references + * (detached) causes the thread to remain in the registry. + * It can only be removed by performing a registry scan operation. + * @post Eventual code after this function will never be executed, + * this function never returns. The compiler has no way to + * know this so do not assume that the compiler would remove + * the dead code. + * + * @param[in] msg thread exit code + * + * @api + */ +void chThdExit(msg_t msg) { + + chSysLock(); + + /* Exit handler hook.*/ + CH_CFG_THREAD_EXIT_HOOK(tp); + +#if CH_CFG_USE_WAITEXIT == TRUE + { + /* Waking up any waiting thread.*/ + thread_t *tp = nil.threads; + while (tp < &nil.threads[CH_CFG_MAX_THREADS]) { + /* Is this thread waiting for current thread termination?*/ + if ((tp->state == NIL_STATE_WTEXIT) && (tp->u1.tp == nil.current)) { + (void) chSchReadyI(tp, msg); + } + tp++; + } + } +#endif + + /* Going into final state with exit message stored.*/ + chSchGoSleepTimeoutS(NIL_STATE_FINAL, msg); + + /* The thread never returns here.*/ + chDbgAssert(false, "zombies apocalypse"); +} + +/** + * @brief Blocks the execution of the invoking thread until the specified + * thread terminates then the exit code is returned. + * + * @param[in] tp pointer to the thread + * @return The exit code from the terminated thread. + * + * @api + */ +msg_t chThdWait(thread_t *tp) { + msg_t msg; + + chSysLock(); + if (NIL_THD_IS_FINAL(tp)) { + msg = tp->u1.msg; + } + else { + nil.current->u1.tp = tp; + msg = chSchGoSleepTimeoutS(NIL_STATE_WTEXIT, TIME_INFINITE); + } + chSysUnlock(); + + return msg; +} + /** * @brief Sends the current thread sleeping and sets a reference variable. * @note This function must reschedule, it can only be called from thread @@ -755,8 +872,8 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, sysinterval_t timeout) { * @param[in] trp a pointer to a thread reference object * @param[in] timeout the number of ticks before the operation timeouts, * the following special values are allowed: - * - @a TIME_INFINITE no timeout. * - @a TIME_IMMEDIATE immediate timeout. + * - @a TIME_INFINITE no timeout. * . * @return The wake up message. * @@ -772,7 +889,7 @@ msg_t chThdSuspendTimeoutS(thread_reference_t *trp, sysinterval_t timeout) { *trp = nil.current; nil.current->u1.trp = trp; - return chSchGoSleepTimeoutS(NIL_STATE_SUSP, timeout); + return chSchGoSleepTimeoutS(NIL_STATE_SUSPENDED, timeout); } /** @@ -790,7 +907,7 @@ void chThdResumeI(thread_reference_t *trp, msg_t msg) { if (*trp != NULL) { thread_reference_t tr = *trp; - chDbgAssert(NIL_THD_IS_SUSP(tr), "not suspended"); + chDbgAssert(NIL_THD_IS_SUSPENDED(tr), "not suspended"); *trp = NULL; (void) chSchReadyI(tr, msg); @@ -852,8 +969,8 @@ void chThdSleepUntil(systime_t abstime) { * @param[in] tqp pointer to the threads queue object * @param[in] timeout the timeout in system ticks, the special values are * handled as follow: - * - @a TIME_INFINITE no timeout. * - @a TIME_IMMEDIATE immediate timeout. + * - @a TIME_INFINITE no timeout. * . * @return The message from @p osalQueueWakeupOneI() or * @p osalQueueWakeupAllI() functions. @@ -943,8 +1060,8 @@ void chThdDequeueAllI(threads_queue_t *tqp, msg_t msg) { * @param[in] sp pointer to a @p semaphore_t structure * @param[in] timeout the number of ticks before the operation timeouts, * the following special values are allowed: - * - @a TIME_INFINITE no timeout. * - @a TIME_IMMEDIATE immediate timeout. + * - @a TIME_INFINITE no timeout. * . * @return A message specifying how the invoking thread has been * released from the semaphore. @@ -972,8 +1089,8 @@ msg_t chSemWaitTimeout(semaphore_t *sp, sysinterval_t timeout) { * @param[in] sp pointer to a @p semaphore_t structure * @param[in] timeout the number of ticks before the operation timeouts, * the following special values are allowed: - * - @a TIME_INFINITE no timeout. * - @a TIME_IMMEDIATE immediate timeout. + * - @a TIME_INFINITE no timeout. * . * @return A message specifying how the invoking thread has been * released from the semaphore. @@ -1130,8 +1247,10 @@ void chEvtSignalI(thread_t *tp, eventmask_t mask) { chDbgCheck(tp != NULL); tp->epmask |= mask; - if (NIL_THD_IS_WTOREVT(tp) && - ((tp->epmask & tp->u1.ewmask) != (eventmask_t)0)) { + if ((NIL_THD_IS_WTOREVT(tp) && + ((tp->epmask & tp->u1.ewmask) != (eventmask_t)0)) || + (NIL_THD_IS_WTANDEVT(tp) && + ((tp->epmask & tp->u1.ewmask) == tp->u1.ewmask))) { (void) chSchReadyI(tp, MSG_OK); } } @@ -1146,8 +1265,8 @@ void chEvtSignalI(thread_t *tp, eventmask_t mask) { * for, @p ALL_EVENTS enables all the events * @param[in] timeout the number of ticks before the operation timeouts, * the following special values are allowed: - * - @a TIME_INFINITE no timeout. * - @a TIME_IMMEDIATE immediate timeout. + * - @a TIME_INFINITE no timeout. * . * @return The mask of the served and cleared events. * @retval 0 if the operation has timed out. @@ -1178,6 +1297,46 @@ eventmask_t chEvtWaitAnyTimeout(eventmask_t mask, sysinterval_t timeout) { return m; } + +/** + * @brief Waits for all the specified events. + * @details The function waits for all the events specified in @p mask to + * become pending then the events are cleared and returned. + * + * @param[in] mask mask of the event flags that the function should wait + * for, @p ALL_EVENTS enables all the events + * @param[in] timeout the number of ticks before the operation timeouts, + * the following special values are allowed: + * - @a TIME_IMMEDIATE immediate timeout. + * - @a TIME_INFINITE no timeout. + * . + * @return The mask of the served and cleared events. + * @retval 0 if the operation has timed out. + * + * @api + */ +eventmask_t chEvtWaitAllTimeout(eventmask_t mask, sysinterval_t timeout) { + thread_t *ctp = nil.current; + + chSysLock(); + if ((ctp->epmask & mask) != mask) { + if (TIME_IMMEDIATE == timeout) { + chSysUnlock(); + + return (eventmask_t)0; + } + ctp->u1.ewmask = mask; + if (chSchGoSleepTimeoutS(NIL_STATE_WTANDEVT, timeout) < MSG_OK) { + chSysUnlock(); + + return (eventmask_t)0; + } + } + ctp->epmask &= ~mask; + chSysUnlock(); + + return mask; +} #endif /* CH_CFG_USE_EVENTS == TRUE */ /** @} */ diff --git a/os/nil/templates/chconf.h b/os/nil/templates/chconf.h index 7efabe727..fc1d98a74 100644 --- a/os/nil/templates/chconf.h +++ b/os/nil/templates/chconf.h @@ -29,7 +29,7 @@ #define CHCONF_H #define _CHIBIOS_NIL_CONF_ -#define _CHIBIOS_NIL_CONF_VER_3_2_ +#define _CHIBIOS_NIL_CONF_VER_4_0_ /*===========================================================================*/ /** @@ -39,11 +39,20 @@ /*===========================================================================*/ /** - * @brief Number of user threads in the application. + * @brief Maximum number of user threads in the application. * @note This number is not inclusive of the idle thread which is - * Implicitly handled. + * implicitly handled. + * @note Set this value to be exactly equal to the number of threads you + * will use or you would be wasting RAM and cycles. + * @note This values also defines the number of available priorities + * (0..CH_CFG_MAX_THREADS-1). */ -#define CH_CFG_NUM_THREADS 3 +#define CH_CFG_MAX_THREADS 4 + +/** + * @brief Auto starts threads when @p chSysInit() is invoked. + */ +#define CH_CFG_AUTOSTART_THREADS TRUE /** @} */ @@ -87,6 +96,15 @@ */ /*===========================================================================*/ +/** + * @brief Threads synchronization APIs. + * @details If enabled then the @p chThdWait() function is included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_WAITEXIT TRUE + /** * @brief Semaphores APIs. * @details If enabled then the Semaphores APIs are included in the kernel. @@ -292,10 +310,8 @@ /** * @brief System initialization hook. */ -#if !defined(CH_CFG_SYSTEM_INIT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_INIT_HOOK() { \ } -#endif /** * @brief Threads descriptor structure extension. @@ -311,6 +327,12 @@ /* Add custom threads initialization code here.*/ \ } +/** + * @brief Threads finalization hook. + * @details User finalization code added to the @p chThdExit() API. + */ +#define CH_CFG_THREAD_EXIT_HOOK(tp) {} + /** * @brief Idle thread enter hook. * @note This hook is invoked within a critical zone, no OS functions @@ -332,10 +354,8 @@ /** * @brief System halt hook. */ -#if !defined(CH_CFG_SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) #define CH_CFG_SYSTEM_HALT_HOOK(reason) { \ } -#endif /** @} */ diff --git a/readme.txt b/readme.txt index 2945230c7..f35048c07 100644 --- a/readme.txt +++ b/readme.txt @@ -74,271 +74,4 @@ ***************************************************************************** *** Next *** -- NEW: Added a sanity check on GCC version for ARMv6-M, a version below 6 - must be used. -- NEW: Removed deprecated EXT driver. -- NEW: Added a new function chMtxGetOwnerI() to RT mutexes subsystem. -- NEW: STM32L433 added to STM32L4xx HAL. -- CHG: chFifoObjectInit() renamed to chFifoObjectInitAligned(). Added a new - chFifoObjectInit() without the alignment parameter. -- NEW: Stricter alignment checks in memory pools. -- NEW: Added chvsnprintf(). -- NEW: Event enable check API added to PAL driver. -- NEW: Now it is possible to define separate directories for each - configuration file. -- NEW: Added option to enable bypass on SDIOv1 driver allowing to use a - 50MHz clock. -- NEW: Added TIM15, TIM16 and TIM17 support on GPT, ICU and PWM drivers, - limited to STM32F3, L4 and L4+ platforms. -- NEW: STM32H7xx and STM32L4+ ports reworked to support dynamic DMA - allocation. Updated all drivers to use the new DMA API. -- NEW: Both DMAv1 and DMAv2 have been reworked to support DMAMUX, DMAv3 has - been removed. In addition, both drivers are now able to support dynamic - channel allocation. -- NEW: The callback of drivers with circular buffers (ADC, DAC, I2S, SPI) has - been simplified, no parameters. A driver function xxxIsBufferComplete() - has been added to determine if it is the half buffer callback or the - final callback. -- NEW: ADC driver state machine change, now the state ADC_COMPLETE is set - before calling the 2nd callback even in circular mode. This has been - done for consistency with other drivers with circular buffers. -- NEW: Low level drivers simplification. There is a new template of LLD, now - driver and configuration types are defined in the HLD, LLD just exports - macros with the fields to be added to the structures. - So far the drivers updated are: ADC, DAC, I2S, RTC, SPI, TRNG, WSPI. -- NEW: Added UART7/8 support to STM32 UART USARTv1 driver. -- NEW: Added persistent storage interface to the STM32 RTCv2 driver. -- NEW: STM32 RTCv2 driver now supports callbacks on events. -- NEW: Added an EXTI helper driver for STM32. -- NEW: Added demo for STM32L4R9I-Discovery board. -- NEW: Support for new serial NOR device MX25LM51245G. Other Macronix devices - should work but not tested. -- NEW: Serial NOR flash infrastructure reworked and made simpler. -- NEW_ Modified the RTC driver to implement the persistent storage interface - instead of files interface. -- NEW: Added a new "persistent storage" base class to HAL. -- NEW: Added support for TIM21 and TIM22 in STM32 GPT driver. -- NEW: Reinforced checks in TIM-related drivers. -- NEW: Added support for STM32L072 and STM32L073. -- NEW: Added chThdResume() function to NIL. -- NEW: Removed QSPI driver model, entirely replaced by WSPI. -- NEW: Added demos regarding WSPI, serial nor driver and MFS. -- NEW: Modified the serial nor driver to work with WSPI instead of QSPI, - improved it in several way, simplicity mainly. -- NEW: Added an STM32 QUADSPIv1 implementation for WSPI. -- NEW: Added a new WSPI driver model to HAL, it is a redesign of the - existing QSPI for generic "Wide SPI" interfaces. It now supports up - to eight data lines so "quad" was no more appropriate. -- NEW: Added a new SIO driver model to HAL, it is a low level abstraction of - an UART. -- NEW: Added separate "load key" functions for each algorithm in the CRY - driver. Each "engine" is supposed to have its own transient key. -- NEW: Removed TRNG functionality from CRY driver, it is a separate thing now. -- NEW: Independent TRNG driver model added to HAL. Implemented a RNGv1 driver - for STM32, added test application. -- NEW: Added a new "pipes" subsystem to the OS library. -- NEW: Added mcuconf.h generators for STM32L432xx, STM32L476xx, STM32L496xx, - STM32L4Rxxx, STM32F72x/73x, STM32F746/756, STM32F76x/77x, STM32F413xx - and STM32F303xx devices. -- NEW: Added demo for STM32L496ZG-Nucleo144 and STM32L4R5ZI-Nucleo144 boards. -- NEW: Modified USARTv2 to support HW FIFOs where present. -- NEW: STM32 DMAv1, ADCv3, DACv1, I2Cv2, SPIv2 and USARTv2 are now - DMAMUX-aware. -- NEW: Introduced support for STM32L4+ devices. -- NEW: TRNG API now takes a new "size" parameter, the API can now generate - random numbers of variable size. The crypto driver now does not store - a copy of the transient key inside, the low level can do that if - required. -- NEW: Added analog watchdog functionality to STM32 ADCv2 driver. -- NEW: Added a termination check to the shell. -- NEW: Updated CMSIS to version 5.4.0. -- NEW: Now chconf.h files have preprocessor checks around each definition, - this allows to override settings from makefiles. -- NEW: Added new functions to I/O queues: qSetLink()(backported to 18.2.2). -- NEW: Added new functions to objects fifos: chFifoReturnObjectS()(backported - to 18.2.2), - chFifoSendObjectAheadI(), chFifoSendObjectAheadS() and - chFifoSendObjectAhead()(backported to 18.2.2). -- NEW: Added new functions to guarded pools: chGuardedPoolFreeS() and - chGuardedPoolAddS(). -- NEW: Added initializer sections for flash0...flash7 memory areas in - GCC Cortex-M linker scripts. -- NEW: Added support for oversampling in STM32 ADCv3 driver. -- NEW: Restructured the STM32F4xx HAL support, added support for STM32F413, - added ability to handle the TIMPRE bit, separated the clock tree in - two distinct implementation to reduce the proliferation of compiler - time conditionals, added more checks to the input parameters. -- NEW: Added optional support for character match callback in the UART - high level driver. -- NEW: Change, chMtxGetNextMutexS() renamed to chMtxGetNextMutexX(). -- NEW: RT C++ wrapper reworked, now it is mostly inline code, added some new - wrappers and methods. Added wrappers for more API functions. BaseThreads - are no more descendants of ThreadReference. -- NEW: Updated STM32L4xx headers to version 1.11.0. -- NEW: Added HAL support for STM32L443. -- NEW: Added support for LDM303AGR 6 axis Accelerometer\Magnetometer MEMS. -- NEW: Added support for LSM6DSL 6 axis Accelerometer\Gyroscope MEMS. -- NEW: Added support for LPS22HB 2 axis Barometer\Thermometer MEMS. -- NEW: Separated OSLIB from RT and NIL, now it is a separate "product" with - its own version, configuration file and licensing. The library will - grow to include more functionalities. - RT and NIL will contain only the core functionalities, everything else - is shared library code. -- EX. Global version number moved to 1.1.0. -- EX: Updated HTS221 to 1.1.1 (backported to 18.2.2). -- EX: Updated L3GD20 to 1.1.1 (backported to 18.2.2). -- EX: Updated LIS3DSH to 1.1.1 (backported to 18.2.2). -- EX: Updated LIS3MDL to 1.1.1 (backported to 18.2.2). -- EX: Updated LPS25H to 1.1.1 (backported to 18.2.2). -- EX: Updated LSM303DLHC to 1.1.1 (backported to 18.2.2). -- EX: Updated LSM6DS0 to 1.1.1 (backported to 18.2.2). -- EX: Updated HTS221 to 1.1.0 (backported to 18.2.1). -- EX: Updated L3GD20 to 1.1.0 (backported to 18.2.1). -- EX: Updated LIS3DSH to 1.1.0 (backported to 18.2.1). -- EX: Updated LIS3MDL to 1.1.0 (backported to 18.2.1). -- EX: Updated LIS302DL to 1.1.0 (backported to 18.2.1). -- EX: Updated LPS25H to 1.1.0 (backported to 18.2.1). -- EX: Updated LSM303DLHC to 1.1.0 (backported to 18.2.1). -- HAL: Fixed STM32 ST driver problem in free running mode (bug #1003) - (backported to 18.2.3 and 17.6.5). -- HAL: Fixed invalid checks in STM32H7 HAL (bug #1000) - (backported to 18.2.2). -- OTH: Fixed problem in STM32H743 GCC linker file (bug #998) - (backported to 18.2.2). -- HAL: Fixed extra parenthesis in STM32F4 registry (bug #997) - (backported to 18.2.2 and 17.6.5). -- HAL: Fixed timing problem in STM32 OTGv1 driver (bug #996) - (backported to 18.2.2 and 17.6.5). -- HAL: Fixed restrictive check in MMC-SPI driver (bug #995) - (backported to 18.2.2 and 17.6.5). -- HAL: Fixed misplaced check in STM32 ST driver (bug #994) - (backported to 18.2.2 and 17.6.5). -- OTH: Fixed ARM CMx vectors table without thumb bit set for unused vectors - (bug #993)(backported to 18.2.2). -- HAL: Fixed STM32F7xx I2SPLL not fully initialized (bug #992) - (backported to 18.2.2 and 17.6.5). -- BLD: Fixed PRE_MAKE_ALL_RULE_HOOK is not executed before creating object - file when using multible jobs (bug #991). -- HAL: Fixed ethernet registry error for STM32F469/479 (bug #990) - (backported to 18.2.2 and 17.6.5). -- RT: Fixed bug in chEvtBroadcastFlagsI (bug #989) - (backported to 18.2.2 and 17.6.5). -- HAL: Fixed OS-Less Cortex-M HAL functionality broken (bug #987) - (backported to 18.2.2). -- HAL: Fixed broken functionality of MFS module (bug #986) - (backported to 18.2.2). -- NIL: Fixed scheduler misbehaving in rare cases (bug #983) - (backported to 18.2.2 and 17.6.5). -- NIL: Fixed function chThdSuspendTimeoutS() ignoring TIME_IMMEDIATE (bug #982) - (backported to 18.2.2 and 17.6.5). -- HAL: Fixed mTM32L071/72 entries in registry (bug #981) - (backported to 18.2.2 and 17.6.5). -- HAL: Fixed TIM3 missing from STM32L0xx RCC macros (bug #980) - (backported to 18.2.2 and 17.6.5). -- HAL: Fixed invalid STM32 ADCv3 clock selection for L4 and L4+ (bug #979) - (backported to 18.2.2 and 17.6.5). -- HAL: Fixed wrong number of endpoints fot STM32F412/413 (bug #978) - (backported to 18.2.2 and 17.6.5). -- RT: Fixed chEvtGetAndClearFlags(...) does not mask events (bug #977) - (backported to 18.2.2 and 17.6.5). -- HAL: Fixed HAL channels chnControl() macro broken (bug #976) - (backported to 18.2.2). -- OTH: Fixed wrong timeout handling in CMSIS OS layer (bug #975) - (backported to 18.2.2 and 17.6.5). -- HAL: Fixed invalid checks in STM32F37x HAL related to SDADC (bug #974) - (backported to 18.2.2 and 17.6.5). -- HAL: Fixed mii_find_phy excludes PHY address 31 (bug #971) - (backported to 18.2.2 and 17.6.5). -- HAL: Fixed option STM32_LSCOSEL not written in STM32L4 HAL (bug #970) - (backported to 18.2.2 and 17.6.5). -- HAL: Fixed invalid DFSDM1SEL option in STM32L4 HAL (bug #969)(backported - to 18.2.2 and 17.6.5). -- HAL: Fixed incorrect checks on STM32_SAI2SEL option in STM32L4 HAL - (bug #968)(backported to 18.2.2 and 17.6.5). -- HAL: Fixed incorrect handling of PDIV dividers in STM32L4 HAL (bug #967) - (backported to 18.2.2). -- HAL: Fixed documentation error in spiStop() (bug #966)(backported - to 18.2.2 and 17.6.5). -- HAL: Fixed missing parenthesis in STM32L073 registry entry (bug #965) - (backported to 18.2.2 and 17.6.5). -- HAL: Fixed problem with STM32 RTCv1 and GCC7 compiler (bug #964)(backported - to 18.2.2 and 17.6.5). -- HAL: Fixed invalid timeout calculation in hal_buffers (bug #963)(backported - to 18.2.2 and 17.6.5). -- RT: Fixed invalid parameter in CH_CFG_SYSTEM_INIT_HOOK hook macro - (bug #962)(backported to 18.2.2). -- OTH: Fixed demos failing to compile (bug #961)(backported to 18.2.2). -- HAL: Fixed issue in hal_queues (bug #960)(backported to 18.2.2). -- HAL: Fixed incorrect state change in I2S driver (bug #959)(backported - to 18.2.2 and 17.6.5). -- HAL: Fixed incorrect TCIE handling in STM32 serial drivers (bug #958) - (backported to 18.2.2 and 17.6.5). -- HAL: Fixed invalid period calculation in STM32 GPT driver (bug #957) - (backported to 18.2.2 and 17.6.5). -- HAL: Fixed missing USART7/8 definitions in STM32F0 HAL (bug #956)(backported - to 18.2.2). -- LIB: Fixed heap allocation issue (bug #955)(backported to 18.2.2 and 17.6.5). -- HAL: Fixed win32 simulator HAL broken because a typo (bug #954)(backported - to 18.2.2). -- HAL: Fixed race condition in STM32 ADCv3 driver (bug #953)(backported to - 18.2.2 and 17.6.5). -- HAL: Fixed wrong registry entries for STM32F030x4 (bug #952)(backported - to 18.2.2). -- HAL: Fixed invalid divider settings in Serial and UART STM32 drivers - when USART_CR1_OVER8 is specified (bug #951)(backported to 18.2.2 - and 17.6.5). -- NIL: Fixed missing extern declaration in IAR Cortex-M port (bug #950) - (backported to 18.2.2 and 17.6.5). -- HAL: Fixed ASCR register invalid handling in STM32 GPIOv3 driver (bug #949) - (backported to 18.2.2 and 17.6.5). -- HAL: Fixed missing definition in UART driver (bug #948)(backported - to 18.2.2). -- OTH: Fixed wrong macro check in GCC Cortex-M startup files (bug #947) - (backported to 18.2.2 and 17.6.5). -- HAL: Fixed binary instead of logic operator in STM32F4 HAL (bug #946) - (backported to 18.2.2 and 17.6.5). -- HAL: Fixed Mikroe clicker 2 misaligned board file (bug #945) - (backported to 18.2.2 and 17.6.5). -- EX: Fixed ChibiOS/EX documentation misalignments (bug #943). -- HAL: Fixed invalid settings in STM32F769I-Discovery board files (bug #942) - (backported to 18.2.1 and 17.6.5). -- OTH: Fixed short branch to _unhandled_exception in vectors.S (bug #941) - (backported to 18.2.1). -- HAL: Fixed IOBus PAL functions missing the const qualifier (bug #940) - (backported to 18.2.1 and 17.6.5). -- HAL: Fixed STM32 USBv1 driver does not reset data toggling bits on endpoint - initialization (bug #939)(backported to 18.2.1 and 17.6.5). -- HAL: Fixed incorrect behavior of USB driver on SET CONFIGURATION (bug #938) - (backported to 18.2.1 and 17.6.5). -- HAL: Fixed macro expansion problem in SPI high level driver (bug #937) - (backported to 18.2.1). -- HAL: Fixed missing CAN2 macros from STM32L4xx stm32_rcc.h file (bug #936) - (backported to 18.2.1). -- OTH: Fixed inclusion order problem in STM32L4 cmparams.h file (bug #935) - (backported to 18.2.1 and 17.6.5). -- HAL: Fixed problem clearing UIF timer flag in STM32 PWM driver (bug #934) - (backported to 18.2.1 and 17.6.5). -- HAL: Fixed USB Serial driver problem with zero-size OUT transactions - (bug #933)(backported to 18.2.1 and 17.6.5). -- HAL: Fixed race condition in STM32 QSPI driver (bug #932)(backported to - 18.2.1 and 17.6.5). -- HAL: Fixed function mfsReadRecord() causes memory corruption because a - buffer overflow (bug #931)(backported to 18.2.1). -- HAL: Fixed silence GCC 7.3.0 warning (bug #930)(backported to 18.2.1 - and 17.6.5). -- HAL: Fixed invalid SAI1 clock selection on STM32F7xx (bug #929)(backported - to 18.2.1 and 17.6.4). -- HAL: Fixed invalid clock checks for SDMMC1 and SDMMC2 on STM32F7xx - (bug #928)(backported to 18.2.1). -- HAL: Fixed useless writes in read-only CFGR_SWS field on all STM32Fxx - (bug #927)(backported to 18.2.1 and 17.6.4). -- HAL: Fixed typo in hal_pal.h (bug #926)(backported to 18.2.1). -- HAL: Fixed I2C address not accepted (bug #923)(backported to 18.2.1 - and 17.6.4). -- HAL: Fixed problem with HSI48 on STM32L4xx (bug #922)(backported to 18.2.1). -- HAL: Fixed invalid implementation of palWaitPadTimeoutS() and - palWaitLineTimeoutS() APIs (bug #921)(backported to 18.2.1). -- HAL: Fixed wrong DMA settings for STM32F76x I2C3 and I2C4 (bug #920) - (backported to 18.2.1 and 17.6.4). -- HAL: Fixed wrong flash waiting state for STM32F7xx (bug #918) - (backported to 18.2.1 and 17.6.4). +- NIL: Integrated NIL 4.0. diff --git a/test/nil/configuration.xml b/test/nil/configuration.xml index 9b98f3e72..7cee31a3f 100644 --- a/test/nil/configuration.xml +++ b/test/nil/configuration.xml @@ -245,21 +245,27 @@ test_println("");]]> -