aboutsummaryrefslogtreecommitdiffstats
path: root/os/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'os/kernel')
-rw-r--r--os/kernel/include/ch.h4
-rw-r--r--os/kernel/include/chdebug.h43
-rw-r--r--os/kernel/include/chregistry.h28
-rw-r--r--os/kernel/include/chthreads.h66
-rw-r--r--os/kernel/src/chdebug.c23
-rw-r--r--os/kernel/src/chsys.c3
-rw-r--r--os/kernel/src/chthreads.c11
7 files changed, 107 insertions, 71 deletions
diff --git a/os/kernel/include/ch.h b/os/kernel/include/ch.h
index 250f6adbf..db96d4338 100644
--- a/os/kernel/include/ch.h
+++ b/os/kernel/include/ch.h
@@ -40,7 +40,7 @@
/**
* @brief Kernel version string.
*/
-#define CH_KERNEL_VERSION "2.3.4unstable"
+#define CH_KERNEL_VERSION "2.3.3unstable"
/**
* @brief Kernel version major number.
@@ -55,7 +55,7 @@
/**
* @brief Kernel version patch number.
*/
-#define CH_KERNEL_PATCH 4
+#define CH_KERNEL_PATCH 3
/*
* Common values.
diff --git a/os/kernel/include/chdebug.h b/os/kernel/include/chdebug.h
index 471da5532..2fb3b2385 100644
--- a/os/kernel/include/chdebug.h
+++ b/os/kernel/include/chdebug.h
@@ -32,15 +32,15 @@
/**
* @brief Trace buffer entries.
*/
-#ifndef TRACE_BUFFER_SIZE
-#define TRACE_BUFFER_SIZE 64
+#ifndef CH_TRACE_BUFFER_SIZE
+#define CH_TRACE_BUFFER_SIZE 64
#endif
/**
* @brief Fill value for thread stack area in debug mode.
*/
-#ifndef STACK_FILL_VALUE
-#define STACK_FILL_VALUE 0x55
+#ifndef CH_STACK_FILL_VALUE
+#define CH_STACK_FILL_VALUE 0x55
#endif
/**
@@ -50,39 +50,34 @@
* a debugger. A uninitialized field is not an error in itself but it
* better to know it.
*/
-#ifndef THREAD_FILL_VALUE
-#define THREAD_FILL_VALUE 0xFF
+#ifndef CH_THREAD_FILL_VALUE
+#define CH_THREAD_FILL_VALUE 0xFF
#endif
+#define __QUOTE_THIS(p) #p
+
#if CH_DBG_ENABLE_TRACE || defined(__DOXYGEN__)
/**
* @brief Trace buffer record.
*/
typedef struct {
- void *cse_wtobjp; /**< @brief Object where going to
- sleep. */
- systime_t cse_time; /**< @brief Time of the switch
- event. */
- uint16_t cse_state: 4; /**< @brief Switched out thread
- state. */
- uint16_t cse_tid: 12; /**< @brief Switched in thread id. */
-} CtxSwcEvent;
+ systime_t se_time; /**< @brief Time of the switch event. */
+ Thread *se_tp; /**< @brief Switched in thread. */
+ void *se_wtobjp; /**< @brief Object where going to sleep.*/
+ uint8_t se_state; /**< @brief Switched out thread state. */
+} ch_swc_event_t;
/**
* @brief Trace buffer header.
*/
typedef struct {
- unsigned tb_size; /**< @brief Trace buffer size
- (entries). */
- CtxSwcEvent *tb_ptr; /**< @brief Pointer to the ring buffer
- front. */
+ unsigned tb_size; /**< @brief Trace buffer size (entries).*/
+ ch_swc_event_t *tb_ptr; /**< @brief Pointer to the buffer front.*/
/** @brief Ring buffer.*/
- CtxSwcEvent tb_buffer[TRACE_BUFFER_SIZE];
-} TraceBuffer;
+ ch_swc_event_t tb_buffer[CH_TRACE_BUFFER_SIZE];
+} ch_trace_buffer_t;
#endif /* CH_DBG_ENABLE_TRACE */
-#define __QUOTE_THIS(p) #p
-
#if CH_DBG_ENABLE_CHECKS || defined(__DOXYGEN__)
/**
* @brief Function parameter check.
@@ -150,12 +145,12 @@ typedef struct {
extern "C" {
#endif
#if CH_DBG_ENABLE_TRACE || defined(__DOXYGEN__)
- extern TraceBuffer trace_buffer;
+ extern ch_trace_buffer_t dbg_trace_buffer;
void _trace_init(void);
void chDbgTrace(Thread *otp);
#endif
#if CH_DBG_ENABLE_ASSERTS || CH_DBG_ENABLE_CHECKS || CH_DBG_ENABLE_STACK_CHECK
- extern char *panic_msg;
+ extern char *dbg_panic_msg;
void chDbgPanic(char *msg);
#endif
#ifdef __cplusplus
diff --git a/os/kernel/include/chregistry.h b/os/kernel/include/chregistry.h
index 3e9cc5508..0967f699e 100644
--- a/os/kernel/include/chregistry.h
+++ b/os/kernel/include/chregistry.h
@@ -30,6 +30,34 @@
#define _CHREGISTRY_H_
#if CH_USE_REGISTRY || defined(__DOXYGEN__)
+/**
+ * @brief Sets the current thread name.
+ * @pre This function only stores the pointer to the name if the option
+ * @p CH_USE_REGISTRY is enabled else no action is performed.
+ *
+ * @param[in] p thread name as a zero terminated string
+ *
+ * @api
+ */
+#define chRegSetThreadName(p) (currp->p_name = (p))
+
+/**
+ * @brief Returns the name of the specified thread.
+ * @pre This function only returns the pointer to the name if the option
+ * @p CH_USE_REGISTRY is enabled else @p NULL is returned.
+ *
+ * @param[in] tp pointer to the thread
+ *
+ * @return Thread name as a zero terminated string.
+ * @retval NULL if the thread name has not been set.
+ */
+#define chRegGetThreadName(tp) ((tp)->p_name)
+#else /* !CH_USE_REGISTRY */
+#define chRegSetThreadName(p)
+#define chRegGetThreadName(tp) NULL
+#endif /* !CH_USE_REGISTRY */
+
+#if CH_USE_REGISTRY || defined(__DOXYGEN__)
/**
* @brief Removes a thread from the registry list.
diff --git a/os/kernel/include/chthreads.h b/os/kernel/include/chthreads.h
index 215bb9920..e0f1b3e95 100644
--- a/os/kernel/include/chthreads.h
+++ b/os/kernel/include/chthreads.h
@@ -49,6 +49,12 @@ struct Thread {
Thread *p_older; /**< @brief Older registry element. */
#endif
/* End of the fields shared with the ReadyList structure. */
+#if CH_USE_REGISTRY
+ /**
+ * @brief Thread name or @p NULL.
+ */
+ const char *p_name;
+#endif
/**
* @brief Current thread state.
*/
@@ -197,36 +203,10 @@ struct Thread {
#define THD_MEM_MODE_MEMPOOL 2 /**< @brief Thread memory mode: pool. */
#define THD_TERMINATE 4 /**< @brief Termination requested. */
-/** @brief Thread function.*/
-typedef msg_t (*tfunc_t)(void *);
-
-/*
- * Threads APIs.
+/**
+ * @brief Thread function.
*/
-#ifdef __cplusplus
-extern "C" {
-#endif
- Thread *_thread_init(Thread *tp, tprio_t prio);
-#if CH_DBG_FILL_THREADS
- void _thread_memfill(uint8_t *startp, uint8_t *endp, uint8_t v);
-#endif
- Thread *chThdCreateI(void *wsp, size_t size,
- tprio_t prio, tfunc_t pf, void *arg);
- Thread *chThdCreateStatic(void *wsp, size_t size,
- tprio_t prio, tfunc_t pf, void *arg);
- tprio_t chThdSetPriority(tprio_t newprio);
- Thread *chThdResume(Thread *tp);
- void chThdTerminate(Thread *tp);
- void chThdSleep(systime_t time);
- void chThdSleepUntil(systime_t time);
- void chThdYield(void);
- void chThdExit(msg_t msg);
-#if CH_USE_WAITEXIT
- msg_t chThdWait(Thread *tp);
-#endif
-#ifdef __cplusplus
-}
-#endif
+typedef msg_t (*tfunc_t)(void *);
/**
* @brief Returns a pointer to the current @p Thread.
@@ -342,6 +322,34 @@ extern "C" {
*/
#define chThdSleepMicroseconds(usec) chThdSleep(US2ST(usec))
+/*
+ * Threads APIs.
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+ Thread *_thread_init(Thread *tp, tprio_t prio);
+#if CH_DBG_FILL_THREADS
+ void _thread_memfill(uint8_t *startp, uint8_t *endp, uint8_t v);
+#endif
+ Thread *chThdCreateI(void *wsp, size_t size,
+ tprio_t prio, tfunc_t pf, void *arg);
+ Thread *chThdCreateStatic(void *wsp, size_t size,
+ tprio_t prio, tfunc_t pf, void *arg);
+ tprio_t chThdSetPriority(tprio_t newprio);
+ Thread *chThdResume(Thread *tp);
+ void chThdTerminate(Thread *tp);
+ void chThdSleep(systime_t time);
+ void chThdSleepUntil(systime_t time);
+ void chThdYield(void);
+ void chThdExit(msg_t msg);
+#if CH_USE_WAITEXIT
+ msg_t chThdWait(Thread *tp);
+#endif
+#ifdef __cplusplus
+}
+#endif
+
#endif /* _CHTHREADS_H_ */
/** @} */
diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c
index 3c3c34c70..0e378cc6d 100644
--- a/os/kernel/src/chdebug.c
+++ b/os/kernel/src/chdebug.c
@@ -40,7 +40,7 @@
/**
* @brief Public trace buffer.
*/
-TraceBuffer trace_buffer;
+ch_trace_buffer_t dbg_trace_buffer;
/**
* @brief Trace circular buffer subsystem initialization.
@@ -48,8 +48,8 @@ TraceBuffer trace_buffer;
*/
void _trace_init(void) {
- trace_buffer.tb_size = TRACE_BUFFER_SIZE;
- trace_buffer.tb_ptr = &trace_buffer.tb_buffer[0];
+ dbg_trace_buffer.tb_size = CH_TRACE_BUFFER_SIZE;
+ dbg_trace_buffer.tb_ptr = &dbg_trace_buffer.tb_buffer[0];
}
/**
@@ -61,12 +61,13 @@ void _trace_init(void) {
*/
void chDbgTrace(Thread *otp) {
- trace_buffer.tb_ptr->cse_wtobjp = otp->p_u.wtobjp;
- trace_buffer.tb_ptr->cse_time = chTimeNow();
- trace_buffer.tb_ptr->cse_state = otp->p_state;
- trace_buffer.tb_ptr->cse_tid = (unsigned)currp >> 6;
- if (++trace_buffer.tb_ptr >= &trace_buffer.tb_buffer[TRACE_BUFFER_SIZE])
- trace_buffer.tb_ptr = &trace_buffer.tb_buffer[0];
+ dbg_trace_buffer.tb_ptr->se_time = chTimeNow();
+ dbg_trace_buffer.tb_ptr->se_tp = currp;
+ dbg_trace_buffer.tb_ptr->se_wtobjp = otp->p_u.wtobjp;
+ dbg_trace_buffer.tb_ptr->se_state = (uint8_t)otp->p_state;
+ if (++dbg_trace_buffer.tb_ptr >=
+ &dbg_trace_buffer.tb_buffer[CH_TRACE_BUFFER_SIZE])
+ dbg_trace_buffer.tb_ptr = &dbg_trace_buffer.tb_buffer[0];
}
#endif /* CH_DBG_ENABLE_TRACE */
@@ -78,7 +79,7 @@ void chDbgTrace(Thread *otp) {
* written once and then the system is halted. This variable can be
* set to @p NULL if the halt is caused by a stack overflow.
*/
-char *panic_msg;
+char *dbg_panic_msg;
/**
* @brief Prints a panic message on the console and then halts the system.
@@ -87,7 +88,7 @@ char *panic_msg;
*/
void chDbgPanic(char *msg) {
- panic_msg = msg;
+ dbg_panic_msg = msg;
chSysHalt();
}
#endif /* CH_DBG_ENABLE_ASSERTS || CH_DBG_ENABLE_CHECKS || CH_DBG_ENABLE_STACK_CHECK */
diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c
index 6892ec73a..8d9ce4905 100644
--- a/os/kernel/src/chsys.c
+++ b/os/kernel/src/chsys.c
@@ -55,6 +55,7 @@ WORKING_AREA(_idle_thread_wa, PORT_IDLE_THREAD_STACK_SIZE);
void _idle_thread(void *p) {
(void)p;
+ chRegSetThreadName("idle");
while (TRUE) {
port_wait_for_interrupt();
IDLE_LOOP_HOOK();
@@ -95,6 +96,8 @@ void chSysInit(void) {
currp->p_state = THD_STATE_CURRENT;
chSysEnable();
+ chRegSetThreadName("main");
+
#if !CH_NO_IDLE_THREAD
/* 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
diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c
index 7df276bea..b68263a7b 100644
--- a/os/kernel/src/chthreads.c
+++ b/os/kernel/src/chthreads.c
@@ -89,15 +89,16 @@ Thread *_thread_init(Thread *tp, tprio_t prio) {
#if CH_USE_DYNAMIC
tp->p_refs = 1;
#endif
+#if CH_USE_REGISTRY
+ tp->p_name = NULL;
+ REG_INSERT(tp);
+#endif
#if CH_USE_WAITEXIT
list_init(&tp->p_waiting);
#endif
#if CH_USE_MESSAGES
queue_init(&tp->p_msgqueue);
#endif
-#if CH_USE_REGISTRY
- REG_INSERT(tp);
-#endif
#if defined(THREAD_EXT_INIT_HOOK)
THREAD_EXT_INIT_HOOK(tp);
#endif
@@ -180,10 +181,10 @@ Thread *chThdCreateStatic(void *wsp, size_t size,
#if CH_DBG_FILL_THREADS
_thread_memfill((uint8_t *)wsp,
(uint8_t *)wsp + sizeof(Thread),
- THREAD_FILL_VALUE);
+ CH_THREAD_FILL_VALUE);
_thread_memfill((uint8_t *)wsp + sizeof(Thread),
(uint8_t *)wsp + size,
- STACK_FILL_VALUE);
+ CH_STACK_FILL_VALUE);
#endif
chSysLock();
chSchWakeupS(tp = chThdCreateI(wsp, size, prio, pf, arg), RDY_OK);