git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@594 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
gdisirio 2009-01-09 10:48:30 +00:00
parent 58d7edb486
commit a07bd21d44
4 changed files with 156 additions and 77 deletions

View File

@ -39,7 +39,7 @@ void sys_puts(char *msg) {
void sys_halt(void) { void sys_halt(void) {
asm volatile ("cpsid i"); asm volatile ("cpsid i");
while(TRUE) { while (TRUE) {
} }
} }

View File

@ -17,70 +17,31 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/**
* @addtogroup MSP430_CORE
* @{
*/
#include <ch.h> #include <ch.h>
/** /*
* This function implements the idle thread infinite loop. The function should * This file is a template of the system driver functions provided by a port.
* put the processor in the lowest power mode capable to serve interrupts. * Some of the following functions may be implemented as macros in chcore.h if
* The priority is internally set to the minimum system value so that this * the implementer decides that there is an advantage in doing so, as example
* thread is executed only if there are no other ready threads in the system. * because performance concerns.
*/ */
void _idle(void *p) {
while (TRUE) void sys_puts(char *msg) {
;
} }
/** void sys_switch(Thread *otp, Thread *ntp) {
* Abonormal system termination handler. Invoked by the ChibiOS/RT when an
* abnormal unrecoverable condition is met.
*/
void chSysHalt(void) {
chSysLock();
while (TRUE)
;
} }
/** void sys_halt(void) {
* Context switch.
*/
__attribute__((naked))
void chSysSwitchI(Thread *otp, Thread *ntp) {
register struct intctx *sp asm("r1");
asm volatile ("push r11 \n\t" \ sys_disable();
"push r10 \n\t" \ while (TRUE) {
"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));
} }
/** /** @} */
* Prints a message on the system console (if any).
*/
void chSysPuts(char *msg) {
}
void threadstart(void) {
asm volatile ("eint \n\t" \
"mov r11, r15 \n\t" \
"call r10 \n\t" \
"call #chThdExit");
}

View File

@ -17,6 +17,11 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/**
* @addtogroup MSP430_CORE
* @{
*/
#ifndef _CHCORE_H_ #ifndef _CHCORE_H_
#define _CHCORE_H_ #define _CHCORE_H_
@ -24,21 +29,28 @@
#include <msp430/common.h> #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. * Macro defining the MSP430 architecture.
*/ */
#define CH_ARCHITECTURE_MSP430 #define CH_ARCHITECTURE_MSP430
/* /**
* 16 bit stack alignment. * 16 bit stack alignment.
*/ */
typedef uint16_t stkalign_t; typedef uint16_t stkalign_t;
/* /**
* Generic MSP430 register. * Generic MSP430 register.
*/ */
typedef void *regmsp_t; typedef void *regmsp_t;
/* /**
* Interrupt saved context. * Interrupt saved context.
*/ */
struct extctx { struct extctx {
@ -50,8 +62,9 @@ struct extctx {
regmsp_t pc; regmsp_t pc;
}; };
/* /**
* System saved context. * System saved context.
* This structure represents the inner stack frame during a context switching.
*/ */
struct intctx { struct intctx {
regmsp_t r4; regmsp_t r4;
@ -62,14 +75,21 @@ struct intctx {
regmsp_t r9; regmsp_t r9;
regmsp_t r10; regmsp_t r10;
regmsp_t r11; regmsp_t r11;
// regmsp_t sr;
regmsp_t pc; 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 { typedef struct {
struct intctx *sp; struct intctx *sp;
} Context; } Context;
/**
* Platform dependent part of the @p chThdInit() API.
*/
#define SETUP_CONTEXT(workspace, wsize, pf, arg) { \ #define SETUP_CONTEXT(workspace, wsize, pf, arg) { \
tp->p_ctx.sp = (struct intctx *)((uint8_t *)workspace + \ tp->p_ctx.sp = (struct intctx *)((uint8_t *)workspace + \
wsize - \ wsize - \
@ -79,42 +99,103 @@ typedef struct {
tp->p_ctx.sp->pc = threadstart; \ 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 #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 #ifndef INT_REQUIRED_STACK
#define INT_REQUIRED_STACK 32 #define INT_REQUIRED_STACK 32
#endif #endif
/**
* Enforces a correct alignment for a stack area size value.
*/
#define STACK_ALIGN(n) ((((n) - 1) | sizeof(stkalign_t)) + 1) #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) + \ #define THD_WA_SIZE(n) STACK_ALIGN(sizeof(Thread) + \
sizeof(struct intctx) + \ sizeof(struct intctx) + \
sizeof(struct extctx) + \ sizeof(struct extctx) + \
(n) + \ (n) + (INT_REQUIRED_STACK))
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 WORKING_AREA(s, n) stkalign_t s[THD_WA_SIZE(n) / sizeof(stkalign_t)];
#define chSysLock() asm volatile ("dint") /**
#define chSysUnlock() asm volatile ("eint") * IRQ prologue code, inserted at the start of all IRQ handlers enabled to
#define chSysEnable() asm volatile ("eint") * invoke system APIs.
*/
#define SYS_IRQ_PROLOGUE()
#define chSysIRQEnterI() /**
#define chSysIRQExitI() { \ * IRQ epilogue code, inserted at the end of all IRQ handlers enabled to
if (chSchRescRequiredI()) \ * invoke system APIs.
chSchDoRescheduleI(); \ */
#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 #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
void _idle(void *p) __attribute__((weak, noreturn)); void sys_puts(char *msg);
void chSysHalt(void); void sys_switch(Thread *otp, Thread *ntp);
void chSysSwitchI(Thread *otp, Thread *ntp); void sys_halt(void);
void chSysPuts(char *msg);
void threadstart(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* _CHCORE_H_ */ #endif /* _CHCORE_H_ */
/** @} */

View File

@ -31,30 +31,67 @@
* because performance concerns. * because performance concerns.
*/ */
/**
* Prints a message on the system console.
* @param msg pointer to the message
*/
void sys_puts(char *msg) { void sys_puts(char *msg) {
} }
/**
* Performs a context switch between two threads.
* @param otp the thread to be switched out
* @param ntp the thread to be switched in
*/
void sys_switch(Thread *otp, Thread *ntp) { void sys_switch(Thread *otp, Thread *ntp) {
} }
/**
* Kernel-unlock action. Usually this function just enables interrupts.
*/
void sys_enable(void) { void sys_enable(void) {
} }
/**
* Kernel-lock action. Usually this function just disables interrupts.
*/
void sys_disable(void) { void sys_disable(void) {
} }
/**
* Kernel-lock action from an interrupt handler. This function is invoked
* before invoking I-class APIs from interrupt handlers. The implementation
* is architecture dependent, in its simplest form it is void.
*/
void sys_disable_from_isr(void) { void sys_disable_from_isr(void) {
} }
/**
* Kernel-unlock action from an interrupt handler. This function is invoked
* after invoking I-class APIs from interrupt handlers. The implementation
* is architecture dependent, in its simplest form it is void.
*/
void sys_enable_from_isr(void) { void sys_enable_from_isr(void) {
} }
/**
* Enters an architecture-dependent halt mode. The function is meant to return
* when an interrupt becomes pending. The simplest implementation is an empty
* function but this will not take advantage of architecture-specific power
* saving modes.
*/
void sys_wait_for_interrupt(void) { void sys_wait_for_interrupt(void) {
} }
/**
* Halts the system. This function is invoked by the operating system when an
* unrecoverable error is detected (as example because a programming error in
* the application code that triggers an assertion while in debug mode).
*/
void sys_halt(void) { void sys_halt(void) {
while(TRUE) { sys_disable();
while (TRUE) {
} }
} }