diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-01-09 10:48:30 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-01-09 10:48:30 +0000 |
commit | a07bd21d4427c9f254aae8f6da10dabdaedea43e (patch) | |
tree | c0b4509c8b96daa8eb1dc6bf6c58abf133d0e21d /ports | |
parent | 58d7edb48610cd855c3638cfceabd564471bc316 (diff) | |
download | ChibiOS-a07bd21d4427c9f254aae8f6da10dabdaedea43e.tar.gz ChibiOS-a07bd21d4427c9f254aae8f6da10dabdaedea43e.tar.bz2 ChibiOS-a07bd21d4427c9f254aae8f6da10dabdaedea43e.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@594 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'ports')
-rw-r--r-- | ports/ARMCM3/chcore.c | 2 | ||||
-rw-r--r-- | ports/MSP430/chcore.c | 71 | ||||
-rw-r--r-- | ports/MSP430/chcore.h | 119 |
3 files changed, 117 insertions, 75 deletions
diff --git a/ports/ARMCM3/chcore.c b/ports/ARMCM3/chcore.c index 7110035f1..6b4811904 100644 --- a/ports/ARMCM3/chcore.c +++ b/ports/ARMCM3/chcore.c @@ -39,7 +39,7 @@ void sys_puts(char *msg) { void sys_halt(void) {
asm volatile ("cpsid i");
- while(TRUE) {
+ while (TRUE) {
}
}
diff --git a/ports/MSP430/chcore.c b/ports/MSP430/chcore.c index dc340f9c9..e9a5dc574 100644 --- a/ports/MSP430/chcore.c +++ b/ports/MSP430/chcore.c @@ -17,70 +17,31 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <ch.h>
-
-/**
- * This function implements the idle thread infinite loop. The function should
- * 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.
- */
-void _idle(void *p) {
-
- while (TRUE)
- ;
-}
-
/**
- * Abonormal system termination handler. Invoked by the ChibiOS/RT when an
- * abnormal unrecoverable condition is met.
+ * @addtogroup MSP430_CORE
+ * @{
*/
-void chSysHalt(void) {
-
- chSysLock();
- while (TRUE)
- ;
-}
+#include <ch.h>
-/**
- * Context switch.
+/*
+ * This file is a template of the system driver functions provided by a port.
+ * Some of the following functions may be implemented as macros in chcore.h if
+ * the implementer decides that there is an advantage in doing so, as example
+ * because performance concerns.
*/
-__attribute__((naked))
-void chSysSwitchI(Thread *otp, Thread *ntp) {
- register struct intctx *sp asm("r1");
- asm volatile ("push r11 \n\t" \
- "push r10 \n\t" \
- "push r9 \n\t" \
- "push r8 \n\t" \
- "push r7 \n\t" \
- "push r6 \n\t" \
- "push r6 \n\t" \
- "push r4");
- otp->p_ctx.sp = sp;
- sp = ntp->p_ctx.sp;
- asm volatile ("pop r4 \n\t" \
- "pop r5 \n\t" \
- "pop r6 \n\t" \
- "pop r7 \n\t" \
- "pop r8 \n\t" \
- "pop r9 \n\t" \
- "pop r10 \n\t" \
- "pop r11 \n\t" \
- "ret" : : "r" (sp));
+void sys_puts(char *msg) {
}
-/**
- * Prints a message on the system console (if any).
- */
-void chSysPuts(char *msg) {
+void sys_switch(Thread *otp, Thread *ntp) {
}
-void threadstart(void) {
+void sys_halt(void) {
- asm volatile ("eint \n\t" \
- "mov r11, r15 \n\t" \
- "call r10 \n\t" \
- "call #chThdExit");
+ sys_disable();
+ while (TRUE) {
+ }
}
+
+/** @} */
diff --git a/ports/MSP430/chcore.h b/ports/MSP430/chcore.h index bf8e0d82d..db0d25f77 100644 --- a/ports/MSP430/chcore.h +++ b/ports/MSP430/chcore.h @@ -17,6 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * @addtogroup MSP430_CORE
+ * @{
+ */
+
#ifndef _CHCORE_H_
#define _CHCORE_H_
@@ -24,21 +29,28 @@ #include <msp430/common.h>
/*
+ * Port-related configuration parameters.
+ */
+#ifndef ENABLE_WFI_IDLE
+#define ENABLE_WFI_IDLE 0 /* Enables the use of the WFI ins. */
+#endif
+
+/**
* Macro defining the MSP430 architecture.
*/
#define CH_ARCHITECTURE_MSP430
-/*
+/**
* 16 bit stack alignment.
*/
typedef uint16_t stkalign_t;
-/*
+/**
* Generic MSP430 register.
*/
typedef void *regmsp_t;
-/*
+/**
* Interrupt saved context.
*/
struct extctx {
@@ -50,8 +62,9 @@ struct extctx { regmsp_t pc;
};
-/*
+/**
* System saved context.
+ * This structure represents the inner stack frame during a context switching.
*/
struct intctx {
regmsp_t r4;
@@ -62,14 +75,21 @@ struct intctx { regmsp_t r9;
regmsp_t r10;
regmsp_t r11;
-// regmsp_t sr;
regmsp_t pc;
};
+/**
+ * Platform dependent part of the @p Thread structure.
+ * In the MSP430 port this structure just holds a pointer to the @p intctx
+ * structure representing the stack pointer at the time of the context switch.
+ */
typedef struct {
struct intctx *sp;
} Context;
+/**
+ * Platform dependent part of the @p chThdInit() API.
+ */
#define SETUP_CONTEXT(workspace, wsize, pf, arg) { \
tp->p_ctx.sp = (struct intctx *)((uint8_t *)workspace + \
wsize - \
@@ -79,42 +99,103 @@ typedef struct { tp->p_ctx.sp->pc = threadstart; \
}
+/**
+ * The default idle thread implementation requires no extra stack space in
+ * this port.
+ */
+#ifndef IDLE_THREAD_STACK_SIZE
#define IDLE_THREAD_STACK_SIZE 0
+#endif
+/**
+ * Per-thread stack overhead for interrupts servicing, it is used in the
+ * calculation of the correct working area size. In this port the default is
+ * 32 bytes per thread.
+ */
#ifndef INT_REQUIRED_STACK
#define INT_REQUIRED_STACK 32
#endif
+/**
+ * Enforces a correct alignment for a stack area size value.
+ */
#define STACK_ALIGN(n) ((((n) - 1) | sizeof(stkalign_t)) + 1)
+ /**
+ * Computes the thread working area global size.
+ */
#define THD_WA_SIZE(n) STACK_ALIGN(sizeof(Thread) + \
sizeof(struct intctx) + \
sizeof(struct extctx) + \
- (n) + \
- INT_REQUIRED_STACK)
+ (n) + (INT_REQUIRED_STACK))
+/**
+ * Macro used to allocate a thread working area aligned as both position and
+ * size.
+ */
#define WORKING_AREA(s, n) stkalign_t s[THD_WA_SIZE(n) / sizeof(stkalign_t)];
-#define chSysLock() asm volatile ("dint")
-#define chSysUnlock() asm volatile ("eint")
-#define chSysEnable() asm volatile ("eint")
+/**
+ * IRQ prologue code, inserted at the start of all IRQ handlers enabled to
+ * invoke system APIs. + */
+#define SYS_IRQ_PROLOGUE()
-#define chSysIRQEnterI()
-#define chSysIRQExitI() { \
- if (chSchRescRequiredI()) \
- chSchDoRescheduleI(); \
+/**
+ * IRQ epilogue code, inserted at the end of all IRQ handlers enabled to
+ * invoke system APIs.
+ */
+#define SYS_IRQ_EPILOGUE() { \
+if (chSchRescRequiredI()) \
+ chSchDoRescheduleI(); \
+}
+
+/**
+ * This port function is implemented as inlined code for performance reasons.
+ */
+#define sys_disable() asm volatile ("dint")
+
+/**
+ * This port function is implemented as inlined code for performance reasons.
+ */
+#define sys_enable() asm volatile ("eint")
+
+/**
+ * This port function is implemented as inlined code for performance reasons.
+ */
+#define sys_disable_from_isr() sys_disable()
+
+/**
+ * This port function is implemented as inlined code for performance reasons.
+ */
+#define sys_enable_from_isr() sys_enable()
+
+#if ENABLE_WFI_IDLE != 0
+/**
+ * This port function is implemented as inlined code for performance reasons.
+ */
+#define sys_wait_for_interrupt() { \
+ asm volatile ("wfi"); \
}
+#else
+#define sys_wait_for_interrupt()
+#endif
+
+/**
+ * IRQ handler function modifier. + */
+#define SYS_IRQ_HANDLER
#ifdef __cplusplus
extern "C" {
#endif
- void _idle(void *p) __attribute__((weak, noreturn));
- void chSysHalt(void);
- void chSysSwitchI(Thread *otp, Thread *ntp);
- void chSysPuts(char *msg);
- void threadstart(void);
+ void sys_puts(char *msg);
+ void sys_switch(Thread *otp, Thread *ntp);
+ void sys_halt(void);
#ifdef __cplusplus
}
#endif
#endif /* _CHCORE_H_ */
+
+/** @} */
|