From d51331c78ad8c4c5ad4769d6271cb0e06c11beb1 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 22 Aug 2012 15:11:04 +0000 Subject: [PATCH] git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4614 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/include/chregistry.h | 19 +++++++++--- os/kernel/include/chsys.h | 4 +++ os/kernel/src/chregistry.c | 57 ++++++++++++++++------------------ os/kernel/src/chsys.c | 12 +++++-- 4 files changed, 53 insertions(+), 39 deletions(-) diff --git a/os/kernel/include/chregistry.h b/os/kernel/include/chregistry.h index 2b1d35795..ad12c5dd6 100644 --- a/os/kernel/include/chregistry.h +++ b/os/kernel/include/chregistry.h @@ -40,11 +40,20 @@ typedef struct { uint8_t ch_reserved5; /**< @brief Reserved field. */ uint16_t ch_version; /**< @brief Encoded ChibiOS/RT version. */ uint8_t ch_ptrsize; /**< @brief Size of a pointer. */ - uint8_t ch_options; /**< @brief Enable options bits mask. */ - uint8_t ch_reserved10; /**< @brief Reserved field. */ - uint8_t ch_reserved11; /**< @brief Reserved field. */ - ReadyList *ch_rlist; /**< @brief Pointer to the ready list. */ - VTList *ch_vtlist; /**< @brief Pointer to the timers list. */ + uint8_t ch_timesize; /**< @brief Size of a systime_t. */ + uint8_t cf_off_prio; /**< @brief Offset of @p p_prio field. */ + uint8_t cf_off_ctx; /**< @brief Offset of @p p_ctx field. */ + uint8_t cf_off_newer; /**< @brief Offset of @p p_newer field. */ + uint8_t cf_off_older; /**< @brief Offset of @p p_older field. */ + uint8_t cf_off_name; /**< @brief Offset of @p p_name field. */ + uint8_t cf_off_stklimit; /**< @brief Offset of @p p_stklimit + field. */ + uint8_t cf_off_state; /**< @brief Offset of @p p_state field. */ + uint8_t cf_off_flags; /**< @brief Offset of @p p_flags field. */ + uint8_t cf_off_refs; /**< @brief Offset of @p p_refs field. */ + uint8_t cf_off_preempt; /**< @brief Offset of @p p_preempt + field. */ + uint8_t cf_off_time; /**< @brief Offset of @p p_time field. */ } chroot_t; /** diff --git a/os/kernel/include/chsys.h b/os/kernel/include/chsys.h index b8784719b..9e623cbd1 100644 --- a/os/kernel/include/chsys.h +++ b/os/kernel/include/chsys.h @@ -233,6 +233,10 @@ #define CH_FAST_IRQ_HANDLER(id) PORT_FAST_IRQ_HANDLER(id) /** @} */ +#if !defined(__DOXYGEN__) +extern Thread _mainthread; +#endif + #ifdef __cplusplus extern "C" { #endif diff --git a/os/kernel/src/chregistry.c b/os/kernel/src/chregistry.c index 5036a52bc..4a383a379 100644 --- a/os/kernel/src/chregistry.c +++ b/os/kernel/src/chregistry.c @@ -50,34 +50,11 @@ #if CH_USE_REGISTRY || defined(__DOXYGEN__) -/* Converting configuration options in bit masks in order to be encoded in - the global variable ch_root.*/ -#if CH_DBG_ENABLE_STACK_CHECK -#define MSK_DBG_ENABLE_STACK_CHECK 1 -#else -#define MSK_DBG_ENABLE_STACK_CHECK 0 -#endif +#define THD_OFFSET(field) (uint8_t)((size_t)&_mainthread.field - \ + (size_t)&_mainthread) -#if CH_USE_DYNAMIC -#define MSK_USE_DYNAMIC 2 -#else -#define MSK_USE_DYNAMIC 0 -#endif - -#if CH_TIME_QUANTUM > 0 -#define MSK_TIME_QUANTUM 4 -#else -#define MSK_TIME_QUANTUM 0 -#endif - -#if CH_DBG_THREADS_PROFILING -#define MSK_DBG_THREADS_PROFILING 8 -#else -#define MSK_DBG_THREADS_PROFILING 0 -#endif - -/** - * @brief OS signature in ROM plus debug-related information. +/* + * OS signature in ROM plus debug-related information. */ ROMCONST chroot_t ch_root = { "CHRT", @@ -87,12 +64,30 @@ ROMCONST chroot_t ch_root = { (CH_KERNEL_MINOR << 6) | (CH_KERNEL_PATCH) << 0), (uint8_t)sizeof (void *), - (uint8_t)(MSK_DBG_THREADS_PROFILING | MSK_TIME_QUANTUM | - MSK_USE_DYNAMIC | MSK_DBG_ENABLE_STACK_CHECK), + (uint8_t)sizeof (systime_t), + THD_OFFSET(p_prio), + THD_OFFSET(p_ctx), + THD_OFFSET(p_newer), + THD_OFFSET(p_older), + THD_OFFSET(p_name), +#if CH_DBG_ENABLE_STACK_CHECK + THD_OFFSET(p_stklimit), +#else (uint8_t)0, +#endif + THD_OFFSET(p_state), + THD_OFFSET(p_flags), +#if CH_USE_DYNAMIC + THD_OFFSET(p_refs), +#else (uint8_t)0, - &rlist, - &vtlist +#endif +#if CH_TIME_QUANTUM > 0 + THD_OFFSET(p_preempt), +#else + (uint8_t)0, +#endif + THD_OFFSET(p_time) }; /** diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index e433a8e42..5bc86807b 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -36,9 +36,16 @@ #include "ch.h" #if !CH_NO_IDLE_THREAD || defined(__DOXYGEN__) -/* Idle thread working area.*/ +/** + * @brief Idle thread working area. + */ WORKING_AREA(_idle_thread_wa, PORT_IDLE_THREAD_STACK_SIZE); +/** + * @brief Main thread structure. + */ +Thread _mainthread; + /** * @brief This function implements the idle thread infinite loop. * @details The function puts the processor in the lowest power mode capable @@ -73,7 +80,6 @@ void _idle_thread(void *p) { * @special */ void chSysInit(void) { - static Thread mainthread; #if CH_DBG_ENABLE_STACK_CHECK extern stkalign_t __main_thread_stack_base__; #endif @@ -92,7 +98,7 @@ void chSysInit(void) { #endif /* Now this instructions flow becomes the main thread.*/ - setcurrp(_thread_init(&mainthread, NORMALPRIO)); + setcurrp(_thread_init(&_mainthread, NORMALPRIO)); currp->p_state = THD_STATE_CURRENT; #if CH_DBG_ENABLE_STACK_CHECK /* This is a special case because the main thread Thread structure is not