diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2008-02-27 15:36:56 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2008-02-27 15:36:56 +0000 |
commit | 1d8c29c017b98aa823230ce49e9dbae2911b1e02 (patch) | |
tree | d3f8d944030c6b4ba6b98b77aa0329cbf2906837 /ports | |
parent | a40f3424bd4c24f28f43746af79eafdc3faf76ce (diff) | |
download | ChibiOS-1d8c29c017b98aa823230ce49e9dbae2911b1e02.tar.gz ChibiOS-1d8c29c017b98aa823230ce49e9dbae2911b1e02.tar.bz2 ChibiOS-1d8c29c017b98aa823230ce49e9dbae2911b1e02.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@206 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'ports')
-rw-r--r-- | ports/AVR/chcore.c | 121 | ||||
-rw-r--r-- | ports/AVR/chcore.h | 127 | ||||
-rw-r--r-- | ports/AVR/chtypes.h | 48 |
3 files changed, 296 insertions, 0 deletions
diff --git a/ports/AVR/chcore.c b/ports/AVR/chcore.c new file mode 100644 index 000000000..7907de1dd --- /dev/null +++ b/ports/AVR/chcore.c @@ -0,0 +1,121 @@ +/*
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+#include <ch.h>
+
+#include <avr/io.h>
+
+void _IdleThread(void *p) {
+
+ while (TRUE) {
+// asm("sleep");
+ }
+}
+
+/*
+ * Threads start code.
+ */
+void threadstart(void) {
+
+ asm volatile ("sei");
+ asm volatile ("movw r24, r4");
+ asm volatile ("movw r30, r2");
+ asm volatile ("icall");
+ asm volatile ("call chThdExit");
+}
+
+/*
+ * Context switch.
+ */
+void chSysSwitchI(Thread *otp, Thread *ntp) {
+
+ asm volatile ("push r2");
+ asm volatile ("push r3");
+ asm volatile ("push r4");
+ asm volatile ("push r5");
+ asm volatile ("push r6");
+ asm volatile ("push r7");
+#ifndef CH_CURRP_REGISTER_CACHE
+ asm volatile ("push r8");
+ asm volatile ("push r9");
+#endif
+ asm volatile ("push r10");
+ asm volatile ("push r11");
+ asm volatile ("push r12");
+ asm volatile ("push r13");
+ asm volatile ("push r14");
+ asm volatile ("push r15");
+ asm volatile ("push r16");
+ asm volatile ("push r17");
+ asm volatile ("push r28");
+ asm volatile ("push r29");
+
+ asm volatile ("movw r30, r24");
+ asm volatile ("in r0, 0x3d");
+ asm volatile ("std Z+8, r0");
+ asm volatile ("in r0, 0x3e");
+ asm volatile ("std Z+9, r0");
+
+ asm volatile ("movw r30, r22");
+ asm volatile ("ldd r0, Z+8");
+ asm volatile ("out 0x3d, r0");
+ asm volatile ("ldd r0, Z+9");
+ asm volatile ("out 0x3e, r0");
+
+ asm volatile ("pop r29");
+ asm volatile ("pop r28");
+ asm volatile ("pop r17");
+ asm volatile ("pop r16");
+ asm volatile ("pop r15");
+ asm volatile ("pop r14");
+ asm volatile ("pop r13");
+ asm volatile ("pop r12");
+ asm volatile ("pop r11");
+ asm volatile ("pop r10");
+#ifndef CH_CURRP_REGISTER_CACHE
+ asm volatile ("pop r9");
+ asm volatile ("pop r8");
+#endif
+ asm volatile ("pop r7");
+ asm volatile ("pop r6");
+ asm volatile ("pop r5");
+ asm volatile ("pop r4");
+ asm volatile ("pop r3");
+ asm volatile ("pop r2");
+ asm volatile ("ret");
+}
+
+/*
+ * System console message (not implemented).
+ */
+__attribute__((weak))
+void chSysPuts(char *msg) {
+}
+
+/*
+ * System halt.
+ */
+__attribute__((noreturn, weak))
+void chSysHalt(void) {
+
+ chSysLock();
+
+ while (TRUE)
+ ;
+}
diff --git a/ports/AVR/chcore.h b/ports/AVR/chcore.h new file mode 100644 index 000000000..3fd027951 --- /dev/null +++ b/ports/AVR/chcore.h @@ -0,0 +1,127 @@ +/*
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _CHCORE_H_
+#define _CHCORE_H_
+
+/*
+ * Interrupt saved context.
+ */
+struct extctx {
+ BYTE8 _next;
+ BYTE8 r31;
+ BYTE8 r30;
+ BYTE8 r27;
+ BYTE8 r26;
+ BYTE8 r25;
+ BYTE8 r24;
+ BYTE8 r23;
+ BYTE8 r22;
+ BYTE8 r21;
+ BYTE8 r20;
+ BYTE8 r19;
+ BYTE8 r18;
+ BYTE8 sr;
+ BYTE8 r1;
+ BYTE8 r0;
+ UWORD16 pc;
+};
+
+/*
+ * System saved context.
+ */
+struct intctx {
+ BYTE8 _next;
+ BYTE8 r29;
+ BYTE8 r28;
+ BYTE8 r17;
+ BYTE8 r16;
+ BYTE8 r15;
+ BYTE8 r14;
+ BYTE8 r13;
+ BYTE8 r12;
+ BYTE8 r11;
+ BYTE8 r10;
+#ifndef CH_CURRP_REGISTER_CACHE
+ BYTE8 r9;
+ BYTE8 r8;
+#endif
+ BYTE8 r7;
+ BYTE8 r6;
+ BYTE8 r5;
+ BYTE8 r4;
+ BYTE8 r3;
+ BYTE8 r2;
+ BYTE8 pcl;
+ BYTE8 pch;
+};
+
+/*
+ * Port dependent part of the Thread structure, you may add fields in
+ * this structure.
+ */
+typedef struct {
+ struct intctx *sp;
+} Context;
+
+/**
+ * Platform dependent part of the \p chThdCreate() API.
+ */
+#define SETUP_CONTEXT(workspace, wsize, pf, arg) { \
+ tp->p_ctx.sp = (struct intctx*)((BYTE8 *)workspace + wsize - 1 - \
+ (sizeof(struct intctx) - 1)); \
+ tp->p_ctx.sp->r2 = (int)pf; \
+ tp->p_ctx.sp->r3 = (int)pf >> 8; \
+ tp->p_ctx.sp->r4 = (int)arg; \
+ tp->p_ctx.sp->r5 = (int)arg >> 8; \
+ tp->p_ctx.sp->pcl = (int)threadstart >> 8; \
+ tp->p_ctx.sp->pch = (int)threadstart; \
+}
+
+#define INT_REQUIRED_STACK 0x10
+#define StackAlign(n) (n)
+#define UserStackSize(n) StackAlign(sizeof(Thread) + \
+ (sizeof(struct intctx) - 1) + \
+ (sizeof(struct extctx) - 1) + \
+ (n) + (INT_REQUIRED_STACK))
+#define WorkingArea(s, n) BYTE8 s[UserStackSize(n)];
+
+#define chSysLock() asm volatile ("cli")
+
+#define chSysUnlock() asm volatile ("sei")
+
+#define chSysIRQEnterI() \
+ asm ("" : : : "r18", "r19", "r20", "r21", "r22", "r23", "r24", \
+ "r25", "r26", "r27", "r30", "r31");
+
+
+#define chSysIRQExitI() { \
+ if (chSchRescRequiredI()) \
+ chSchDoRescheduleI(); \
+}
+
+#define IDLE_THREAD_STACK_SIZE 8
+void _IdleThread(void *p) __attribute__((noreturn));
+
+void chSysHalt(void) __attribute__((noreturn)) ;
+void chSysSwitchI(Thread *otp, Thread *ntp);
+void chSysPuts(char *msg);
+void threadstart(void) __attribute__((naked));
+
+#endif /* _CHCORE_H_ */
diff --git a/ports/AVR/chtypes.h b/ports/AVR/chtypes.h new file mode 100644 index 000000000..60e16aaf4 --- /dev/null +++ b/ports/AVR/chtypes.h @@ -0,0 +1,48 @@ +/*
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _CHTYPES_H_
+#define _CHTYPES_H_
+
+/*
+ * Generic types often dependant on the compiler.
+ */
+#define BOOL char
+#define BYTE8 unsigned char
+#define SBYTE8 signed char
+#define WORD16 int
+#define UWORD16 unsigned int
+#define LONG32 long
+#define ULONG32 unsigned long
+#define PTR_EQ int
+
+typedef BYTE8 t_tmode;
+typedef BYTE8 t_tstate;
+typedef BYTE8 t_tid;
+typedef BYTE8 t_prio;
+typedef WORD16 t_msg;
+typedef BYTE8 t_eventid;
+typedef BYTE8 t_eventmask;
+typedef UWORD16 t_time;
+typedef SBYTE8 t_cnt;
+typedef UWORD16 t_size;
+
+#define INLINE inline
+
+#endif /* _CHTYPES_H_ */
|