diff --git a/demos/ARM7-LPC214x-GCC/buzzer.c b/demos/ARM7-LPC214x-GCC/buzzer.c index 4700bfb45..b0abf9657 100644 --- a/demos/ARM7-LPC214x-GCC/buzzer.c +++ b/demos/ARM7-LPC214x-GCC/buzzer.c @@ -69,7 +69,7 @@ void PlaySound(int freq, t_time duration) { chSysLock(); - if (bvt.vt_func) { // If a sound is already being played + if (chVTIsArmedI(&bvt)) { // If a sound is already being played chVTResetI(&bvt); // then aborts it. StopCounter(tc); } diff --git a/demos/ARM7-LPC214x-GCC/chconf.h b/demos/ARM7-LPC214x-GCC/chconf.h index da8553399..f4d902a9a 100644 --- a/demos/ARM7-LPC214x-GCC/chconf.h +++ b/demos/ARM7-LPC214x-GCC/chconf.h @@ -51,6 +51,10 @@ * function is included in the kernel.*/ #define CH_USE_RESUME +/** Configuration option: if specified then the \p chThdSuspend() + * function is included in the kernel.*/ +#define CH_USE_SUSPEND + /** Configuration option: if specified then the \p chThdTerminate() * and \p chThdShouldTerminate() functions are included in the kernel.*/ #define CH_USE_TERMINATE diff --git a/demos/AVR-AT90CANx-GCC/chconf.h b/demos/AVR-AT90CANx-GCC/chconf.h index 0857a1fbd..2c849b3c6 100644 --- a/demos/AVR-AT90CANx-GCC/chconf.h +++ b/demos/AVR-AT90CANx-GCC/chconf.h @@ -52,6 +52,10 @@ * function is included in the kernel.*/ #define CH_USE_RESUME +/** Configuration option: if specified then the \p chThdSuspend() + * function is included in the kernel.*/ +#define CH_USE_SUSPEND + /** Configuration option: if specified then the \p chThdTerminate() * and \p chThdShouldTerminate() functions are included in the kernel.*/ #define CH_USE_TERMINATE diff --git a/demos/Win32-MSVS/chconf.h b/demos/Win32-MSVS/chconf.h index da7fcd266..1aa089575 100644 --- a/demos/Win32-MSVS/chconf.h +++ b/demos/Win32-MSVS/chconf.h @@ -56,6 +56,10 @@ * function is included in the kernel.*/ #define CH_USE_RESUME +/** Configuration option: if specified then the \p chThdSuspend() + * function is included in the kernel.*/ +#define CH_USE_SUSPEND + /** Configuration option: if specified then the \p chThdTerminate() * and \p chThdShouldTerminate() functions are included in the kernel.*/ #define CH_USE_TERMINATE diff --git a/demos/Win32-MinGW/chconf.h b/demos/Win32-MinGW/chconf.h index 5582ae80a..b7a8acedd 100644 --- a/demos/Win32-MinGW/chconf.h +++ b/demos/Win32-MinGW/chconf.h @@ -56,6 +56,10 @@ * function is included in the kernel.*/ #define CH_USE_RESUME +/** Configuration option: if specified then the \p chThdSuspend() + * function is included in the kernel.*/ +#define CH_USE_SUSPEND + /** Configuration option: if specified then the \p chThdTerminate() * and \p chThdShouldTerminate() functions are included in the kernel.*/ #define CH_USE_TERMINATE diff --git a/docs/Doxyfile b/docs/Doxyfile index 06ec78649..c107c987a 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -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,22 +211,23 @@ 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 \ CH_USE_SYSTEMTIME \ CH_USE_SLEEP \ CH_USE_RESUME \ + CH_USE_SUSPEND \ CH_USE_TERMINATE \ CH_USE_WAITEXIT \ CH_USE_SEMAPHORES \ @@ -243,18 +244,18 @@ PREDEFINED = __JUST_STUBS__ \ CH_USE_MESSAGES_TIMEOUT \ CH_USE_MESSAGES_EVENT \ CH_USE_SEMSW -EXPAND_AS_DEFINED = +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 @@ -271,8 +272,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 @@ -281,6 +282,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/ports/ARM7-LPC214x/GCC/lpc214x_serial.c b/ports/ARM7-LPC214x/GCC/lpc214x_serial.c index 59aa75b6b..e799faf5b 100644 --- a/ports/ARM7-LPC214x/GCC/lpc214x_serial.c +++ b/ports/ARM7-LPC214x/GCC/lpc214x_serial.c @@ -106,12 +106,12 @@ static void OutNotify2(void) { u->UART_IER |= IER_THRE; } -void UART0Irq(void){ +void UART0Irq(void) { ServeInterrupt(U0Base, &COM1); } -void UART1Irq(void){ +void UART1Irq(void) { ServeInterrupt(U1Base, &COM2); } diff --git a/readme.txt b/readme.txt index a3bed78b4..bdf9f5ff1 100644 --- a/readme.txt +++ b/readme.txt @@ -40,9 +40,11 @@ AVR-AT90CANx-GCC - Port on AVER AT90CAN128, not complete yet. *** 0.3.4 *** - Fixed a problem in chVTSetI(). -- Modified chEvtWaitTimeout() to work correctly in the TIME_INFINITE - scenario. - +- New API, chVTIsArmedI(), it is a macro in delta.h. +- New API, chThdResumeI(), it is a macro in threads.h. This function is just + an alias for chSchReadyI() but makes the code more readable. +- New API, chThdSuspend(). New switch CH_USE_SUSPEND added to chconf.h. + *** 0.3.3 *** - Modified the chVTSetI(), now for the "time" parameter can have value zero with meaning "infinite". This allows all the APIs with timeout parameters @@ -54,7 +56,7 @@ AVR-AT90CANx-GCC - Port on AVER AT90CAN128, not complete yet. - Modified the chSysInit() to give the idle thread absolute priority, the priority is then lowered to the minimum value into the chSysPause(). This is done in order to ensure that the initializations performed into the - main() procedure are performed before any thread starts. + main() procedure are finished before any thread starts. - Added chThdSetPriority() new API. - Added a generic events generator timer modulee to the library code. - Modified the ARM7-LPC214x-GCC demo to show the use of the event timer. diff --git a/src/chdelta.c b/src/chdelta.c index 8a8100e5f..16dfac5bc 100644 --- a/src/chdelta.c +++ b/src/chdelta.c @@ -40,7 +40,9 @@ void chVTInit(void) { * Enables a virtual timer. * @param vtp the \p VirtualTimer structure pointer * @param time the number of time ticks, the value zero is allowed with - * meaning "infinite". + * meaning "infinite". In this case the structure is initialized + * but not inserted in the delta list, the timer will never be + * triggered. * @param vtfunc the timer callback function. After invoking the callback * the timer is disabled and the structure can be disposed or * reused. @@ -51,8 +53,8 @@ void chVTInit(void) { void chVTSetI(VirtualTimer *vtp, t_time time, t_vtfunc vtfunc, void *par) { vtp->vt_par = par; + vtp->vt_func = vtfunc; if (time) { - vtp->vt_func = vtfunc; VirtualTimer *p = dlist.dl_next; while (p->vt_dtime < time) { time -= p->vt_dtime; @@ -66,7 +68,7 @@ void chVTSetI(VirtualTimer *vtp, t_time time, t_vtfunc vtfunc, void *par) { p->vt_dtime -= time; } else - vtp->vt_func = NULL; + vtp->vt_next = vtp->vt_prev = vtp; // Allows a chVTResetI() on the fake timer. } /** diff --git a/src/chevents.c b/src/chevents.c index f88412e11..a617e3edf 100644 --- a/src/chevents.c +++ b/src/chevents.c @@ -205,7 +205,6 @@ t_eventid chEvtWaitTimeout(t_eventmask ewmask, t_time time) { t_eventid i; t_eventmask m; - t_msg msg; chSysLock(); @@ -221,11 +220,10 @@ t_eventid chEvtWaitTimeout(t_eventmask ewmask, chVTSetI(&vt, time, unwait, currp); currp->p_ewmask = ewmask; chSchGoSleepS(PRWTEVENT); - if (!vt.vt_func) { - t_msg msg = currp->p_rdymsg; + if (!chVTIsArmedI(&vt)) { chSysUnlock(); - return msg; + return RDY_TIMEOUT; } chVTResetI(&vt); } diff --git a/src/chmsg.c b/src/chmsg.c index 4140e3165..010da86e5 100644 --- a/src/chmsg.c +++ b/src/chmsg.c @@ -115,7 +115,7 @@ t_msg chMsgSendTimeout(Thread *tp, t_msg msg, t_time time) { currp->p_msg = msg; chSchGoSleepS(PRSNDMSG); msg = currp->p_rdymsg; - if (vt.vt_func) + if (chVTIsArmedI(&vt)) chVTResetI(&vt); chSysUnlock(); diff --git a/src/chsem.c b/src/chsem.c index a58ee71b1..091a045b5 100644 --- a/src/chsem.c +++ b/src/chsem.c @@ -139,7 +139,7 @@ t_msg chSemWaitTimeout(Semaphore *sp, t_time time) { currp->p_semp = sp; chSchGoSleepS(PRWTSEM); msg = currp->p_rdymsg; - if (vt.vt_func) + if (chVTIsArmedI(&vt)) chVTResetI(&vt); chSysUnlock(); @@ -169,7 +169,7 @@ t_msg chSemWaitTimeoutS(Semaphore *sp, t_time time) { fifo_insert(currp, &sp->s_queue); currp->p_semp = sp; chSchGoSleepS(PRWTSEM); - if (vt.vt_func) + if (chVTIsArmedI(&vt)) chVTResetI(&vt); return currp->p_rdymsg; } diff --git a/src/chthreads.c b/src/chthreads.c index 00ae04778..a63f5721b 100644 --- a/src/chthreads.c +++ b/src/chthreads.c @@ -121,9 +121,34 @@ void chThdSetPriority(t_prio newprio) { chSysUnlock(); } +#ifdef CH_USE_SUSPEND +/** + * Suspends the invoking thread. + * + * @param tpp pointer to a \p Thread pointer, the \p Thread pointer is set + * to point to the suspended process before it enters the + * \p PRSUSPENDED state, it is set to \p NULL after it is resumed. + * This allows to implement a "test and resume" on the variable + * into interrupt handlers. + * @note The function is available only if the \p CH_USE_SUSPEND + * option is enabled in \p chconf.h. + */ +void chThdSuspend(Thread **tpp) { + + chSysLock(); + + *tpp = currp; + chSchGoSleepS(PRSUSPENDED); + *tpp = NULL; + + chSysUnlock(); +} +#endif /* CH_USE_SUSPEND */ + #ifdef CH_USE_RESUME /** - * Resumes a thread created with the \p P_SUSPENDED option. + * Resumes a thread created with the \p P_SUSPENDED option or suspended with + * \p chThdSuspend(). * @param tp the pointer to the thread * @note The function has no effect on threads in any other state than * \p PRSUSPENDED. @@ -134,8 +159,8 @@ void chThdResume(Thread *tp) { chSysLock(); - if (tp->p_state == PRSUSPENDED) - chSchWakeupS(tp, RDY_OK); + if ((tp)->p_state == PRSUSPENDED) + chSchWakeupS((tp), RDY_OK); chSysUnlock(); } diff --git a/src/include/delta.h b/src/include/delta.h index 1af774959..4365eb482 100644 --- a/src/include/delta.h +++ b/src/include/delta.h @@ -97,6 +97,9 @@ extern "C" { } #endif +/** Returns TRUE if the speciified timer is armed.*/ +#define chVTIsArmedI(vtp) ((vtp)->vt_func != NULL) + #endif /* CH_USE_VIRTUAL_TIMER */ #endif /* _DELTA_H_ */ diff --git a/src/include/threads.h b/src/include/threads.h index 0440b6007..3e1713d31 100644 --- a/src/include/threads.h +++ b/src/include/threads.h @@ -192,8 +192,10 @@ extern "C" { Thread *chThdCreate(t_prio prio, t_tmode mode, void *workspace, t_size wsize, t_tfunc pf, void *arg); void chThdSetPriority(t_prio newprio); - void chThdResume(Thread *tp); void chThdExit(t_msg msg); +#ifdef CH_USE_RESUME + void chThdResume(Thread *tp); +#endif #ifdef CH_USE_TERMINATE void chThdTerminate(Thread *tp); #endif @@ -240,6 +242,13 @@ extern "C" { */ #define chThdGetExitEventSource(tp) (&(tp)->p_exitesource) +/** + * Resumes a thread created with the \p P_SUSPENDED option or suspended with + * \p chThdSuspend(). + * @param tp the pointer to the thread + */ +#define chThdResumeI(tp) chSchReadyI(tp) + #endif /* _THREADS_H_ */ /** @} */ diff --git a/src/lib/evtimer.c b/src/lib/evtimer.c index 1ab384086..b273e1fd3 100644 --- a/src/lib/evtimer.c +++ b/src/lib/evtimer.c @@ -45,7 +45,7 @@ void evtStart(EvTimer *etp) { chSysLock(); - if (!etp->et_vt.vt_func) + if (!chVTIsArmedI(&etp->et_vt)) chVTSetI(&etp->et_vt, etp->et_interval, tmrcb, etp); chSysUnlock(); @@ -60,7 +60,7 @@ void evtStop(EvTimer *etp) { chSysLock(); - if (etp->et_vt.vt_func) + if (chVTIsArmedI(&etp->et_vt)) chVTResetI(&etp->et_vt); chSysUnlock(); diff --git a/src/templates/chconf.h b/src/templates/chconf.h index 478abd8f9..9c5d303bd 100644 --- a/src/templates/chconf.h +++ b/src/templates/chconf.h @@ -52,6 +52,10 @@ * function is included in the kernel.*/ #define CH_USE_RESUME +/** Configuration option: if specified then the \p chThdSuspend() + * function is included in the kernel.*/ +#define CH_USE_SUSPEND + /** Configuration option: if specified then the \p chThdTerminate() * and \p chThdShouldTerminate() functions are included in the kernel.*/ #define CH_USE_TERMINATE