From 476270c2ab91169a8e731562b0e68b86602e0d77 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 4 Nov 2014 10:51:23 +0000 Subject: [PATCH] git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7475 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- demos/various/RT-Win32-Simulator/Makefile | 14 ++- demos/various/RT-Win32-Simulator/chconf.h | 4 +- demos/various/RT-Win32-Simulator/main.c | 40 +++--- os/hal/include/hal.h | 9 +- os/hal/ports/simulator/st_lld.c | 67 ++++++++++ os/hal/ports/simulator/st_lld.h | 141 ++++++++++++++++++++++ os/hal/ports/simulator/win32/hal_lld.c | 10 +- os/hal/ports/simulator/win32/platform.mk | 3 +- os/hal/ports/simulator/win32/serial_lld.c | 4 +- os/hal/ports/simulator/win32/serial_lld.h | 4 +- os/hal/src/hal.c | 7 +- os/rt/ports/SIMIA32/chcore.c | 2 +- os/rt/ports/SIMIA32/chcore.h | 6 +- test/rt/test.c | 2 +- test/rt/testbmk.c | 20 +-- 15 files changed, 277 insertions(+), 56 deletions(-) create mode 100644 os/hal/ports/simulator/st_lld.c create mode 100644 os/hal/ports/simulator/st_lld.h diff --git a/demos/various/RT-Win32-Simulator/Makefile b/demos/various/RT-Win32-Simulator/Makefile index d6499dd77..7621091b1 100644 --- a/demos/various/RT-Win32-Simulator/Makefile +++ b/demos/various/RT-Win32-Simulator/Makefile @@ -60,16 +60,18 @@ CHIBIOS = ../../.. include $(CHIBIOS)/os/hal/boards/simulator/board.mk include ${CHIBIOS}/os/hal/hal.mk include ${CHIBIOS}/os/hal/ports/simulator/win32/platform.mk +include $(CHIBIOS)/os/hal/osal/rt/osal.mk include ${CHIBIOS}/os/rt/ports/SIMIA32/compilers/GCC/port.mk include ${CHIBIOS}/os/rt/rt.mk include ${CHIBIOS}/test/rt/test.mk # List C source files here -SRC = ${PORTSRC} \ - ${KERNSRC} \ - ${TESTSRC} \ - ${HALSRC} \ - ${PLATFORMSRC} \ +SRC = $(PORTSRC) \ + $(KERNSRC) \ + $(TESTSRC) \ + $(HALSRC) \ + $(OSALSRC) \ + $(PLATFORMSRC) \ $(BOARDSRC) \ ${CHIBIOS}/os/various/shell.c \ ${CHIBIOS}/os/various/memstreams.c \ @@ -81,7 +83,7 @@ ASRC = # List all user directories here UINCDIR = $(PORTINC) $(KERNINC) $(TESTINC) \ - $(HALINC) $(PLATFORMINC) $(BOARDINC) \ + $(HALINC) $(OSALINC) $(PLATFORMINC) $(BOARDINC) \ ${CHIBIOS}/os/various # List the user directory to look for the libraries here diff --git a/demos/various/RT-Win32-Simulator/chconf.h b/demos/various/RT-Win32-Simulator/chconf.h index 896f8b437..f38839909 100644 --- a/demos/various/RT-Win32-Simulator/chconf.h +++ b/demos/various/RT-Win32-Simulator/chconf.h @@ -56,7 +56,7 @@ * The value one is not valid, timeouts are rounded up to * this value. */ -#define CH_CFG_ST_TIMEDELTA 1 +#define CH_CFG_ST_TIMEDELTA 0 /** @} */ @@ -394,7 +394,7 @@ * @note This debug option is not currently compatible with the * tickless mode. */ -#define CH_DBG_THREADS_PROFILING FALSE +#define CH_DBG_THREADS_PROFILING TRUE /** @} */ diff --git a/demos/various/RT-Win32-Simulator/main.c b/demos/various/RT-Win32-Simulator/main.c index e904850d5..ccc9aad97 100644 --- a/demos/various/RT-Win32-Simulator/main.c +++ b/demos/various/RT-Win32-Simulator/main.c @@ -20,15 +20,15 @@ #include "shell.h" #include "chprintf.h" -#define SHELL_WA_SIZE THD_WA_SIZE(4096) -#define CONSOLE_WA_SIZE THD_WA_SIZE(4096) -#define TEST_WA_SIZE THD_WA_SIZE(4096) +#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(4096) +#define CONSOLE_WA_SIZE THD_WORKING_AREA_SIZE(4096) +#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(4096) #define cputs(msg) chMsgSend(cdtp, (msg_t)msg) -static Thread *cdtp; -static Thread *shelltp1; -static Thread *shelltp2; +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; @@ -45,8 +45,8 @@ static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) { } static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) { - static const char *states[] = {THD_STATE_NAMES}; - Thread *tp; + static const char *states[] = {CH_STATE_NAMES}; + thread_t *tp; (void)argv; if (argc > 0) { @@ -65,14 +65,14 @@ static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) { } static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) { - Thread *tp; + thread_t *tp; (void)argv; if (argc > 0) { chprintf(chp, "Usage: test\r\n"); return; } - tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(), + tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriorityX(), TestThread, chp); if (tp == NULL) { chprintf(chp, "out of memory\r\n"); @@ -106,11 +106,11 @@ static const ShellConfig shell_cfg2 = { static msg_t console_thread(void *arg) { (void)arg; - while (!chThdShouldTerminate()) { - Thread *tp = chMsgWait(); + while (!chThdShouldTerminateX()) { + thread_t *tp = chMsgWait(); puts((char *)chMsgGet(tp)); fflush(stdout); - chMsgRelease(tp, RDY_OK); + chMsgRelease(tp, MSG_OK); } return 0; } @@ -123,7 +123,7 @@ static msg_t console_thread(void *arg) { static void termination_handler(eventid_t id) { (void)id; - if (shelltp1 && chThdTerminated(shelltp1)) { + if (shelltp1 && chThdTerminatedX(shelltp1)) { chThdWait(shelltp1); shelltp1 = NULL; chThdSleepMilliseconds(10); @@ -132,7 +132,7 @@ static void termination_handler(eventid_t id) { chOQResetI(&SD1.oqueue); chSysUnlock(); } - if (shelltp2 && chThdTerminated(shelltp2)) { + if (shelltp2 && chThdTerminatedX(shelltp2)) { chThdWait(shelltp2); shelltp2 = NULL; chThdSleepMilliseconds(10); @@ -143,7 +143,7 @@ static void termination_handler(eventid_t id) { } } -static EventListener sd1fel, sd2fel; +static event_listener_t sd1fel, sd2fel; /** * @brief SD1 status change handler. @@ -151,7 +151,7 @@ static EventListener sd1fel, sd2fel; * @param[in] id event id. */ static void sd1_handler(eventid_t id) { - flagsmask_t flags; + eventflags_t flags; (void)id; flags = chEvtGetAndClearFlags(&sd1fel); @@ -173,7 +173,7 @@ static void sd1_handler(eventid_t id) { * @param[in] id event id. */ static void sd2_handler(eventid_t id) { - flagsmask_t flags; + eventflags_t flags; (void)id; flags = chEvtGetAndClearFlags(&sd2fel); @@ -199,7 +199,7 @@ static evhandler_t fhandlers[] = { * Simulator main. * *------------------------------------------------------------------------*/ int main(void) { - EventListener tel; + event_listener_t tel; /* * System initializations. @@ -241,7 +241,7 @@ int main(void) { /* * Events servicing loop. */ - while (!chThdShouldTerminate()) + while (!chThdShouldTerminateX()) chEvtDispatch(fhandlers, chEvtWaitOne(ALL_EVENTS)); /* diff --git a/os/hal/include/hal.h b/os/hal/include/hal.h index c29eee17d..5fda51fef 100644 --- a/os/hal/include/hal.h +++ b/os/hal/include/hal.h @@ -61,10 +61,17 @@ #include "serial.h" #include "sdc.h" #include "spi.h" -#include "st.h" #include "uart.h" #include "usb.h" +/* + * The ST driver is a special case, it is only included if the OSAL is + * configured to require it. + */ +#if OSAL_ST_MODE != OSAL_ST_MODE_NONE +#include "st.h" +#endif + /* Complex drivers.*/ #include "mmc_spi.h" #include "serial_usb.h" diff --git a/os/hal/ports/simulator/st_lld.c b/os/hal/ports/simulator/st_lld.c new file mode 100644 index 000000000..d6768ddf9 --- /dev/null +++ b/os/hal/ports/simulator/st_lld.c @@ -0,0 +1,67 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2014 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/** + * @file st_lld.c + * @brief PLATFORM ST subsystem low level driver source. + * + * @addtogroup ST + * @{ + */ + +#include "hal.h" + +#if (OSAL_ST_MODE != OSAL_ST_MODE_NONE) || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables and types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver interrupt handlers. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief Low level ST driver initialization. + * + * @notapi + */ +void st_lld_init(void) { +} + +#endif /* OSAL_ST_MODE != OSAL_ST_MODE_NONE */ + +/** @} */ diff --git a/os/hal/ports/simulator/st_lld.h b/os/hal/ports/simulator/st_lld.h new file mode 100644 index 000000000..b5de30a6d --- /dev/null +++ b/os/hal/ports/simulator/st_lld.h @@ -0,0 +1,141 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2014 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/** + * @file st_lld.h + * @brief PLATFORM ST subsystem low level driver header. + * @details This header is designed to be include-able without having to + * include other files from the HAL. + * + * @addtogroup ST + * @{ + */ + +#ifndef _ST_LLD_H_ +#define _ST_LLD_H_ + +/*===========================================================================*/ +/* Driver constants. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver pre-compile time settings. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver data structures and types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + void st_lld_init(void); +#ifdef __cplusplus +} +#endif + +/*===========================================================================*/ +/* Driver inline functions. */ +/*===========================================================================*/ + +/** + * @brief Returns the time counter value. + * + * @return The counter value. + * + * @notapi + */ +static inline systime_t st_lld_get_counter(void) { + + return (systime_t)0; +} + +/** + * @brief Starts the alarm. + * @note Makes sure that no spurious alarms are triggered after + * this call. + * + * @param[in] time the time to be set for the first alarm + * + * @notapi + */ +static inline void st_lld_start_alarm(systime_t time) { + + (void)time; +} + +/** + * @brief Stops the alarm interrupt. + * + * @notapi + */ +static inline void st_lld_stop_alarm(void) { + +} + +/** + * @brief Sets the alarm time. + * + * @param[in] time the time to be set for the next alarm + * + * @notapi + */ +static inline void st_lld_set_alarm(systime_t time) { + + (void)time; +} + +/** + * @brief Returns the current alarm time. + * + * @return The currently set alarm time. + * + * @notapi + */ +static inline systime_t st_lld_get_alarm(void) { + + return (systime_t)0; +} + +/** + * @brief Determines if the alarm is active. + * + * @return The alarm status. + * @retval false if the alarm is not active. + * @retval true is the alarm is active + * + * @notapi + */ +static inline bool st_lld_is_alarm_active(void) { + + return false; +} + +#endif /* _ST_LLD_H_ */ + +/** @} */ diff --git a/os/hal/ports/simulator/win32/hal_lld.c b/os/hal/ports/simulator/win32/hal_lld.c index a42815c0c..555e749a0 100644 --- a/os/hal/ports/simulator/win32/hal_lld.c +++ b/os/hal/ports/simulator/win32/hal_lld.c @@ -64,7 +64,7 @@ void hal_lld_init(void) { printf("QueryPerformanceFrequency() error"); exit(1); } - slice.QuadPart /= CH_FREQUENCY; + slice.QuadPart /= CH_CFG_ST_FREQUENCY; QueryPerformanceCounter(&nextcnt); nextcnt.QuadPart += slice.QuadPart; @@ -79,10 +79,10 @@ void _sim_check_for_interrupts(void) { #if HAL_USE_SERIAL if (sd_lld_interrupt_pending()) { - dbg_check_lock(); + _dbg_check_lock(); if (chSchIsPreemptionRequired()) chSchDoReschedule(); - dbg_check_unlock(); + _dbg_check_unlock(); return; } #endif @@ -100,10 +100,10 @@ void _sim_check_for_interrupts(void) { CH_IRQ_EPILOGUE(); - dbg_check_lock(); + _dbg_check_lock(); if (chSchIsPreemptionRequired()) chSchDoReschedule(); - dbg_check_unlock(); + _dbg_check_unlock(); } } diff --git a/os/hal/ports/simulator/win32/platform.mk b/os/hal/ports/simulator/win32/platform.mk index 8136324e7..842309c62 100644 --- a/os/hal/ports/simulator/win32/platform.mk +++ b/os/hal/ports/simulator/win32/platform.mk @@ -1,7 +1,8 @@ # 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/pal_lld.c + ${CHIBIOS}/os/hal/ports/simulator/pal_lld.c \ + ${CHIBIOS}/os/hal/ports/simulator/st_lld.c # Required include directories PLATFORMINC = ${CHIBIOS}/os/hal/ports/simulator/win32 \ diff --git a/os/hal/ports/simulator/win32/serial_lld.c b/os/hal/ports/simulator/win32/serial_lld.c index 7cf1e5b66..e33499f1f 100644 --- a/os/hal/ports/simulator/win32/serial_lld.c +++ b/os/hal/ports/simulator/win32/serial_lld.c @@ -133,7 +133,7 @@ static bool inint(SerialDriver *sdp) { /* * Input. */ - int n = recv(sdp->com_data, data, sizeof(data), 0); + int n = recv(sdp->com_data, (char *)data, sizeof(data), 0); switch (n) { case 0: closesocket(sdp->com_data); @@ -174,7 +174,7 @@ static bool outint(SerialDriver *sdp) { if (n < 0) return FALSE; data[0] = (uint8_t)n; - n = send(sdp->com_data, data, sizeof(data), 0); + n = send(sdp->com_data, (char *)data, sizeof(data), 0); switch (n) { case 0: closesocket(sdp->com_data); diff --git a/os/hal/ports/simulator/win32/serial_lld.h b/os/hal/ports/simulator/win32/serial_lld.h index 22fb36b8f..ba49bd671 100644 --- a/os/hal/ports/simulator/win32/serial_lld.h +++ b/os/hal/ports/simulator/win32/serial_lld.h @@ -99,9 +99,9 @@ typedef struct { /* Driver state.*/ \ sdstate_t state; \ /* Input queue.*/ \ - InputQueue iqueue; \ + input_queue_t iqueue; \ /* Output queue.*/ \ - OutputQueue oqueue; \ + output_queue_t oqueue; \ /* Input circular buffer.*/ \ uint8_t ib[SERIAL_BUFFERS_SIZE]; \ /* Output circular buffer.*/ \ diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index d9985993e..b49f7383e 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -122,8 +122,11 @@ void halInit(void) { /* Board specific initialization.*/ boardInit(); -#if (OSAL_ST_MODE != OSAL_ST_MODE_NONE) || defined(__DOXYGEN__) - /* System tick service if the underlying OS requires it.*/ +/* + * The ST driver is a special case, it is only initialized if the OSAL is + * configured to require it. + */ +#if OSAL_ST_MODE != OSAL_ST_MODE_NONE stInit(); #endif } diff --git a/os/rt/ports/SIMIA32/chcore.c b/os/rt/ports/SIMIA32/chcore.c index b4357dfc7..244e4c30f 100644 --- a/os/rt/ports/SIMIA32/chcore.c +++ b/os/rt/ports/SIMIA32/chcore.c @@ -58,7 +58,7 @@ * @param ntp the thread to be switched in */ __attribute__((used)) -static void __dummy(Thread *ntp, Thread *otp) { +static void __dummy(thread_t *ntp, thread_t *otp) { (void)ntp; (void)otp; asm volatile ( diff --git a/os/rt/ports/SIMIA32/chcore.h b/os/rt/ports/SIMIA32/chcore.h index 9c8cd2587..6174f93eb 100644 --- a/os/rt/ports/SIMIA32/chcore.h +++ b/os/rt/ports/SIMIA32/chcore.h @@ -148,7 +148,7 @@ struct port_intctx { * at context switch time. */ struct context { - struct intctx volatile *esp; + struct port_intctx *esp; }; /*===========================================================================*/ @@ -177,11 +177,11 @@ struct context { APUSH(esp, pf); \ APUSH(esp, 0); \ esp -= sizeof(struct port_intctx); \ - ((struct port_intctx *)esp)->eip = _port_thread_start; \ + ((struct port_intctx *)esp)->eip = (void *)_port_thread_start; \ ((struct port_intctx *)esp)->ebx = 0; \ ((struct port_intctx *)esp)->edi = 0; \ ((struct port_intctx *)esp)->esi = 0; \ - ((struct port_intctx *)esp)->ebp = savebp; \ + ((struct port_intctx *)esp)->ebp = (void *)savebp; \ (tp)->p_ctx.esp = (struct port_intctx *)esp; \ } diff --git a/test/rt/test.c b/test/rt/test.c index 0750a0d80..ce56dd5fa 100644 --- a/test/rt/test.c +++ b/test/rt/test.c @@ -229,7 +229,7 @@ void test_cpu_pulse(unsigned duration) { do { now = chThdGetTicksX(chThdGetSelfX()); #if defined(SIMULATOR) - ChkIntSources(); + _sim_check_for_interrupts(); #endif } while (end > start ? (now >= start) && (now < end) : diff --git a/test/rt/testbmk.c b/test/rt/testbmk.c index 4f648fa14..8c3545a1c 100644 --- a/test/rt/testbmk.c +++ b/test/rt/testbmk.c @@ -86,7 +86,7 @@ static unsigned int msg_loop_test(thread_t *tp) { (void)chMsgSend(tp, 1); n++; #if defined(SIMULATOR) - ChkIntSources(); + _sim_check_for_interrupts(); #endif } while (!test_timer_done); (void)chMsgSend(tp, 0); @@ -232,7 +232,7 @@ static void bmk4_execute(void) { chSysUnlock(); n += 4; #if defined(SIMULATOR) - ChkIntSources(); + _sim_check_for_interrupts(); #endif } while (!test_timer_done); chSysLock(); @@ -274,7 +274,7 @@ static void bmk5_execute(void) { chThdWait(chThdCreateStatic(wap, WA_SIZE, prio, thread2, NULL)); n++; #if defined(SIMULATOR) - ChkIntSources(); + _sim_check_for_interrupts(); #endif } while (!test_timer_done); test_print("--- Score : "); @@ -313,7 +313,7 @@ static void bmk6_execute(void) { chThdCreateStatic(wap, WA_SIZE, prio, thread2, NULL); n++; #if defined(SIMULATOR) - ChkIntSources(); + _sim_check_for_interrupts(); #endif } while (!test_timer_done); test_print("--- Score : "); @@ -368,7 +368,7 @@ static void bmk7_execute(void) { chSemReset(&sem1, 0); n++; #if defined(SIMULATOR) - ChkIntSources(); + _sim_check_for_interrupts(); #endif } while (!test_timer_done); test_terminate_threads(); @@ -408,7 +408,7 @@ static msg_t thread8(void *p) { chThdYield(); (*(uint32_t *)p) += 4; #if defined(SIMULATOR) - ChkIntSources(); + _sim_check_for_interrupts(); #endif } while(!chThdShouldTerminateX()); return 0; @@ -475,7 +475,7 @@ static void bmk9_execute(void) { (void)chIQGet(&iq); n++; #if defined(SIMULATOR) - ChkIntSources(); + _sim_check_for_interrupts(); #endif } while (!test_timer_done); test_print("--- Score : "); @@ -517,7 +517,7 @@ static void bmk10_execute(void) { chSysUnlock(); n++; #if defined(SIMULATOR) - ChkIntSources(); + _sim_check_for_interrupts(); #endif } while (!test_timer_done); test_print("--- Score : "); @@ -563,7 +563,7 @@ static void bmk11_execute(void) { chSemSignal(&sem1); n++; #if defined(SIMULATOR) - ChkIntSources(); + _sim_check_for_interrupts(); #endif } while (!test_timer_done); test_print("--- Score : "); @@ -610,7 +610,7 @@ static void bmk12_execute(void) { chMtxUnlock(&mtx1); n++; #if defined(SIMULATOR) - ChkIntSources(); + _sim_check_for_interrupts(); #endif } while (!test_timer_done); test_print("--- Score : ");