mirror of
https://github.com/eddyem/stm32samples.git
synced 2026-10-01 06:10:31 +03:00
add astro-tests
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stm32g4.h>
|
||||
|
||||
#include "astro.h"
|
||||
#include "test.h"
|
||||
#include "hardware.h"
|
||||
#include "cordic.h"
|
||||
@@ -90,38 +91,95 @@ static uint32_t run_test2(void (*gen)(), void (*func)(float, float*, float*)){
|
||||
}
|
||||
|
||||
// ------------- math.h tests -------------
|
||||
uint32_t test_math_sin(){
|
||||
uint32_t test_math_sin(){ // 0.9us per cycle
|
||||
return run_test(fill_random_sin_cos, sinf);
|
||||
}
|
||||
uint32_t test_math_cos(){
|
||||
uint32_t test_math_cos(){ // 0.9us per cycle
|
||||
return run_test(fill_random_sin_cos, cosf);
|
||||
}
|
||||
uint32_t test_math_atan(){
|
||||
uint32_t test_math_atan(){ // 0.9us per cycle
|
||||
return run_test(fill_random_atan, atanf);
|
||||
}
|
||||
uint32_t test_math_sqrt(){
|
||||
uint32_t test_math_sqrt(){ // 0.16us per cycle
|
||||
return run_test(fill_random_sqrt, sqrtf);
|
||||
}
|
||||
uint32_t test_math_log(){
|
||||
uint32_t test_math_log(){ // 0.9us per cycle
|
||||
return run_test(fill_random_log, logf);
|
||||
}
|
||||
|
||||
// ------------- CORDIC tests -------------
|
||||
uint32_t test_cordic_sincos(){
|
||||
uint32_t test_cordic_sincos(){ // 0.4us per cycle
|
||||
return run_test2(fill_random_sin_cos, cordic_sincos);
|
||||
}
|
||||
uint32_t test_cordic_sin(){
|
||||
uint32_t test_cordic_sin(){ // 0.4us per cycle
|
||||
return run_test(fill_random_sin_cos, cordic_sin);
|
||||
}
|
||||
uint32_t test_cordic_cos(){
|
||||
uint32_t test_cordic_cos(){ // 0.4us per cycle
|
||||
return run_test(fill_random_sin_cos, cordic_cos);
|
||||
}
|
||||
uint32_t test_cordic_atan(){
|
||||
uint32_t test_cordic_atan(){ // 0.12us per cycle
|
||||
return run_test(fill_random_atan, cordic_atan);
|
||||
}
|
||||
uint32_t test_cordic_sqrt(){
|
||||
uint32_t test_cordic_sqrt(){ // 0.4us per cycle
|
||||
return run_test(fill_random_sqrt, cordic_sqrt);
|
||||
}
|
||||
uint32_t test_cordic_log(){
|
||||
uint32_t test_cordic_log(){ // 0.4us per cycle
|
||||
return run_test(fill_random_log, cordic_log);
|
||||
}
|
||||
|
||||
// ------------- Astronomy tests -------------
|
||||
// test coordinates transformation: hor2eq and eq2hor
|
||||
uint32_t test_astro_coordsTransform(){
|
||||
volatile float az = 11.3f, alt = 89.3f, ha, dec;
|
||||
timer_start();
|
||||
for(int i = 0; i < N_TESTS; ++i){
|
||||
// 160us per cycle for math.h sin/cos
|
||||
// 15us per cycle for CORDIC sin/cos
|
||||
altaz_to_hadec(alt, az, (float*)&ha, (float*)&dec);
|
||||
hadec_to_altaz(ha, dec, (float*)&alt, (float*)&az);
|
||||
if((az += 9.51f) > 359.99f) az -= 359.9f;
|
||||
if((alt -= 1.76f) < 9.9f) alt += 79.f;
|
||||
(void) ha;
|
||||
(void) dec;
|
||||
}
|
||||
timer_stop();
|
||||
return timer_read();
|
||||
}
|
||||
|
||||
// test refraction correction for HA-DEC (eq2hor->refr->hor2eq)
|
||||
uint32_t test_astro_refraction(){
|
||||
float az = 11.3f, alt = 89.3f, ha, dec;
|
||||
float phpa = 800.f, tc = 10.f, rh = 0.7f;
|
||||
volatile float newha, newdec, newalt;
|
||||
timer_start();
|
||||
for(int i = 0; i < N_TESTS; ++i){
|
||||
// 260us per cycle for math.h sin/cos
|
||||
// 34us per cycle for CORDIC sin/cos
|
||||
altaz_to_hadec(alt, az, &ha, &dec);
|
||||
hadec_to_altaz(ha, dec, &alt, &az);
|
||||
newalt = alt + refraction(phpa, tc, rh, 90.f-alt);
|
||||
altaz_to_hadec(newalt, az, (float*)&newha, (float*)&newdec);
|
||||
(void) newha;
|
||||
(void) newdec;
|
||||
if((az += 9.51f) > 359.99f) az -= 359.9f;
|
||||
if((alt -= 1.76f) < 9.9f) alt += 79.f;
|
||||
}
|
||||
timer_stop();
|
||||
return timer_read();
|
||||
}
|
||||
|
||||
// test LST calculation
|
||||
uint32_t test_astro_LST(){
|
||||
uint32_t *uarr = (uint32_t*) arr;
|
||||
volatile float result;
|
||||
for(int i = 0; i < N_TESTS; ++i){ // fill random data in 21th century
|
||||
uarr[i] = next_rand() % 3155673599 + 978307200;
|
||||
}
|
||||
timer_start();
|
||||
for(int i = 0; i < N_TESTS; ++i){ // 1.5us per cycle
|
||||
result = LST_from_unix(uarr[i]);
|
||||
(void) result;
|
||||
}
|
||||
timer_stop();
|
||||
return timer_read();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user