diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-05-23 09:03:49 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-05-23 09:03:49 +0000 |
commit | 957da89e719258a6cbb4b7c655baeef976d28cb9 (patch) | |
tree | 44f9383b32f8577b8bee1d878c862c268b21768b /demos/GNU-Linux-GCC | |
parent | ee149fd1c7d5a9bfafc69bac428d89a2a3e0b3de (diff) | |
download | ChibiOS-957da89e719258a6cbb4b7c655baeef976d28cb9.tar.gz ChibiOS-957da89e719258a6cbb4b7c655baeef976d28cb9.tar.bz2 ChibiOS-957da89e719258a6cbb4b7c655baeef976d28cb9.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@983 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'demos/GNU-Linux-GCC')
-rw-r--r-- | demos/GNU-Linux-GCC/Makefile | 136 | ||||
-rw-r--r-- | demos/GNU-Linux-GCC/chconf.h | 393 | ||||
-rw-r--r-- | demos/GNU-Linux-GCC/chcore.c | 107 | ||||
-rw-r--r-- | demos/GNU-Linux-GCC/chcore.h | 209 | ||||
-rw-r--r-- | demos/GNU-Linux-GCC/chtypes.h | 47 | ||||
-rw-r--r-- | demos/GNU-Linux-GCC/main.c | 53 | ||||
-rw-r--r-- | demos/GNU-Linux-GCC/readme.txt | 33 |
7 files changed, 978 insertions, 0 deletions
diff --git a/demos/GNU-Linux-GCC/Makefile b/demos/GNU-Linux-GCC/Makefile new file mode 100644 index 000000000..988cf0364 --- /dev/null +++ b/demos/GNU-Linux-GCC/Makefile @@ -0,0 +1,136 @@ +#
+# !!!! Do NOT edit this makefile with an editor which replace tabs by spaces !!!!
+#
+##############################################################################################
+#
+# On command line:
+#
+# make all = Create project
+#
+# make clean = Clean project files.
+#
+# To rebuild project do "make clean" and "make all".
+#
+
+##############################################################################################
+# Start of default section
+#
+
+TRGT = i686-pc-cygwin-
+CC = $(TRGT)gcc-4
+AS = $(TRGT)gcc-4 -x assembler-with-cpp
+
+# List all default C defines here, like -D_DEBUG=1
+DDEFS =
+
+# List all default ASM defines here, like -D_DEBUG=1
+DADEFS =
+
+# List all default directories to look for include files here
+DINCDIR =
+
+# List the default directory to look for the libraries here
+DLIBDIR =
+
+# List all default libraries here
+DLIBS =
+
+#
+# End of default section
+##############################################################################################
+
+##############################################################################################
+# Start of user section
+#
+
+# Define project name here
+PROJECT = ch
+
+# Define linker script file here
+LDSCRIPT=
+
+# List all user C define here, like -D_DEBUG=1
+UDEFS =
+
+# Define ASM defines here
+UADEFS =
+
+# Imported source files
+include ../../src/kernel.mk
+include ../../test/test.mk
+
+# List C source files here
+SRC = chcore.c main.c \
+ ${KERNSRC} \
+ ${TESTSRC}
+
+# List ASM source files here
+ASRC =
+
+# List all user directories here
+UINCDIR = ../../src/include
+
+# List the user directory to look for the libraries here
+ULIBDIR =
+
+# List all user libraries here
+ULIBS =
+
+# Define optimisation level here
+OPT = -ggdb -O2 -fomit-frame-pointer
+
+#
+# End of user defines
+##############################################################################################
+
+
+INCDIR = $(patsubst %,-I%,$(DINCDIR) $(UINCDIR))
+LIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR))
+DEFS = $(DDEFS) $(UDEFS)
+ADEFS = $(DADEFS) $(UADEFS)
+OBJS = $(ASRC:.s=.o) $(SRC:.c=.o)
+LIBS = $(DLIBS) $(ULIBS)
+
+LDFLAGS = -Wl,-Map=$(PROJECT).map,--cref,--no-warn-mismatch $(LIBDIR)
+ASFLAGS = -Wa,-amhls=$(<:.s=.lst) $(ADEFS)
+CPFLAGS = $(OPT) -Wall -Wstrict-prototypes -fverbose-asm -Wa,-alms=$(<:.c=.lst) $(DEFS)
+
+# Generate dependency information
+CPFLAGS += -MD -MP -MF .dep/$(@F).d
+
+#
+# makefile rules
+#
+
+all: $(OBJS) $(PROJECT).exe
+
+%o : %c
+ $(CC) -c $(CPFLAGS) -I . $(INCDIR) $< -o $@
+
+%o : %s
+ $(AS) -c $(ASFLAGS) $< -o $@
+
+%exe: $(OBJS)
+ $(CC) $(OBJS) $(LDFLAGS) $(LIBS) -o $@
+
+gcov:
+ -mkdir gcov
+ $(COV) -u $(subst /,\,$(SRC))
+ -mv *.gcov ./gcov
+
+clean:
+ -rm -f $(OBJS)
+ -rm -f $(PROJECT).exe
+ -rm -f $(PROJECT).map
+ -rm -f $(SRC:.c=.c.bak)
+ -rm -f $(SRC:.c=.lst)
+ -rm -f $(ASRC:.s=.s.bak)
+ -rm -f $(ASRC:.s=.lst)
+ -rm -fR .dep
+
+#
+# Include the dependency files, should be the last of the makefile
+#
+-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
+
+# *** EOF ***
diff --git a/demos/GNU-Linux-GCC/chconf.h b/demos/GNU-Linux-GCC/chconf.h new file mode 100644 index 000000000..273ba602f --- /dev/null +++ b/demos/GNU-Linux-GCC/chconf.h @@ -0,0 +1,393 @@ +/*
+ 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/>.
+*/
+
+/**
+ * @file src/templates/chconf.h
+ * @brief Configuration file template.
+ * @addtogroup Config
+ * @{
+ */
+
+#ifndef _CHCONF_H_
+#define _CHCONF_H_
+
+/*===========================================================================*/
+/* Kernel parameters. */
+/*===========================================================================*/
+
+/**
+ * Frequency of the system timer that drives the system ticks. This also
+ * defines the system tick time unit.
+ */
+#if !defined(CH_FREQUENCY) || defined(__DOXYGEN__)
+#define CH_FREQUENCY 100
+#endif
+
+/**
+ * This constant is the number of system ticks allowed for the threads before
+ * preemption occurs. This option is only meaningful if the option
+ * @p CH_USE_ROUNDROBIN is also active.
+ */
+#if !defined(CH_TIME_QUANTUM) || defined(__DOXYGEN__)
+#define CH_TIME_QUANTUM 20
+#endif
+
+/**
+ * If enabled then the use of nested @p chSysLock() / @p chSysUnlock()
+ * operations is allowed.<br>
+ * For performance and code size reasons the recommended setting is to leave
+ * this option disabled.<br>
+ * You can use this option if you need to merge ChibiOS/RT with external
+ * libraries that require nested lock/unlock operations.
+ * @note The default is @p FALSE.
+ */
+#if !defined(CH_USE_NESTED_LOCKS) || defined(__DOXYGEN__)
+#define CH_USE_NESTED_LOCKS FALSE
+#endif
+
+/**
+ * If specified then the kernel performs the round robin scheduling algorithm
+ * on threads of equal priority.
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_USE_ROUNDROBIN) || defined(__DOXYGEN__)
+#define CH_USE_ROUNDROBIN TRUE
+#endif
+
+/**
+ * Number of RAM bytes to use as system heap. If set to zero then the whole
+ * available RAM is used as system heap.
+ * @note In order to use the whole RAM as system heap the linker script must
+ * provide the @p __heap_base__ and @p __heap_end__ symbols.
+ * @note Requires @p CH_USE_HEAP.
+ */
+#if !defined(CH_HEAP_SIZE) || defined(__DOXYGEN__)
+#define CH_HEAP_SIZE 0x20000
+#endif
+
+/*===========================================================================*/
+/* Performance options. */
+/*===========================================================================*/
+
+/**
+ * If specified then time efficient rather than space efficient code is used
+ * when two possible implementations exist.
+ * @note This is not related to the compiler optimization options.
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_OPTIMIZE_SPEED) || defined(__DOXYGEN__)
+#define CH_OPTIMIZE_SPEED TRUE
+#endif
+
+/**
+ * If enabled defines a CPU register to be used as storage for the global
+ * @p currp variable. Caching this variable in a register can greatly
+ * improve both space and time efficiency of the generated code. Another side
+ * effect is that one less register has to be saved during the context switch
+ * resulting in lower RAM usage and faster code.
+ * @note This option is only usable with the GCC compiler and is only useful
+ * on processors with many registers like ARM cores.
+ * @note If this option is enabled then ALL the libraries linked to the
+ * ChibiOS/RT code <b>must</b> be recompiled with the GCC option @p
+ * -ffixed-@<reg@>.
+ * @note This option must be enabled in the Makefile, it is listed here for
+ * documentation.
+ */
+#if defined(__DOXYGEN__)
+#define CH_CURRP_REGISTER_CACHE "reg"
+#endif
+
+/*===========================================================================*/
+/* Subsystem options. */
+/*===========================================================================*/
+
+/**
+ * If specified then the @p chThdWait() function is included in the kernel.
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_USE_WAITEXIT) || defined(__DOXYGEN__)
+#define CH_USE_WAITEXIT TRUE
+#endif
+
+/**
+ * If specified then the Semaphores APIs are included in the kernel.
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_USE_SEMAPHORES) || defined(__DOXYGEN__)
+#define CH_USE_SEMAPHORES TRUE
+#endif
+
+/**
+ * If enabled then the threads are enqueued on semaphores by priority rather
+ * than FIFO order.
+ * @note The default is @p FALSE. Enable this if you have special requirements.
+ * @note Requires @p CH_USE_SEMAPHORES.
+ */
+#if !defined(CH_USE_SEMAPHORES_PRIORITY) || defined(__DOXYGEN__)
+#define CH_USE_SEMAPHORES_PRIORITY FALSE
+#endif
+
+/**
+ * If specified then the Semaphores the @p chSemWaitSignal() API is included
+ * in the kernel.
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_USE_SEMAPHORES.
+ */
+#if !defined(CH_USE_SEMSW) || defined(__DOXYGEN__)
+#define CH_USE_SEMSW TRUE
+#endif
+
+/**
+ * If specified then the Mutexes APIs are included in the kernel.
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_USE_MUTEXES) || defined(__DOXYGEN__)
+#define CH_USE_MUTEXES TRUE
+#endif
+
+/**
+ * If specified then the Conditional Variables APIs are included in the kernel.
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_USE_MUTEXES.
+ */
+#if !defined(CH_USE_CONDVARS) || defined(__DOXYGEN__)
+#define CH_USE_CONDVARS TRUE
+#endif
+
+/**
+ * If specified then the Conditional Variables APIs are included in the kernel.
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_USE_CONDVARS.
+ */
+#if !defined(CH_USE_CONDVARS_TIMEOUT) || defined(__DOXYGEN__)
+#define CH_USE_CONDVARS_TIMEOUT TRUE
+#endif
+
+/**
+ * If specified then the Event flags APIs are included in the kernel.
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_USE_EVENTS) || defined(__DOXYGEN__)
+#define CH_USE_EVENTS TRUE
+#endif
+
+/**
+ * If specified then the @p chEvtWaitXXXTimeout() functions are included in
+ * the kernel.
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_USE_EVENTS.
+ */
+#if !defined(CH_USE_EVENTS_TIMEOUT) || defined(__DOXYGEN__)
+#define CH_USE_EVENTS_TIMEOUT TRUE
+#endif
+
+/**
+ * If specified then the Synchronous Messages APIs are included in the kernel.
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_USE_MESSAGES) || defined(__DOXYGEN__)
+#define CH_USE_MESSAGES TRUE
+#endif
+
+/**
+ * If enabled then messages are served by priority rather than in FIFO order.
+ * @note The default is @p FALSE. Enable this if you have special requirements.
+ * @note Requires @p CH_USE_MESSAGES.
+ */
+#if !defined(CH_USE_MESSAGES_PRIORITY) || defined(__DOXYGEN__)
+#define CH_USE_MESSAGES_PRIORITY FALSE
+#endif
+
+/**
+ * If specified then the Asynchronous Messages (Mailboxes) APIs are included
+ * in the kernel.
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_USE_MAILBOXES) || defined(__DOXYGEN__)
+#define CH_USE_MAILBOXES TRUE
+#endif
+
+/**
+ * If specified then the I/O queues APIs are included in the kernel.
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_USE_SEMAPHORES.
+ */
+#if !defined(CH_USE_QUEUES) || defined(__DOXYGEN__)
+#define CH_USE_QUEUES TRUE
+#endif
+
+/**
+ * If specified then the full duplex serial driver APIs are included in the
+ * kernel.
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_USE_QUEUES.
+ */
+#if !defined(CH_USE_SERIAL_FULLDUPLEX) || defined(__DOXYGEN__)
+#define CH_USE_SERIAL_FULLDUPLEX TRUE
+#endif
+
+/**
+ * If specified then the memory heap allocator APIs are included in the kernel.
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_USE_MUTEXES or @p CH_USE_SEMAPHORES.
+ * @note Mutexes are recommended.
+ */
+#if !defined(CH_USE_HEAP) || defined(__DOXYGEN__)
+#define CH_USE_HEAP TRUE
+#endif
+
+/**
+ * If enabled enforces the use of the C-runtime @p malloc() and @p free()
+ * functions as backend for the system heap allocator.
+ * @note The default is @p FALSE.
+ * @note Requires @p CH_USE_HEAP.
+ */
+#if !defined(CH_USE_MALLOC_HEAP) || defined(__DOXYGEN__)
+#define CH_USE_MALLOC_HEAP FALSE
+#endif
+
+/**
+ * If specified then the memory pools allocator APIs are included in the
+ * kernel.
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_USE_MEMPOOLS) || defined(__DOXYGEN__)
+#define CH_USE_MEMPOOLS TRUE
+#endif
+
+/**
+ * If specified then the dynamic threads creation APIs are included in the
+ * kernel.
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_USE_WAITEXIT.
+ */
+#if !defined(CH_USE_DYNAMIC) || defined(__DOXYGEN__)
+#define CH_USE_DYNAMIC TRUE
+#endif
+
+/*===========================================================================*/
+/* Debug options. */
+/*===========================================================================*/
+
+/**
+ * Debug option, if enabled then the checks on the API functions input
+ * parameters are activated.
+ * @note The default is @p FALSE.
+ */
+#if !defined(CH_DBG_ENABLE_CHECKS) || defined(__DOXYGEN__)
+#define CH_DBG_ENABLE_CHECKS FALSE
+#endif
+
+/**
+ * Debug option, if enabled then all the assertions in the kernel code are
+ * activated. This includes consistency checks inside the kernel, runtime
+ * anomalies and port-defined checks.
+ * @note The default is @p FALSE.
+ */
+#if !defined(CH_DBG_ENABLE_ASSERTS) || defined(__DOXYGEN__)
+#define CH_DBG_ENABLE_ASSERTS FALSE
+#endif
+
+/**
+ * Debug option, if enabled the context switch circular trace buffer is
+ * activated.
+ * @note The default is @p FALSE.
+ */
+#if !defined(CH_DBG_ENABLE_TRACE) || defined(__DOXYGEN__)
+#define CH_DBG_ENABLE_TRACE FALSE
+#endif
+
+/**
+ * Debug option, if enabled a runtime stack check is performed.
+ * @note The stack check is performed in a architecture/port dependent way. It
+ * may not be implemented at all.
+ */
+#if !defined(CH_DBG_ENABLE_STACK_CHECK) || defined(__DOXYGEN__)
+#define CH_DBG_ENABLE_STACK_CHECK FALSE
+#endif
+
+/**
+ * Debug option, if enabled the threads working area is filled with a byte
+ * pattern when a thread is created. + */
+#if !defined(CH_DBG_FILL_THREADS) || defined(__DOXYGEN__)
+#define CH_DBG_FILL_THREADS FALSE
+#endif
+
+/**
+ * Debug option, if enabled a field is added to the @p Thread structure that
+ * counts the system ticks occurred while executing the thread.
+ */
+#if !defined(CH_DBG_THREADS_PROFILING) || defined(__DOXYGEN__)
+#define CH_DBG_THREADS_PROFILING TRUE
+#endif
+
+/*===========================================================================*/
+/* Kernel hooks. */
+/*===========================================================================*/
+
+/**
+ * User fields added to the end of the @p Thread structure.
+ */
+#if !defined(THREAD_EXT_FIELDS) || defined(__DOXYGEN__)
+#define THREAD_EXT_FIELDS \
+struct { \
+ /* Add thread custom fields here.*/ \
+ /* The thread termination \p EventSource.*/ \
+ EventSource p_exitesource; \
+};
+#endif
+
+/**
+ * User initialization code added to the @p chThdInit() API.
+ * @note It is invoked from within @p chThdInit().
+ */
+#if !defined(THREAD_EXT_INIT) || defined(__DOXYGEN__)
+#define THREAD_EXT_INIT(tp) { \
+ /* Add thread initialization code here.*/ \
+ chEvtInit(&tp->p_exitesource); \
+}
+#endif
+
+/**
+ * User finalization code added to the @p chThdExit() API.
+ * @note It is inserted into lock zone.
+ */
+#if !defined(THREAD_EXT_EXIT) || defined(__DOXYGEN__)
+#define THREAD_EXT_EXIT(tp) { \
+ /* Add thread finalization code here.*/ \
+ chEvtBroadcastI(&currp->p_exitesource); \
+}
+#endif
+
+/**
+ * Code inserted inside the idle thread loop immediately after an interrupt
+ * resumed execution. + */
+#if !defined(IDLE_LOOP_HOOK) || defined(__DOXYGEN__)
+#define IDLE_LOOP_HOOK() { \
+ /* Idle loop code here.*/ \
+}
+#endif
+
+#define chThdGetExitEventSource(tp) (&(tp)->p_exitesource)
+
+#endif /* _CHCONF_H_ */
+
+/** @} */
diff --git a/demos/GNU-Linux-GCC/chcore.c b/demos/GNU-Linux-GCC/chcore.c new file mode 100644 index 000000000..b9aa187ab --- /dev/null +++ b/demos/GNU-Linux-GCC/chcore.c @@ -0,0 +1,107 @@ +/*
+ 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 <time.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <sys/time.h>
+
+/**
+ * @addtogroup LINUXSIM_CORE
+ * @{
+ */
+
+#include <ch.h>
+
+static struct itimerval tempo;
+static bool_t pending = FALSE;
+
+void timer(int numSignal) {
+
+ pending = TRUE;
+}
+
+/*
+ * Simulated HW initialization.
+ */
+void _init_core(void) {
+
+ signal(SIGALRM, timer);
+ tempo.it_value.tv_sec = 0;
+ tempo.it_value.tv_usec = 10000;
+ tempo.it_interval.tv_sec = 0;
+ tempo.it_interval.tv_usec = 10000;
+ setitimer(ITIMER_REAL, &tempo, NULL);
+}
+
+/*
+ * Interrupt simulation.
+ */
+void ChkIntSources(void) {
+
+ if (pending) {
+ chSysTimerHandlerI();
+ pending = FALSE;
+ }
+
+ if (chSchRescRequiredI())
+ chSchDoRescheduleI();
+}
+
+/**
+ * Performs a context switch between two threads.
+ * @param otp the thread to be switched out
+ * @param ntp the thread to be switched in + */
+__attribute__((used))
+static void __dummy(Thread *otp, Thread *ntp) {
+ asm volatile (".globl @port_switch@8 \n\t" \
+ "@port_switch@8: \n\t" \
+ "push %ebp \n\t" \
+ "push %esi \n\t" \
+ "push %edi \n\t" \
+ "push %ebx \n\t" \
+ "movl %esp, 16(%ecx) \n\t" \
+ "movl 16(%edx), %esp \n\t" \
+ "pop %ebx \n\t" \
+ "pop %edi \n\t" \
+ "pop %esi \n\t" \
+ "pop %ebp \n\t" \
+ "ret");
+}
+
+/**
+ * Halts the system. In this implementation it just exits the simulation. + */
+__attribute__((fastcall))
+void port_halt(void) {
+
+ exit(2);
+}
+
+/**
+ * Threads return point, it just invokes @p chThdExit(). + */
+void threadexit(void) {
+
+ asm volatile ("push %eax \n\t" \
+ "call _chThdExit");
+}
+
+/** @} */
diff --git a/demos/GNU-Linux-GCC/chcore.h b/demos/GNU-Linux-GCC/chcore.h new file mode 100644 index 000000000..fca0a03ea --- /dev/null +++ b/demos/GNU-Linux-GCC/chcore.h @@ -0,0 +1,209 @@ +/*
+ 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/>.
+*/
+
+/**
+ * @addtogroup WIN32SIM_CORE
+ * @{
+ */
+
+#ifndef _CHCORE_H_
+#define _CHCORE_H_
+
+/**
+ * Macro defining the a simulated architecture into Win32.
+ */
+#define CH_ARCHITECTURE_WIN32SIM
+
+/**
+ * Name of the implemented architecture.
+ */
+#define CH_ARCHITECTURE_NAME "WIN32 Simulator"
+
+/**
+ * 32 bit stack alignment.
+ */
+typedef uint32_t stkalign_t;
+
+/**
+ * Generic x86 register. + */
+typedef void *regx86;
+
+/**
+ * Interrupt saved context.
+ * This structure represents the stack frame saved during a preemption-capable
+ * interrupt handler.
+ */
+struct extctx {
+};
+
+/**
+ * System saved context.
+ * @note In this demo the floating point registers are not saved.
+ */
+struct intctx {
+ regx86 ebx;
+ regx86 edi;
+ regx86 esi;
+ regx86 ebp;
+ regx86 eip;
+};
+
+/**
+ * Platform dependent part of the @p Thread structure.
+ * This structure usually contains just the saved stack pointer defined as a
+ * pointer to a @p intctx structure.
+ */
+struct context {
+ struct intctx volatile *esp;
+};
+
+#define APUSH(p, a) (p) -= sizeof(void *), *(void **)(p) = (void*)(a)
+
+/**
+ * Platform dependent part of the @p chThdInit() API.
+ * This code usually setup the context switching frame represented by a
+ * @p intctx structure.
+ */
+#define SETUP_CONTEXT(workspace, wsize, pf, arg) { \
+ uint8_t *esp = (uint8_t *)workspace + wsize; \
+ APUSH(esp, arg); \
+ APUSH(esp, threadexit); \
+ esp -= sizeof(struct intctx); \
+ ((struct intctx *)esp)->eip = pf; \
+ ((struct intctx *)esp)->ebx = 0; \
+ ((struct intctx *)esp)->edi = 0; \
+ ((struct intctx *)esp)->esi = 0; \
+ ((struct intctx *)esp)->ebp = 0; \
+ tp->p_ctx.esp = (struct intctx *)esp; \
+}
+
+/**
+ * Stack size for the system idle thread.
+ */
+#ifndef IDLE_THREAD_STACK_SIZE
+#define IDLE_THREAD_STACK_SIZE 256
+#endif
+
+/**
+ * Per-thread stack overhead for interrupts servicing, it is used in the
+ * calculation of the correct working area size.
+ */
+#ifndef INT_REQUIRED_STACK
+#define INT_REQUIRED_STACK 0x40000
+#endif
+
+/**
+ * Enforces a correct alignment for a stack area size value.
+ */
+#define STACK_ALIGN(n) ((((n) - 1) | (sizeof(stkalign_t) - 1)) + 1)
+
+ /**
+ * Computes the thread working area global size.
+ */
+#define THD_WA_SIZE(n) STACK_ALIGN(sizeof(Thread) + \
+ sizeof(void *) * 2 + \
+ sizeof(struct intctx) + \
+ sizeof(struct extctx) + \
+ (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)];
+
+/**
+ * IRQ prologue code, inserted at the start of all IRQ handlers enabled to
+ * invoke system APIs. + */
+#define PORT_IRQ_PROLOGUE()
+
+/**
+ * IRQ epilogue code, inserted at the end of all IRQ handlers enabled to
+ * invoke system APIs.
+ */
+#define PORT_IRQ_EPILOGUE()
+
+/**
+ * IRQ handler function declaration.
+ */
+#define PORT_IRQ_HANDLER(id) void id(void)
+
+/**
+ * Simulator initialization.
+ */
+#define port_init() _init_core()
+
+/**
+ * Does nothing in this simulator.
+ */
+#define port_lock()
+
+/**
+ * Does nothing in this simulator.
+ */
+#define port_unlock()
+
+/**
+ * Does nothing in this simulator.
+ */
+#define port_lock_from_isr()
+
+/**
+ * Does nothing in this simulator.
+ */
+#define port_unlock_from_isr()
+
+/**
+ * Does nothing in this simulator.
+ */
+#define port_disable()
+
+/**
+ * Does nothing in this simulator.
+ */
+#define port_suspend()
+
+/**
+ * Does nothing in this simulator.
+ */
+#define port_enable()
+
+/**
+ * In the simulator this does a polling pass on the simulated interrupt
+ * sources.
+ */
+#define port_wait_for_interrupt() ChkIntSources()
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ __attribute__((fastcall)) void port_switch(Thread *otp, Thread *ntp);
+ __attribute__((fastcall)) void port_halt(void);
+ void _init_core(void);
+ void ChkIntSources(void);
+ void threadexit(void);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _CHCORE_H_ */
+
+/** @} */
diff --git a/demos/GNU-Linux-GCC/chtypes.h b/demos/GNU-Linux-GCC/chtypes.h new file mode 100644 index 000000000..354da269e --- /dev/null +++ b/demos/GNU-Linux-GCC/chtypes.h @@ -0,0 +1,47 @@ +/*
+ 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_
+
+#define __need_NULL
+#define __need_size_t
+#define __need_ptrdiff_t
+#include <stddef.h>
+
+#if !defined(_STDINT_H) && !defined(__STDINT_H_)
+#include <stdint.h>
+#endif
+
+typedef int8_t bool_t;
+typedef uint8_t tmode_t;
+typedef uint8_t tstate_t;
+typedef uint32_t tprio_t;
+typedef int32_t msg_t;
+typedef int32_t eventid_t;
+typedef uint32_t eventmask_t;
+typedef uint32_t systime_t;
+typedef int32_t cnt_t;
+
+#define INLINE inline
+#define PACK_STRUCT_STRUCT __attribute__((packed))
+#define PACK_STRUCT_BEGIN
+#define PACK_STRUCT_END
+
+#endif /* _CHTYPES_H_ */
diff --git a/demos/GNU-Linux-GCC/main.c b/demos/GNU-Linux-GCC/main.c new file mode 100644 index 000000000..15cb358fd --- /dev/null +++ b/demos/GNU-Linux-GCC/main.c @@ -0,0 +1,53 @@ +/*
+ 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 <stdio.h>
+
+#include <ch.h>
+
+static WORKING_AREA(waThread1, 2048);
+static msg_t Thread1(void *arg) {
+
+ while (TRUE) {
+ chThdSleepMilliseconds(1000);
+ printf("Hello World!");
+ }
+ return 0;
+}
+
+/*------------------------------------------------------------------------*
+ * Simulator main, start here your threads, examples inside. *
+ *------------------------------------------------------------------------*/
+int main(void) {
+
+ /*
+ * ChibiOS/RT initialization. + */
+ chSysInit();
+
+ /*
+ * Starting threads. + */
+ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
+
+ while (TRUE)
+ chThdSleepSeconds(1);
+
+ return 0;
+}
diff --git a/demos/GNU-Linux-GCC/readme.txt b/demos/GNU-Linux-GCC/readme.txt new file mode 100644 index 000000000..48bb35048 --- /dev/null +++ b/demos/GNU-Linux-GCC/readme.txt @@ -0,0 +1,33 @@ +*****************************************************************************
+** ChibiOS/RT port for x86 into a Win32 process **
+*****************************************************************************
+
+** TARGET **
+
+The demo runs under Linux as an application program. The serial I/O is
+simulated over TCP/IP sockets.
+
+** The Demo **
+
+The demo listens on the two serial ports, when a connection is detected a
+thread is started that serves a small command shell.
+The demo shows how create/terminate threads at runtime, how listen to events,
+how ho work with serial ports, how use the messages.
+You can develop your ChibiOS/RT application using this demo as a simulator
+then you can recompile it for a different architecture.
+See demo.c for details.
+
+** Build Procedure **
+
+Makefile.
+
+** Connect to the demo **
+
+In order to connect to the demo a telnet client is required. A good choice
+is PuTTY:
+
+http://www.putty.org/
+
+Host Name: 127.0.0.1
+Port: 29001 and/or 29002
+Connection Type: Raw
|