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

This commit is contained in:
gdisirio 2009-12-23 20:11:44 +00:00
parent 0750743bb4
commit a2e989330e
6 changed files with 334 additions and 25 deletions

View File

@ -16,12 +16,12 @@
# Start of default section
#
TRGT =
TRGT =
CC = $(TRGT)gcc
AS = $(TRGT)gcc -x assembler-with-cpp
# List all default C defines here, like -D_DEBUG=1
DDEFS =
DDEFS = -DSHELL_USE_IPRINTF=FALSE
# List all default ASM defines here, like -D_DEBUG=1
DADEFS =
@ -47,7 +47,7 @@ DLIBS =
PROJECT = ch
# Define linker script file here
LDSCRIPT=
LDSCRIPT =
# List all user C define here, like -D_DEBUG=1
UDEFS =
@ -57,19 +57,27 @@ UADEFS =
# Imported source files
CHIBIOS = ../..
include ${CHIBIOS}/src/kernel.mk
include ${CHIBIOS}/os/hal/hal.mk
include ${CHIBIOS}/os/hal/platforms/Linux/platform.mk
include ${CHIBIOS}/os/ports/GCC/SIMIA32/port.mk
include ${CHIBIOS}/os/kernel/kernel.mk
include ${CHIBIOS}/test/test.mk
# List C source files here
SRC = chcore.c main.c \
SRC = ${PORTSRC} \
${KERNSRC} \
${TESTSRC}
${TESTSRC} \
${HALSRC} \
${PLATFORMSRC} \
${CHIBIOS}/os/various/shell.c \
main.c
# List ASM source files here
ASRC =
# List all user directories here
UINCDIR = ${CHIBIOS}/src/include
UINCDIR = $(PORTINC) $(KERNINC) $(TESTINC) $(HALINC) $(PLATFORMINC) \
${CHIBIOS}/os/various
# List the user directory to look for the libraries here
ULIBDIR =
@ -94,7 +102,7 @@ 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)
CPFLAGS = $(OPT) -Wall -Wextra -Wstrict-prototypes -fverbose-asm -Wa,-alms=$(<:.c=.lst) $(DEFS)
# Generate dependency information
CPFLAGS += -MD -MP -MF .dep/$(@F).d
@ -119,7 +127,7 @@ gcov:
$(COV) -u $(subst /,\,$(SRC))
-mv *.gcov ./gcov
clean:
clean:
-rm -f $(OBJS)
-rm -f $(PROJECT)
-rm -f $(PROJECT).map

View File

@ -0,0 +1,23 @@
/*
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 _BOARD_H_
#define _BOARD_H_
#endif /* _BOARD_H_ */

View File

@ -37,7 +37,7 @@
* setting also defines the system tick time unit.
*/
#if !defined(CH_FREQUENCY) || defined(__DOXYGEN__)
#define CH_FREQUENCY 100
#define CH_FREQUENCY 1000
#endif
/**
@ -80,7 +80,7 @@
* @note Requires @p CH_USE_COREMEM.
*/
#if !defined(CH_MEMCORE_SIZE) || defined(__DOXYGEN__)
#define CH_MEMCORE_SIZE 0
#define CH_MEMCORE_SIZE 0x20000
#endif
/*===========================================================================*/
@ -459,6 +459,8 @@ struct { \
}
#endif
#define chThdGetExitEventSource(tp) (&(tp)->p_exitesource)
#endif /* _CHCONF_H_ */
/** @} */

View File

@ -0,0 +1,96 @@
/*
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 templates/halconf.h
* @brief HAL configuration header.
* @addtogroup HAL_CONF
* @{
*/
/*
* HAL configuration file, this file allows to enable or disable the various
* device drivers from your application. You may also use this file in order
* to change the device drivers settings found in the low level drivers
* headers, just define here the new settings and those will override the
* defaults defined in the LLD headers.
*/
#ifndef _HALCONF_H_
#define _HALCONF_H_
/**
* @brief Enables the PAL subsystem.
*/
#if !defined(CH_HAL_USE_PAL) || defined(__DOXYGEN__)
#define CH_HAL_USE_PAL FALSE
#endif
/**
* @brief Enables the ADC subsystem.
*/
#if !defined(CH_HAL_USE_ADC) || defined(__DOXYGEN__)
#define CH_HAL_USE_ADC FALSE
#endif
/**
* @brief Enables the CAN subsystem.
*/
#if !defined(CH_HAL_USE_CAN) || defined(__DOXYGEN__)
#define CH_HAL_USE_CAN FALSE
#endif
/**
* @brief Enables the MAC subsystem.
*/
#if !defined(CH_HAL_USE_MAC) || defined(__DOXYGEN__)
#define CH_HAL_USE_MAC FALSE
#endif
/**
* @brief Enables the PWM subsystem.
*/
#if !defined(CH_HAL_USE_PWM) || defined(__DOXYGEN__)
#define CH_HAL_USE_PWM FALSE
#endif
/**
* @brief Enables the SERIAL subsystem.
*/
#if !defined(CH_HAL_USE_SERIAL) || defined(__DOXYGEN__)
#define CH_HAL_USE_SERIAL TRUE
#endif
/**
* @brief Enables the SPI subsystem.
*/
#if !defined(CH_HAL_USE_SPI) || defined(__DOXYGEN__)
#define CH_HAL_USE_SPI FALSE
#endif
/**
* @brief Enables the MMC_SPI subsystem.
*/
#if !defined(CH_HAL_USE_MMC_SPI) || defined(__DOXYGEN__)
#define CH_HAL_USE_MMC_SPI FALSE
#endif
#endif /* _HALCONF_H_ */
/** @} */

View File

