From 549f84d1206d14b5778cf5a723ee6b0942132158 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 18 Sep 2007 12:36:20 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- demos/Win32-MinGW/chconf.h | 158 +++++++++++++++++++++++ demos/Win32-MinGW/chcore.c | 105 +++++++++++++++ demos/Win32-MinGW/chcore.h | 74 +++++++++++ demos/Win32-MinGW/chcore2.s | 43 +++++++ demos/Win32-MinGW/chtypes.h | 52 ++++++++ demos/Win32-MinGW/demo.c | 305 ++++++++++++++++++++++++++++++++++++++++++++ demos/Win32-MinGW/makefile | 129 +++++++++++++++++++ 7 files changed, 866 insertions(+) create mode 100644 demos/Win32-MinGW/chconf.h create mode 100644 demos/Win32-MinGW/chcore.c create mode 100644 demos/Win32-MinGW/chcore.h create mode 100644 demos/Win32-MinGW/chcore2.s create mode 100644 demos/Win32-MinGW/chtypes.h create mode 100644 demos/Win32-MinGW/demo.c create mode 100644 demos/Win32-MinGW/makefile (limited to 'demos/Win32-MinGW') diff --git a/demos/Win32-MinGW/chconf.h b/demos/Win32-MinGW/chconf.h new file mode 100644 index 000000000..13de9f457 --- /dev/null +++ b/demos/Win32-MinGW/chconf.h @@ -0,0 +1,158 @@ +/* + 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 . +*/ + +/* + * Configuration file for MingGW32 demo project. + */ + +/** + * @addtogroup Config + * @{ + */ + +#ifndef _CHCONF_H_ +#define _CHCONF_H_ + +/* + * NOTE: this is just documentation for doxigen, the real configuration file + * is the one into the project directories. + */ + +/** Configuration option: if specified then time efficient rather than space + * efficient code is used when two possible implementations exist, note + * that this is not related to the compiler optimization options.*/ +#define CH_OPTIMIZE_SPEED + +/** Configuration option: if specified then the Virtual Timers subsystem is + * included in the kernel.*/ +#define CH_USE_VIRTUAL_TIMERS + +/** Configuration option: if specified then the System Timer subsystem is + * included in the kernel.*/ +#define CH_USE_SYSTEMTIME + +/** Configuration option: if specified then the \p chThdSleep() function is + * included in the kernel. + * @note requires \p CH_USE_VIRTUAL_TIMERS.*/ +#define CH_USE_SLEEP + +/** Configuration option: if specified then the \p chThdResume() + * function is included in the kernel.*/ +#define CH_USE_RESUME + +/** Configuration option: if specified then the \p chThdTerminate() + * and \p chThdShouldTerminate() functions are included in the kernel.*/ +#define CH_USE_TERMINATE + +/** Configuration option: if specified then the \p chThdWait() function + * is included in the kernel.*/ +#define CH_USE_WAITEXIT + +/** Configuration option: if specified then the Semaphores APIs are included + * in the kernel.*/ +#define CH_USE_SEMAPHORES + +/** Configuration option: if specified then the Semaphores with timeout APIs + * are included in the kernel. + * @note requires \p CH_USE_SEMAPHORES. + * @note requires \p CH_USE_VIRTUAL_TIMERS.*/ +#define CH_USE_SEMAPHORES_TIMEOUT + +/** Configuration option: if specified then the Semaphores APIs with priority + * shift are included in the kernel. + * @note requires \p CH_USE_SEMAPHORES.*/ +#define CH_USE_RT_SEMAPHORES + +/** Configuration option: if specified then the Events APIs are included in + * the kernel.*/ +#define CH_USE_EVENTS + +/** Configuration option: if specified then the \p chEvtWaitTimeout() + * function is included in the kernel. + * @note requires \p CH_USE_EVENTS. + * @note requires \p CH_USE_VIRTUAL_TIMERS.*/ +#define CH_USE_EVENTS_TIMEOUT + +/** Configuration option: if specified then the Synchronous Messages APIs are + * included in the kernel.*/ +#define CH_USE_MESSAGES + +/** Configuration option: if specified then the \p chMsgSendTimeout() + * function is included in the kernel. + * @note requires \p CH_USE_MESSAGES. + * @note requires \p CH_USE_VIRTUAL_TIMERS.*/ +#define CH_USE_MESSAGES_TIMEOUT + +/** Configuration option: if specified then the \p chMsgSendWithEvent() + * function is included in the kernel. + * @note requires \p CH_USE_MESSAGES. + * @note requires \p CH_USE_VIRTUAL_TIMERS.*/ +#define CH_USE_MESSAGES_EVENT + +/** Configuration option: if specified then the + * \p chThdGetExitEventSource() function is included in the kernel. + * @note requires \p CH_USE_MESSAGES. + * @note requires \p CH_USE_EVENTS.*/ +#define CH_USE_EXIT_EVENT + +/** Configuration option: if specified then the I/O queues APIs are included + * in the kernel.*/ +#define CH_USE_QUEUES + +/** Configuration option: if specified then the halfduplex queue APIs are + * included in the kernel.*/ +#define CH_USE_QUEUES_HALFDUPLEX + +/** Configuration option: if specified then the I/O queues with timeout + * APIs are included in the kernel. + * @note requires \p CH_USE_SEMAPHORES_TIMEOUT.*/ +#define CH_USE_QUEUES_TIMEOUT + +/** Configuration option: if specified then the full duplex serial driver APIs + * are included in the kernel.*/ +#define CH_USE_SERIAL_FULLDUPLEX + +/** Configuration option: if specified then the half duplex serial driver APIs + * are included in the kernel.*/ +#define CH_USE_SERIAL_HALFDUPLEX + +/** Configuration option: Frequency of the system timer that drives the system + * ticks. This also defines the system time unit.*/ +#define CH_FREQUENCY 100 + +/** Configuration option: This constant is the number of ticks allowed for the + * threads before preemption occurs.*/ +#define CH_TIME_QUANTUM 10 + +/** Configuration option: 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 useable 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 must be recompiled with the GCC option \p + * -ffixed-\. + */ +//#define CH_CURRP_REGISTER_CACHE "reg" + +#endif /* _CHCONF_H_ */ + +/** @} */ diff --git a/demos/Win32-MinGW/chcore.c b/demos/Win32-MinGW/chcore.c new file mode 100644 index 000000000..d48188b49 --- /dev/null +++ b/demos/Win32-MinGW/chcore.c @@ -0,0 +1,105 @@ +/* + 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 . +*/ + +/* + * Core file for MingGW32 demo project. + */ + +#include +#include + +#undef CDECL + +#include + +static LARGE_INTEGER nextcnt; +static LARGE_INTEGER slice; + +void InitSimCom1(void); +void InitSimCom2(void); +BOOL Com1ConnInterruptSimCom(void); +BOOL Com2ConnInterruptSimCom(void); +BOOL Com1InInterruptSimCom(void); +BOOL Com2InInterruptSimCom(void); +BOOL Com1OutInterruptSimCom(void); +BOOL Com2OutInterruptSimCom(void); + +/* + * Simulated HW initialization. + */ +void InitCore(void) { + WSADATA wsaData; + + // Initialization. + if (WSAStartup(2, &wsaData) != 0) { + printf("Unable to locate a winsock DLL\n"); + exit(1); + } + + printf("Win32 ChobiOS/RT simulator\n\n"); + printf("Thread structure %d bytes\n", sizeof(Thread)); + if (!QueryPerformanceFrequency(&slice)) { + printf("QueryPerformanceFrequency() error"); + exit(1); + } + printf("Core Frequency %d Hz\n", (int)slice.LowPart); + slice.QuadPart /= CH_FREQUENCY; + QueryPerformanceCounter(&nextcnt); + nextcnt.QuadPart += slice.QuadPart; + + InitSimCom1(); + InitSimCom2(); +} + +/* + * Interrupt simulation. + */ +static void ChkIntSources(void) { + LARGE_INTEGER n; + + if (Com1InInterruptSimCom() || Com2InInterruptSimCom() || + Com1OutInterruptSimCom() || Com2OutInterruptSimCom() || + Com1ConnInterruptSimCom() || Com2ConnInterruptSimCom()) { + chSchRescheduleI(); + return; + } + + // Interrupt Timer simulation (10ms interval). + QueryPerformanceCounter(&n); + if (n.QuadPart > nextcnt.QuadPart) { + nextcnt.QuadPart += slice.QuadPart; + chSchTimerHandlerI(); + if (chSchRescRequiredI()) + chSchDoRescheduleI(); + } +} + +__attribute__((fastcall)) void chSysPause(void) { + + while (TRUE) { + + ChkIntSources(); + Sleep(0); + } +} + +__attribute__((fastcall)) void chSysHalt(void) { + + exit(2); +} diff --git a/demos/Win32-MinGW/chcore.h b/demos/Win32-MinGW/chcore.h new file mode 100644 index 000000000..b8872c819 --- /dev/null +++ b/demos/Win32-MinGW/chcore.h @@ -0,0 +1,74 @@ +/* + 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 . +*/ + +/* + * Core file for MingGW32 demo project. + */ + +#ifndef _CHCORE_H_ +#define _CHCORE_H_ + +typedef void *regx86; + +/* + * Stack saved context. + */ +struct stackregs { + regx86 ebx; + regx86 edi; + regx86 esi; + regx86 ebp; + regx86 eip; +}; + +typedef struct { + struct stackregs *esp; +} Context; + +#define APUSH(p, a) (p) -= sizeof(void *), *(void **)(p) = (void*)(a) + +#define SETUP_CONTEXT(workspace, wsize, pf, arg) \ +{ \ + BYTE8 *esp = (BYTE8 *)workspace + wsize; \ + APUSH(esp, arg); \ + APUSH(esp, threadstart); \ + esp -= sizeof(struct stackregs); \ + ((struct stackregs *)esp)->eip = pf; \ + ((struct stackregs *)esp)->ebx = 0; \ + ((struct stackregs *)esp)->edi = 0; \ + ((struct stackregs *)esp)->esi = 0; \ + ((struct stackregs *)esp)->ebp = 0; \ + tp->p_ctx.esp = (struct stackregs *)esp; \ +} + +#define chSysLock() + +#define chSysUnlock() + +#define INT_REQUIRED_STACK 0x0 + +#define UserStackSize(n) (sizeof(Thread) + sizeof(PTR_EQ) + sizeof(PTR_EQ) + \ + sizeof(struct stackregs) + (n) + (INT_REQUIRED_STACK)) + +__attribute__((fastcall)) void chSysHalt(void); +__attribute__((fastcall)) void chSysPause(void); +__attribute__((fastcall)) void chSysSwitchI(Context *oldp, Context *newp); +__attribute__((fastcall)) void threadstart(void); + +#endif /* _CHCORE_H_ */ diff --git a/demos/Win32-MinGW/chcore2.s b/demos/Win32-MinGW/chcore2.s new file mode 100644 index 000000000..80985e3f7 --- /dev/null +++ b/demos/Win32-MinGW/chcore2.s @@ -0,0 +1,43 @@ +/* + 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 . +*/ + +.text + +.p2align 4,,15 +.globl @chSysSwitchI@8 +@chSysSwitchI@8: + # Switch out + push %ebp + push %esi + push %edi + push %ebx + movl %esp,(%ecx) + # Switch in + movl (%edx),%esp + pop %ebx + pop %edi + pop %esi + pop %ebp + ret + +.p2align 4,,15 +.globl @threadstart@0 +@threadstart@0: + push %ecx + call _chThdExit diff --git a/demos/Win32-MinGW/chtypes.h b/demos/Win32-MinGW/chtypes.h new file mode 100644 index 000000000..48bf7a7d9 --- /dev/null +++ b/demos/Win32-MinGW/chtypes.h @@ -0,0 +1,52 @@ +/* + 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 _CHTYPES_H_ +#define _CHTYPES_H_ + +/* + * Generic types often dependant on the compiler. + */ +#define BOOL char +#define BYTE8 unsigned char +#define WORD16 short +#define UWORD16 unsigned short +#define LONG32 int +#define ULONG32 unsigned int +#define PTR_EQ int + +typedef BYTE8 t_tmode; +typedef BYTE8 t_tstate; +typedef WORD16 t_prio; +typedef PTR_EQ t_msg; +typedef LONG32 t_eventid; +typedef ULONG32 t_eventmask; +typedef ULONG32 t_time; +typedef LONG32 t_semcnt; +typedef ULONG32 t_size; + +#define MINPRIO 0x8000 +#define MAXPRIO 0x7fff + +#define MINDELTA 0 +#define MAXDELTA 0xffff + +#define INLINE inline + +#endif /* _CHTYPES_H_ */ diff --git a/demos/Win32-MinGW/demo.c b/demos/Win32-MinGW/demo.c new file mode 100644 index 000000000..166923d2c --- /dev/null +++ b/demos/Win32-MinGW/demo.c @@ -0,0 +1,305 @@ +/* + 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 +#include + +#include + +static ULONG32 wdguard; +static BYTE8 wdarea[UserStackSize(2048)]; + +static ULONG32 iguard; +static BYTE8 iarea[UserStackSize(2048)]; + +static ULONG32 cdguard; +static BYTE8 cdarea[UserStackSize(2048)]; +static Thread *cdtp; + +static t_msg WatchdogThread(void *arg); +static t_msg ConsoleThread(void *arg); +static t_msg InitThread(void *arg); + +void InitCore(void); +extern FullDuplexDriver COM1, COM2; + +#define cprint(msg) chMsgSend(cdtp, (t_msg)msg) + +/*------------------------------------------------------------------------* + * Simulator main, start here your threads, examples inside. * + *------------------------------------------------------------------------*/ +int main(void) { + + InitCore(); + + // Startup ChibiOS/RT. + chSysInit(); + chThdCreate(NORMALPRIO + 2, 0, wdarea, sizeof(wdarea), WatchdogThread, NULL); + cdtp = chThdCreate(NORMALPRIO + 1, 0, cdarea, sizeof(cdarea), ConsoleThread, NULL); + chThdCreate(NORMALPRIO, 0, iarea, sizeof(iarea), InitThread, NULL); + chSysPause(); + return 0; +} + +/* + * Watchdog thread, it checks magic values located under the various stack + * areas. The system is halted if something is wrong. + */ +static t_msg WatchdogThread(void *arg) { + wdguard = 0xA51F2E3D; + iguard = 0xA51F2E3D; + cdguard = 0xA51F2E3D; + while (TRUE) { + + if ((wdguard != 0xA51F2E3D) || + (iguard != 0xA51F2E3D) || + (cdguard != 0xA51F2E3D)) { + printf("Halted by watchdog"); + chSysHalt(); + } + chThdSleep(5); + } + return 0; +} + +/* + * Console print server done using synchronous messages. This makes the access + * to the C printf() thread safe and the print operation atomic among threads. + * In this example the message is the zero termitated string itself. + */ +static t_msg ConsoleThread(void *arg) { + + while (!chThdShouldTerminate()) { + printf((char *)chMsgWait()); + chMsgRelease(RDY_OK); + } + return 0; +} + +static void PrintLineFDD(FullDuplexDriver *sd, char *msg) { + + while (*msg) + chFDDPut(sd, *msg++); +} + +static BOOL GetLineFDD(FullDuplexDriver *sd, char *line, int size) { + char *p = line; + + while (TRUE) { + short c = chIQGet(&sd->sd_iqueue); + if (c < 0) + return TRUE; + if (c == 4) { + PrintLineFDD(sd, "^D\r\n"); + return TRUE; + } + if (c == 8) { + if (p != line) { + chFDDPut(sd, (BYTE8)c); + chFDDPut(sd, 0x20); + chFDDPut(sd, (BYTE8)c); + p--; + } + continue; + } + if (c == '\r') { + PrintLineFDD(sd, "\r\n"); + *p = 0; + return FALSE; + } + if (c < 0x20) + continue; + if (p < line + size - 1) { + chFDDPut(sd, (BYTE8)c); + *p++ = (BYTE8)c; + } + } +} + +/* + * Example thread, not much to see here. It simulates the CTRL-C but there + * are no real signals involved. + */ +static t_msg HelloWorldThread(void *arg) { + int i; + short c; + FullDuplexDriver *sd = (FullDuplexDriver *)arg; + + for (i = 0; i < 100; i++) { + + PrintLineFDD(sd, "Hello World\r\n"); + c = chFDDGetTimeout(sd, 33); + switch (c) { + case -1: + continue; + case -2: + return 1; + case 3: + PrintLineFDD(sd, "^C\r\n"); + return 0; + default: + chThdSleep(33); + } + } + return 0; +} + +static BOOL checkend(FullDuplexDriver *sd) { + + char * lp = strtok(NULL, " \009"); /* It is not thread safe but this is a demo.*/ + if (lp) { + PrintLineFDD(sd, lp); + PrintLineFDD(sd, " ?\r\n"); + return TRUE; + } + return FALSE; +} + +/* + * Simple command shell thread, the argument is the serial line for the + * standard input and output. It recognizes few simple commands. + */ +static t_msg ShellThread(void *arg) { + FullDuplexDriver *sd = (FullDuplexDriver *)arg; + char *lp, line[64]; + Thread *tp; + BYTE8 tarea[UserStackSize(1024)]; + + chIQReset(&sd->sd_iqueue); + chOQReset(&sd->sd_oqueue); + PrintLineFDD(sd, "ChibiOS/RT Command Shell\r\n\n"); + while (TRUE) { + PrintLineFDD(sd, "ch> "); + if (GetLineFDD(sd, line, sizeof(line))) { + PrintLineFDD(sd, "\nlogout"); + break; + } + lp = strtok(line, " \009"); // Note: not thread safe but it is just a demo. + if (lp) { + if ((stricmp(lp, "help") == 0) || + (stricmp(lp, "h") == 0) || + (stricmp(lp, "?") == 0)) { + if (checkend(sd)) + continue; + PrintLineFDD(sd, "Commands:\r\n"); + PrintLineFDD(sd, " help,h,? - This help\r\n"); + PrintLineFDD(sd, " exit - Logout from ChibiOS/RT\r\n"); + PrintLineFDD(sd, " time - Prints the system timer value\r\n"); + PrintLineFDD(sd, " hello - Runs the Hello World demo thread\r\n"); + } + else if (stricmp(lp, "exit") == 0) { + if (checkend(sd)) + continue; + PrintLineFDD(sd, "\nlogout"); + break; + } + else if (stricmp(lp, "time") == 0) { + if (checkend(sd)) + continue; + sprintf(line, "Time: %d\r\n", chSysGetTime()); + PrintLineFDD(sd, line); + } + else if (stricmp(lp, "hello") == 0) { + if (checkend(sd)) + continue; + tp = chThdCreate(NORMALPRIO, 0, tarea, sizeof(tarea), + HelloWorldThread, sd); + if (chThdWait(tp)) + break; // Lost connection while executing the hello thread. + } + else { + PrintLineFDD(sd, lp); + PrintLineFDD(sd, " ?\r\n"); + } + } + } + return 0; +} + +static BYTE8 s1area[UserStackSize(4096)]; +static Thread *s1; +EventListener s1tel; + +static void COM1Handler(t_eventid id) { + t_dflags flags; + + if (s1 && chThdTerminated(s1)) { + s1 = NULL; + cprint("Init: disconnection on COM1\n"); + } + flags = chFDDGetAndClearFlags(&COM1); + if ((flags & SD_CONNECTED) && (s1 == NULL)) { + cprint("Init: connection on COM1\n"); + s1 = chThdCreate(NORMALPRIO, P_SUSPENDED, s1area, sizeof(s1area), + ShellThread, &COM1); + chEvtRegister(chThdGetExitEventSource(s1), &s1tel, 0); + chThdResume(s1); + } + if ((flags & SD_DISCONNECTED) && (s1 != NULL)) + chIQReset(&COM1.sd_iqueue); +} + +static BYTE8 s2area[UserStackSize(4096)]; +static Thread *s2; +EventListener s2tel; + +static void COM2Handler(t_eventid id) { + t_dflags flags; + + if (s2 && chThdTerminated(s2)) { + s2 = NULL; + cprint("Init: disconnection on COM2\n"); + } + flags = chFDDGetAndClearFlags(&COM2); + if ((flags & SD_CONNECTED) && (s2 == NULL)) { + cprint("Init: connection on COM2\n"); + s2 = chThdCreate(NORMALPRIO, P_SUSPENDED, s2area, sizeof(s1area), + ShellThread, &COM2); + chEvtRegister(chThdGetExitEventSource(s2), &s2tel, 1); + chThdResume(s2); + } + if ((flags & SD_DISCONNECTED) && (s2 != NULL)) + chIQReset(&COM2.sd_iqueue); +} + +static t_evhandler fhandlers[2] = { + COM1Handler, + COM2Handler +}; + +/* + * Init-like thread, it starts the shells and handles their termination. + * It is a good example of events usage. + */ +static t_msg InitThread(void *arg) { + EventListener c1fel, c2fel; + + cprint("Console service started on COM1, COM2\n"); + cprint(" - Listening for connections on COM1\n"); + chFDDGetAndClearFlags(&COM1); + chEvtRegister(&COM1.sd_sevent, &c1fel, 0); + cprint(" - Listening for connections on COM2\n"); + chFDDGetAndClearFlags(&COM2); + chEvtRegister(&COM2.sd_sevent, &c2fel, 1); + while (!chThdShouldTerminate()) + chEvtWait(ALL_EVENTS, fhandlers); + chEvtUnregister(&COM2.sd_sevent, &c2fel); // Never invoked but this is an example... + chEvtUnregister(&COM1.sd_sevent, &c1fel); // Never invoked but this is an example... + return 0; +} diff --git a/demos/Win32-MinGW/makefile b/demos/Win32-MinGW/makefile new file mode 100644 index 000000000..b7dc8b024 --- /dev/null +++ b/demos/Win32-MinGW/makefile @@ -0,0 +1,129 @@ +# +# !!!! 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 = mingw32- +CC = $(TRGT)gcc +AS = $(TRGT)gcc -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 = -lws2_32 + +# +# 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 = + +# List C source files here +SRC = chcore.c demo.c \ + ../../ports/win32/simcom.c \ + ../../src/chinit.c ../../src/chdelta.c ../../src/chschd.c ../../src/chthreads.c \ + ../../src/chsem.c ../../src/chevents.c ../../src/chmsg.c ../../src/chsleep.c \ + ../../src/chqueues.c ../../src/chserial.c + +# List ASM source files here +ASRC = chcore2.s + +# 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 = -Os -fomit-frame-pointer -fno-strict-aliasing + +# +# 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,-ahlms=$(<:.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 $@ + +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 *** -- cgit v1.2.3