From f5551fd8d6e8b7db2537d8ec14b936d2ad897441 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 7 May 2008 13:08:43 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@283 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- ports/ARM7/chcore.h | 2 ++ ports/ARMCM3/chcore.h | 2 ++ ports/AVR/chcore.h | 2 ++ ports/MSP430/chcore.c | 84 +++++++++++++++++++++++++++++++++++++++++++ ports/MSP430/chcore.h | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++ ports/MSP430/chtypes.h | 51 ++++++++++++++++++++++++++ 6 files changed, 239 insertions(+) create mode 100644 ports/MSP430/chcore.c create mode 100644 ports/MSP430/chcore.h create mode 100644 ports/MSP430/chtypes.h (limited to 'ports') diff --git a/ports/ARM7/chcore.h b/ports/ARM7/chcore.h index eed850266..4f8e187cc 100644 --- a/ports/ARM7/chcore.h +++ b/ports/ARM7/chcore.h @@ -20,6 +20,8 @@ #ifndef _CHCORE_H_ #define _CHCORE_H_ +#define CH_ARCHITECTURE_ARM7 + typedef void *regarm; /* diff --git a/ports/ARMCM3/chcore.h b/ports/ARMCM3/chcore.h index 5b9a0915b..9a8f00bee 100644 --- a/ports/ARMCM3/chcore.h +++ b/ports/ARMCM3/chcore.h @@ -20,6 +20,8 @@ #ifndef _CHCORE_H_ #define _CHCORE_H_ +#define CH_ARCHITECTURE_ARMCM3 + typedef void *regarm; /* diff --git a/ports/AVR/chcore.h b/ports/AVR/chcore.h index eb7e334f6..cb2920a2d 100644 --- a/ports/AVR/chcore.h +++ b/ports/AVR/chcore.h @@ -20,6 +20,8 @@ #ifndef _CHCORE_H_ #define _CHCORE_H_ +#define CH_ARCHITECTURE_AVR + /* * Interrupt saved context. */ diff --git a/ports/MSP430/chcore.c b/ports/MSP430/chcore.c new file mode 100644 index 000000000..86765c675 --- /dev/null +++ b/ports/MSP430/chcore.c @@ -0,0 +1,84 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include + +/** + * 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 _IdleThread(void *p) { + + while (TRUE) + ; +} + +/** + * Abonormal system termination handler. Invoked by the ChibiOS/RT when an + * abnormal unrecoverable condition is met. + */ +void chSysHalt(void) { + + chSysLock(); + + while (TRUE) + ; +} + +/** + * Context switch. + */ +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" : : "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"); +} diff --git a/ports/MSP430/chcore.h b/ports/MSP430/chcore.h new file mode 100644 index 000000000..b67e90d26 --- /dev/null +++ b/ports/MSP430/chcore.h @@ -0,0 +1,98 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef _CHCORE_H_ +#define _CHCORE_H_ + +#define CH_ARCHITECTURE_MSP430 + +typedef void *regmsp; + +/* + * Interrupt saved context. + */ +struct extctx { + regmsp r12; + regmsp r13; + regmsp r14; + regmsp r15; + regmsp sr; + regmsp pc; +}; + +/* + * System saved context. + */ +struct intctx { + regmsp r4; + regmsp r5; + regmsp r6; + regmsp r7; + regmsp r8; + regmsp r9; + regmsp r10; + regmsp r11; + regmsp pc; +}; + +typedef struct { + struct intctx *sp; +} Context; + +#define SETUP_CONTEXT(workspace, wsize, pf, arg) { \ + tp->p_ctx.sp = (struct intctx *)((uint8_t *)workspace + \ + wsize - \ + sizeof(struct intctx)); \ + tp->p_ctx.sp->r10 = pf; \ + tp->p_ctx.sp->r11 = arg; \ + tp->p_ctx.sp->pc = threadstart; \ +} + +#define IDLE_THREAD_STACK_SIZE 0 + +#define INT_REQUIRED_STACK 16 +#define StackAlign(n) ((((n) - 1) | 1) + 1) +#define UserStackSize(n) StackAlign(sizeof(Thread) + \ + sizeof(struct intctx) + \ + sizeof(struct extctx) + \ + (n) + (INT_REQUIRED_STACK)) +#define WorkingArea(s, n) uint16_t s[UserStackSize(n >> 1)]; + +#define chSysLock() asm volatile ("dint") +#define chSysUnlock() asm volatile ("eint") + +#define chSysIRQEnterI() +#define chSysIRQExitI() { \ + if (chSchRescRequiredI1()) \ + chSchDoRescheduleI(); \ +} + +#ifdef __cplusplus +extern "C" { +#endif + void _IdleThread(void *p); + void chSysHalt(void); + void chSysSwitchI(Thread *otp, Thread *ntp); + void chSysPuts(char *msg); + void threadstart(void); +#ifdef __cplusplus +} +#endif + +#endif /* _CHCORE_H_ */ diff --git a/ports/MSP430/chtypes.h b/ports/MSP430/chtypes.h new file mode 100644 index 000000000..e1fc14ef6 --- /dev/null +++ b/ports/MSP430/chtypes.h @@ -0,0 +1,51 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @addtogroup Core + * @{ + */ + +#ifndef _CHTYPES_H_ +#define _CHTYPES_H_ + +#define __need_NULL +#define __need_size_t +#include + +#if !defined(_STDINT_H) && !defined(__STDINT_H_) +#include +#endif + +typedef int16_t bool_t; /* Signed boolean. */ +typedef uint8_t tmode_t; /* Thread mode flags, uint8_t is ok. */ +typedef uint8_t tstate_t; /* Thread state, uint8_t is ok. */ +typedef uint16_t tid_t; /* Thread id. */ +typedef uint16_t tprio_t; /* Priority, use the fastest unsigned type. */ +typedef int16_t msg_t; /* Message, use signed pointer equivalent.*/ +typedef int16_t eventid_t; /* Event Id, use fastest signed.*/ +typedef uint16_t eventmask_t;/* Event Mask, recommended fastest unsigned.*/ +typedef uint16_t systime_t; /* System Time, recommended fastest unsigned.*/ +typedef int16_t cnt_t; /* Counter, recommended fastest signed.*/ + +#define INLINE inline + +#endif /* _CHTYPES_H_ */ + +/** @} */ -- cgit v1.2.3