@ -20,34 +20,203 @@
#include <stdio.h>
#include "ch.h"
#include "hal.h"
#include "test.h"
#include "shell.h"
static WORKING_AREA(waThread1, 2048);
static msg_t Thread1(void *arg) {
#define SHELL_WA_SIZE THD_WA_SIZE(4096)
#define CONSOLE_WA_SIZE THD_WA_SIZE(4096)
#define TEST_WA_SIZE THD_WA_SIZE(4096)
while (TRUE) {
chThdSleepMilliseconds(1000);
printf("-\n");
#define cprint(msg) chMsgSend(cdtp, (msg_t)msg)
static Thread *cdtp;
static Thread *shelltp1;
static Thread *shelltp2;
void cmd_test(BaseChannel *chp, int argc, char *argv[]) {
Thread *tp;
(void)argv;
if (argc > 0) {
shellPrintLine(chp, "Usage: test");
return;
}
tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
TestThread, chp);
if (tp == NULL) {
shellPrintLine(chp, "out of memory");
return;
}
chThdWait(tp);
}
static const ShellCommand commands[] = {
{"test", cmd_test},
{NULL, NULL}
};
static const ShellConfig shell_cfg1 = {
(BaseChannel *)&SD1,
commands
};
static const ShellConfig shell_cfg2 = {
(BaseChannel *)&SD2,
commands
};
/*
* 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 msg_t console_thread(void *arg) {
(void)arg;
while (!chThdShouldTerminate()) {
puts((char *)chMsgWait());
fflush(stdout);
chMsgRelease(RDY_OK);
}
return 0;
}
/**
* @brief Shell termination handler.
*
* @param[in] id event id.
*/
static void termination_handler(eventid_t id) {
(void)id;
if (shelltp1 && chThdTerminated(shelltp1)) {
chThdWait(shelltp1);
shelltp1 = NULL;
chThdSleepMilliseconds(10);
cprint("Init: shell on SD1 terminated\n");
chSysLock();
chOQResetI(&SD1.d2.oqueue);
chSysUnlock();
}
if (shelltp2 && chThdTerminated(shelltp2)) {
chThdWait(shelltp2);
shelltp2 = NULL;
chThdSleepMilliseconds(10);
cprint("Init: shell on SD2 terminated\n");
chSysLock();
chOQResetI(&SD2.d2.oqueue);
chSysUnlock();
}
}
/**
* @brief SD1 status change handler.
*
* @param[in] id event id.
*/
static void sd1_handler(eventid_t id) {
sdflags_t flags;
(void)id;
flags = sdGetAndClearFlags(&SD1);
if ((flags & SD_CONNECTED) && (shelltp1 == NULL)) {
cprint("Init: connection on SD1\n");
shelltp1 = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO + 1);
}
if (flags & SD_DISCONNECTED) {
cprint("Init: disconnection on SD1\n");
chSysLock();
chIQResetI(&SD1.d2.iqueue);
chSysUnlock();
}
}
/**
* @brief SD2 status change handler.
*
* @param[in] id event id.
*/
static void sd2_handler(eventid_t id) {
sdflags_t flags;
(void)id;
flags = sdGetAndClearFlags(&SD2);
if ((flags & SD_CONNECTED) && (shelltp2 == NULL)) {
cprint("Init: connection on SD2\n");
shelltp2 = shellCreate(&shell_cfg2, SHELL_WA_SIZE, NORMALPRIO + 10);
}
if (flags & SD_DISCONNECTED) {
cprint("Init: disconnection on SD2\n");
chSysLock();
chIQResetI(&SD2.d2.iqueue);
chSysUnlock();
}
}
static evhandler_t fhandlers[] = {
termination_handler,
sd1_handler,
sd2_handler
};
/*------------------------------------------------------------------------*
* Simulator main, start here your threads, examples inside. *
* Simulator main. *
*------------------------------------------------------------------------*/
int main(void) {
EventListener sd1fel, sd2fel, tel;
/*
* ChibiOS/RT initialization.
* HAL initialization.
*/
halInit();
/*
* ChibiOS/RT initialization.
*/
chSysInit();
/*
* Starting threads.
* Serial ports (simulated) initialization.
*/
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
sdStart(&SD1, NULL);
sdStart(&SD2, NULL);
while (TRUE)
chThdSleepSeconds(1);
/*
* Shell manager initialization.
*/
shellInit();
chEvtRegister(&shell_terminated, &tel, 0);
/*
* Console thread started.
*/
cdtp = chThdCreateFromHeap(NULL, CONSOLE_WA_SIZE, NORMALPRIO + 1,
console_thread, NULL);
/*
* Initializing connection/disconnection events.
*/
cprint("Shell service started on SD1, SD2\n");
cprint(" - Listening for connections on SD1\n");
(void) sdGetAndClearFlags(&SD1);
chEvtRegister(&SD1.d2.sevent, &sd1fel, 1);
cprint(" - Listening for connections on SD2\n");
(void) sdGetAndClearFlags(&SD2);
chEvtRegister(&SD2.d2.sevent, &sd2fel, 2);
/*
* Events servicing loop.
*/
while (!chThdShouldTerminate())
chEvtDispatch(fhandlers, chEvtWaitOne(ALL_EVENTS));
/*
* Clean simulator exit.
*/
chEvtUnregister(&SD1.d2.sevent, &sd1fel);
chEvtUnregister(&SD2.d2.sevent, &sd2fel);
return 0;
}

View File

@ -4,12 +4,23 @@
** TARGET **
The demo runs under Linux as an application program.
The demo runs under x86 Linux as an application program. The serial
I/O is simulated over TCP/IP sockets.
** The Demo **
The demo just creates a thread. It is not complete yet.
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.
GCC required.
** Connect to the demo **
In order to connect to the demo use telnet on the listening ports.