summaryrefslogtreecommitdiff
path: root/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions
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/BasicMathFunctions
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/BasicMathFunctions')
-rw-r--r--Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/abs.c53
-rw-r--r--Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/add.c57
-rw-r--r--Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/dot_prod.c65
-rw-r--r--Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/mult.c64
-rw-r--r--Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/negate.c53
-rw-r--r--Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/offset.c57
-rw-r--r--Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/scale.c69
-rw-r--r--Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/shift.c73
-rw-r--r--Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/sub.c57
9 files changed, 548 insertions, 0 deletions
diff --git a/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/abs.c b/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/abs.c
new file mode 100644
index 0000000..baca23f
--- /dev/null
+++ b/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/abs.c
@@ -0,0 +1,53 @@
+#include "ref.h"
+
+void ref_abs_f32(
+ float32_t * pSrc,
+ float32_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrc[i] < 0 ? -pSrc[i] : pSrc[i];
+ }
+}
+
+void ref_abs_q31(
+ q31_t * pSrc,
+ q31_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrc[i] < 0 ? -pSrc[i] : pSrc[i];
+ }
+}
+
+void ref_abs_q15(
+ q15_t * pSrc,
+ q15_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrc[i] < 0 ? -pSrc[i] : pSrc[i];
+ }
+}
+
+void ref_abs_q7(
+ q7_t * pSrc,
+ q7_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrc[i] < 0 ? -pSrc[i] : pSrc[i];
+ }
+}
diff --git a/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/add.c b/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/add.c
new file mode 100644
index 0000000..489c8a0
--- /dev/null
+++ b/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/add.c
@@ -0,0 +1,57 @@
+#include "ref.h"
+
+void ref_add_f32(
+ float32_t * pSrcA,
+ float32_t * pSrcB,
+ float32_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrcA[i] + pSrcB[i];
+ }
+}
+
+void ref_add_q31(
+ q31_t * pSrcA,
+ q31_t * pSrcB,
+ q31_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = ref_sat_q31( (q63_t)pSrcA[i] + pSrcB[i] );
+ }
+}
+
+void ref_add_q15(
+ q15_t * pSrcA,
+ q15_t * pSrcB,
+ q15_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = ref_sat_q15( (q31_t)pSrcA[i] + pSrcB[i] );
+ }
+}
+
+void ref_add_q7(
+ q7_t * pSrcA,
+ q7_t * pSrcB,
+ q7_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = ref_sat_q7( (q15_t)pSrcA[i] + pSrcB[i] );
+ }
+}
diff --git a/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/dot_prod.c b/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/dot_prod.c
new file mode 100644
index 0000000..08f6178
--- /dev/null
+++ b/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/dot_prod.c
@@ -0,0 +1,65 @@
+#include "ref.h"
+
+void ref_dot_prod_f32(
+ float32_t * pSrcA,
+ float32_t * pSrcB,
+ uint32_t blockSize,
+ float32_t * result)
+{
+ uint32_t i;
+ float32_t sum = 0.0f;
+
+ for(i=0;i<blockSize;i++)
+ {
+ sum += pSrcA[i] * pSrcB[i];
+ }
+ *result = sum;
+}
+
+void ref_dot_prod_q31(
+ q31_t * pSrcA,
+ q31_t * pSrcB,
+ uint32_t blockSize,
+ q63_t * result)
+{
+ uint32_t i;
+ q63_t sum = 0.0f;
+
+ for(i=0;i<blockSize;i++)
+ {
+ sum += ((q63_t)pSrcA[i] * pSrcB[i]) >> 14; //16.48
+ }
+ *result = sum;
+}
+
+void ref_dot_prod_q15(
+ q15_t * pSrcA,
+ q15_t * pSrcB,
+ uint32_t blockSize,
+ q63_t * result)
+{
+ uint32_t i;
+ q63_t sum = 0.0f;
+
+ for(i=0;i<blockSize;i++)
+ {
+ sum += (q31_t)pSrcA[i] * pSrcB[i]; //34.30
+ }
+ *result = sum;
+}
+
+void ref_dot_prod_q7(
+ q7_t * pSrcA,
+ q7_t * pSrcB,
+ uint32_t blockSize,
+ q31_t * result)
+{
+ uint32_t i;
+ q31_t sum = 0.0f;
+
+ for(i=0;i<blockSize;i++)
+ {
+ sum += (q31_t)pSrcA[i] * pSrcB[i]; //18.14
+ }
+ *result = sum;
+}
diff --git a/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/mult.c b/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/mult.c
new file mode 100644
index 0000000..a77c870
--- /dev/null
+++ b/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/mult.c
@@ -0,0 +1,64 @@
+#include "ref.h"
+
+void ref_mult_f32(
+ float32_t * pSrcA,
+ float32_t * pSrcB,
+ float32_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrcA[i] * pSrcB[i];
+ }
+}
+
+void ref_mult_q31(
+ q31_t * pSrcA,
+ q31_t * pSrcB,
+ q31_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+ q63_t temp;
+
+ for(i=0;i<blockSize;i++)
+ {
+ temp = ((q63_t)pSrcA[i] * pSrcB[i]) >> 32;
+ temp = temp << 1;
+ pDst[i] = ref_sat_q31(temp);
+ }
+}
+
+void ref_mult_q15(
+ q15_t * pSrcA,
+ q15_t * pSrcB,
+ q15_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+ q31_t temp;
+
+ for(i=0;i<blockSize;i++)
+ {
+ temp = ((q31_t)pSrcA[i] * pSrcB[i]) >> 15; //this comment is for JD, this is specifically 15 and not 16 like the q31 case might imply. This is because CMSIS DSP lib does it this way. No other reason.
+ pDst[i] = ref_sat_q15(temp);
+ }
+}
+
+void ref_mult_q7(
+ q7_t * pSrcA,
+ q7_t * pSrcB,
+ q7_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+ q15_t temp;
+
+ for(i=0;i<blockSize;i++)
+ {
+ temp = ((q15_t)pSrcA[i] * pSrcB[i]) >> 7;
+ pDst[i] = ref_sat_q7(temp);
+ }
+}
diff --git a/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/negate.c b/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/negate.c
new file mode 100644
index 0000000..192da1b
--- /dev/null
+++ b/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/negate.c
@@ -0,0 +1,53 @@
+#include "ref.h"
+
+void ref_negate_f32(
+ float32_t * pSrc,
+ float32_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = -pSrc[i];
+ }
+}
+
+void ref_negate_q31(
+ q31_t * pSrc,
+ q31_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = -pSrc[i];
+ }
+}
+
+void ref_negate_q15(
+ q15_t * pSrc,
+ q15_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = -pSrc[i];
+ }
+}
+
+void ref_negate_q7(
+ q7_t * pSrc,
+ q7_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = -pSrc[i];
+ }
+}
diff --git a/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/offset.c b/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/offset.c
new file mode 100644
index 0000000..b076e75
--- /dev/null
+++ b/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/offset.c
@@ -0,0 +1,57 @@
+#include "ref.h"
+
+void ref_offset_f32(
+ float32_t * pSrc,
+ float32_t offset,
+ float32_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrc[i] + offset;
+ }
+}
+
+void ref_offset_q31(
+ q31_t * pSrc,
+ q31_t offset,
+ q31_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = ref_sat_q31( (q63_t)pSrc[i] + offset );
+ }
+}
+
+void ref_offset_q15(
+ q15_t * pSrc,
+ q15_t offset,
+ q15_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = ref_sat_q15( (q31_t)pSrc[i] + offset );
+ }
+}
+
+void ref_offset_q7(
+ q7_t * pSrc,
+ q7_t offset,
+ q7_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = ref_sat_q7( (q15_t)pSrc[i] + offset );
+ }
+}
diff --git a/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/scale.c b/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/scale.c
new file mode 100644
index 0000000..5ab655c
--- /dev/null
+++ b/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/scale.c
@@ -0,0 +1,69 @@
+#include "ref.h"
+
+void ref_scale_f32(
+ float32_t * pSrc,
+ float32_t scale,
+ float32_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrc[i] * scale;
+ }
+}
+
+void ref_scale_q31(
+ q31_t * pSrc,
+ q31_t scaleFract,
+ int8_t shift,
+ q31_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+ int8_t kShift = shift + 1; /* Shift to apply after scaling */
+ int8_t sign = (kShift & 0x80);
+ q63_t temp;
+
+ for(i=0;i<blockSize;i++)
+ {
+ temp = ((q63_t) pSrc[i] * scaleFract) >> 32;
+ if (sign)
+ pDst[i] = temp >> -kShift;
+ else
+ pDst[i] = ref_sat_q31( (q63_t)temp << kShift );
+ }
+}
+
+void ref_scale_q15(
+ q15_t * pSrc,
+ q15_t scaleFract,
+ int8_t shift,
+ q15_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+ int8_t kShift = 15 - shift; /* Shift to apply after scaling */
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = ref_sat_q15(((q31_t) pSrc[i] * scaleFract) >> kShift);
+ }
+}
+
+void ref_scale_q7(
+ q7_t * pSrc,
+ q7_t scaleFract,
+ int8_t shift,
+ q7_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+ int8_t kShift = 7 - shift; /* Shift to apply after scaling */
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = ref_sat_q7(((q15_t) pSrc[i] * scaleFract) >> kShift);
+ }
+}
diff --git a/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/shift.c b/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/shift.c
new file mode 100644
index 0000000..3bc53ad
--- /dev/null
+++ b/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/shift.c
@@ -0,0 +1,73 @@
+#include "ref.h"
+
+void ref_shift_q31(
+ q31_t * pSrc,
+ int8_t shiftBits,
+ q31_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ if (shiftBits < 0)
+ {
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrc[i] << shiftBits;
+ }
+ }
+ else
+ {
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrc[i] >> -shiftBits;
+ }
+ }
+}
+
+void ref_shift_q15(
+ q15_t * pSrc,
+ int8_t shiftBits,
+ q15_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ if (shiftBits < 0)
+ {
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrc[i] << shiftBits;
+ }
+ }
+ else
+ {
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrc[i] >> -shiftBits;
+ }
+ }
+}
+
+void ref_shift_q7(
+ q7_t * pSrc,
+ int8_t shiftBits,
+ q7_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ if (shiftBits < 0)
+ {
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrc[i] << shiftBits;
+ }
+ }
+ else
+ {
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrc[i] >> -shiftBits;
+ }
+ }
+}
diff --git a/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/sub.c b/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/sub.c
new file mode 100644
index 0000000..da89e95
--- /dev/null
+++ b/Blink/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/sub.c
@@ -0,0 +1,57 @@
+#include "ref.h"
+
+void ref_sub_f32(
+ float32_t * pSrcA,
+ float32_t * pSrcB,
+ float32_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrcA[i] - pSrcB[i];
+ }
+}
+
+void ref_sub_q31(
+ q31_t * pSrcA,
+ q31_t * pSrcB,
+ q31_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = ref_sat_q31( (q63_t)pSrcA[i] - pSrcB[i] );
+ }
+}
+
+void ref_sub_q15(
+ q15_t * pSrcA,
+ q15_t * pSrcB,
+ q15_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = ref_sat_q15( (q31_t)pSrcA[i] - pSrcB[i] );
+ }
+}
+
+void ref_sub_q7(
+ q7_t * pSrcA,
+ q7_t * pSrcB,
+ q7_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = ref_sat_q7( (q15_t)pSrcA[i] - pSrcB[i] );
+ }
+}