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

master
gdisirio 2007-09-18 12:36:20 +00:00
parent 9f5b0b0b76
commit 549f84d120
14 changed files with 1834 additions and 0 deletions

21
demos/Win32-MSVS/ch.sln Normal file
View File

@ -0,0 +1,21 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ch", "ch.vcproj", "{0A528619-7F3F-4459-AAC5-DE8BA570D51D}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
Release = Release
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{0A528619-7F3F-4459-AAC5-DE8BA570D51D}.Debug.ActiveCfg = Debug|Win32
{0A528619-7F3F-4459-AAC5-DE8BA570D51D}.Debug.Build.0 = Debug|Win32
{0A528619-7F3F-4459-AAC5-DE8BA570D51D}.Release.ActiveCfg = Release|Win32
{0A528619-7F3F-4459-AAC5-DE8BA570D51D}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal

246
demos/Win32-MSVS/ch.vcproj Normal file
View File

@ -0,0 +1,246 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="ch"
ProjectGUID="{0A528619-7F3F-4459-AAC5-DE8BA570D51D}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\src\include;."
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="TRUE"
ExceptionHandling="FALSE"
RuntimeLibrary="5"
UsePrecompiledHeader="0"
AssemblerOutput="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"
CompileAs="1"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="WS2_32.lib"
OutputFile="$(OutDir)/ch.exe"
LinkIncremental="2"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/ch.pdb"
GenerateMapFile="TRUE"
MapFileName="Debug\ch.map"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="3"
GlobalOptimizations="TRUE"
FavorSizeOrSpeed="2"
OmitFramePointers="TRUE"
AdditionalIncludeDirectories="..\..\src\include;."
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
StringPooling="TRUE"
ExceptionHandling="FALSE"
RuntimeLibrary="4"
BufferSecurityCheck="FALSE"
UsePrecompiledHeader="0"
AssemblerOutput="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"
CompileAs="1"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="WS2_32.lib"
OutputFile="$(OutDir)/ch.exe"
LinkIncremental="1"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/ch.pdb"
GenerateMapFile="TRUE"
MapFileName="Release\ch.map"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
RelativePath=".\chcore.c">
</File>
<File
RelativePath=".\demo.c">
</File>
<Filter
Name="src"
Filter="">
<File
RelativePath="..\..\src\chdelta.c">
</File>
<File
RelativePath="..\..\src\chevents.c">
</File>
<File
RelativePath="..\..\src\chinit.c">
</File>
<File
RelativePath="..\..\src\chmsg.c">
</File>
<File
RelativePath="..\..\src\chqueues.c">
</File>
<File
RelativePath="..\..\src\chschd.c">
</File>
<File
RelativePath="..\..\src\chsem.c">
</File>
<File
RelativePath="..\..\src\chserial.c">
</File>
<File
RelativePath="..\..\src\chsleep.c">
</File>
<File
RelativePath="..\..\src\chthreads.c">
</File>
</Filter>
<Filter
Name="win32"
Filter="">
<File
RelativePath="..\..\ports\Win32\simcom.c">
</File>
</Filter>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
<File
RelativePath=".\chconf.h">
</File>
<File
RelativePath=".\chcore.h">
</File>
<File
RelativePath=".\chtypes.h">
</File>
<Filter
Name="include"
Filter="">
<File
RelativePath="..\..\src\include\ch.h">
</File>
<File
RelativePath="..\..\src\include\delta.h">
</File>
<File
RelativePath="..\..\src\include\events.h">
</File>
<File
RelativePath="..\..\src\include\messages.h">
</File>
<File
RelativePath="..\..\src\include\queues.h">
</File>
<File
RelativePath="..\..\src\include\scheduler.h">
</File>
<File
RelativePath="..\..\src\include\semaphores.h">
</File>
<File
RelativePath="..\..\src\include\serial.h">
</File>
<File
RelativePath="..\..\src\include\sleep.h">
</File>
<File
RelativePath="..\..\src\include\threads.h">
</File>
</Filter>
</Filter>
<File
RelativePath="..\..\docs\ch.txt">
</File>
<File
RelativePath="..\..\license.txt">
</File>
<File
RelativePath="..\..\readme.txt">
</File>
<File
RelativePath="..\..\ToDo.txt">
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

158
demos/Win32-MSVS/chconf.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
/*
* Configuration file for Visual Studio 7 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 <b>must</b> be recompiled with the GCC option \p
* -ffixed-\<reg\>.
*/
//#define CH_CURRP_REGISTER_CACHE "reg"
#endif /* _CHCONF_H_ */
/** @} */

112
demos/Win32-MSVS/chcore.c Normal file
View File

@ -0,0 +1,112 @@
#include <windows.h>
#include <stdio.h>
#undef CDECL
#include <ch.h>
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 ChibiOS/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", 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();
}
}
void __fastcall chSysPause(void) {
while (TRUE) {
ChkIntSources();
Sleep(0);
}
}
__declspec(naked) void __fastcall chSysHalt(void) {
exit(2);
}
__declspec(naked) void __fastcall chSysSwitchI(Context *oldp, Context *newp) {
__asm {
// Switch out code
push ebp
push esi
push edi
push ebx
mov dword ptr [ecx],esp
// Switch in code
mov esp,[edx]
pop ebx
pop edi
pop esi
pop ebp
ret
}
}
__declspec(naked) void __fastcall threadexit(void) {
__asm {
// add esp,4 ; The thread parameter
push eax ; The exit code returned by the thread
call chThdExit
add esp,4
call chSysHalt ; Should *never* happen
}
}

74
demos/Win32-MSVS/chcore.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
/*
* Core file for Visual Studio 7 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, threadexit); \
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))
void __fastcall chSysHalt(void);
void __fastcall chSysPause(void);
void __fastcall chSysSwitchI(Context *oldp, Context *newp);
void __fastcall threadexit(void);
#endif /* _CHCORE_H_ */

View File

@ -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 <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 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_ */

305
demos/Win32-MSVS/demo.c Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <stdio.h>
#include <ch.h>
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;
}

158
demos/Win32-MinGW/chconf.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
/*
* 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 <b>must</b> be recompiled with the GCC option \p
* -ffixed-\<reg\>.
*/
//#define CH_CURRP_REGISTER_CACHE "reg"
#endif /* _CHCONF_H_ */
/** @} */

105
demos/Win32-MinGW/chcore.c Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
/*
* Core file for MingGW32 demo project.
*/
#include <windows.h>
#include <stdio.h>
#undef CDECL
#include <ch.h>
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);
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
/*
* 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_ */

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
.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

View File

@ -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 <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 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_ */

305
demos/Win32-MinGW/demo.c Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <stdio.h>
#include <ch.h>
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;
}

129
demos/Win32-MinGW/makefile Normal file
View File

@ -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 ***