2013-08-23 08:11:27 +00:00
|
|
|
/*
|
2015-01-11 13:56:55 +00:00
|
|
|
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
2013-08-23 08:11:27 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "ch.h"
|
|
|
|
#include "hal.h"
|
|
|
|
|
|
|
|
float ff1(float par);
|
|
|
|
|
|
|
|
float ff2(float par1, float par2, float par3, float par4);
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Configurable settings. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
#ifndef RANDOMIZE
|
|
|
|
#define RANDOMIZE FALSE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ITERATIONS
|
|
|
|
#define ITERATIONS 100
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Test related code. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2013-08-23 11:26:33 +00:00
|
|
|
static bool saturated;
|
2013-08-23 08:11:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Test worker thread.
|
|
|
|
*/
|
2013-09-05 09:01:21 +00:00
|
|
|
static THD_WORKING_AREA(waWorkerThread, 128);
|
2015-04-03 12:48:22 +00:00
|
|
|
static THD_FUNCTION(WorkerThread, arg) {
|
2013-08-23 08:11:27 +00:00
|
|
|
|
|
|
|
(void)arg;
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
float f1, f2, f3, f4, f5;
|
|
|
|
|
|
|
|
f1 = ff1(3.0f);
|
|
|
|
f2 = ff1(4.0f);
|
|
|
|
f3 = ff1(5.0f);
|
|
|
|
f5 = f1 + f2 + f3;
|
|
|
|
f4 = ff1(6.0f);
|
|
|
|
f5 = ff2(f5, f4, f5, f4);
|
|
|
|
if (f5 != 324.0f)
|
2013-08-23 11:26:33 +00:00
|
|
|
chSysHalt("float corrupion #1");
|
2013-08-23 08:11:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test periodic thread.
|
|
|
|
*/
|
2013-09-05 09:01:21 +00:00
|
|
|
static THD_WORKING_AREA(waPeriodicThread, 128);
|
2015-04-03 12:48:22 +00:00
|
|
|
static THD_FUNCTION(PeriodicThread, arg) {
|
2013-08-23 08:11:27 +00:00
|
|
|
|
|
|
|
(void)arg;
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
float f1, f2, f3, f4, f5;
|
|
|
|
|
|
|
|
f1 = ff1(4.0f);
|
|
|
|
f2 = ff1(5.0f);
|
|
|
|
f3 = ff1(6.0f);
|
|
|
|
f5 = f1 + f2 + f3;
|
|
|
|
f4 = ff1(7.0f);
|
|
|
|
f5 = ff2(f5, f4, f5, f4);
|
|
|
|
if (f5 != 484.0f)
|
2013-08-23 11:26:33 +00:00
|
|
|
chSysHalt("float corrupion #2");
|
2013-08-23 08:11:27 +00:00
|
|
|
chThdSleepSeconds(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* GPT2 callback.
|
|
|
|
*/
|
2013-08-23 11:26:33 +00:00
|
|
|
static void gpt4cb(GPTDriver *gptp) {
|
2013-08-23 08:11:27 +00:00
|
|
|
float f1, f2, f3, f4, f5;
|
|
|
|
|
|
|
|
(void)gptp;
|
|
|
|
|
|
|
|
f1 = ff1(2.0f);
|
|
|
|
f2 = ff1(3.0f);
|
|
|
|
f3 = ff1(4.0f);
|
|
|
|
f5 = f1 + f2 + f3;
|
|
|
|
f4 = ff1(5.0f);
|
|
|
|
f5 = ff2(f5, f4, f5, f4);
|
|
|
|
if (f5 != 196.0f)
|
2013-08-23 11:26:33 +00:00
|
|
|
chSysHalt("float corrupion #3");
|
2013-08-23 08:11:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* GPT3 callback.
|
|
|
|
*/
|
|
|
|
static void gpt3cb(GPTDriver *gptp) {
|
|
|
|
float f1, f2, f3, f4, f5;
|
|
|
|
|
|
|
|
(void)gptp;
|
|
|
|
|
|
|
|
f1 = ff1(1.0f);
|
|
|
|
f2 = ff1(2.0f);
|
|
|
|
f3 = ff1(3.0f);
|
|
|
|
f5 = f1 + f2 + f3;
|
|
|
|
f4 = ff1(4.0f);
|
|
|
|
f5 = ff2(f5, f4, f5, f4);
|
|
|
|
if (f5 != 100.0f)
|
2013-08-23 11:26:33 +00:00
|
|
|
chSysHalt("float corrupion #4");
|
2013-08-23 08:11:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-04-13 13:06:18 +00:00
|
|
|
* GPT4 configuration.
|
2013-08-23 08:11:27 +00:00
|
|
|
*/
|
2013-08-23 11:26:33 +00:00
|
|
|
static const GPTConfig gpt4cfg = {
|
2013-08-23 08:11:27 +00:00
|
|
|
1000000, /* 1MHz timer clock.*/
|
2013-08-23 11:26:33 +00:00
|
|
|
gpt4cb, /* Timer callback.*/
|
2014-03-07 18:01:52 +00:00
|
|
|
0,
|
2013-08-23 08:11:27 +00:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* GPT3 configuration.
|
|
|
|
*/
|
|
|
|
static const GPTConfig gpt3cfg = {
|
|
|
|
1000000, /* 1MHz timer clock.*/
|
|
|
|
gpt3cb, /* Timer callback.*/
|
2014-03-07 18:01:52 +00:00
|
|
|
0,
|
2013-08-23 08:11:27 +00:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2015-04-26 09:24:44 +00:00
|
|
|
CH_FAST_IRQ_HANDLER(STM32_TIM1_UP_HANDLER) {
|
|
|
|
float f1, f2, f3, f4, f5;
|
|
|
|
|
|
|
|
TIM1->SR = 0;
|
|
|
|
|
|
|
|
f1 = ff1(3.0f);
|
|
|
|
f2 = ff1(4.0f);
|
|
|
|
f3 = ff1(5.0f);
|
|
|
|
f5 = f1 + f2 + f3;
|
|
|
|
f4 = ff1(4.0f);
|
|
|
|
f5 = ff2(f5, f4, f5, f4);
|
|
|
|
if (f5 != 256.0f) {
|
|
|
|
chSysHalt("float corrupion #5");
|
|
|
|
}
|
|
|
|
}
|
2013-08-23 08:11:27 +00:00
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Generic demo code. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2014-09-13 08:18:23 +00:00
|
|
|
CH_FAST_IRQ_HANDLER(Vector184) {
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2013-08-23 08:11:27 +00:00
|
|
|
static void print(char *p) {
|
|
|
|
|
|
|
|
while (*p) {
|
|
|
|
chSequentialStreamPut(&SD2, *p++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void println(char *p) {
|
|
|
|
|
|
|
|
while (*p) {
|
|
|
|
chSequentialStreamPut(&SD2, *p++);
|
|
|
|
}
|
|
|
|
chSequentialStreamWrite(&SD2, (uint8_t *)"\r\n", 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printn(uint32_t n) {
|
|
|
|
char buf[16], *p;
|
|
|
|
|
|
|
|
if (!n)
|
|
|
|
chSequentialStreamPut(&SD2, '0');
|
|
|
|
else {
|
|
|
|
p = buf;
|
|
|
|
while (n)
|
|
|
|
*p++ = (n % 10) + '0', n /= 10;
|
|
|
|
while (p > buf)
|
|
|
|
chSequentialStreamPut(&SD2, *--p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Application entry point.
|
|
|
|
*/
|
|
|
|
int main(void) {
|
|
|
|
unsigned i;
|
|
|
|
gptcnt_t interval, threshold, worst;
|
|
|
|
|
2014-09-13 08:18:23 +00:00
|
|
|
/* Enables FPU exceptions.*/
|
|
|
|
nvicEnableVector(FPU_IRQn, 1);
|
|
|
|
|
2013-08-23 08:11:27 +00:00
|
|
|
/*
|
|
|
|
* System initializations.
|
|
|
|
* - HAL initialization, this also initializes the configured device drivers
|
|
|
|
* and performs the board-specific initializations.
|
|
|
|
* - Kernel initialization, the main() function becomes a thread and the
|
|
|
|
* RTOS is active.
|
|
|
|
*/
|
|
|
|
halInit();
|
|
|
|
chSysInit();
|
|
|
|
|
|
|
|
/*
|
2015-04-13 13:06:18 +00:00
|
|
|
* Prepares the Serial driver 2 and GPT drivers 4 and 3.
|
2013-08-23 08:11:27 +00:00
|
|
|
*/
|
|
|
|
sdStart(&SD2, NULL); /* Default is 38400-8-N-1.*/
|
|
|
|
palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7));
|
|
|
|
palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));
|
2013-08-23 11:26:33 +00:00
|
|
|
gptStart(&GPTD4, &gpt4cfg);
|
2013-08-23 08:11:27 +00:00
|
|
|
gptStart(&GPTD3, &gpt3cfg);
|
|
|
|
|
2015-04-26 09:24:44 +00:00
|
|
|
/*
|
|
|
|
* Enabling TIM1 as a fast interrupts source.
|
|
|
|
*/
|
|
|
|
rccEnableTIM1(false);
|
|
|
|
nvicEnableVector(STM32_TIM1_UP_NUMBER, 0);
|
|
|
|
TIM1->ARR = 10000;
|
|
|
|
TIM1->PSC = 0;
|
|
|
|
TIM1->CNT = 0;
|
|
|
|
TIM1->DIER = TIM_DIER_UIE;
|
|
|
|
TIM1->CR1 = TIM_CR1_CEN;
|
|
|
|
|
2013-08-23 08:11:27 +00:00
|
|
|
/*
|
|
|
|
* Initializes the worker threads.
|
|
|
|
*/
|
|
|
|
chThdCreateStatic(waWorkerThread, sizeof waWorkerThread,
|
|
|
|
NORMALPRIO - 20, WorkerThread, NULL);
|
|
|
|
chThdCreateStatic(waPeriodicThread, sizeof waPeriodicThread,
|
|
|
|
NORMALPRIO - 10, PeriodicThread, NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test procedure.
|
|
|
|
*/
|
|
|
|
println("");
|
|
|
|
println("*** ChibiOS/RT IRQ-STORM-FPU long duration test");
|
|
|
|
println("***");
|
|
|
|
print("*** Kernel: ");
|
|
|
|
println(CH_KERNEL_VERSION);
|
|
|
|
print("*** Compiled: ");
|
|
|
|
println(__DATE__ " - " __TIME__);
|
2013-09-05 09:01:21 +00:00
|
|
|
#ifdef PORT_COMPILER_NAME
|
2013-08-23 08:11:27 +00:00
|
|
|
print("*** Compiler: ");
|
2013-09-05 09:01:21 +00:00
|
|
|
println(PORT_COMPILER_NAME);
|
2013-08-23 08:11:27 +00:00
|
|
|
#endif
|
|
|
|
print("*** Architecture: ");
|
2013-09-05 09:01:21 +00:00
|
|
|
println(PORT_ARCHITECTURE_NAME);
|
|
|
|
#ifdef PORT_CORE_VARIANT_NAME
|
2013-08-23 08:11:27 +00:00
|
|
|
print("*** Core Variant: ");
|
2013-09-05 09:01:21 +00:00
|
|
|
println(PORT_CORE_VARIANT_NAME);
|
2013-08-23 08:11:27 +00:00
|
|
|
#endif
|
2013-09-05 09:01:21 +00:00
|
|
|
#ifdef PORT_INFO
|
2013-08-23 08:11:27 +00:00
|
|
|
print("*** Port Info: ");
|
2013-09-05 09:01:21 +00:00
|
|
|
println(PORT_INFO);
|
2013-08-23 08:11:27 +00:00
|
|
|
#endif
|
|
|
|
#ifdef PLATFORM_NAME
|
|
|
|
print("*** Platform: ");
|
|
|
|
println(PLATFORM_NAME);
|
|
|
|
#endif
|
|
|
|
#ifdef BOARD_NAME
|
|
|
|
print("*** Test Board: ");
|
|
|
|
println(BOARD_NAME);
|
|
|
|
#endif
|
|
|
|
println("***");
|
|
|
|
print("*** System Clock: ");
|
|
|
|
printn(STM32_SYSCLK);
|
|
|
|
println("");
|
|
|
|
print("*** Iterations: ");
|
|
|
|
printn(ITERATIONS);
|
|
|
|
println("");
|
|
|
|
print("*** Randomize: ");
|
|
|
|
printn(RANDOMIZE);
|
|
|
|
println("");
|
|
|
|
|
|
|
|
println("");
|
|
|
|
worst = 0;
|
|
|
|
for (i = 1; i <= ITERATIONS; i++){
|
|
|
|
print("Iteration ");
|
|
|
|
printn(i);
|
|
|
|
println("");
|
|
|
|
saturated = FALSE;
|
|
|
|
threshold = 0;
|
|
|
|
for (interval = 2000; interval >= 10; interval -= interval / 10) {
|
2013-08-23 11:26:33 +00:00
|
|
|
gptStartContinuous(&GPTD4, interval - 1); /* Slightly out of phase.*/
|
2013-08-23 08:11:27 +00:00
|
|
|
gptStartContinuous(&GPTD3, interval + 1); /* Slightly out of phase.*/
|
|
|
|
chThdSleepMilliseconds(1000);
|
2013-08-23 11:26:33 +00:00
|
|
|
gptStopTimer(&GPTD4);
|
2013-08-23 08:11:27 +00:00
|
|
|
gptStopTimer(&GPTD3);
|
|
|
|
if (!saturated)
|
|
|
|
print(".");
|
|
|
|
else {
|
|
|
|
print("#");
|
|
|
|
if (threshold == 0)
|
|
|
|
threshold = interval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Gives the worker threads a chance to empty the mailboxes before next
|
|
|
|
cycle.*/
|
|
|
|
chThdSleepMilliseconds(20);
|
|
|
|
println("");
|
|
|
|
print("Saturated at ");
|
|
|
|
printn(threshold);
|
|
|
|
println(" uS");
|
|
|
|
println("");
|
|
|
|
if (threshold > worst)
|
|
|
|
worst = threshold;
|
|
|
|
}
|
2013-08-23 11:26:33 +00:00
|
|
|
gptStopTimer(&GPTD4);
|
2013-08-23 08:11:27 +00:00
|
|
|
gptStopTimer(&GPTD3);
|
|
|
|
|
|
|
|
print("Worst case at ");
|
|
|
|
printn(worst);
|
|
|
|
println(" uS");
|
|
|
|
println("");
|
|
|
|
println("Test Complete");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Normal main() thread activity, nothing in this test.
|
|
|
|
*/
|
2015-04-03 12:48:22 +00:00
|
|
|
while (true) {
|
2013-08-23 08:11:27 +00:00
|
|
|
chThdSleepMilliseconds(5000);
|
|
|
|
}
|
|
|
|
}
|