aboutsummaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2014-12-11 15:44:16 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2014-12-11 15:44:16 +0000
commite023f0058dcb36075f3a51072593aeff334eff3c (patch)
treed0484b57493dc0dae439056adae615ff5369a5a8 /os
parent055fea386e4994a35b758b94f948f9de1c8ba091 (diff)
downloadChibiOS-e023f0058dcb36075f3a51072593aeff334eff3c.tar.gz
ChibiOS-e023f0058dcb36075f3a51072593aeff334eff3c.tar.bz2
ChibiOS-e023f0058dcb36075f3a51072593aeff334eff3c.zip
Incorporated main and idle threads data areas into the ch_system structure, moved around some definitions in order to allow this.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7572 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r--os/rt/include/chschd.h109
-rw-r--r--os/rt/include/chthreads.h99
-rw-r--r--os/rt/src/chsys.c26
3 files changed, 117 insertions, 117 deletions
diff --git a/os/rt/include/chschd.h b/os/rt/include/chschd.h
index 3b17a417e..d5075dec4 100644
--- a/os/rt/include/chschd.h
+++ b/os/rt/include/chschd.h
@@ -56,6 +56,105 @@
#define ABSPRIO 255 /**< @brief Greatest possible priority. */
/** @} */
+/**
+ * @name Thread states
+ * @{
+ */
+#define CH_STATE_READY 0 /**< @brief Waiting on the ready list. */
+#define CH_STATE_CURRENT 1 /**< @brief Currently running. */
+#define CH_STATE_WTSTART 2 /**< @brief Created but not started. */
+#define CH_STATE_SUSPENDED 3 /**< @brief Suspended state. */
+#define CH_STATE_QUEUED 4 /**< @brief Waiting on an I/O queue. */
+#define CH_STATE_WTSEM 5 /**< @brief Waiting on a semaphore. */
+#define CH_STATE_WTMTX 6 /**< @brief Waiting on a mutex. */
+#define CH_STATE_WTCOND 7 /**< @brief Waiting on a condition
+ variable. */
+#define CH_STATE_SLEEPING 8 /**< @brief Waiting in @p chThdSleep()
+ or @p chThdSleepUntil(). */
+#define CH_STATE_WTEXIT 9 /**< @brief Waiting in @p chThdWait(). */
+#define CH_STATE_WTOREVT 10 /**< @brief Waiting for an event. */
+#define CH_STATE_WTANDEVT 11 /**< @brief Waiting for several events. */
+#define CH_STATE_SNDMSGQ 12 /**< @brief Sending a message, in queue.*/
+#define CH_STATE_SNDMSG 13 /**< @brief Sent a message, waiting
+ answer. */
+#define CH_STATE_WTMSG 14 /**< @brief Waiting for a message. */
+#define CH_STATE_FINAL 15 /**< @brief Thread terminated. */
+
+/**
+ * @brief Thread states as array of strings.
+ * @details Each element in an array initialized with this macro can be
+ * indexed using the numeric thread state values.
+ */
+#define CH_STATE_NAMES \
+ "READY", "CURRENT", "WTSTART", "SUSPENDED", "QUEUED", "WTSEM", "WTMTX", \
+ "WTCOND", "SLEEPING", "WTEXIT", "WTOREVT", "WTANDEVT", "SNDMSGQ", \
+ "SNDMSG", "WTMSG", "FINAL"
+/** @} */
+
+/**
+ * @name Thread flags and attributes
+ * @{
+ */
+#define CH_FLAG_MODE_MASK 3 /**< @brief Thread memory mode mask. */
+#define CH_FLAG_MODE_STATIC 0 /**< @brief Static thread. */
+#define CH_FLAG_MODE_HEAP 1 /**< @brief Thread allocated from a
+ Memory Heap. */
+#define CH_FLAG_MODE_MEMPOOL 2 /**< @brief Thread allocated from a
+ Memory Pool. */
+#define CH_FLAG_TERMINATE 4 /**< @brief Termination requested flag. */
+/** @} */
+
+/**
+ * @name Working Areas and Alignment
+ */
+/**
+ * @brief Enforces a correct alignment for a stack area size value.
+ *
+ * @param[in] n the stack size to be aligned to the next stack
+ * alignment boundary
+ * @return The aligned stack size.
+ *
+ * @api
+ */
+#define THD_ALIGN_STACK_SIZE(n) \
+ ((((n) - 1) | (sizeof(stkalign_t) - 1)) + 1)
+
+/**
+ * @brief Calculates the total Working Area size.
+ *
+ * @param[in] n the stack size to be assigned to the thread
+ * @return The total used memory in bytes.
+ *
+ * @api
+ */
+#define THD_WORKING_AREA_SIZE(n) \
+ THD_ALIGN_STACK_SIZE(sizeof(thread_t) + PORT_WA_SIZE(n))
+
+/**
+ * @brief Static working area allocation.
+ * @details This macro is used to allocate a static thread working area
+ * aligned as both position and size.
+ *
+ * @param[in] s the name to be assigned to the stack array
+ * @param[in] n the stack size to be assigned to the thread
+ *
+ * @api
+ */
+#define THD_WORKING_AREA(s, n) \
+ stkalign_t s[THD_WORKING_AREA_SIZE(n) / sizeof(stkalign_t)]
+/** @} */
+
+/**
+ * @name Threads abstraction macros
+ */
+/**
+ * @brief Thread declaration macro.
+ * @note Thread declarations should be performed using this macro because
+ * the port layer could define optimizations for thread functions.
+ */
+#define THD_FUNCTION(tname, arg) PORT_THD_FUNCTION(tname, arg)
+/** @} */
+
/*===========================================================================*/
/* Module pre-compile time settings. */
/*===========================================================================*/
@@ -332,6 +431,10 @@ struct ch_system {
* @brief System debug.
*/
system_debug_t dbg;
+ /**
+ * @brief Main thread descriptor.
+ */
+ thread_t mainthread;
#if CH_CFG_USE_TM || defined(__DOXYGEN__)
/**
* @brief Time measurement calibration data.
@@ -344,6 +447,12 @@ struct ch_system {
*/
kernel_stats_t kernel_stats;
#endif
+#if !CH_CFG_NO_IDLE_THREAD
+ /**
+ * @brief Idle thread working area.
+ */
+ THD_WORKING_AREA(idle_thread_wa, PORT_IDLE_THREAD_STACK_SIZE);
+#endif
};
/*===========================================================================*/
diff --git a/os/rt/include/chthreads.h b/os/rt/include/chthreads.h
index 24349000d..0713fb6a4 100644
--- a/os/rt/include/chthreads.h
+++ b/os/rt/include/chthreads.h
@@ -33,54 +33,6 @@
/* Module constants. */
/*===========================================================================*/
-/**
- * @name Thread states
- * @{
- */
-#define CH_STATE_READY 0 /**< @brief Waiting on the ready list. */
-#define CH_STATE_CURRENT 1 /**< @brief Currently running. */
-#define CH_STATE_WTSTART 2 /**< @brief Created but not started. */
-#define CH_STATE_SUSPENDED 3 /**< @brief Suspended state. */
-#define CH_STATE_QUEUED 4 /**< @brief Waiting on an I/O queue. */
-#define CH_STATE_WTSEM 5 /**< @brief Waiting on a semaphore. */
-#define CH_STATE_WTMTX 6 /**< @brief Waiting on a mutex. */
-#define CH_STATE_WTCOND 7 /**< @brief Waiting on a condition
- variable. */
-#define CH_STATE_SLEEPING 8 /**< @brief Waiting in @p chThdSleep()
- or @p chThdSleepUntil(). */
-#define CH_STATE_WTEXIT 9 /**< @brief Waiting in @p chThdWait(). */
-#define CH_STATE_WTOREVT 10 /**< @brief Waiting for an event. */
-#define CH_STATE_WTANDEVT 11 /**< @brief Waiting for several events. */
-#define CH_STATE_SNDMSGQ 12 /**< @brief Sending a message, in queue.*/
-#define CH_STATE_SNDMSG 13 /**< @brief Sent a message, waiting
- answer. */
-#define CH_STATE_WTMSG 14 /**< @brief Waiting for a message. */
-#define CH_STATE_FINAL 15 /**< @brief Thread terminated. */
-
-/**
- * @brief Thread states as array of strings.
- * @details Each element in an array initialized with this macro can be
- * indexed using the numeric thread state values.
- */
-#define CH_STATE_NAMES \
- "READY", "CURRENT", "WTSTART", "SUSPENDED", "QUEUED", "WTSEM", "WTMTX", \
- "WTCOND", "SLEEPING", "WTEXIT", "WTOREVT", "WTANDEVT", "SNDMSGQ", \
- "SNDMSG", "WTMSG", "FINAL"
-/** @} */
-
-/**
- * @name Thread flags and attributes
- * @{
- */
-#define CH_FLAG_MODE_MASK 3 /**< @brief Thread memory mode mask. */
-#define CH_FLAG_MODE_STATIC 0 /**< @brief Static thread. */
-#define CH_FLAG_MODE_HEAP 1 /**< @brief Thread allocated from a
- Memory Heap. */
-#define CH_FLAG_MODE_MEMPOOL 2 /**< @brief Thread allocated from a
- Memory Pool. */
-#define CH_FLAG_TERMINATE 4 /**< @brief Termination requested flag. */
-/** @} */
-
/*===========================================================================*/
/* Module pre-compile time settings. */
/*===========================================================================*/
@@ -108,57 +60,6 @@ typedef msg_t (*tfunc_t)(void *);
/*===========================================================================*/
/**
- * @name Working Areas and Alignment
- */
-/**
- * @brief Enforces a correct alignment for a stack area size value.
- *
- * @param[in] n the stack size to be aligned to the next stack
- * alignment boundary
- * @return The aligned stack size.
- *
- * @api
- */
-#define THD_ALIGN_STACK_SIZE(n) \
- ((((n) - 1) | (sizeof(stkalign_t) - 1)) + 1)
-
-/**
- * @brief Calculates the total Working Area size.
- *
- * @param[in] n the stack size to be assigned to the thread
- * @return The total used memory in bytes.
- *
- * @api
- */
-#define THD_WORKING_AREA_SIZE(n) \
- THD_ALIGN_STACK_SIZE(sizeof(thread_t) + PORT_WA_SIZE(n))
-
-/**
- * @brief Static working area allocation.
- * @details This macro is used to allocate a static thread working area
- * aligned as both position and size.
- *
- * @param[in] s the name to be assigned to the stack array
- * @param[in] n the stack size to be assigned to the thread
- *
- * @api
- */
-#define THD_WORKING_AREA(s, n) \
- stkalign_t s[THD_WORKING_AREA_SIZE(n) / sizeof(stkalign_t)]
-/** @} */
-
-/**
- * @name Threads abstraction macros
- */
-/**
- * @brief Thread declaration macro.
- * @note Thread declarations should be performed using this macro because
- * the port layer could define optimizations for thread functions.
- */
-#define THD_FUNCTION(tname, arg) PORT_THD_FUNCTION(tname, arg)
-/** @} */
-
-/**
* @name Threads queues
*/
/**
diff --git a/os/rt/src/chsys.c b/os/rt/src/chsys.c
index 2a60e6d69..db25fc9d7 100644
--- a/os/rt/src/chsys.c
+++ b/os/rt/src/chsys.c
@@ -48,13 +48,6 @@
/* Module local variables. */
/*===========================================================================*/
-#if !CH_CFG_NO_IDLE_THREAD || defined(__DOXYGEN__)
-/**
- * @brief Idle thread working area.
- */
-static THD_WORKING_AREA(_idle_thread_wa, PORT_IDLE_THREAD_STACK_SIZE);
-#endif /* CH_CFG_NO_IDLE_THREAD */
-
/*===========================================================================*/
/* Module local functions. */
/*===========================================================================*/
@@ -68,7 +61,7 @@ static THD_WORKING_AREA(_idle_thread_wa, PORT_IDLE_THREAD_STACK_SIZE);
* that this thread is executed only if there are no other ready
* threads in the system.
*
- * @param[in] p the thread parameter, unused in this scenario
+ * @param[in] p the thread parameter, unused in this scenario
*/
static void _idle_thread(void *p) {
@@ -89,16 +82,13 @@ static void _idle_thread(void *p) {
* @brief ChibiOS/RT initialization.
* @details After executing this function the current instructions stream
* becomes the main thread.
- * @pre Interrupts must be still disabled when @p chSysInit() is invoked
- * and are internally enabled.
- * @post The main thread is created with priority @p NORMALPRIO.
- * @note This function has special, architecture-dependent, requirements,
- * see the notes into the various port reference manuals.
+ * @pre Interrupts must disabled before invoking this function.
+ * @post The main thread is created with priority @p NORMALPRIO and
+ * interrupts are enabled.
*
* @special
*/
void chSysInit(void) {
- static thread_t mainthread;
#if CH_DBG_ENABLE_STACK_CHECK
extern stkalign_t __main_thread_stack_base__;
#endif
@@ -124,10 +114,10 @@ void chSysInit(void) {
#if !CH_CFG_NO_IDLE_THREAD
/* Now this instructions flow becomes the main thread.*/
- setcurrp(_thread_init(&mainthread, NORMALPRIO));
+ setcurrp(_thread_init(&ch.mainthread, NORMALPRIO));
#else
- /* Now this instructions flow becomes the main thread.*/
- setcurrp(_thread_init(&mainthread, IDLEPRIO));
+ /* Now this instructions flow becomes the idle thread.*/
+ setcurrp(_thread_init(&ch.mainthread, IDLEPRIO));
#endif
currp->p_state = CH_STATE_CURRENT;
@@ -146,7 +136,7 @@ void chSysInit(void) {
/* This thread has the lowest priority in the system, its role is just to
serve interrupts in its context while keeping the lowest energy saving
mode compatible with the system status.*/
- chThdCreateStatic(_idle_thread_wa, sizeof(_idle_thread_wa), IDLEPRIO,
+ chThdCreateStatic(ch.idle_thread_wa, sizeof(ch.idle_thread_wa), IDLEPRIO,
(tfunc_t)_idle_thread, NULL);
#endif
}