From 138c0f900d823b2c953038048bc40b14610f958a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 21 Aug 2010 08:38:14 +0000 Subject: Added new kernel hooks (on halt and on systick). git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2136 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/include/chsys.h | 7 +++++++ os/kernel/include/chthreads.h | 4 +++- os/kernel/src/chsys.c | 3 +++ os/kernel/src/chthreads.c | 8 ++++++-- os/kernel/templates/chconf.h | 46 +++++++++++++++++++++++++++++++------------ 5 files changed, 52 insertions(+), 16 deletions(-) (limited to 'os/kernel') diff --git a/os/kernel/include/chsys.h b/os/kernel/include/chsys.h index 2f94c5209..22396f41f 100644 --- a/os/kernel/include/chsys.h +++ b/os/kernel/include/chsys.h @@ -45,7 +45,14 @@ * error in the application code that triggers an assertion while * in debug mode. */ +#if !defined(SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) #define chSysHalt() port_halt() +#else +#define chSysHalt() { \ + SYSTEM_HALT_HOOK(); \ + port_halt(); \ +} +#endif /** * @brief Performs a context switch. diff --git a/os/kernel/include/chthreads.h b/os/kernel/include/chthreads.h index 1e659b768..9748166b9 100644 --- a/os/kernel/include/chthreads.h +++ b/os/kernel/include/chthreads.h @@ -160,8 +160,10 @@ struct Thread { */ void *p_mpool; #endif +#if defined(THREAD_EXT_FIELDS_HOOK) /* Extra fields defined in chconf.h.*/ - THREAD_EXT_FIELDS + THREAD_EXT_FIELDS_HOOK +#endif }; /** @brief Thread state: Ready to run, waiting on the ready list.*/ diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index d34e7e73a..22860b317 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -117,6 +117,9 @@ void chSysTimerHandlerI(void) { currp->p_time++; #endif chVTDoTickI(); +#if defined(SYSTEM_TICK_EVENT_HOOK) + SYSTEM_TICK_EVENT_HOOK(); +#endif } #if CH_USE_NESTED_LOCKS && !CH_OPTIMIZE_SPEED diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index 3f2f88899..ae38dc11a 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -94,7 +94,9 @@ Thread *init_thread(Thread *tp, tprio_t prio) { #if CH_USE_EVENTS tp->p_epending = 0; #endif - THREAD_EXT_INIT(tp); +#if defined(THREAD_EXT_EXIT_HOOK) + THREAD_EXT_INIT_HOOK(tp); +#endif return tp; } @@ -357,7 +359,9 @@ void chThdExit(msg_t msg) { chSysLock(); tp->p_u.exitcode = msg; - THREAD_EXT_EXIT(tp); +#if defined(THREAD_EXT_EXIT_HOOK) + THREAD_EXT_EXIT_HOOK(tp); +#endif #if CH_USE_WAITEXIT while (notempty(&tp->p_waiting)) chSchReadyI(list_remove(&tp->p_waiting)); diff --git a/os/kernel/templates/chconf.h b/os/kernel/templates/chconf.h index 6522e0b3b..8f2c4b3e3 100644 --- a/os/kernel/templates/chconf.h +++ b/os/kernel/templates/chconf.h @@ -434,11 +434,9 @@ * @brief Threads descriptor structure hook. * @details User fields added to the end of the @p Thread structure. */ -#if !defined(THREAD_EXT_FIELDS) || defined(__DOXYGEN__) -#define THREAD_EXT_FIELDS \ -struct { \ - /* Add threads custom fields here.*/ \ -}; +#if !defined(THREAD_EXT_FIELDS_HOOK) || defined(__DOXYGEN__) +#define THREAD_EXT_FIELDS_HOOK \ + /* Add threads custom fields here.*/ #endif /** @@ -448,9 +446,9 @@ struct { \ * @note It is invoked from within @p chThdInit() and implicitily from all * the threads creation APIs. */ -#if !defined(THREAD_EXT_INIT) || defined(__DOXYGEN__) -#define THREAD_EXT_INIT(tp) { \ - /* Add threads initialization code here.*/ \ +#if !defined(THREAD_EXT_INIT_HOOK) || defined(__DOXYGEN__) +#define THREAD_EXT_INIT_HOOK(tp) { \ + /* Add threads initialization code here.*/ \ } #endif @@ -462,9 +460,9 @@ struct { \ * @note It is also invoked when the threads simply return in order to * terminate. */ -#if !defined(THREAD_EXT_EXIT) || defined(__DOXYGEN__) -#define THREAD_EXT_EXIT(tp) { \ - /* Add threads finalization code here.*/ \ +#if !defined(THREAD_EXT_EXIT_HOOK) || defined(__DOXYGEN__) +#define THREAD_EXT_EXIT_HOOK(tp) { \ + /* Add threads finalization code here.*/ \ } #endif @@ -473,8 +471,30 @@ struct { \ * @details This hook is continuously invoked by the idle thread loop. */ #if !defined(IDLE_LOOP_HOOK) || defined(__DOXYGEN__) -#define IDLE_LOOP_HOOK() { \ - /* Idle loop code here.*/ \ +#define IDLE_LOOP_HOOK() { \ + /* Idle loop code here.*/ \ +} +#endif + +/** + * @brief System tick event hook. + * @details This hook is invoked in the system tick handler immediately + * after processing the virtual timers queue. + */ +#if !defined(SYSTEM_TICK_EVENT_HOOK) || defined(__DOXYGEN__) +#define SYSTEM_TICK_EVENT_HOOK() { \ + /* System tick event code here.*/ \ +} +#endif + +/** + * @brief System halt hook. + * @details This hook is invoked in case to a system halting error before + * the system is halted. + */ +#if !defined(SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) +#define SYSTEM_HALT_HOOK() { \ + /* System halt code here.*/ \ } #endif -- cgit v1.2.3