15
15
#include < SoftwareSerial.h>
16
16
#include < Wire.h>
17
17
18
+ #include < CMSIS_DSP.h>
19
+ /* ----------------------------------------------------------------------
20
+ Defines each of the tests performed
21
+ ------------------------------------------------------------------- */
22
+ #define MAX_BLOCKSIZE 2
23
+ #define DELTA (0 .0001f )
24
+ /* ----------------------------------------------------------------------
25
+ Test input data for Floating point sin_cos example for 32-blockSize
26
+ Generated by the MATLAB randn() function
27
+ ------------------------------------------------------------------- */
28
+ const float32_t testInput_f32[MAX_BLOCKSIZE] =
29
+ {
30
+ -1.244916875853235400 , -4.793533929171324800
31
+ };
32
+ const float32_t testRefOutput_f32 = 1.000000000 ;
33
+ /* ----------------------------------------------------------------------
34
+ Declare Global variables
35
+ ------------------------------------------------------------------- */
36
+ uint32_t blockSize = 2 ;
37
+ float32_t testOutput;
38
+ float32_t cosOutput;
39
+ float32_t sinOutput;
40
+ float32_t cosSquareOutput;
41
+ float32_t sinSquareOutput;
42
+ /* ----------------------------------------------------------------------
43
+ Max magnitude FFT Bin test
44
+ ------------------------------------------------------------------- */
45
+ arm_status status;
46
+ /* CMSIS_DSP */
47
+
18
48
#ifndef USER_BTN
19
49
#define USER_BTN 2
20
50
#endif
@@ -103,6 +133,28 @@ void setup() {
103
133
Wire.endTransmission ();
104
134
Wire.requestFrom (2 , 1 );
105
135
Wire.end ();
136
+
137
+ // CMSIS DSP
138
+ float32_t diff;
139
+ for (uint32_t i = 0 ; i < blockSize; i++) {
140
+ cosOutput = arm_cos_f32 (testInput_f32[i]);
141
+ sinOutput = arm_sin_f32 (testInput_f32[i]);
142
+ arm_mult_f32 (&cosOutput, &cosOutput, &cosSquareOutput, 1 );
143
+ arm_mult_f32 (&sinOutput, &sinOutput, &sinSquareOutput, 1 );
144
+ arm_add_f32 (&cosSquareOutput, &sinSquareOutput, &testOutput, 1 );
145
+ /* absolute value of difference between ref and test */
146
+ diff = fabsf (testRefOutput_f32 - testOutput);
147
+ /* Comparison of sin_cos value with reference */
148
+ status = (diff > DELTA) ? ARM_MATH_TEST_FAILURE : ARM_MATH_SUCCESS;
149
+ if ( status == ARM_MATH_TEST_FAILURE) {
150
+ break ;
151
+ }
152
+ }
153
+ if (status != ARM_MATH_SUCCESS) {
154
+ Serial.printf (" FAILURE\n " );
155
+ } else {
156
+ Serial.printf (" SUCCESS\n " );
157
+ }
106
158
}
107
159
108
160
void loop () {
@@ -120,4 +172,4 @@ void receiveEvent(int) {
120
172
// this function is registered as an event, see setup()
121
173
void requestEvent () {
122
174
Wire.write (" x" );
123
- }
175
+ }
0 commit comments