aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/chinit.c5
-rw-r--r--src/chthreads.c2
-rw-r--r--src/templates/chcore.c10
-rw-r--r--src/templates/chcore.h53
4 files changed, 50 insertions, 20 deletions
diff --git a/src/chinit.c b/src/chinit.c
index d93ac1581..a675d6910 100644
--- a/src/chinit.c
+++ b/src/chinit.c
@@ -33,7 +33,7 @@
*/
void chSysInit(void) {
static Thread mainthread;
- static WorkingArea(waIdleThread, IDLE_THREAD_STACK_SIZE);
+ static WORKING_AREA(idle_wa, IDLE_THREAD_STACK_SIZE);
chSchInit();
chDbgInit();
@@ -54,8 +54,7 @@ void chSysInit(void) {
* serve interrupts in its context while keeping the lowest energy saving
* mode compatible with the system status.
*/
- chThdCreateStatic(waIdleThread, sizeof(waIdleThread),
- IDLEPRIO, (tfunc_t)_IdleThread, NULL);
+ chThdCreateStatic(idle_wa, sizeof(idle_wa), IDLEPRIO, (tfunc_t)_idle, NULL);
}
/**
diff --git a/src/chthreads.c b/src/chthreads.c
index f2afdac89..394da5d2a 100644
--- a/src/chthreads.c
+++ b/src/chthreads.c
@@ -85,7 +85,7 @@ Thread *chThdInit(void *workspace, size_t wsize,
/* thread structure is layed out in the lower part of the thread workspace */
Thread *tp = workspace;
- chDbgAssert((wsize >= UserStackSize(0)) && (prio <= HIGHPRIO) &&
+ chDbgAssert((wsize >= THD_WA_SIZE(0)) && (prio <= HIGHPRIO) &&
(workspace != NULL) && (pf != NULL),
"chthreads.c, chThdInit()");
#ifdef CH_USE_DEBUG
diff --git a/src/templates/chcore.c b/src/templates/chcore.c
index 95427c161..40dd4315b 100644
--- a/src/templates/chcore.c
+++ b/src/templates/chcore.c
@@ -35,8 +35,10 @@
* put the processor in the lowest power mode capable to serve interrupts.
* The priority is internally set to the minimum system value so that this
* thread is executed only if there are no other ready threads in the system.
+ * @note Implementation should declare this function as a weak symbol in order
+ * to allow applications to re-implement it.
*/
-void _IdleThread(void *p) {
+void _idle(void *p) {
while (TRUE)
;
@@ -55,6 +57,12 @@ void chSysHalt(void) {
}
/**
+ * Enables the interrupts, it is only invoked once into \p chSysInit().
+ */
+void chSysEnable(void) {
+}
+
+/**
* Enters the ChibiOS/RT system mutual exclusion zone. The implementation is
* architecture dependent, on single core systems usually this function usually
* just disables the interrupts.
diff --git a/src/templates/chcore.h b/src/templates/chcore.h
index 1be2d7145..663033fb5 100644
--- a/src/templates/chcore.h
+++ b/src/templates/chcore.h
@@ -31,6 +31,11 @@
#define CH_ARCHITECTURE_XXX
/**
+ * Base type for stack alignment.
+ */
+typedef uint8_t stkalign_t;
+
+/**
* Interrupt saved context.
*/
struct extctx {
@@ -59,38 +64,55 @@ typedef struct {
#define IDLE_THREAD_STACK_SIZE 0
/**
- * Per-thread stack overhead for interrupts servicing.
+ * Per-thread stack overhead for interrupts servicing, it is used in the
+ * calculation of the correct working area size.
*/
#define INT_REQUIRED_STACK 0
/**
- * Enforces a stack size alignment.
+ * Enforces a correct alignment for a stack area size value.
+ * @deprecated Use STACK_ALIGN() instead, this macro will be removed in
+ * version 1.0.0.
+ */
+#define StackAlign(n) STACK_ALIGN(n)
+
+/**
+ * Enforces a correct alignment for a stack area size value.
*/
-#define StackAlign(n) (n)
+#define STACK_ALIGN(n) ((((n) - 1) | sizeof(stkalign_t)) + 1)
/**
- * Macro to be used when allocating stack spaces, it adds the system-specific
- * overhead.
+ * Computes the thread working area global size.
+ * @deprecated Use THD_WA_SIZE() instead, this macro will be removed in
+ * version 1.0.0.
*/
-#define UserStackSize(n) StackAlign(sizeof(Thread) + \
- sizeof(struct intctx) + \
- sizeof(struct extctx) + \
- (n) + (INT_REQUIRED_STACK))
+#define UserStackSize(n) THD_WA_SIZE(n)
+
+ /**
+ * Computes the thread working area global size.
+ */
+#define THD_WA_SIZE(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.
+ * @deprecated Use WORKING_AREA() instead, this macro will be removed in
+ * version 1.0.0.
*/
-#define WorkingArea(s, n) uint8_t s[UserStackSize(n)];
+#define WorkingArea(s, n) WORKING_AREA(s, n)
/**
- * Enables the interrupts, it is only invoked once into \p chSysInit().
+ * Macro used to allocate a thread working area aligned as both position and
+ * size.
*/
-#define chSysEnable()
+#define WORKING_AREA(s, n) stkalign_t s[THD_WA_SIZE(n)];
/**
* IRQ handler enter code.
- * @note Usually IRQ handlers function are also declared naked.
+ * @note Usually IRQ handlers functions are also declared naked.
* @note On some architectures this macro can be empty.
*/
#define chSysIRQEnterI()
@@ -98,7 +120,7 @@ typedef struct {
/**
* IRQ handler exit code.
* @note Usually IRQ handlers function are also declared naked.
- * @note This macro must perform the final reschedulation by using
+ * @note This macro usually performs the final reschedulation by using
* \p chSchRescRequiredI() and \p chSchDoRescheduleI().
*/
#define chSysIRQExitI()
@@ -106,8 +128,9 @@ typedef struct {
#ifdef __cplusplus
extern "C" {
#endif
- void _IdleThread(void *p);
+ void _idle(void *p);
void chSysHalt(void);
+ void chSysEnable(void);
void chSysLock(void);
void chSysUnlock(void);
void chSysSwitchI(Thread *otp, Thread *ntp);