summaryrefslogtreecommitdiff
path: root/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/HelperFunctions
diff options
context:
space:
mode:
authorJanHenrik <janhenrik@janhenrik.org>2020-01-19 00:56:37 +0100
committerJanHenrik <janhenrik@janhenrik.org>2020-01-19 00:56:37 +0100
commita81fc41c3eb99e8fc52aa734ee63e13c937aab81 (patch)
tree19974c4676ed64d6e4260b79fc3f1eaeda58a289 /Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/HelperFunctions
parenta96ec5d9995e7e4b7315a192e543b88f0aff4930 (diff)
downloadminikbd-a81fc41c3eb99e8fc52aa734ee63e13c937aab81.tar.gz
minikbd-a81fc41c3eb99e8fc52aa734ee63e13c937aab81.tar.bz2
minikbd-a81fc41c3eb99e8fc52aa734ee63e13c937aab81.zip
added blink example
Diffstat (limited to 'Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/HelperFunctions')
-rw-r--r--Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/HelperFunctions/mat_helper.c193
-rw-r--r--Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/HelperFunctions/ref_helper.c103
2 files changed, 296 insertions, 0 deletions
diff --git a/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/HelperFunctions/mat_helper.c b/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/HelperFunctions/mat_helper.c
new file mode 100644
index 0000000..0174ccf
--- /dev/null
+++ b/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/HelperFunctions/mat_helper.c
@@ -0,0 +1,193 @@
+#include "ref.h"
+
+float32_t ref_detrm(float32_t *pSrc, float32_t *temp, uint32_t size)
+{
+ float32_t s = 1, det = 0;
+ int i, j, m, n, c;
+
+ if ( size == 1 )
+ {
+ return ( pSrc[ 0 ] );
+ }
+ else
+ {
+ det = 0;
+
+ for ( c = 0;c < size;c++ )
+ {
+ m = 0;
+ n = 0;
+
+ for ( i = 0;i < size;i++ )
+ {
+ for ( j = 0;j < size;j++ )
+ {
+ temp[ i*size + j ] = 0;
+
+ if ( i != 0 && j != c )
+ {
+ temp[ m*(size-1) + n ] = pSrc[ i*size + j ];
+
+ if ( n < ( size - 2 ) )
+ {
+ n++;
+ }
+ else
+ {
+ n = 0;
+ m++;
+ }
+ }
+ }
+ }
+
+ det += s * ( pSrc[ c ] * ref_detrm( temp, temp + size*size, size - 1 ) );
+ s = -s;
+ }
+ }
+
+ return ( det );
+}
+
+
+void ref_cofact(float32_t *pSrc, float32_t *pDst, float32_t *temp, uint32_t size)
+{
+ int p, q, m, n, i, j;
+
+ if (size == 1)
+ {
+ pDst[0] = 1;
+ return;
+ }
+
+ for ( q = 0;q < size;q++ )
+ {
+ for ( p = 0;p < size;p++ )
+ {
+ m = 0;
+ n = 0;
+
+ for ( i = 0;i < size;i++ )
+ {
+ for ( j = 0;j < size;j++ )
+ {
+ temp[ i*size + j ] = 0;
+
+ if ( i != q && j != p )
+ {
+ temp[ m*(size-1) + n ] = pSrc[ i*size + j ];
+
+ if ( n < ( size - 2 ) )
+ {
+ n++;
+ }
+ else
+ {
+ n = 0;
+ m++;
+ }
+ }
+ }
+ }
+
+ pDst[ q*size + p ] = ref_pow( -1, q + p ) * ref_detrm( temp, temp + (size-1)*(size-1), size - 1 );
+ }
+ }
+}
+
+
+
+float64_t ref_detrm64(float64_t *pSrc, float64_t *temp, uint32_t size)
+{
+ float64_t s = 1, det = 0;
+ int i, j, m, n, c;
+
+ if ( size == 1 )
+ {
+ return ( pSrc[ 0 ] );
+ }
+ else
+ {
+ det = 0;
+
+ for ( c = 0;c < size;c++ )
+ {
+ m = 0;
+ n = 0;
+
+ for ( i = 0;i < size;i++ )
+ {
+ for ( j = 0;j < size;j++ )
+ {
+ temp[ i*size + j ] = 0;
+
+ if ( i != 0 && j != c )
+ {
+ temp[ m*(size-1) + n ] = pSrc[ i*size + j ];
+
+ if ( n < ( size - 2 ) )
+ {
+ n++;
+ }
+ else
+ {
+ n = 0;
+ m++;
+ }
+ }
+ }
+ }
+
+ det += s * ( pSrc[ c ] * ref_detrm64( temp, temp + size*size, size - 1 ) );
+ s = -s;
+ }
+ }
+
+ return ( det );
+}
+
+
+void ref_cofact64(float64_t *pSrc, float64_t *pDst, float64_t *temp, uint32_t size)
+{
+ int p, q, m, n, i, j;
+
+ if (size == 1)
+ {
+ pDst[0] = 1;
+ return;
+ }
+
+ for ( q = 0;q < size;q++ )
+ {
+ for ( p = 0;p < size;p++ )
+ {
+ m = 0;
+ n = 0;
+
+ for ( i = 0;i < size;i++ )
+ {
+ for ( j = 0;j < size;j++ )
+ {
+ temp[ i*size + j ] = 0;
+
+ if ( i != q && j != p )
+ {
+ temp[ m*(size-1) + n ] = pSrc[ i*size + j ];
+
+ if ( n < ( size - 2 ) )
+ {
+ n++;
+ }
+ else
+ {
+ n = 0;
+ m++;
+ }
+ }
+ }
+ }
+
+ pDst[ q*size + p ] = ref_pow( -1, q + p ) * ref_detrm64( temp, temp + (size-1)*(size-1), size - 1 );
+ }
+ }
+}
diff --git a/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/HelperFunctions/ref_helper.c b/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/HelperFunctions/ref_helper.c
new file mode 100644
index 0000000..57ecf1b
--- /dev/null
+++ b/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/HelperFunctions/ref_helper.c
@@ -0,0 +1,103 @@
+#include "ref.h"
+
+float32_t scratchArray[8192*2];
+
+arm_cfft_instance_f32 ref_cfft_sR_f32_len8192 = { 8192, 0, 0, 0 };
+
+q31_t ref_sat_n(q31_t num, uint32_t bits)
+{
+ int32_t posMax, negMin;
+ uint32_t i;
+
+ posMax = 1;
+ for (i = 0; i < (bits - 1); i++)
+ {
+ posMax = posMax * 2;
+ }
+
+ if (num > 0)
+ {
+ posMax = (posMax - 1);
+
+ if (num > posMax)
+ {
+ num = posMax;
+ }
+ }
+ else
+ {
+ negMin = -posMax;
+
+ if (num < negMin)
+ {
+ num = negMin;
+ }
+ }
+ return (num);
+}
+
+q31_t ref_sat_q31(q63_t num)
+{
+ if (num > (q63_t)INT_MAX)
+ {
+ return INT_MAX;
+ }
+ else if (num < (q63_t)0xffffffff80000000ll)
+ {
+ return INT_MIN;
+ }
+ else
+ {
+ return (q31_t)num;
+ }
+}
+
+q15_t ref_sat_q15(q31_t num)
+{
+ if (num > (q31_t)SHRT_MAX)
+ {
+ return SHRT_MAX;
+ }
+ else if (num < (q31_t)0xffff8000)
+ {
+ return SHRT_MIN;
+ }
+ else
+ {
+ return (q15_t)num;
+ }
+}
+
+q7_t ref_sat_q7(q15_t num)
+{
+ if (num > (q15_t)SCHAR_MAX)
+ {
+ return SCHAR_MAX;
+ }
+ else if (num < (q15_t)0xff80)
+ {
+ return SCHAR_MIN;
+ }
+ else
+ {
+ return (q7_t)num;
+ }
+}
+
+float32_t ref_pow(float32_t a, uint32_t b)
+{
+ uint32_t i;
+ float32_t r = a;
+
+ for(i=1;i<b;i++)
+ {
+ r *= a;
+ }
+
+ if ( b == 0)
+ {
+ return 1;
+ }
+
+ return r;
+}