1515#include < SoftwareSerial.h>
1616#include < Wire.h>
1717
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+
1848#ifndef USER_BTN
1949#define USER_BTN 2
2050#endif
@@ -103,6 +133,28 @@ void setup() {
103133 Wire.endTransmission ();
104134 Wire.requestFrom (2 , 1 );
105135 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+ }
106158}
107159
108160void loop () {
@@ -120,4 +172,4 @@ void receiveEvent(int) {
120172// this function is registered as an event, see setup()
121173void requestEvent () {
122174 Wire.write (" x" );
123- }
175+ }
0 commit comments