diff --git a/demos/ARM7-LPC214x-GCC/Makefile b/demos/ARM7-LPC214x-GCC/Makefile index 0ee445783..755c134e5 100644 --- a/demos/ARM7-LPC214x-GCC/Makefile +++ b/demos/ARM7-LPC214x-GCC/Makefile @@ -65,9 +65,9 @@ UADEFS = ASRC = chcore.c main.c buzzer.c mmcsd.c ../../src/lib/evtimer.c ../../test/test.c \ ../../ports/ARM7-LPC214x/GCC/vic.c ../../ports/ARM7-LPC214x/GCC/lpc214x_serial.c \ ../../ports/ARM7-LPC214x/GCC/lpc214x_ssp.c \ - ../../src/chinit.c ../../src/chlists.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 + ../../src/chinit.c ../../src/chdebug.c ../../src/chlists.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 THUMB-mode C sources here # NOTE: If any module is compiled in thumb mode then -mthumb-interwork is diff --git a/demos/ARM7-LPC214x-GCC/buzzer.c b/demos/ARM7-LPC214x-GCC/buzzer.c index a93bafa98..218d920d0 100644 --- a/demos/ARM7-LPC214x-GCC/buzzer.c +++ b/demos/ARM7-LPC214x-GCC/buzzer.c @@ -89,4 +89,4 @@ void PlaySoundWait(int freq, t_time duration) { StartCounter(tc); chThdSleep(duration); StopCounter(tc); -} \ No newline at end of file +} diff --git a/demos/ARM7-LPC214x-GCC/buzzer.h b/demos/ARM7-LPC214x-GCC/buzzer.h index f5f9e82ac..464e081d8 100644 --- a/demos/ARM7-LPC214x-GCC/buzzer.h +++ b/demos/ARM7-LPC214x-GCC/buzzer.h @@ -20,9 +20,15 @@ #ifndef _BUZZER_H_ #define _BUZZER_H_ -void InitBuzzer(void); -void PlaySound(int freq, t_time duration); -void PlaySoundWait(int freq, t_time duration); +#ifdef __cplusplus +extern "C" { +#endif + void InitBuzzer(void); + void PlaySound(int freq, t_time duration); + void PlaySoundWait(int freq, t_time duration); +#ifdef __cplusplus +} +#endif extern EventSource BuzzerSilentEventSource; diff --git a/demos/ARM7-LPC214x-GCC/chconf.h b/demos/ARM7-LPC214x-GCC/chconf.h index f4d902a9a..ba9957e49 100644 --- a/demos/ARM7-LPC214x-GCC/chconf.h +++ b/demos/ARM7-LPC214x-GCC/chconf.h @@ -156,6 +156,12 @@ */ //#define CH_CURRP_REGISTER_CACHE "r7" +/** Configuration option: Includes basic debug support to the kernel. + * @note the debug support is port-dependent, it may be not present on some + * targets. In that case stub functions will be included. + */ +#define CH_USE_DEBUG + #endif /* _CHCONF_H_ */ /** @} */ diff --git a/demos/ARM7-LPC214x-GCC/chcore.h b/demos/ARM7-LPC214x-GCC/chcore.h index 9c583c2ac..5a42cdf89 100644 --- a/demos/ARM7-LPC214x-GCC/chcore.h +++ b/demos/ARM7-LPC214x-GCC/chcore.h @@ -92,8 +92,9 @@ extern void chSysUnlock(void); #define chSysUnlock() asm("msr CPSR_c, #0x1F") #endif /* THUMB */ -#define INT_REQUIRED_STACK 0x40 // Must include registers and stack frames. +#define chSysPuts(msg) {} +#define INT_REQUIRED_STACK 0x40 // Must include registers and stack frames. #define UserStackSize(n) (sizeof(Thread) + \ sizeof(struct stackregs) + (n) + (INT_REQUIRED_STACK)) @@ -105,6 +106,4 @@ void DefFiqHandler(void); void DefIrqHandler(void); void SpuriousHandler(void); -void SetVICVector(void *handler, int vector, int source); - #endif /* _CHCORE_H_ */ diff --git a/demos/ARM7-LPC214x-GCC/chtypes.h b/demos/ARM7-LPC214x-GCC/chtypes.h index 803b5ead4..2ac219148 100644 --- a/demos/ARM7-LPC214x-GCC/chtypes.h +++ b/demos/ARM7-LPC214x-GCC/chtypes.h @@ -33,6 +33,7 @@ typedef BYTE8 t_tmode; typedef BYTE8 t_tstate; +typedef UWORD16 t_tid; typedef ULONG32 t_prio; typedef LONG32 t_msg; typedef LONG32 t_eventid; diff --git a/demos/ARM7-LPC214x-GCC/mmcsd.h b/demos/ARM7-LPC214x-GCC/mmcsd.h index 823a76a3d..b5f0ea57c 100644 --- a/demos/ARM7-LPC214x-GCC/mmcsd.h +++ b/demos/ARM7-LPC214x-GCC/mmcsd.h @@ -43,18 +43,24 @@ typedef struct { extern EventSource MMCInsertEventSource, MMCRemoveEventSource; -void InitMMC(void); +#ifdef __cplusplus +} +#endif + void InitMMC(void); -BOOL mmcInit(void); -void mmcStartPolling(void); -void mmcStopPolling(void); -BOOL mmcCardInserted (void); -BYTE8 mmcSendCommand(BYTE8 cmd, ULONG32 arg); -BOOL mmcGetSize(MMCCSD *data); -BOOL mmcRead(BYTE8 *buf, ULONG32 blknum); -BOOL mmcReadMultiple(BYTE8 *buf, ULONG32 blknum, ULONG32 n); -BOOL mmcWrite(BYTE8 *buf, ULONG32 blknum); -BOOL mmcWriteMultiple(BYTE8 *buf, ULONG32 blknum, ULONG32 n); -void mmcSynch(void); + BOOL mmcInit(void); + void mmcStartPolling(void); + void mmcStopPolling(void); + BOOL mmcCardInserted (void); + BYTE8 mmcSendCommand(BYTE8 cmd, ULONG32 arg); + BOOL mmcGetSize(MMCCSD *data); + BOOL mmcRead(BYTE8 *buf, ULONG32 blknum); + BOOL mmcReadMultiple(BYTE8 *buf, ULONG32 blknum, ULONG32 n); + BOOL mmcWrite(BYTE8 *buf, ULONG32 blknum); + BOOL mmcWriteMultiple(BYTE8 *buf, ULONG32 blknum, ULONG32 n); + void mmcSynch(void); +#ifdef __cplusplus +} +#endif #endif /* _MMCSD_H_*/ diff --git a/docs/Doxyfile b/docs/Doxyfile index c107c987a..1a98bb58c 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -4,7 +4,7 @@ # Project related configuration options #--------------------------------------------------------------------------- PROJECT_NAME = ChibiOS/RT -PROJECT_NUMBER = "0.3.4 beta" +PROJECT_NUMBER = "0.4.0 beta" OUTPUT_DIRECTORY = . CREATE_SUBDIRS = NO OUTPUT_LANGUAGE = English @@ -26,7 +26,7 @@ ALWAYS_DETAILED_SEC = NO INLINE_INHERITED_MEMB = NO FULL_PATH_NAMES = NO STRIP_FROM_PATH = "C:/Documents and Settings/Administrator/" -STRIP_FROM_INC_PATH = +STRIP_FROM_INC_PATH = SHORT_NAMES = NO JAVADOC_AUTOBRIEF = YES MULTILINE_CPP_IS_BRIEF = NO @@ -34,7 +34,7 @@ DETAILS_AT_TOP = YES INHERIT_DOCS = NO SEPARATE_MEMBER_PAGES = NO TAB_SIZE = 2 -ALIASES = +ALIASES = OPTIMIZE_OUTPUT_FOR_C = YES OPTIMIZE_OUTPUT_JAVA = NO BUILTIN_STL_SUPPORT = NO @@ -64,11 +64,11 @@ GENERATE_TODOLIST = YES GENERATE_TESTLIST = YES GENERATE_BUGLIST = YES GENERATE_DEPRECATEDLIST= YES -ENABLED_SECTIONS = +ENABLED_SECTIONS = MAX_INITIALIZER_LINES = 30 SHOW_USED_FILES = NO SHOW_DIRECTORIES = NO -FILE_VERSION_FILTER = +FILE_VERSION_FILTER = #--------------------------------------------------------------------------- # configuration options related to warning and progress messages #--------------------------------------------------------------------------- @@ -78,7 +78,7 @@ WARN_IF_UNDOCUMENTED = YES WARN_IF_DOC_ERROR = YES WARN_NO_PARAMDOC = NO WARN_FORMAT = "$file:$line: $text" -WARN_LOGFILE = +WARN_LOGFILE = #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- @@ -115,15 +115,15 @@ FILE_PATTERNS = *.c \ *.py \ *.ddf RECURSIVE = YES -EXCLUDE = +EXCLUDE = EXCLUDE_SYMLINKS = NO -EXCLUDE_PATTERNS = -EXAMPLE_PATH = +EXCLUDE_PATTERNS = +EXAMPLE_PATH = EXAMPLE_PATTERNS = * EXAMPLE_RECURSIVE = NO IMAGE_PATH = ./img -INPUT_FILTER = -FILTER_PATTERNS = +INPUT_FILTER = +FILTER_PATTERNS = FILTER_SOURCE_FILES = NO #--------------------------------------------------------------------------- # configuration options related to source browsing @@ -141,20 +141,20 @@ VERBATIM_HEADERS = NO #--------------------------------------------------------------------------- ALPHABETICAL_INDEX = NO COLS_IN_ALPHA_INDEX = 5 -IGNORE_PREFIX = +IGNORE_PREFIX = #--------------------------------------------------------------------------- # configuration options related to the HTML output #--------------------------------------------------------------------------- GENERATE_HTML = YES HTML_OUTPUT = html HTML_FILE_EXTENSION = .html -HTML_HEADER = -HTML_FOOTER = -HTML_STYLESHEET = +HTML_HEADER = +HTML_FOOTER = +HTML_STYLESHEET = HTML_ALIGN_MEMBERS = YES GENERATE_HTMLHELP = NO -CHM_FILE = -HHC_LOCATION = +CHM_FILE = +HHC_LOCATION = GENERATE_CHI = NO BINARY_TOC = NO TOC_EXPAND = NO @@ -171,8 +171,8 @@ LATEX_CMD_NAME = latex MAKEINDEX_CMD_NAME = makeindex COMPACT_LATEX = NO PAPER_TYPE = a4wide -EXTRA_PACKAGES = -LATEX_HEADER = +EXTRA_PACKAGES = +LATEX_HEADER = PDF_HYPERLINKS = NO USE_PDFLATEX = NO LATEX_BATCHMODE = NO @@ -184,8 +184,8 @@ GENERATE_RTF = NO RTF_OUTPUT = rtf COMPACT_RTF = NO RTF_HYPERLINKS = NO -RTF_STYLESHEET_FILE = -RTF_EXTENSIONS_FILE = +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = #--------------------------------------------------------------------------- # configuration options related to the man page output #--------------------------------------------------------------------------- @@ -198,8 +198,8 @@ MAN_LINKS = NO #--------------------------------------------------------------------------- GENERATE_XML = NO XML_OUTPUT = xml -XML_SCHEMA = -XML_DTD = +XML_SCHEMA = +XML_DTD = XML_PROGRAMLISTING = YES #--------------------------------------------------------------------------- # configuration options for the AutoGen Definitions output @@ -211,16 +211,16 @@ GENERATE_AUTOGEN_DEF = NO GENERATE_PERLMOD = NO PERLMOD_LATEX = NO PERLMOD_PRETTY = YES -PERLMOD_MAKEVAR_PREFIX = +PERLMOD_MAKEVAR_PREFIX = #--------------------------------------------------------------------------- -# Configuration options related to the preprocessor +# Configuration options related to the preprocessor #--------------------------------------------------------------------------- ENABLE_PREPROCESSING = YES MACRO_EXPANSION = NO EXPAND_ONLY_PREDEF = NO SEARCH_INCLUDES = YES -INCLUDE_PATH = -INCLUDE_FILE_PATTERNS = +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = PREDEFINED = __JUST_STUBS__ \ __DOXIGEN__ \ CH_USE_VIRTUAL_TIMERS \ @@ -243,19 +243,20 @@ PREDEFINED = __JUST_STUBS__ \ CH_USE_MESSAGES \ CH_USE_MESSAGES_TIMEOUT \ CH_USE_MESSAGES_EVENT \ - CH_USE_SEMSW -EXPAND_AS_DEFINED = + CH_USE_SEMSW \ + CH_USE_DEBUG +EXPAND_AS_DEFINED = SKIP_FUNCTION_MACROS = YES #--------------------------------------------------------------------------- -# Configuration::additions related to external references +# Configuration::additions related to external references #--------------------------------------------------------------------------- -TAGFILES = -GENERATE_TAGFILE = +TAGFILES = +GENERATE_TAGFILE = ALLEXTERNALS = NO EXTERNAL_GROUPS = YES PERL_PATH = /usr/bin/perl #--------------------------------------------------------------------------- -# Configuration options related to the dot tool +# Configuration options related to the dot tool #--------------------------------------------------------------------------- CLASS_DIAGRAMS = NO HIDE_UNDOC_RELATIONS = YES @@ -272,8 +273,8 @@ CALLER_GRAPH = NO GRAPHICAL_HIERARCHY = YES DIRECTORY_GRAPH = YES DOT_IMAGE_FORMAT = png -DOT_PATH = -DOTFILE_DIRS = +DOT_PATH = +DOTFILE_DIRS = MAX_DOT_GRAPH_WIDTH = 1024 MAX_DOT_GRAPH_HEIGHT = 1024 MAX_DOT_GRAPH_DEPTH = 1000 @@ -282,6 +283,6 @@ DOT_MULTI_TARGETS = NO GENERATE_LEGEND = YES DOT_CLEANUP = YES #--------------------------------------------------------------------------- -# Configuration::additions related to the search engine +# Configuration::additions related to the search engine #--------------------------------------------------------------------------- SEARCHENGINE = NO diff --git a/docs/ch.txt b/docs/ch.txt index 38d6d589a..02152047b 100644 --- a/docs/ch.txt +++ b/docs/ch.txt @@ -152,6 +152,16 @@ */ /** @} */ +/** + * @defgroup Debug Debug + * @{ + * Debug APIs and procedures. + * @ingroup Kernel + * @file debug.h Debug macros and structures. + * @file chdebug.c ChibiOS/RT Debug code. + */ +/** @} */ + /** * @defgroup Scheduler Scheduler * @{ diff --git a/ports/ARM7-LPC214x/GCC/lpc214x_serial.h b/ports/ARM7-LPC214x/GCC/lpc214x_serial.h index 1ee910b4a..2d82817cb 100644 --- a/ports/ARM7-LPC214x/GCC/lpc214x_serial.h +++ b/ports/ARM7-LPC214x/GCC/lpc214x_serial.h @@ -37,10 +37,16 @@ */ #define SERIAL_BUFFERS_SIZE 128 -void InitSerial(void); -void SetUARTI(UART *u, int speed, int lcr, int fcr); -void UART0IrqHandler(void); -void UART1IrqHandler(void); +#ifdef __cplusplus +} +#endif + void InitSerial(void); + void UART0IrqHandler(void); + void UART1IrqHandler(void); + void SetUARTI(UART *u, int speed, int lcr, int fcr); +#ifdef __cplusplus +} +#endif extern FullDuplexDriver COM1, COM2; diff --git a/ports/ARM7-LPC214x/GCC/lpc214x_ssp.h b/ports/ARM7-LPC214x/GCC/lpc214x_ssp.h index c7b4bcbdd..07401d173 100644 --- a/ports/ARM7-LPC214x/GCC/lpc214x_ssp.h +++ b/ports/ARM7-LPC214x/GCC/lpc214x_ssp.h @@ -26,11 +26,17 @@ */ #define SSP_USE_MUTEX -void InitSSP(void); -void SetSSP(int cpsr, int cr0, int cr1); +#ifdef __cplusplus +} +#endif + void InitSSP(void); + void SetSSP(int cpsr, int cr0, int cr1); -void sspAcquireBus(void); -void sspReleaseBus(void); -void sspRW(BYTE8 *in, BYTE8 *out, t_size n); + void sspAcquireBus(void); + void sspReleaseBus(void); + void sspRW(BYTE8 *in, BYTE8 *out, t_size n); +#ifdef __cplusplus +} +#endif #endif /* _LPC214x_SSP_H_*/ diff --git a/ports/ARM7-LPC214x/GCC/vic.h b/ports/ARM7-LPC214x/GCC/vic.h index cbcb525fc..9d8ba93ad 100644 --- a/ports/ARM7-LPC214x/GCC/vic.h +++ b/ports/ARM7-LPC214x/GCC/vic.h @@ -20,7 +20,13 @@ #ifndef _VIC_H_ #define _VIC_H_ -void InitVIC(void); -void SetVICVector(void *handler, int vector, int source); +#ifdef __cplusplus +} +#endif + void InitVIC(void); + void SetVICVector(void *handler, int vector, int source); +#ifdef __cplusplus +} +#endif #endif /* _VIC_H_*/ diff --git a/readme.txt b/readme.txt index 733f9f08c..38792a82e 100644 --- a/readme.txt +++ b/readme.txt @@ -38,6 +38,17 @@ AVR-AT90CANx-GCC - Port on AVR AT90CAN128, not complete yet. *** Releases *** ***************************************************************************** +*** 0.4.0 *** +- Implemented a debug subsystem, it supports debug messages and a context + switch circular trace buffer. The debug code can be enabled/disabled by + using the CH_USE_DEBUG in chconf.h. + The trace buffer is meant to be fetched and decoded by an external tool + (coming soon, it can be accessed using JTAG in the meanwhile). +- Implemented panic messages when CH_USE_DEBUG is enabled. +- Added a thread identifier field to the Thread structure, it is used only + for debug. +- Fixed an harmless warning message in buzzer.c. + *** 0.3.6 *** - Added SSP (SPI1) and ext.interrupts definitions to the lpc214x.h file. - Added SSP driver for the LPC2148. diff --git a/src/chdebug.c b/src/chdebug.c new file mode 100644 index 000000000..d08f91fd1 --- /dev/null +++ b/src/chdebug.c @@ -0,0 +1,75 @@ +/* + 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 + +#ifdef CH_USE_DEBUG + +TraceBuffer dbgtb; +char *dbglastmsg; + +/** + * Debug subsystem initialization. + */ +void chDbgInit(void) { + + dbgtb.tb_size = TRACE_BUFFER_SIZE; + dbgtb.tb_ptr = &dbgtb.tb_buffer[0]; +} + +/** + * Inserts in the circular debug trace buffer a context switch record. + * @param otp the thread being switched out + * @param ntp the thread to be resumed + */ +void chDbgTrace(Thread *otp, Thread *ntp) { + + dbgtb.tb_ptr->cse_slpdata = otp->p_common; +#ifdef CH_USE_SYSTEMTIME + dbgtb.tb_ptr->cse_time = chSysGetTime(); +#else + dbgtb.tb_ptr->cse_time = 0; +#endif + dbgtb.tb_ptr->cse_state = otp->p_state; + dbgtb.tb_ptr->cse_tid = ntp->p_tid; + if (++dbgtb.tb_ptr >= &dbgtb.tb_buffer[TRACE_BUFFER_SIZE]) + dbgtb.tb_ptr = &dbgtb.tb_buffer[0]; +} + +/** + * Prints a message on the console/debugger. The latest message pointer + * is retained. + */ +void chDbgPuts(char *msg) { + + dbglastmsg = msg; + chSysPuts(msg); +} + +/** + * Prints a panic message on the console/debugger and then halts the system. + */ +void chDbgPanic(char *msg) { + + chSysPuts("PANIC: "); + chDbgPuts(msg); + chSysHalt(); +} + +#endif /* CH_USE_DEBUG */ diff --git a/src/chevents.c b/src/chevents.c index 93d93ff3d..5f7ce6aaa 100644 --- a/src/chevents.c +++ b/src/chevents.c @@ -160,10 +160,11 @@ t_eventid chEvtWait(t_eventmask ewmask, } #ifdef CH_USE_EVENTS_TIMEOUT -static void unwait(void *p) { - -// Test removed, it should never happen. -// if (((Thread *)p)->p_state == PRWTEVENT) +static void wakeup(void *p) { +#ifdef CH_USE_DEBUG + if (((Thread *)p)->p_state != PRWTEVENT) + chDbgPanic("chevents.c, wakeup()\r\n"); +#endif chSchReadyI(p)->p_rdymsg = RDY_TIMEOUT; } @@ -200,7 +201,7 @@ t_eventid chEvtWaitTimeout(t_eventmask ewmask, if ((currp->p_epending & ewmask) == 0) { VirtualTimer vt; - chVTSetI(&vt, time, unwait, currp); + chVTSetI(&vt, time, wakeup, currp); currp->p_ewmask = ewmask; chSchGoSleepS(PRWTEVENT); if (!chVTIsArmedI(&vt)) { diff --git a/src/chinit.c b/src/chinit.c index 55a69b1fc..4a25567a8 100644 --- a/src/chinit.c +++ b/src/chinit.c @@ -47,6 +47,7 @@ static Thread idlethread; void chSysInit(void) { chSchInit(); + chDbgInit(); #ifdef CH_USE_VIRTUAL_TIMERS chVTInit(); #endif diff --git a/src/chmsg.c b/src/chmsg.c index 010da86e5..5ea3f9821 100644 --- a/src/chmsg.c +++ b/src/chmsg.c @@ -80,10 +80,12 @@ t_msg chMsgSendWithEvent(Thread *tp, t_msg msg, EventSource *esp) { #endif #ifdef CH_USE_MESSAGES_TIMEOUT -static void unsend(void *p) { +static void wakeup(void *p) { -// Test removed, it should never happen. -// if (((Thread *)p)->p_state == PRSNDMSG) +#ifdef CH_USE_DEBUG + if (((Thread *)p)->p_state != PRSNDMSG) + chDbgPanic("chmsg.c, wakeup()\r\n"); +#endif chSchReadyI(dequeue(p))->p_rdymsg = RDY_TIMEOUT; } @@ -108,7 +110,7 @@ t_msg chMsgSendTimeout(Thread *tp, t_msg msg, t_time time) { chSysLock(); - chVTSetI(&vt, time, unsend, currp); + chVTSetI(&vt, time, wakeup, currp); fifo_insert(currp, &tp->p_msgqueue); if (tp->p_state == PRWTMSG) chSchReadyI(tp); diff --git a/src/chschd.c b/src/chschd.c index c95c0cd0e..c30040520 100644 --- a/src/chschd.c +++ b/src/chschd.c @@ -86,6 +86,9 @@ static void nextready(void) { (currp = fifo_remove(&rlist.r_queue))->p_state = PRCURR; preempt = CH_TIME_QUANTUM; +#ifdef CH_USE_DEBUG + chDbgTrace(otp, currp); +#endif chSysSwitchI(&otp->p_ctx, &currp->p_ctx); } @@ -125,6 +128,9 @@ void chSchWakeupS(Thread *tp, t_msg msg) { (currp = tp)->p_state = PRCURR; tp->p_rdymsg = msg; preempt = CH_TIME_QUANTUM; +#ifdef CH_USE_DEBUG + chDbgTrace(ctp, tp); +#endif chSysSwitchI(&ctp->p_ctx, &tp->p_ctx); } } diff --git a/src/chsem.c b/src/chsem.c index 091a045b5..099dc4db4 100644 --- a/src/chsem.c +++ b/src/chsem.c @@ -112,10 +112,11 @@ void chSemWaitS(Semaphore *sp) { } #ifdef CH_USE_SEMAPHORES_TIMEOUT -static void unwait(void *p) { - -// Test removed, it should never happen. -// if (((Thread *)p)->p_state == PRWTSEM) +static void wakeup(void *p) { +#ifdef CH_USE_DEBUG + if (((Thread *)p)->p_state != PRWTSEM) + chDbgPanic("chsem.c, wakeup()\r\n"); +#endif chSemFastSignalI(((Thread *)p)->p_semp); chSchReadyI(dequeue(p))->p_rdymsg = RDY_TIMEOUT; } @@ -134,7 +135,7 @@ t_msg chSemWaitTimeout(Semaphore *sp, t_time time) { if (--sp->s_cnt < 0) { VirtualTimer vt; - chVTSetI(&vt, time, unwait, currp); + chVTSetI(&vt, time, wakeup, currp); fifo_insert(currp, &sp->s_queue); currp->p_semp = sp; chSchGoSleepS(PRWTSEM); @@ -165,7 +166,7 @@ t_msg chSemWaitTimeoutS(Semaphore *sp, t_time time) { if (--sp->s_cnt < 0) { VirtualTimer vt; - chVTSetI(&vt, time, unwait, currp); + chVTSetI(&vt, time, wakeup, currp); fifo_insert(currp, &sp->s_queue); currp->p_semp = sp; chSchGoSleepS(PRWTSEM); diff --git a/src/chthreads.c b/src/chthreads.c index 56ab4969e..9729a9b59 100644 --- a/src/chthreads.c +++ b/src/chthreads.c @@ -28,7 +28,9 @@ * Initializes a thread structure. */ void _InitThread(t_prio prio, t_tmode mode, Thread *tp) { + static t_tid nextid = 0; + tp->p_tid = nextid++; tp->p_flags = mode; tp->p_prio = prio; tp->p_rdymsg = RDY_OK; diff --git a/src/include/ch.h b/src/include/ch.h index 9df1b8363..1102f4013 100644 --- a/src/include/ch.h +++ b/src/include/ch.h @@ -83,6 +83,10 @@ #include "serial.h" #endif +#ifndef _DEBUG_H_ +#include "debug.h" +#endif + /* * Common values. */ diff --git a/src/include/debug.h b/src/include/debug.h new file mode 100644 index 000000000..5a4f3ac44 --- /dev/null +++ b/src/include/debug.h @@ -0,0 +1,70 @@ +/* + 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 . +*/ + +/** + * @addtogroup Debug + * @{ + */ + +#ifndef _DEBUG_H_ +#define _DEBUG_H_ + +#ifdef CH_USE_DEBUG + +#define TRACE_BUFFER_SIZE 1024 + +typedef struct { + void *cse_slpdata; + t_time cse_time; + UWORD16 cse_state: 4; + UWORD16 cse_tid: 12; +} CtxSwcEvent; + +typedef struct { + t_size tb_size; + CtxSwcEvent *tb_ptr; + CtxSwcEvent tb_buffer[TRACE_BUFFER_SIZE]; +} TraceBuffer; + +extern CtxSwcEvent *dbgnext; +extern TraceBuffer dbgtb; +extern char *dbglastmsg; + +#ifdef __cplusplus +extern "C" { +#endif + void chDbgInit(void); + void chDbgTrace(Thread *otp, Thread *ntp); + void chDbgPuts(char *msg); + void chDbgPanic(char *msg); +#ifdef __cplusplus +} +#endif + +#else /* CH_USE_DEBUG */ + +#define chDbgInit() +#define chDbgPuts(msg) {} +#define chDbgPanic(msg) {} + +#endif /* CH_USE_DEBUG */ + +#endif /* _DEBUG_H_ */ + +/** @} */ diff --git a/src/include/threads.h b/src/include/threads.h index effad525c..e4cd8376e 100644 --- a/src/include/threads.h +++ b/src/include/threads.h @@ -41,6 +41,8 @@ struct Thread { /** The thread priority.*/ t_prio p_prio; /* End of the fields shared with the ReadyList structure. */ + /** Thread identifier. */ + t_tid p_tid; /** Current thread state.*/ t_tstate p_state; /** Mode flags.*/ @@ -68,6 +70,8 @@ struct Thread { /** Message (only while in \p PRSNDMSG state).*/ t_msg p_msg; #endif + /** Generic way to access the union.*/ + void *p_common; }; /** Machine dependent processor context.*/ Context p_ctx; diff --git a/src/templates/chconf.h b/src/templates/chconf.h index 9c5d303bd..c8214c623 100644 --- a/src/templates/chconf.h +++ b/src/templates/chconf.h @@ -157,6 +157,12 @@ */ //#define CH_CURRP_REGISTER_CACHE "reg" +/** Configuration option: Includes basic debug support to the kernel. + * @note the debug support is port-dependent, it may be not present on some + * targets. In that case stub functions will be included. + */ +#define CH_USE_DEBUG + #endif /* _CHCONF_H_ */ /** @} */ diff --git a/src/templates/chcore.h b/src/templates/chcore.h index a9bfcce63..e917ffa6f 100644 --- a/src/templates/chcore.h +++ b/src/templates/chcore.h @@ -69,6 +69,11 @@ typedef struct { */ #define chSysUnlock() +/** + * Prints a message on the system console (if any). + */ +#define chSysPuts(msg) {} + void chSysHalt(void); void chSysPause(void); void chSysSwitchI(Context *oldp, Context *newp); diff --git a/src/templates/chtypes.h b/src/templates/chtypes.h index 45f60a1a3..fdbdae7b9 100644 --- a/src/templates/chtypes.h +++ b/src/templates/chtypes.h @@ -38,6 +38,7 @@ typedef BYTE8 t_tmode; /* Thread mode flags, BYTE8 is ok. */ typedef BYTE8 t_tstate; /* Thread state, BYTE8 is ok. */ +typedef UWORD16 t_tid; /* Thread id. */ typedef ULONG32 t_prio; /* Priority, use the fastest unsigned type. */ typedef LONG32 t_msg; /* Message, use signed pointer equivalent.*/ typedef LONG32 t_eventid; /* Event Id, use fastest signed.*/