From e8f67437d0007a2a4cd5a05afbd525a1960c188c Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sat, 2 Apr 2016 13:05:59 +0000 Subject: Simulator updates, not complete. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9223 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- demos/various/RT-Win32-Simulator/Makefile | 9 ++- demos/various/RT-Win32-Simulator/chconf.h | 48 +++++++++--- demos/various/RT-Win32-Simulator/main.c | 70 +++-------------- os/common/oslib/include/chmemcore.h | 2 + os/common/oslib/src/chmemcore.c | 9 +-- os/common/ports/SIMIA32/chcore.h | 109 +++++++++++++++++++++----- os/common/ports/SIMIA32/compilers/GCC/port.mk | 6 +- os/hal/ports/simulator/win32/platform.mk | 6 +- 8 files changed, 156 insertions(+), 103 deletions(-) diff --git a/demos/various/RT-Win32-Simulator/Makefile b/demos/various/RT-Win32-Simulator/Makefile index cdb121b6b..35e705616 100644 --- a/demos/various/RT-Win32-Simulator/Makefile +++ b/demos/various/RT-Win32-Simulator/Makefile @@ -64,6 +64,8 @@ include $(CHIBIOS)/os/hal/osal/rt/osal.mk include $(CHIBIOS)/os/common/ports/SIMIA32/compilers/GCC/port.mk include $(CHIBIOS)/os/rt/rt.mk include $(CHIBIOS)/test/rt/test.mk +include $(CHIBIOS)/os/hal/lib/streams/streams.mk +include $(CHIBIOS)/os/various/shell/shell.mk # List C source files here SRC = $(PORTSRC) \ @@ -73,9 +75,8 @@ SRC = $(PORTSRC) \ $(OSALSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ - $(CHIBIOS)/os/various/shell.c \ - $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ - $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ + $(STREAMSSRC) \ + $(SHELLSRC) \ main.c # List ASM source files here @@ -84,7 +85,7 @@ ASRC = # List all user directories here UINCDIR = $(PORTINC) $(KERNINC) $(TESTINC) \ $(HALINC) $(OSALINC) $(PLATFORMINC) $(BOARDINC) \ - $(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various + $(STREAMSINC) $(SHELLINC) $(CHIBIOS)/os/various # List the user directory to look for the libraries here ULIBDIR = diff --git a/demos/various/RT-Win32-Simulator/chconf.h b/demos/various/RT-Win32-Simulator/chconf.h index 7c596f355..708b2b065 100644 --- a/demos/various/RT-Win32-Simulator/chconf.h +++ b/demos/various/RT-Win32-Simulator/chconf.h @@ -28,6 +28,8 @@ #ifndef CHCONF_H #define CHCONF_H +#define _CHIBIOS_RT_CONF_ + /*===========================================================================*/ /** * @name System timers settings @@ -79,7 +81,7 @@ * @note The round robin preemption is not supported in tickless mode and * must be set to zero in that case. */ -#define CH_CFG_TIME_QUANTUM 20 +#define CH_CFG_TIME_QUANTUM 0 /** * @brief Managed RAM size. @@ -138,7 +140,7 @@ * * @note The default is @p TRUE. */ -#define CH_CFG_USE_TM FALSE +#define CH_CFG_USE_TM TRUE /** * @brief Threads registry APIs. @@ -352,9 +354,16 @@ * @details If enabled then the context switch circular trace buffer is * activated. * - * @note The default is @p FALSE. + * @note The default is @p CH_DBG_TRACE_MASK_NONE. + */ +#define CH_DBG_TRACE_MASK CH_DBG_TRACE_MASK_NONE + +/** + * @brief Trace buffer entries. + * @note The trace buffer is only allocated if @p CH_DBG_TRACE_MASK is + * different from @p CH_DBG_TRACE_MASK_NONE. */ -#define CH_DBG_ENABLE_TRACE FALSE +#define CH_DBG_TRACE_BUFFER_SIZE 128 /** * @brief Debug option, stack checks. @@ -387,7 +396,7 @@ * @note This debug option is not currently compatible with the * tickless mode. */ -#define CH_DBG_THREADS_PROFILING TRUE +#define CH_DBG_THREADS_PROFILING FALSE /** @} */ @@ -419,10 +428,6 @@ /** * @brief Threads finalization hook. * @details User finalization code added to the @p chThdExit() API. - * - * @note It is inserted into lock zone. - * @note It is also invoked when the threads simply return in order to - * terminate. */ #define CH_CFG_THREAD_EXIT_HOOK(tp) { \ /* Add threads finalization code here.*/ \ @@ -436,6 +441,20 @@ /* Context switch code here.*/ \ } +/** + * @brief ISR enter hook. + */ +#define CH_CFG_IRQ_PROLOGUE_HOOK() { \ + /* IRQ prologue code here.*/ \ +} + +/** + * @brief ISR exit hook. + */ +#define CH_CFG_IRQ_EPILOGUE_HOOK() { \ + /* IRQ epilogue code here.*/ \ +} + /** * @brief Idle thread enter hook. * @note This hook is invoked within a critical zone, no OS functions @@ -443,6 +462,7 @@ * @note This macro can be used to activate a power saving mode. */ #define CH_CFG_IDLE_ENTER_HOOK() { \ + /* Idle-enter code here.*/ \ } /** @@ -452,6 +472,7 @@ * @note This macro can be used to deactivate a power saving mode. */ #define CH_CFG_IDLE_LEAVE_HOOK() { \ + /* Idle-leave code here.*/ \ } /** @@ -480,6 +501,15 @@ /* System halt code here.*/ \ } +/** + * @brief Trace hook. + * @details This hook is invoked each time a new record is written in the + * trace buffer. + */ +#define CH_CFG_TRACE_HOOK(tep) { \ + /* Trace code here.*/ \ +} + /** @} */ /*===========================================================================*/ diff --git a/demos/various/RT-Win32-Simulator/main.c b/demos/various/RT-Win32-Simulator/main.c index 17b2346c6..d4a3da302 100644 --- a/demos/various/RT-Win32-Simulator/main.c +++ b/demos/various/RT-Win32-Simulator/main.c @@ -30,61 +30,7 @@ static thread_t *cdtp; static thread_t *shelltp1; static thread_t *shelltp2; -static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) { - size_t n, size; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: mem\r\n"); - return; - } - n = chHeapStatus(NULL, &size); - chprintf(chp, "core free memory : %u bytes\r\n", chCoreGetStatusX()); - chprintf(chp, "heap fragments : %u\r\n", n); - chprintf(chp, "heap free total : %u bytes\r\n", size); -} - -static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) { - static const char *states[] = {CH_STATE_NAMES}; - thread_t *tp; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: threads\r\n"); - return; - } - chprintf(chp, " addr stack prio refs state time\r\n"); - tp = chRegFirstThread(); - do { - chprintf(chp, "%.8lx %.8lx %4lu %4lu %9s %lu\r\n", - (uint32_t)tp, (uint32_t)tp->p_ctx.esp, - (uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1), - states[tp->p_state], (uint32_t)tp->p_time); - tp = chRegNextThread(tp); - } while (tp != NULL); -} - -static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) { - thread_t *tp; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: test\r\n"); - return; - } - tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriorityX(), - TestThread, chp); - if (tp == NULL) { - chprintf(chp, "out of memory\r\n"); - return; - } - chThdWait(tp); -} - static const ShellCommand commands[] = { - {"mem", cmd_mem}, - {"threads", cmd_threads}, - {"test", cmd_test}, {NULL, NULL} }; @@ -128,7 +74,8 @@ static void termination_handler(eventid_t id) { chThdSleepMilliseconds(10); cputs("Init: shell on SD1 terminated"); chSysLock(); - chOQResetI(&SD1.oqueue); + oqResetI(&SD1.oqueue); + chSchRescheduleS(); chSysUnlock(); } if (shelltp2 && chThdTerminatedX(shelltp2)) { @@ -137,7 +84,8 @@ static void termination_handler(eventid_t id) { chThdSleepMilliseconds(10); cputs("Init: shell on SD2 terminated"); chSysLock(); - chOQResetI(&SD2.oqueue); + oqResetI(&SD2.oqueue); + chSchRescheduleS(); chSysUnlock(); } } @@ -161,7 +109,8 @@ static void sd1_handler(eventid_t id) { if (flags & CHN_DISCONNECTED) { cputs("Init: disconnection on SD1"); chSysLock(); - chIQResetI(&SD1.iqueue); + iqResetI(&SD1.iqueue); + chSchRescheduleS(); chSysUnlock(); } } @@ -183,7 +132,8 @@ static void sd2_handler(eventid_t id) { if (flags & CHN_DISCONNECTED) { cputs("Init: disconnection on SD2"); chSysLock(); - chIQResetI(&SD2.iqueue); + iqResetI(&SD2.iqueue); + chSchRescheduleS(); chSysUnlock(); } } @@ -225,8 +175,8 @@ int main(void) { /* * Console thread started. */ - cdtp = chThdCreateFromHeap(NULL, CONSOLE_WA_SIZE, NORMALPRIO + 1, - console_thread, NULL); + cdtp = chThdCreateFromHeap(NULL, CONSOLE_WA_SIZE, "console", + NORMALPRIO + 1, console_thread, NULL); /* * Initializing connection/disconnection events. diff --git a/os/common/oslib/include/chmemcore.h b/os/common/oslib/include/chmemcore.h index 014af50d6..539d71ecf 100644 --- a/os/common/oslib/include/chmemcore.h +++ b/os/common/oslib/include/chmemcore.h @@ -49,7 +49,9 @@ * provide the @p __heap_base__ and @p __heap_end__ symbols. * @note Requires @p CH_CFG_USE_MEMCORE. */ +#if !defined(CH_CFG_MEMCORE_SIZE) || defined(__DOXYGEN__) #define CH_CFG_MEMCORE_SIZE 0 +#endif /*===========================================================================*/ /* Derived constants and error checks. */ diff --git a/os/common/oslib/src/chmemcore.c b/os/common/oslib/src/chmemcore.c index af733f395..d72bf73bb 100644 --- a/os/common/oslib/src/chmemcore.c +++ b/os/common/oslib/src/chmemcore.c @@ -86,12 +86,11 @@ void _core_init(void) { endmem = (uint8_t *)MEM_ALIGN_PREV(__heap_end__, PORT_NATURAL_ALIGN); /*lint restore*/ #else - static stkalign_t buffer[MEM_ALIGN_NEXT(CH_CFG_MEMCORE_SIZE) / - PORT_NATURAL_ALIGN]; + static uint8_t default_heap[MEM_ALIGN_NEXT(CH_CFG_MEMCORE_SIZE, + PORT_NATURAL_ALIGN)]; - nextmem = (uint8_t *)&buffer[0]; - endmem = (uint8_t *)&buffer[MEM_ALIGN_NEXT(CH_CFG_MEMCORE_SIZE) / - PORT_NATURAL_ALIGN]; + nextmem = (uint8_t *)MEM_ALIGN_NEXT(default_heap, PORT_NATURAL_ALIGN); + endmem = (uint8_t *)MEM_ALIGN_PREV(default_heap, PORT_NATURAL_ALIGN); #endif } diff --git a/os/common/ports/SIMIA32/chcore.h b/os/common/ports/SIMIA32/chcore.h index b7db58e4b..125792145 100644 --- a/os/common/ports/SIMIA32/chcore.h +++ b/os/common/ports/SIMIA32/chcore.h @@ -32,6 +32,38 @@ /* Module constants. */ /*===========================================================================*/ +/** + * @name Port Capabilities and Constants + * @{ + */ +/** + * @brief This port supports a realtime counter. + */ +#define PORT_SUPPORTS_RT TRUE + +/** + * @brief Natural alignment constant. + * @note It is the minimum alignment for pointer-size variables. + */ +#define PORT_NATURAL_ALIGN sizeof (void *) + +/** + * @brief Stack alignment constant. + * @note It is the alignement required for the stack pointer. + */ +#define PORT_STACK_ALIGN sizeof (stkalign_t) + +/** + * @brief Working Areas alignment constant. + * @note It is the alignment to be enforced for thread working areas. + */ +#define PORT_WORKING_AREA_ALIGN sizeof (stkalign_t) +/** @} */ + +/** + * @name Architecture and Compiler + * @{ + */ /** * Macro defining the a simulated architecture into x86. */ @@ -56,11 +88,7 @@ * @brief Port-specific information string. */ #define PORT_INFO "No preemption" - -/** - * @brief This port supports a realtime counter. - */ -#define PORT_SUPPORTS_RT TRUE +/** @} */ /*===========================================================================*/ /* Module pre-compile time settings. */ @@ -72,7 +100,7 @@ * the idle thread should take no more space than those reserved * by @p PORT_INT_REQUIRED_STACK. */ -#ifndef PORT_IDLE_THREAD_STACK_SIZE +#if !defined(PORT_IDLE_THREAD_STACK_SIZE) || defined(__DOXYGEN__) #define PORT_IDLE_THREAD_STACK_SIZE 256 #endif @@ -81,7 +109,7 @@ * @details This constant is used in the calculation of the correct working * area size. */ -#ifndef PORT_INT_REQUIRED_STACK +#if !defined(PORT_INT_REQUIRED_STACK) || defined(__DOXYGEN__) #define PORT_INT_REQUIRED_STACK 16384 #endif @@ -91,7 +119,7 @@ * @p chcore_timer.h, if this option is enabled then the file * @p chcore_timer_alt.h is included instead. */ -#if !defined(PORT_USE_ALT_TIMER) +#if !defined(PORT_USE_ALT_TIMER) || defined(__DOXYGEN__) #define PORT_USE_ALT_TIMER FALSE #endif @@ -107,6 +135,10 @@ /* Module data structures and types. */ /*===========================================================================*/ +/* The following code is not processed when the file is included from an + asm module.*/ +#if !defined(_FROM_ASM_) + /** * @brief 16 bytes stack and memory alignment enforcement. */ @@ -142,14 +174,15 @@ struct port_intctx { /** * @brief Platform dependent part of the @p thread_t structure. - * @details In this port the structure just holds a pointer to the - * @p port_intctx structure representing the stack pointer - * at context switch time. + * @details This structure usually contains just the saved stack pointer + * defined as a pointer to a @p port_intctx structure. */ -struct context { - struct port_intctx *esp; +struct port_context { + struct port_intctx *sp; }; +#endif /* !defined(_FROM_ASM_) */ + /*===========================================================================*/ /* Module macros. */ /*===========================================================================*/ @@ -171,9 +204,9 @@ struct context { * @details This code usually setup the context switching frame represented * by an @p port_intctx structure. */ -#define PORT_SETUP_CONTEXT(tp, workspace, wsize, pf, arg) { \ +#define PORT_SETUP_CONTEXT(tp, wbase, wtop, pf, arg) { \ /*lint -save -e611 -e9033 -e9074 -e9087 [10.8, 11.1, 11.3] Valid casts.*/ \ - uint8_t *esp = (uint8_t *)workspace + wsize; \ + uint8_t *esp = (uint8_t *)wtop; \ APUSH(esp, 0); \ uint8_t *savebp = esp; \ AALIGN(esp, 15, 8); \ @@ -186,7 +219,7 @@ struct context { ((struct port_intctx *)esp)->edi = NULL; \ ((struct port_intctx *)esp)->esi = NULL; \ ((struct port_intctx *)esp)->ebp = (void *)savebp; \ - (tp)->p_ctx.esp = (struct port_intctx *)esp; \ + (tp)->ctx.sp = (struct port_intctx *)esp; \ /*lint -restore*/ \ } @@ -194,11 +227,22 @@ struct context { * @brief Computes the thread working area global size. * @note There is no need to perform alignments in this macro. */ -#define PORT_WA_SIZE(n) ((sizeof(void *) * 4U) + \ - sizeof(struct port_intctx) + \ +#define PORT_WA_SIZE(n) ((sizeof (void *) * 4U) + \ + sizeof (struct port_intctx) + \ ((size_t)(n)) + \ ((size_t)(PORT_INT_REQUIRED_STACK))) +/** + * @brief Static working area allocation. + * @details This macro is used to allocate a static thread working area + * aligned as both position and size. + * + * @param[in] s the name to be assigned to the stack array + * @param[in] n the stack size to be assigned to the thread + */ +#define PORT_WORKING_AREA(s, n) \ + stkalign_t s[THD_WORKING_AREA_SIZE(n) / sizeof (stkalign_t)] + /** * @brief IRQ prologue code. * @details This macro must be inserted at the start of all IRQ handlers @@ -217,7 +261,6 @@ struct context { port_isr_context_flag = false; \ } - /** * @brief IRQ handler function declaration. * @note @p id can be a function name or a vector number depending on the @@ -236,6 +279,10 @@ struct context { /* External declarations. */ /*===========================================================================*/ +/* The following code is not processed when the file is included from an + asm module.*/ +#if !defined(_FROM_ASM_) + extern bool port_isr_context_flag; extern syssts_t port_irq_sts; @@ -253,10 +300,16 @@ extern "C" { } #endif +#endif /* !defined(_FROM_ASM_) */ + /*===========================================================================*/ /* Module inline functions. */ /*===========================================================================*/ +/* The following code is not processed when the file is included from an + asm module.*/ +#if !defined(_FROM_ASM_) + /** * @brief Port-related initialization code. */ @@ -377,6 +430,24 @@ static inline void port_wait_for_interrupt(void) { _sim_check_for_interrupts(); } +#endif /* !defined(_FROM_ASM_) */ + +/*===========================================================================*/ +/* Module late inclusions. */ +/*===========================================================================*/ + +#if !defined(_FROM_ASM_) + +#if CH_CFG_ST_TIMEDELTA > 0 +#if !PORT_USE_ALT_TIMER +#include "chcore_timer.h" +#else /* PORT_USE_ALT_TIMER */ +#include "chcore_timer_alt.h" +#endif /* PORT_USE_ALT_TIMER */ +#endif /* CH_CFG_ST_TIMEDELTA > 0 */ + +#endif /* !defined(_FROM_ASM_) */ + #endif /* CHCORE_H */ /** @} */ diff --git a/os/common/ports/SIMIA32/compilers/GCC/port.mk b/os/common/ports/SIMIA32/compilers/GCC/port.mk index 0d5f0903d..124ad35c8 100644 --- a/os/common/ports/SIMIA32/compilers/GCC/port.mk +++ b/os/common/ports/SIMIA32/compilers/GCC/port.mk @@ -1,7 +1,7 @@ # List of the ChibiOS/RT SIMIA32 port files. -PORTSRC = ${CHIBIOS}/os/rt/ports/SIMIA32/chcore.c +PORTSRC = ${CHIBIOS}/os/common/ports/SIMIA32/chcore.c PORTASM = -PORTINC = ${CHIBIOS}/os/rt/ports/SIMIA32/compilers/GCC \ - ${CHIBIOS}/os/rt/ports/SIMIA32 +PORTINC = ${CHIBIOS}/os/common/ports/SIMIA32/compilers/GCC \ + ${CHIBIOS}/os/common/ports/SIMIA32 diff --git a/os/hal/ports/simulator/win32/platform.mk b/os/hal/ports/simulator/win32/platform.mk index 619d3b806..c56724f9f 100644 --- a/os/hal/ports/simulator/win32/platform.mk +++ b/os/hal/ports/simulator/win32/platform.mk @@ -1,9 +1,9 @@ # List of all the Win32 platform files. PLATFORMSRC = ${CHIBIOS}/os/hal/ports/simulator/win32/hal_lld.c \ - ${CHIBIOS}/os/hal/ports/simulator/win32/serial_lld.c \ + ${CHIBIOS}/os/hal/ports/simulator/win32/hal_serial_lld.c \ ${CHIBIOS}/os/hal/ports/simulator/console.c \ - ${CHIBIOS}/os/hal/ports/simulator/pal_lld.c \ - ${CHIBIOS}/os/hal/ports/simulator/st_lld.c + ${CHIBIOS}/os/hal/ports/simulator/hal_pal_lld.c \ + ${CHIBIOS}/os/hal/ports/simulator/hal_st_lld.c # Required include directories PLATFORMINC = ${CHIBIOS}/os/hal/ports/simulator/win32 \ -- cgit v1.2.3