aboutsummaryrefslogtreecommitdiffstats
path: root/os/nil
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2013-09-05 14:54:24 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2013-09-05 14:54:24 +0000
commit15a54ae359d342b296b7740dcfaf0580d606b3c6 (patch)
treeb385117ee6197a6f9efcdfe82ad687c801c61bed /os/nil
parent986a9d1db14a5d2d4621bd44ece5fd2cfb3482cf (diff)
downloadChibiOS-15a54ae359d342b296b7740dcfaf0580d606b3c6.tar.gz
ChibiOS-15a54ae359d342b296b7740dcfaf0580d606b3c6.tar.bz2
ChibiOS-15a54ae359d342b296b7740dcfaf0580d606b3c6.zip
Nil working on M3/M4.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6265 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/nil')
-rw-r--r--os/nil/include/nil.h38
-rw-r--r--os/nil/osal/osal.h2
-rw-r--r--os/nil/ports/ARMCMx/nilcore_v6m.h7
-rw-r--r--os/nil/ports/ARMCMx/nilcore_v7m.h7
-rw-r--r--os/nil/src/nil.c27
5 files changed, 51 insertions, 30 deletions
diff --git a/os/nil/include/nil.h b/os/nil/include/nil.h
index ee575d466..1c8aaf359 100644
--- a/os/nil/include/nil.h
+++ b/os/nil/include/nil.h
@@ -30,8 +30,11 @@
#ifndef _NIL_H_
#define _NIL_H_
+typedef struct nil_thread thread_t;
+
#include "nilconf.h"
#include "niltypes.h"
+#include "nilcore.h"
/*===========================================================================*/
/* Module constants. */
@@ -197,9 +200,21 @@
#endif
#if NIL_CFG_ENABLE_ASSERTS
-#define CH_DBG_ENABLED TRUE
+#define NIL_DBG_ENABLED TRUE
+#else
+#define NIL_DBG_ENABLED FALSE
+#endif
+
+/** Boundaries of the idle thread boundaries, only required if stack checking
+ is enabled.*/
+#if NIL_CFG_ENABLE_STACK_CHECK
+extern stkalign_t __main_thread_stack_base__, __main_thread_stack_end__;
+
+#define THD_IDLE_BASE (&__main_thread_stack_base__)
+#define THD_IDLE_END (&__main_thread_stack_end__)
#else
-#define CH_DBG_ENABLED FALSE
+#define THD_IDLE_BASE NULL
+#define THD_IDLE_END NULL
#endif
/*===========================================================================*/
@@ -237,11 +252,11 @@ typedef struct nil_thread thread_t;
* @brief Structure representing a thread static configuration.
*/
struct nil_thread_cfg {
+ stkalign_t *wbase; /**< @brief Thread working area base. */
+ stkalign_t *wend; /**< @brief Thread working area end. */
const char *namep; /**< @brief Thread name, for debugging. */
tfunc_t funcp; /**< @brief Thread function. */
void *arg; /**< @brief Thread function argument. */
- void *wap; /**< @brief Thread working area base. */
- size_t size; /**< @brief Thread working area size. */
};
/**
@@ -271,6 +286,9 @@ struct nil_thread {
#if NIL_CFG_USE_EVENTS
eventmask_t epmask; /**< @brief Pending events mask. */
#endif
+#if NIL_CFG_ENABLE_STACK_CHECK || defined(__DOXYGEN__)
+ stkalign_t *stklim;/**< @brief Thread stack boundary. */
+#endif
/* Optional extra fields.*/
NIL_CFG_THREAD_EXT_FIELDS
};
@@ -311,7 +329,7 @@ typedef struct {
* @brief Thread structures for all the defined threads.
*/
thread_t threads[NIL_CFG_NUM_THREADS + 1];
-#if CH_DBG_ENABLED || defined(__DOXYGEN__)
+#if NIL_DBG_ENABLED || defined(__DOXYGEN__)
/**
* @brief Panic message.
* @note This field is only present if some debug options have been
@@ -343,14 +361,14 @@ typedef struct {
/**
* @brief Entry of user threads table
*/
-#define THD_TABLE_ENTRY(name, funcp, arg, wap, size) \
- {name, funcp, arg, wap, size},
+#define THD_TABLE_ENTRY(wap, name, funcp, arg) \
+ {wap, (wap) + sizeof (wap), name, funcp, arg},
/**
* @brief End of user threads table.
*/
#define THD_TABLE_END \
- {"idle", 0, NULL, NULL, 0} \
+ {THD_IDLE_BASE, THD_IDLE_END, "idle", 0, NULL} \
};
/** @} */
@@ -754,10 +772,6 @@ extern "C" {
}
#endif
-/* Late inclusion, this is done in order to let the port layer access
- the OS services like assertions.*/
-#include "nilcore.h"
-
#endif /* _NIL_H_ */
/** @} */
diff --git a/os/nil/osal/osal.h b/os/nil/osal/osal.h
index a974452da..d4394687e 100644
--- a/os/nil/osal/osal.h
+++ b/os/nil/osal/osal.h
@@ -246,7 +246,7 @@ typedef struct {
*
* @api
*/
-#define osalDbgCheck(c) /*chDbgCheck(c)*/
+#define osalDbgCheck(c) chDbgAssert(c, "parameter check")
/**
* @brief I-Class state check.
diff --git a/os/nil/ports/ARMCMx/nilcore_v6m.h b/os/nil/ports/ARMCMx/nilcore_v6m.h
index 60a2549a2..159ce9989 100644
--- a/os/nil/ports/ARMCMx/nilcore_v6m.h
+++ b/os/nil/ports/ARMCMx/nilcore_v6m.h
@@ -192,9 +192,8 @@ struct port_intctx {
* @details This code usually setup the context switching frame represented
* by an @p port_intctx structure.
*/
-#define PORT_SETUP_CONTEXT(tp, workspace, wsize, pf, arg) { \
- (tp)->ctxp = (struct port_intctx *)((uint8_t *)workspace + \
- (size_t)wsize - \
+#define PORT_SETUP_CONTEXT(tp, wend, pf, arg) { \
+ (tp)->ctxp = (struct port_intctx *)(((uint8_t *)(wend)) - \
sizeof(struct port_intctx)); \
(tp)->ctxp->r4 = (regarm_t)(pf); \
(tp)->ctxp->r5 = (regarm_t)(arg); \
@@ -254,7 +253,7 @@ struct port_intctx {
#else
#define port_switch(ntp, otp) { \
struct port_intctx *r13 = (struct port_intctx *)__get_PSP(); \
- if ((stkalign_t *)(r13 - 1) < otp->p_stklimit) \
+ if ((stkalign_t *)(r13 - 1) < (otp)->stklim) \
chSysHalt("stack overflow"); \
_port_switch(ntp, otp); \
}
diff --git a/os/nil/ports/ARMCMx/nilcore_v7m.h b/os/nil/ports/ARMCMx/nilcore_v7m.h
index 4cbcc6e28..0bc4fdf05 100644
--- a/os/nil/ports/ARMCMx/nilcore_v7m.h
+++ b/os/nil/ports/ARMCMx/nilcore_v7m.h
@@ -291,9 +291,8 @@ struct port_intctx {
* @details This code usually setup the context switching frame represented
* by an @p port_intctx structure.
*/
-#define PORT_SETUP_CONTEXT(tp, workspace, wsize, pf, arg) { \
- (tp)->ctxp = (struct port_intctx *)((uint8_t *)workspace + \
- (size_t)wsize - \
+#define PORT_SETUP_CONTEXT(tp, wend, pf, arg) { \
+ (tp)->ctxp = (struct port_intctx *)(((uint8_t *)(wend)) - \
sizeof(struct port_intctx)); \
(tp)->ctxp->r4 = (regarm_t)(pf); \
(tp)->ctxp->r5 = (regarm_t)(arg); \
@@ -351,7 +350,7 @@ struct port_intctx {
#else
#define port_switch(ntp, otp) { \
struct port_intctx *r13 = (struct port_intctx *)__get_PSP(); \
- if ((stkalign_t *)(r13 - 1) < otp->p_stklimit) \
+ if ((stkalign_t *)(r13 - 1) < (otp)->stklim) \
chSysHalt("stack overflow"); \
_port_switch(ntp, otp); \
}
diff --git a/os/nil/src/nil.c b/os/nil/src/nil.c
index 546854280..aefe4ccb2 100644
--- a/os/nil/src/nil.c
+++ b/os/nil/src/nil.c
@@ -62,6 +62,9 @@ nil_system_t nil;
* @details Initializes the kernel structures, the current instructions flow
* becomes the idle thread upon return. The idle thread must not
* invoke any kernel primitive able to change state to not runnable.
+ * @note This function assumes that the @p nil global variable has been
+ * zeroed by the runtime environment. If this is not the case then
+ * make sure to clear it before calling this function.
*
* @special
*/
@@ -73,28 +76,34 @@ void chSysInit(void) {
port_init();
/* Iterates through the list of defined threads.*/
- for (tp = &nil.threads[0], tcp = nil_thd_configs;
- tp < &nil.threads[NIL_CFG_NUM_THREADS];
- tp++, tcp++) {
- tp->state = NIL_STATE_READY;
- tp->timeout = 0;
-#if NIL_CFG_USE_EVENTS
- tp->epmask = 0;
+ tp = &nil.threads[0];
+ tcp = nil_thd_configs;
+ while (tp < &nil.threads[NIL_CFG_NUM_THREADS]) {
+#if NIL_CFG_ENABLE_STACK_CHECK
+ tp->stklim = (stkalign_t *)tcp->wbase;
#endif
/* Port dependent thread initialization.*/
- PORT_SETUP_CONTEXT(tp, tcp->wap, tcp->size, tcp->funcp, tcp->arg);
+ PORT_SETUP_CONTEXT(tp, tcp->wend, tcp->funcp, tcp->arg);
/* Initialization hook.*/
#if defined(NIL_CFG_THREAD_EXT_INIT_HOOK)
NIL_CFG_THREAD_EXT_INIT_HOOK(tp);
#endif
+
+ tp++, tcp++;
}
+#if NIL_CFG_ENABLE_STACK_CHECK
+ /* The idle thread is a special case because its stack is set up by the
+ runtime environment.*/
+ tp->stklim = THD_IDLE_BASE;
+#endif
+
/* Runs the highest priority thread, the current one becomes the null
thread.*/
nil.current = nil.next = nil.threads;
- port_switch(nil.threads, &nil.threads[NIL_CFG_NUM_THREADS]);
+ port_switch(nil.current, tp);
/* Interrupts enabled for the idle thread.*/
chSysEnable();