From aa38e5c1f48e31213ee349aa5cd6f06c85bda70d Mon Sep 17 00:00:00 2001
From: android <android@lingyun.com>
Date: Tue, 25 Jun 2024 21:49:39 +0800
Subject: [PATCH] Add GD32F103RCT6 ADC converter board SDK source code

---
 mcu_sdk/gd32f103/rk_eFire/Board/CMSIS/DSP/DSP_Lib_TestSuite/Common/src/controller_tests/sin_cos_tests.c |  151 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 151 insertions(+), 0 deletions(-)

diff --git a/mcu_sdk/gd32f103/rk_eFire/Board/CMSIS/DSP/DSP_Lib_TestSuite/Common/src/controller_tests/sin_cos_tests.c b/mcu_sdk/gd32f103/rk_eFire/Board/CMSIS/DSP/DSP_Lib_TestSuite/Common/src/controller_tests/sin_cos_tests.c
new file mode 100644
index 0000000..e3887ac
--- /dev/null
+++ b/mcu_sdk/gd32f103/rk_eFire/Board/CMSIS/DSP/DSP_Lib_TestSuite/Common/src/controller_tests/sin_cos_tests.c
@@ -0,0 +1,151 @@
+#include "jtest.h"
+#include "arr_desc.h"
+#include "arm_math.h"
+#include "ref.h"
+#include "type_abbrev.h"
+#include "test_templates.h"
+
+/*--------------------------------------------------------------------------------*/
+/* Input Data */
+/*--------------------------------------------------------------------------------*/
+
+ARR_DESC_DEFINE(float32_t,
+                arm_sin_cos_degrees_f32,
+                9,
+                CURLY(
+                    0,
+                    17,
+                    45,
+                    90,
+                    180,
+                    360,
+                    362,
+                    -73,
+                    -191.111
+                      ));
+
+/* The Q31 version of the function maps numbers in the range [-1, 0.9999999]
+ * to degrees in the range [-180, 179]*/
+ARR_DESC_DEFINE(q31_t,
+                arm_sin_cos_degrees_q31,
+                6,
+                CURLY(
+                    0,
+                    0x80000000, /* -1 */
+                    0x7fffffff, /* 0.99999 */
+                    /* Randoms */
+                    0xf7badafa,
+                    0x285954a1,
+                    0xb9d09511
+                      ));
+
+/*--------------------------------------------------------------------------------*/
+/* Output Variables */
+/*--------------------------------------------------------------------------------*/
+float32_t sin_val_fut = 0;
+float32_t cos_val_fut = 0;
+float32_t sin_val_ref = 0;
+float32_t cos_val_ref = 0;
+
+/*--------------------------------------------------------------------------------*/
+/* Test Definitions */
+/*--------------------------------------------------------------------------------*/
+
+#define MAX_DELTA_f32 50.0e-8f
+#define ABS(x) ((x) > 0 ? (x) : -(x))
+
+/*
+  Function to test correctness of sin_cos output by comparing it with reference library
+*/
+#define COMPARISON_INTERFACE(type, threshold)                           \
+    if ( (ABS((type) sin_val_ref - (type) sin_val_fut) >                 \
+         (type) threshold ) ||                                          \
+        (ABS((type) cos_val_ref - (type) cos_val_fut) >                 \
+         (type) threshold))                                             \
+    {                                                                   \
+        JTEST_DUMP_STRF("Error: %f %f\n",                               \
+                        ABS((type) sin_val_ref - (type) sin_val_fut),   \
+                        ABS((type) cos_val_ref - (type) cos_val_fut));  \
+        return JTEST_TEST_FAILED;                                       \
+    }
+
+/*
+  Sine and cosine test function for float32_t input
+*/
+JTEST_DEFINE_TEST(arm_sin_cos_f32_test, arm_sin_cos_f32)
+{
+    /* Test function for all input degree values */
+    TEMPLATE_DO_ARR_DESC(
+        degree_idx, TYPE_FROM_ABBREV(f32),
+        degree, arm_sin_cos_degrees_f32
+        ,
+        /* Display cycle count and run test */
+        JTEST_COUNT_CYCLES(
+            arm_sin_cos_f32(
+                degree,
+                (TYPE_FROM_ABBREV(f32) *) &sin_val_fut,
+                (TYPE_FROM_ABBREV(f32) *) &cos_val_fut)
+        );
+        ref_sin_cos_f32(
+            degree,
+            (TYPE_FROM_ABBREV(f32) *) &sin_val_ref,
+            (TYPE_FROM_ABBREV(f32) *) &cos_val_ref);
+
+        /* Test correctness */
+        COMPARISON_INTERFACE(
+            TYPE_FROM_ABBREV(f32),
+            MAX_DELTA_f32));
+
+    return JTEST_TEST_PASSED;
+}
+
+
+/*
+  Sine and cosine test function for q31_t input
+*/
+JTEST_DEFINE_TEST(arm_sin_cos_q31_test,
+                  arm_sin_cos_q31)
+{
+    /* Test function for all input degree values */
+    TEMPLATE_DO_ARR_DESC(
+        degree_idx, TYPE_FROM_ABBREV(q31),
+        degree, arm_sin_cos_degrees_q31
+        ,
+        /* Display cycle count and run test */
+        JTEST_COUNT_CYCLES(
+            arm_sin_cos_q31(
+                degree,
+                (TYPE_FROM_ABBREV(q31) *) &sin_val_fut,
+                (TYPE_FROM_ABBREV(q31) *) &cos_val_fut)
+        );
+        ref_sin_cos_q31(
+            degree,
+            (TYPE_FROM_ABBREV(q31) *) &sin_val_ref,
+            (TYPE_FROM_ABBREV(q31) *) &cos_val_ref);
+
+        /* Convert q31 numbers to float for comparison purposes. */
+        ref_q31_t_to_float((TYPE_FROM_ABBREV(q31) *) &sin_val_fut, &sin_val_fut, 1);
+        ref_q31_t_to_float((TYPE_FROM_ABBREV(q31) *) &cos_val_fut, &cos_val_fut, 1);
+        ref_q31_t_to_float((TYPE_FROM_ABBREV(q31) *) &sin_val_ref, &sin_val_ref, 1);
+        ref_q31_t_to_float((TYPE_FROM_ABBREV(q31) *) &cos_val_ref, &cos_val_ref, 1);
+
+        /* Test correctness */
+        COMPARISON_INTERFACE(
+            TYPE_FROM_ABBREV(f32),
+            MAX_DELTA_f32));
+
+    return JTEST_TEST_PASSED;
+}
+
+/*--------------------------------------------------------------------------------*/
+/* Collect all tests in a group */
+/*--------------------------------------------------------------------------------*/
+
+JTEST_DEFINE_GROUP(sin_cos_tests)
+{
+    /*
+      To skip a test, comment it out.
+    */
+    JTEST_TEST_CALL(arm_sin_cos_f32_test);
+    JTEST_TEST_CALL(arm_sin_cos_q31_test);
+}

--
Gitblit v1.9.1