aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2007-11-27 11:43:28 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2007-11-27 11:43:28 +0000
commita134cd919ea3e6fee591bc29d360f3da74f46a8b (patch)
tree621c6bd96434a06ce6fd517934f1db6255187c60 /src
parenta62cb84475bb6212554b847751a409a6183f05a0 (diff)
downloadChibiOS-a134cd919ea3e6fee591bc29d360f3da74f46a8b.tar.gz
ChibiOS-a134cd919ea3e6fee591bc29d360f3da74f46a8b.tar.bz2
ChibiOS-a134cd919ea3e6fee591bc29d360f3da74f46a8b.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@115 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'src')
-rw-r--r--src/chdebug.c46
-rw-r--r--src/chschd.c4
-rw-r--r--src/include/debug.h13
-rw-r--r--src/templates/chconf.h6
-rw-r--r--src/templates/chcore.c6
-rw-r--r--src/templates/chcore.h41
6 files changed, 79 insertions, 37 deletions
diff --git a/src/chdebug.c b/src/chdebug.c
index d08f91fd1..29e855e9c 100644
--- a/src/chdebug.c
+++ b/src/chdebug.c
@@ -21,7 +21,6 @@
#ifdef CH_USE_DEBUG
-TraceBuffer dbgtb;
char *dbglastmsg;
/**
@@ -29,27 +28,10 @@ char *dbglastmsg;
*/
void chDbgInit(void) {
+#ifdef CH_USE_TRACE
dbgtb.tb_size = TRACE_BUFFER_SIZE;
dbgtb.tb_ptr = &dbgtb.tb_buffer[0];
-}
-
-/**
- * Inserts in the circular debug trace buffer a context switch record.
- * @param otp the thread being switched out
- * @param ntp the thread to be resumed
- */
-void chDbgTrace(Thread *otp, Thread *ntp) {
-
- dbgtb.tb_ptr->cse_slpdata = otp->p_common;
-#ifdef CH_USE_SYSTEMTIME
- dbgtb.tb_ptr->cse_time = chSysGetTime();
-#else
- dbgtb.tb_ptr->cse_time = 0;
#endif
- dbgtb.tb_ptr->cse_state = otp->p_state;
- dbgtb.tb_ptr->cse_tid = ntp->p_tid;
- if (++dbgtb.tb_ptr >= &dbgtb.tb_buffer[TRACE_BUFFER_SIZE])
- dbgtb.tb_ptr = &dbgtb.tb_buffer[0];
}
/**
@@ -72,4 +54,30 @@ void chDbgPanic(char *msg) {
chSysHalt();
}
+#ifdef CH_USE_TRACE
+/**
+ * Public trace buffer.
+ */
+TraceBuffer dbgtb;
+
+/**
+ * Inserts in the circular debug trace buffer a context switch record.
+ * @param otp the thread being switched out
+ * @param ntp the thread to be resumed
+ */
+void chDbgTrace(Thread *otp, Thread *ntp) {
+
+ dbgtb.tb_ptr->cse_slpdata = otp->p_common;
+#ifdef CH_USE_SYSTEMTIME
+ dbgtb.tb_ptr->cse_time = chSysGetTime();
+#else
+ dbgtb.tb_ptr->cse_time = 0;
+#endif
+ dbgtb.tb_ptr->cse_state = otp->p_state;
+ dbgtb.tb_ptr->cse_tid = ntp->p_tid;
+ if (++dbgtb.tb_ptr >= &dbgtb.tb_buffer[TRACE_BUFFER_SIZE])
+ dbgtb.tb_ptr = &dbgtb.tb_buffer[0];
+}
+#endif /* CH_USE_TRACE */
+
#endif /* CH_USE_DEBUG */
diff --git a/src/chschd.c b/src/chschd.c
index fe42f7ccc..c4b5df5a9 100644
--- a/src/chschd.c
+++ b/src/chschd.c
@@ -88,7 +88,7 @@ void chSchGoSleepS(t_tstate newstate) {
(otp = currp)->p_state = newstate;
(currp = fifo_remove(&rlist.r_queue))->p_state = PRCURR;
rlist.r_preempt = CH_TIME_QUANTUM;
-#ifdef CH_USE_DEBUG
+#ifdef CH_USE_TRACE
chDbgTrace(otp, currp);
#endif
chSysSwitchI(&otp->p_ctx, &currp->p_ctx);
@@ -115,7 +115,7 @@ void chSchWakeupS(Thread *ntp, t_msg msg) {
(currp = ntp)->p_state = PRCURR;
ntp->p_rdymsg = msg;
rlist.r_preempt = CH_TIME_QUANTUM;
-#ifdef CH_USE_DEBUG
+#ifdef CH_USE_TRACE
chDbgTrace(otp, ntp);
#endif
chSysSwitchI(&otp->p_ctx, &ntp->p_ctx);
diff --git a/src/include/debug.h b/src/include/debug.h
index 38d9c2ff1..bf5b3ee7d 100644
--- a/src/include/debug.h
+++ b/src/include/debug.h
@@ -27,7 +27,7 @@
#ifdef CH_USE_DEBUG
-#ifndef TRACE_BUFFER_SIZE
+#ifndef TRACE_BUFFER_SIZE
#define TRACE_BUFFER_SIZE 64
#endif
@@ -52,7 +52,6 @@ extern char *dbglastmsg;
extern "C" {
#endif
void chDbgInit(void);
- void chDbgTrace(Thread *otp, Thread *ntp);
void chDbgPuts(char *msg);
void chDbgPanic(char *msg);
#ifdef __cplusplus
@@ -67,6 +66,16 @@ extern "C" {
#endif /* CH_USE_DEBUG */
+#ifdef CH_USE_TRACE
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void chDbgTrace(Thread *otp, Thread *ntp);
+#ifdef __cplusplus
+}
+#endif
+#endif /* CH_USE_TRACE */
+
#endif /* _DEBUG_H_ */
/** @} */
diff --git a/src/templates/chconf.h b/src/templates/chconf.h
index c8214c623..d8f0f9ae4 100644
--- a/src/templates/chconf.h
+++ b/src/templates/chconf.h
@@ -157,12 +157,16 @@
*/
//#define CH_CURRP_REGISTER_CACHE "reg"
-/** Configuration option: Includes basic debug support to the kernel.
+/** Debug option: Includes basic debug support to the kernel.
* @note the debug support is port-dependent, it may be not present on some
* targets. In that case stub functions will be included.
*/
#define CH_USE_DEBUG
+/** Debug option: Includes the threads context switch tracing feature.
+ */
+#define CH_USE_TRACE
+
#endif /* _CHCONF_H_ */
/** @} */
diff --git a/src/templates/chcore.c b/src/templates/chcore.c
index ec2b39592..195113abf 100644
--- a/src/templates/chcore.c
+++ b/src/templates/chcore.c
@@ -59,4 +59,10 @@ void chSysHalt(void) {
*/
void chSysSwitchI(Context *oldp, Context *newp) {}
+/**
+ * Prints a message on the system console (if any).
+ */
+void chSysPuts(char *msg) {
+}
+
/** @} */
diff --git a/src/templates/chcore.h b/src/templates/chcore.h
index 7f2c5fb0b..c88748f8b 100644
--- a/src/templates/chcore.h
+++ b/src/templates/chcore.h
@@ -25,21 +25,27 @@
#ifndef _CHCORE_H_
#define _CHCORE_H_
-/*
- * Stack saved context.
+/**
+ * Interrupt saved context.
+ */
+struct extctx {
+};
+
+/**
+ * System saved context.
*/
-struct stackregs {
+struct intctx {
};
typedef struct {
- struct stackregs *sp;
+ struct intctx *sp;
} Context;
/**
* Platform dependent part of the \p chThdCreate() API.
*/
-#define SETUP_CONTEXT(workspace, wsize, pf, arg) \
-{ \
+#define SETUP_CONTEXT(workspace, wsize, pf, arg) \
+{ \
}
/**
@@ -53,11 +59,24 @@ typedef struct {
#define INT_REQUIRED_STACK 0
/**
+ * Enforces a stack size alignment.
+ */
+#define StackAlign(n) (n)
+
+/**
* Macro to be used when allocating stack spaces, it adds the system-specific
* overhead.
*/
-#define UserStackSize(n) (sizeof(Thread) + \
- sizeof(struct stackregs) + (n) + (INT_REQUIRED_STACK))
+#define UserStackSize(n) StackAlign(sizeof(Thread) + \
+ sizeof(struct intctx) + \
+ sizeof(struct extctx) + \
+ (n) + (INT_REQUIRED_STACK))
+
+/**
+ * Macro used to allocate a thread working area aligned as both position and
+ * size.
+ */
+#define WorkingArea(s, n) BYTE8 s[UserStackSize(n)];
/**
* Enters the ChibiOS/RT system mutual exclusion zone, the implementation is
@@ -81,14 +100,10 @@ typedef struct {
*/
#define chSysUnlock()
-/**
- * Prints a message on the system console (if any).
- */
-#define chSysPuts(msg) {}
-
void _IdleThread(void *p);
void chSysHalt(void);
void chSysSwitchI(Context *oldp, Context *newp);
+void chSysPuts(char *msg);
#endif /* _CHCORE_H_ */