From b143106fe1457c85f8d25f4386b75bdea5efb521 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sat, 29 May 2021 16:49:49 +0000 Subject: [PATCH] Improved VT_Storm. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@14440 27425a3e-05d8-49a3-a47f-9c15f0e5edd8 --- .../cfg/stm32g474re_nucleo64/chconf.h | 2 +- .../cfg/stm32g474re_nucleo64/portab.c | 28 ++++++ testrt/VT_STORM/source/vt_storm.c | 96 ++++++++++--------- testrt/VT_STORM/source/vt_storm.h | 26 ++++- 4 files changed, 106 insertions(+), 46 deletions(-) diff --git a/testrt/VT_STORM/cfg/stm32g474re_nucleo64/chconf.h b/testrt/VT_STORM/cfg/stm32g474re_nucleo64/chconf.h index dfd55acef..551df211c 100644 --- a/testrt/VT_STORM/cfg/stm32g474re_nucleo64/chconf.h +++ b/testrt/VT_STORM/cfg/stm32g474re_nucleo64/chconf.h @@ -72,7 +72,7 @@ * setting also defines the system tick time unit. */ #if !defined(CH_CFG_ST_FREQUENCY) -#define CH_CFG_ST_FREQUENCY 1000000 +#define CH_CFG_ST_FREQUENCY 21250000 #endif /** diff --git a/testrt/VT_STORM/cfg/stm32g474re_nucleo64/portab.c b/testrt/VT_STORM/cfg/stm32g474re_nucleo64/portab.c index cc5ff4ddb..42d690eee 100644 --- a/testrt/VT_STORM/cfg/stm32g474re_nucleo64/portab.c +++ b/testrt/VT_STORM/cfg/stm32g474re_nucleo64/portab.c @@ -35,12 +35,40 @@ /* Module exported variables. */ /*===========================================================================*/ +#if VT_STORM_CFG_HAMMERS || defined(__DOXYGEN__) +/* + * GPT4 configuration. + */ +static const GPTConfig gpt3cfg = { + 1000000, /* 1MHz timer clock.*/ + vt_storm_gpt1_cb, /* Timer callback.*/ + 0, + 0 +}; + +/* + * GPT3 configuration. + */ +static const GPTConfig gpt4cfg = { + 1000000, /* 1MHz timer clock.*/ + vt_storm_gpt2_cb, /* Timer callback.*/ + 0, + 0 +}; +#endif + /* * VT Storm configuration. */ const vt_storm_config_t portab_vt_storm_config = { (BaseSequentialStream *)&PORTAB_SD1, PORTAB_LINE_LED1, +#if VT_STORM_CFG_HAMMERS + &GPTD3, + &GPTD4, + &gpt3cfg, + &gpt4cfg, +#endif STM32_SYSCLK }; diff --git a/testrt/VT_STORM/source/vt_storm.c b/testrt/VT_STORM/source/vt_storm.c index 2d6d780a6..f641083ef 100644 --- a/testrt/VT_STORM/source/vt_storm.c +++ b/testrt/VT_STORM/source/vt_storm.c @@ -58,19 +58,6 @@ static volatile sysinterval_t delay; static volatile bool saturated; static uint32_t vtcus; -#if VT_STORM_CFG_HAMMERS -/* - * GPTs configuration. - */ -static void hammer_gpt_cb(GPTDriver *gptp); -static const GPTConfig hammer_gpt_cfg = { - 1000000, /* 1MHz timer clock.*/ - hammer_gpt_cb, /* Timer callback.*/ - 0, - 0 -}; -#endif - /*===========================================================================*/ /* Module local functions. */ /*===========================================================================*/ @@ -232,31 +219,6 @@ static void guard_cb(virtual_timer_t *vtp, void *p) { (void)p; } -#if VT_STORM_CFG_HAMMERS -/** - * @brief GPT callback. - */ -static void hammer_gpt_cb(GPTDriver *gptp) { - - (void)gptp; - -#if VT_STORM_CFG_RANDOMIZE != FALSE - /* Pseudo-random delay.*/ - { - static volatile unsigned x = 0; - unsigned r; - - chSysLockFromISR(); - r = rand() & 31; - chSysUnlockFromISR(); - while (r--) { - x++; - } - } -#endif -} -#endif - /*===========================================================================*/ /* Module exported functions. */ /*===========================================================================*/ @@ -302,15 +264,15 @@ void vt_storm_execute(const vt_storm_config_t *cfg) { chprintf(cfg->out, "*** System Time size: %d bits\r\n", CH_CFG_ST_RESOLUTION); chprintf(cfg->out, "*** Intervals size: %d bits\r\n", CH_CFG_INTERVALS_SIZE); chprintf(cfg->out, "*** SysTick: %d Hz\r\n", CH_CFG_ST_FREQUENCY); - chprintf(cfg->out, "*** Delta: %d cycles\r\n", CH_CFG_ST_TIMEDELTA); + chprintf(cfg->out, "*** Delta: %d ticks\r\n", CH_CFG_ST_TIMEDELTA); chprintf(cfg->out, "\r\n"); #if VT_STORM_CFG_HAMMERS /* Starting hammer timers.*/ - gptStart(&GPTD3, &hammer_gpt_cfg); - gptStart(&GPTD4, &hammer_gpt_cfg); - gptStartContinuous(&GPTD3, 99); - gptStartContinuous(&GPTD4, 101); + gptStart(cfg->gpt1p, cfg->gptcfg1p); + gptStart(cfg->gpt2p, cfg->gptcfg2p); + gptStartContinuous(cfg->gpt1p, 99); + gptStartContinuous(cfg->gpt2p, 101); #endif for (i = 1; i <= VT_STORM_CFG_ITERATIONS; i++) { @@ -380,4 +342,52 @@ void vt_storm_execute(const vt_storm_config_t *cfg) { } } +#if VT_STORM_CFG_HAMMERS || defined(__DOXYGEN__) +/** + * @brief GPT callback 1. + */ +void vt_storm_gpt1_cb(GPTDriver *gptp) { + + (void)gptp; + +#if VT_STORM_CFG_RANDOMIZE != FALSE + /* Pseudo-random delay.*/ + { + static volatile unsigned x = 0; + unsigned r; + + chSysLockFromISR(); + r = rand() & 31; + chSysUnlockFromISR(); + while (r--) { + x++; + } + } +#endif +} + +/** + * @brief GPT callback 2. + */ +void vt_storm_gpt2_cb(GPTDriver *gptp) { + + (void)gptp; + +#if VT_STORM_CFG_RANDOMIZE != FALSE + /* Pseudo-random delay.*/ + { + static volatile unsigned x = 0; + unsigned r; + + chSysLockFromISR(); + r = rand() & 31; + chSysUnlockFromISR(); + while (r--) { + x++; + } + } +#endif +} +#endif + /** @} */ diff --git a/testrt/VT_STORM/source/vt_storm.h b/testrt/VT_STORM/source/vt_storm.h index 38cc709d3..8356baa62 100644 --- a/testrt/VT_STORM/source/vt_storm.h +++ b/testrt/VT_STORM/source/vt_storm.h @@ -41,7 +41,7 @@ * @brief Timings randomization. */ #if !defined(VT_STORM_CFG_RANDOMIZE) || defined(__DOXYGEN__) -#define VT_STORM_CFG_RANDOMIZE 0 +#define VT_STORM_CFG_RANDOMIZE TRUE #endif /** @@ -62,7 +62,7 @@ * @brief Enable hammer timers. */ #if !defined(VT_STORM_CFG_HAMMERS) || defined(__DOXYGEN__) -#define VT_STORM_CFG_HAMMERS 0 +#define VT_STORM_CFG_HAMMERS TRUE #endif /** @} */ @@ -87,6 +87,24 @@ typedef struct { * @brief LED line. */ ioline_t line; +#if VT_STORM_CFG_HAMMERS || defined(__DOXYGEN__) + /** + * @brief GPT driver 1. + */ + GPTDriver *gpt1p; + /** + * @brief GPT driver 2. + */ + GPTDriver *gpt2p; + /** + * @brief GPT1 configuration 1. + */ + const GPTConfig *gptcfg1p; + /** + * @brief GPT1 configuration 2. + */ + const GPTConfig *gptcfg2p; +#endif /** * @brief System clock. */ @@ -105,6 +123,10 @@ typedef struct { extern "C" { #endif void vt_storm_execute(const vt_storm_config_t *cfg); +#if VT_STORM_CFG_HAMMERS + void vt_storm_gpt1_cb(GPTDriver *gptp); + void vt_storm_gpt2_cb(GPTDriver *gptp); +#endif #ifdef __cplusplus } #endif