IRPyro API unit test console
Functions for single and multiple sensor configurations in a Unit test format
IRPyro_UT.c
Go to the documentation of this file.
1 /**
2 ******************************************************************************
3 * @file IRPyro_UT.c
4 * @author _KEMET, Ltd
5 * @date March 2018
6 * @version Release 1.0.6
7 * @copyright (c) 2018 _KEMET, Ltd
8 * @brief Low level Unit Testing module
9 ******************************************************************************
10  @attention <h2><center>&copy; COPYRIGHT 2018 _KEMET, Ltd</center></h2>
11 
12  @verbatim
13  Copyright (c) 2018, _KEMET, Ltd
14  All rights reserved.
15 
16  THIS SOFTWARE IS PROVIDED BY _KEMET, Ltd ''AS IS'' AND ANY
17  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  DISCLAIMED. IN NO EVENT SHALL _KEMET, Ltd BE LIABLE FOR ANY
20  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  @endverbatim
27 ******************************************************************************
28 
29 */
30 /* Includes ------------------------------------------------------------------*/
31 #include "IRPyro_UT.h"
32 /* Unit Test Private variables -----------------------------------------------*/
33 /* Unit Test Private function prototypes--------------------------------------*/
34 /*--------------------- TEST FRAME COUNTING ----------------------------------*/
35 static uint8_t IRPyro_test_single_sensor_read_sample(IRPyro_sensor_device_type* this_device);
36 static uint8_t IRPyro_test_multiple_sensor_read_sample(IRPyro_devices this_list, uint8_t list_size);
37 /* Unit Test Support function prototypes--------------------------------------*/
38 static uint8_t AFE_compare(AFE_reg_type first, AFE_reg_type second);
39 static uint8_t CCP_compare(CCP_reg_type first, CCP_reg_type second);
40 static uint8_t WUP_compare(WUP_reg_type first, WUP_reg_type second);
41 static uint8_t check_results(uint8_t * test_results, uint8_t number_of_tests);
42 static uint8_t FIFO_reset(IRPyro_sensor_device_type* this_device);
43 static void wakeup_event_callback(void);
44 
45 /** @defgroup IRPyroAPI_UnitTest Unit Test Module
46  * @brief Implements the general case of each unit test description
47  * @verbatim
48  * Functions to validate and test the IRPyro API implementation
49  * Each function covers a point of the product verification plan
50  * @endverbatim
51  * @{
52  */
53 /** @defgroup UT_02_IRPyro 9.6.1 Single Sensor initialization
54  * @brief Verification of single sensor initialization in multiple modes
55  <table>
56  <tr><td> 9.6.1.1 </td><td> Initialize a single device for interrupt configuration </td></tr>
57  <tr><td> </td><td> Written configuration matches registers stored on memory.</td></tr>
58  <tr><td> 9.6.1.2 </td><td> Initialize a single device for polled configuration </td></tr>
59  <tr><td> </td><td> Written configuration matches registers stored on memory.</td></tr>
60  <tr><td> 9.6.1.3 </td><td> Initialize a single device for synchronized configuration </td></tr>
61  <tr><td> </td><td> Written configuration matches registers stored on memory.</td></tr>
62  </table>
63  * @{
64  */
65 uint8_t ut01_single_sensor_init(IRPyro_sensor_device_type *IRPyro_test_Sensor)
66 {
67  uint8_t op_result = 0;
68  uint8_t test_results[10]= {0};
69  IRPyro_cmd_type IOCTL_cmd = {0};
70  IRPyro_arg_type IOCTL_arg = {0};
71 
72  UART_PutString(USART2, (uint8_t*)"UT_01_IRPyro 9.6.1 Single Sensor initialization \n");
73  /*-------------------------- start test ----------------------------------*/
74  IOCTL_cmd.cmd = register_get;
75 
76  test_results[0] = IRPyro_open(IRPyro_test_Sensor);
77  UART_PutString(USART2, (uint8_t*)"OPEN SENSOR \n");
78  test_results[1] = IRPyro_ioctl(IRPyro_test_Sensor, &IOCTL_cmd, IOCTL_arg);
79  UART_PutString(USART2, (uint8_t*)"AFE compare \n");
80  test_results[2] =AFE_compare(IRPyro_test_Sensor->AFE_register, IOCTL_cmd.AFE_register);
81  UART_PutString(USART2, (uint8_t*)"CCP compare \n");
82  for(uint8_t idx=0; idx<IRPyro_CCP_SIZE; ++idx)
83  {
84  test_results[3+idx]=CCP_compare(IRPyro_test_Sensor->CCP_register[idx], IOCTL_cmd.CCP_register[idx]);
85  }
86  UART_PutString(USART2, (uint8_t*)"WUP compare \n");
87  test_results[8]=WUP_compare(IRPyro_test_Sensor->WUP_register, IOCTL_cmd.WUP_register);
88  test_results[9]=IRPyro_close(IRPyro_test_Sensor);
89  /*-------------------------- collate results -----------------------------*/
90  UART_PutString(USART2, (uint8_t*)"============\n");
91  op_result = check_results(test_results, 10);
92  if (op_result == 1)
93  {
94  UART_PutString(USART2, (uint8_t*)"PASSED \n");
95  }
96  else
97  {
98  UART_PutString(USART2, (uint8_t*)"FAILED WITH CODE ");
99  UART_PutNumber(USART2, (uint32_t) op_result);
100  UART_PutString(USART2, (uint8_t*)" \n.");
101  }
102  UART_PutString(USART2, (uint8_t*)"============\n");
103  UART_PutString(USART2, (uint8_t*)"--------------END OF SINGLE SENSOR INIT-------------------------\n");
104  return op_result;
105 }
106 /** end of 9.6.1
107  * @}
108  */
109 /** @defgroup UT_03_IRPyro 9.6.2 Multiple Sensor initialization
110  * @brief Verification of multiple sensors initialization in multiple modes
111  <table>
112  <tr><td> 9.6.2.1 </td><td> Initialize multiple devices for interrupt configuration </td></tr>
113  <tr><td> </td><td> Written configuration matches registers stored on memory. </td></tr>
114  <tr><td> 9.6.2.2 </td><td> Initialize multiple devices for polled configuration </td></tr>
115  <tr><td> </td><td> Written configuration matches registers stored on memory. </td></tr>
116  <tr><td> 9.6.2.3 </td><td> Initialize multiple devices for synchronized configuration </td></tr>
117  <tr><td> </td><td> Written configuration matches registers stored on memory. </td></tr>
118  </table>
119  * @{
120  */
121 uint8_t ut02_multiple_sensor_init(IRPyro_devices this_list, uint8_t list_size)
122 {
123  uint8_t op_result = 0;
124  uint8_t test_results[2] = {0};
125  UART_PutString(USART2, (uint8_t*)"UT_02_IRPyro 9.6.2 Multiple Sensor initialization \n");
126  /*-------- test the open_list, read_list and close_list functions --------*/
127  /*-------------------------- open_list ---------------------------------*/
128  UART_PutString(USART2, (uint8_t*)"OPEN devices \n");
129  test_results[0] = IRPyro_open_devices(this_list, list_size);
130  /*-------------------------- close_list ---------------------------------*/
131  UART_PutString(USART2, (uint8_t*)"CLOSE devices \n");
132  test_results[1] = IRPyro_close_devices(this_list, list_size);
133  /*-------------------------- collate results -----------------------------*/
134  UART_PutString(USART2, (uint8_t*)"============\n");
135  op_result = check_results(test_results, 2);
136  if (op_result == 1)
137  {
138  UART_PutString(USART2, (uint8_t*)"PASSED \n");
139  }
140  else
141  {
142  UART_PutString(USART2, (uint8_t*)"FAILED WITH CODE ");
143  UART_PutNumber(USART2, (uint32_t) op_result);
144  UART_PutString(USART2, (uint8_t*)" \n.");
145  }
146  UART_PutString(USART2, (uint8_t*)"============\n");
147  UART_PutString(USART2, (uint8_t*)"--------------END OF MULTIPLE SENSOR INIT-------------------------\n");
148  return op_result;
149 }
150 /** end of 9.6.2
151  * @}
152  */
153 /** @defgroup UT_04_IRPyro 9.6.3 Single Sensor Data Read
154  * @brief Single sensor data reading with frame detection
155  <table>
156  <tr><td> 9.6.3.1 </td><td> Read data from a single sensor and detect frames missing with the sensor configured for interrupt. </td></tr>
157  <tr><td> </td><td> No frames should be missing from a sample period. </td></tr>
158  <tr><td> 9.6.3.2 </td><td> Read data from a single sensor and detect frames missing with the sensor configured for polled </td></tr>
159  <tr><td> </td><td> No frames should be missing from a sample period. </td></tr>
160  <tr><td> 9.6.3.3 </td><td> Read data from a single sensor and detect frames missing with the sensor configured for synchronized </td></tr>
161  <tr><td> </td><td> No frames should be missing from a sample period. </td></tr>
162  </table>
163  * @{
164  */
165 uint8_t ut03_single_sensor_read(IRPyro_sensor_device_type *IRPyro_test_Sensor)
166 {
167  uint8_t op_result = 0;
168  /*-------------------------- template definition -------------------------*/
169  uint8_t test_results[3] = {0};
170  UART_PutString(USART2, (uint8_t*)"UT_03_IRPyro 9.6.3 Single Sensor Data Read \n");
171  /*-------------------------- TEST BEGINS ---------------------------------*/
172  UART_PutString(USART2, (uint8_t*)"OPEN device \n");
173  test_results[0] = IRPyro_open(IRPyro_test_Sensor);
174  UART_PutString(USART2, (uint8_t*)"READING SAMPLE \n");
175  test_results[1] = IRPyro_test_single_sensor_read_sample(IRPyro_test_Sensor);
176  UART_PutString(USART2, (uint8_t*)"CLOSE device \n");
177  test_results[2] = IRPyro_close(IRPyro_test_Sensor);
178 
179  /*-------------------------- collate results -----------------------------*/
180  UART_PutString(USART2, (uint8_t*)"============\n");
181  op_result = check_results(test_results, 3);
182  if (op_result == 1)
183  {
184  UART_PutString(USART2, (uint8_t*)"PASSED \n");
185  }
186  else
187  {
188  UART_PutString(USART2, (uint8_t*)"FAILED WITH CODE ");
189  UART_PutNumber(USART2, (uint32_t) op_result);
190  UART_PutString(USART2, (uint8_t*)" \n.");
191  }
192  UART_PutString(USART2, (uint8_t*)"============\n");
193  UART_PutString(USART2, (uint8_t*)"--------------END OF SINGLE SENSOR READ-------------------------\n");
194  return op_result;
195 }
196 /** end of 9.6.3
197  * @}
198  */
199 /** @defgroup UT_05_IRPyro 9.6.4 Multiple Sensor Data Reading
200  * @brief Multiple sensor reading with frame detection
201  <table>
202  <tr><td> 9.6.4.1 </td><td> Read data from multiple sensors and detect frames missing with the sensors configured for interrupt </td></tr>
203  <tr><td> </td><td> No frames should be missing from a sample period. </td></tr>
204  <tr><td> 9.6.4.2 </td><td> Read data from multiple sensors and detect frames missing with the sensors configured for polled </td></tr>
205  <tr><td> </td><td> No frames should be missing from a sample period. </td></tr>
206  <tr><td> 9.6.4.3 </td><td> Read data from multiple sensors and detect frames missing with the sensors configured for synchronized </td></tr>
207  <tr><td> </td><td> No frames should be missing from a sample period. </td></tr>
208  </table>
209  * @{
210  */
211 uint8_t ut04_multiple_sensor_read(IRPyro_devices this_list, uint8_t list_size)
212 {
213  uint8_t op_result=0;
214  uint8_t test_results[3] = {0};
215  UART_PutString(USART2, (uint8_t*)"UT_04_IRPyro 9.6.4 Multiple Sensor Data Reading \n");
216  /*-------- test the open_list, read_list and close_list functions --------*/
217  /*-------------------------- open_list ---------------------------------*/
218  UART_PutString(USART2, (uint8_t*)"OPEN devices \n");
219  test_results[0] = IRPyro_open_devices(this_list, list_size);
220  /*-------------------------- read_list ---------------------------------*/
221  UART_PutString(USART2, (uint8_t*)"READING devices \n");
222  test_results[1] = IRPyro_test_multiple_sensor_read_sample(this_list, list_size);
223  /*-------------------------- close_list ---------------------------------*/
224  UART_PutString(USART2, (uint8_t*)"CLOSE devices \n");
225  test_results[2] = IRPyro_close_devices(this_list, list_size);
226  /*-------------------------- collate results -----------------------------*/
227  UART_PutString(USART2, (uint8_t*)"============\n");
228  op_result = check_results(test_results, 2);
229  if (op_result == 1)
230  {
231  UART_PutString(USART2, (uint8_t*)"PASSED \n");
232  }
233  else
234  {
235  UART_PutString(USART2, (uint8_t*)"FAILED WITH CODE ");
236  UART_PutNumber(USART2, (uint32_t) op_result);
237  UART_PutString(USART2, (uint8_t*)" \n.");
238  }
239  UART_PutString(USART2, (uint8_t*)"============\n");
240  UART_PutString(USART2, (uint8_t*)"--------------END OF MULTIPLE SENSOR READ-------------------------\n");
241  return op_result;
242 }
243 /** end of 9.6.4
244  * @}
245  */
246 /** @defgroup UT_06_IRPyro 9.6.5 Data collection with NORTH channel enabled
247  * @brief Data collection with orientation enabled
248  <table>
249  <tr><td> 9.6.5 </td><td> Read data from devices with 1 to 4 channels enabled changing NORTH channel designation </td></tr>
250  <tr><td> </td><td> Data frame returns ordered </td></tr>
251  </table>
252  * @{
253  */
254 // deprecated
255 /** end of 9.6.5
256  * @}
257  */
258 /** @defgroup UT_07_IRPyro 9.6.6 Power options testing
259  * @brief Power options testing
260  <table>
261  <tr><td> 9.6.6 </td><td> Change sensor power configuration </td></tr>
262  <tr><td> </td><td> </td></tr>
263  </table>
264  * @{
265  */
266 /**
267  * @brief Test of IOCTL functions
268  */
269 uint8_t ut06_IOCTL01(IRPyro_sensor_device_type *IRPyro_test_Sensor)
270 {
271 #define IOCTL01_TEST_NUMBER 5
272  /*-------------------------- memory allocation----------------------------*/
273  uint8_t op_result = 0;
274  IRPyro_cmd_type IOCTL_cmd = {0};
275  IRPyro_arg_type IOCTL_arg = {0};
276  uint8_t IOCTL_result[IOCTL01_TEST_NUMBER] = {0};
277 
278  IRPyro_open(IRPyro_test_Sensor);
279  UART_PutString(USART2, (uint8_t*)"UT_06_IRPyro 9.6.6 Power options testing \n");
280 
281  /*------------------------ Power control ---------------------------------*/
282  UART_PutString(USART2, (uint8_t*)"POWER NORMAL \n");
283  IOCTL_cmd.cmd = power_normal;
284  IOCTL_result[0] = IRPyro_ioctl(IRPyro_test_Sensor, &IOCTL_cmd, IOCTL_arg);
285  IRPyro_test_single_sensor_read_sample(IRPyro_test_Sensor);
286 
287  UART_PutString(USART2, (uint8_t*)"POWER LOW \n");
288  IOCTL_cmd.cmd = power_low;
289  IOCTL_result[1] = IRPyro_ioctl(IRPyro_test_Sensor, &IOCTL_cmd, IOCTL_arg);
290  IRPyro_test_single_sensor_read_sample(IRPyro_test_Sensor);
291 
292  UART_PutString(USART2, (uint8_t*)"POWER SLEEP \n");
293  IOCTL_cmd.cmd = power_sleep;
294  IOCTL_result[2] = IRPyro_ioctl(IRPyro_test_Sensor, &IOCTL_cmd, IOCTL_arg);
295 
296  IOCTL_cmd.cmd = power_wakeup;
297  UART_PutString(USART2, (uint8_t*)"POWER WAKE UP \n");
298  IOCTL_result[3] = IRPyro_ioctl(IRPyro_test_Sensor, &IOCTL_cmd, IOCTL_arg);
299 
300  IOCTL_cmd.cmd = power_off;
301  UART_PutString(USART2, (uint8_t*)"POWER OFF \n");
302  IOCTL_result[4] = IRPyro_ioctl(IRPyro_test_Sensor, &IOCTL_cmd, IOCTL_arg);
303 
304  IRPyro_close(IRPyro_test_Sensor);
305  /*-------------------------- collate results -----------------------------*/
306  UART_PutString(USART2, (uint8_t*)"============\n");
307  op_result = check_results(IOCTL_result, IOCTL01_TEST_NUMBER);
308  if (op_result == 1)
309  {
310  UART_PutString(USART2, (uint8_t*)"PASSED \n");
311  }
312  else
313  {
314  UART_PutString(USART2, (uint8_t*)"FAILED WITH CODE ");
315  UART_PutNumber(USART2, (uint32_t) op_result);
316  UART_PutString(USART2, (uint8_t*)" \n.");
317  }
318  UART_PutString(USART2, (uint8_t*)"============\n");
319  UART_PutString(USART2, (uint8_t*)"--------------END OF MULTIPLE SENSOR READ-------------------------\n");
320  return op_result;
321 };
322 /** end of 9.6.6
323  * @}
324  */
325 /** @defgroup UT_08_IRPyro 9.6.7 Sleep and Wake-up operation
326  * @brief Configuration recovery after sleep command and wake-up event
327  <table>
328  <tr><td> 9.6.7 </td><td> Wake command response </td></tr>
329  <tr><td> </td><td> </td></tr>
330  </table>
331  * @{
332  */
333 /**
334  * @brief Wake up event
335  */
336 uint8_t ut_wake_up_event(IRPyro_sensor_device_type *IRPyro_test_Sensor)
337 {
338 #define WAKE_UP_EVENT_TEST_NUMBER 3
339  /*-------------------------- memory allocation----------------------------*/
340  uint8_t op_result = 0;
341  uint8_t wake_up_event_result[WAKE_UP_EVENT_TEST_NUMBER] = {0};
342  uint32_t time_to_wait = TIME_TO_WAIT;
343  uint8_t wake_up_detected = 0;
344  IRPyro_cmd_type IOCTL_cmd = {0};
345  IRPyro_arg_type IOCTL_arg = {0};
346 
347  /*------------------------ Begin Test ------------------------------------*/
348  IRPyro_open(IRPyro_test_Sensor);
349  UART_PutString(USART2, (uint8_t*)"WAKE UP EVENT DETECTION BY HARDWARE INTERRUPT \n");
350  /*------------------------ Power control ---------------------------------*/
351  UART_PutString(USART2, (uint8_t*)"POWER NORMAL \n");
352  IOCTL_cmd.cmd = power_normal;
353  wake_up_event_result[0] = IRPyro_ioctl(IRPyro_test_Sensor, &IOCTL_cmd, IOCTL_arg);
354  IRPyro_test_single_sensor_read_sample(IRPyro_test_Sensor);
355 
356  UART_PutString(USART2, (uint8_t*)"POWER SLEEP \n");
357  IOCTL_cmd.cmd = power_sleep;
358  wake_up_event_result[1] = IRPyro_ioctl(IRPyro_test_Sensor, &IOCTL_cmd, IOCTL_arg);
359 
360  EXTernal_Callback_Setup(wakeup_event_callback);
361  PWR_EnterSleepMode(PWR_SLEEPEntry_WFI);
362 
363  /*wait for the sensor to wake up or time to run out*/
364  do
365  {
366  wake_up_detected = EXTI_detected(0);
367  --time_to_wait;
368  }
369  while ((time_to_wait != 0) && (wake_up_detected == 0));
370 
371  if (time_to_wait == 0 && wake_up_detected == 0)
372  {
373  IOCTL_cmd.cmd = power_wakeup;
374  UART_PutString(USART2, (uint8_t*)"FORCED POWER WAKE UP \n");
375  IRPyro_ioctl(IRPyro_test_Sensor, &IOCTL_cmd, IOCTL_arg);
376  UART_PutString(USART2, (uint8_t*)"READ TEST AFTER FORCED POWER WAKE UP \n");
377  IRPyro_test_single_sensor_read_sample(IRPyro_test_Sensor);
378  }
379  else
380  {
381  UART_PutString(USART2, (uint8_t*)"WAKE UP EVENT DETECTED!! \n");
382  wake_up_event_result[2] = wake_up_detected;
383  UART_PutString(USART2, (uint8_t*)"READ TEST AFTER WAKE UP EVENT \n");
384  IRPyro_test_single_sensor_read_sample(IRPyro_test_Sensor);
385  }
386 
387  IRPyro_close(IRPyro_test_Sensor);
388  /*-------------------------- collate results -----------------------------*/
389  UART_PutString(USART2, (uint8_t*)"============\n");
390  op_result = check_results(wake_up_event_result, WAKE_UP_EVENT_TEST_NUMBER);
391  if (op_result == 1)
392  {
393  UART_PutString(USART2, (uint8_t*)"PASSED \n");
394  }
395  else
396  {
397  UART_PutString(USART2, (uint8_t*)"FAILED WITH CODE ");
398  UART_PutNumber(USART2, (uint32_t) op_result);
399  UART_PutString(USART2, (uint8_t*)" \n.");
400  }
401  UART_PutString(USART2, (uint8_t*)"============\n");
402  UART_PutString(USART2, (uint8_t*)"--------------WAKE UP EVENT DETECTION BY HARDWARE INTERRUPT-------------------------\n");
403  return op_result;
404 }
405 /** end of 9.6.7
406  * @}
407  */
408 
409 /** @defgroup UT_09_IRPyro 9.6.8 On the fly configuration
410  * @brief IRPyro configuration parameters can be changed on the fly
411  <table>
412  <tr><td> 9.6.8 </td><td> Change parameters on the fly </td></tr>
413  <tr><td> </td><td> </td></tr>
414  </table>
415  * @{
416  */
417 uint8_t ut06_IOCTL02(IRPyro_sensor_device_type *IRPyro_test_Sensor)
418 {
419 #define IOCTL_TEST_NUMBER 12
420  /*-------------------------- memory allocation----------------------------*/
421  uint8_t op_result = 0;
422  IRPyro_cmd_type IOCTL_cmd = {0};
423  IRPyro_arg_type IOCTL_arg = {0};
424  uint8_t IOCTL_result[IOCTL_TEST_NUMBER] = {0};
425 
426  IRPyro_open(IRPyro_test_Sensor);
427  UART_PutString(USART2, (uint8_t*)"UT_06_IRPyro 9.6.8 On the fly configuration \n");
428 
429  /*------------------------ Sampling rate ---------------------------------*/
430  UART_PutString(USART2, (uint8_t*)"SAMPLING RATE 1MS \n");
431  IOCTL_cmd.cmd = sampling_rate_get; // Normal power, 0x00 = 1ms
432  IOCTL_result[0] = IRPyro_ioctl(IRPyro_test_Sensor, &IOCTL_cmd, IOCTL_arg);
433  IRPyro_test_single_sensor_read_sample(IRPyro_test_Sensor);
434 
435  UART_PutString(USART2, (uint8_t*)"SAMPLING RATE 10MS \n");
436  IOCTL_cmd.cmd = sampling_rate_set; // Normal power, 0xaa = 10 ms
437  IOCTL_arg.arg = 0x0A;
438  IOCTL_result[1] = IRPyro_ioctl(IRPyro_test_Sensor, &IOCTL_cmd, IOCTL_arg);
439  IRPyro_test_single_sensor_read_sample(IRPyro_test_Sensor);
440 
441  UART_PutString(USART2, (uint8_t*)"SAMPLING RATE 1MS \n");
442  IOCTL_cmd.cmd = sampling_rate_set; // Normal power, 0x00 = 1 ms
443  IOCTL_arg.arg = 0x00;
444  IOCTL_result[2] = IRPyro_ioctl(IRPyro_test_Sensor, &IOCTL_cmd, IOCTL_arg);
445  IRPyro_test_single_sensor_read_sample(IRPyro_test_Sensor);
446 
447  /*------------------------ High pass filter ------------------------------*/
448  UART_PutString(USART2, (uint8_t*)"SET HIGH PASS FILTER 2HZ \n");
449  IOCTL_cmd.cmd = high_pass_set; // Normal power, 0x02 = 2 Hz
450  IOCTL_arg.arg = HIGH_PASS_2HZ;
451  IOCTL_arg.channel = 1;
452  IOCTL_result[3] = IRPyro_ioctl(IRPyro_test_Sensor, &IOCTL_cmd, IOCTL_arg);
453  IRPyro_test_single_sensor_read_sample(IRPyro_test_Sensor);
454 
455  UART_PutString(USART2, (uint8_t*)"GET HIGH PASS FILTER 2HZ \n");
456  IOCTL_cmd.cmd = high_pass_get;
457  IOCTL_result[4] = IRPyro_ioctl(IRPyro_test_Sensor, &IOCTL_cmd, IOCTL_arg);
458  IRPyro_test_single_sensor_read_sample(IRPyro_test_Sensor);
459 
460  UART_PutString(USART2, (uint8_t*)"SET HIGH PASS FILTER 8HZ \n");
461  IOCTL_cmd.cmd = high_pass_set;
462  IOCTL_arg.arg = HIGH_PASS_8HZ;
463  IOCTL_arg.channel = 2;
464  IOCTL_result[5] = IRPyro_ioctl(IRPyro_test_Sensor, &IOCTL_cmd, IOCTL_arg);
465  IRPyro_test_single_sensor_read_sample(IRPyro_test_Sensor);
466 
467  UART_PutString(USART2, (uint8_t*)"GET HIGH PASS FILTER 8HZ \n");
468  IOCTL_cmd.cmd = high_pass_get;
469  IOCTL_result[6] = IRPyro_ioctl(IRPyro_test_Sensor, &IOCTL_cmd, IOCTL_arg);
470  IRPyro_test_single_sensor_read_sample(IRPyro_test_Sensor);
471 
472  /*------------------------ Low pass filter ------------------------------*/
473  UART_PutString(USART2, (uint8_t*)"SET LOW PASS FILTER 45HZ \n");
474  IOCTL_cmd.cmd = low_pass_set;
475  IOCTL_arg.arg = LOW_PASS_45;
476  IOCTL_result[7] = IRPyro_ioctl(IRPyro_test_Sensor, &IOCTL_cmd, IOCTL_arg);
477  IRPyro_test_single_sensor_read_sample(IRPyro_test_Sensor);
478 
479  UART_PutString(USART2, (uint8_t*)"GET LOW PASS FILTER 45HZ \n");
480  IOCTL_cmd.cmd = low_pass_get;
481  IOCTL_result[8] = IRPyro_ioctl(IRPyro_test_Sensor, &IOCTL_cmd, IOCTL_arg);
482  IRPyro_test_single_sensor_read_sample(IRPyro_test_Sensor);
483 
484  /*------------------------ Gain changes ----------------------------------*/
485  UART_PutString(USART2, (uint8_t*)"SET GAIN TO 8X \n");
486  IOCTL_cmd.cmd = gain_set;
487  IOCTL_arg.arg = GAIN_08;
488  IOCTL_arg.channel = 3;
489  IOCTL_result[9] = IRPyro_ioctl(IRPyro_test_Sensor, &IOCTL_cmd, IOCTL_arg);
490  IRPyro_test_single_sensor_read_sample(IRPyro_test_Sensor);
491 
492  UART_PutString(USART2, (uint8_t*)"GET GAIN TO 8X \n");
493  IOCTL_cmd.cmd = gain_get;
494  IOCTL_result[10] = IRPyro_ioctl(IRPyro_test_Sensor, &IOCTL_cmd, IOCTL_arg);
495  IRPyro_test_single_sensor_read_sample(IRPyro_test_Sensor);
496 
497  UART_PutString(USART2, (uint8_t*)"SET GAIN TO 16X \n");
498  IOCTL_cmd.cmd = gain_set;
499  IOCTL_arg.arg = GAIN_16;
500  IOCTL_arg.channel = 4;
501  IOCTL_result[11] = IRPyro_ioctl(IRPyro_test_Sensor, &IOCTL_cmd, IOCTL_arg);
502  IRPyro_test_single_sensor_read_sample(IRPyro_test_Sensor);
503  /*-------------------------- collate results -----------------------------*/
504  UART_PutString(USART2, (uint8_t*)"============\n");
505  op_result = check_results(IOCTL_result, IOCTL_TEST_NUMBER);
506  if (op_result == 1)
507  {
508  UART_PutString(USART2, (uint8_t*)"PASSED \n");
509  }
510  else
511  {
512  UART_PutString(USART2, (uint8_t*)"FAILED WITH CODE ");
513  UART_PutNumber(USART2, (uint32_t) op_result);
514  UART_PutString(USART2, (uint8_t*)" \n.");
515  }
516  UART_PutString(USART2, (uint8_t*)"============\n");
517  UART_PutString(USART2, (uint8_t*)"--------------END OF MULTIPLE SENSOR READ-------------------------\n");
518  return op_result;
519 }
520 /** end of 9.6.8
521  * @}
522  */
523 
524 /**
525  * @brief Single TO-CAN read
526  * @note The TO-CAN is a four pin sensor with no CS nor INT lines.
527  * As a result the device is controlled only via I2C. Power control
528  * should be independently supplied.
529  *
530  * This is important in two ways:
531  * - Stabilization of the device should be allowed.
532  * - I2C address collision should be controlled externally.
533  *
534  * This is a self-contained test that should be called directly from an
535  * empty main() function
536  */
537 void ut_TO_CAN_read(void)
538 {
539  /*------------------ Memory allocation, initialization-------------------*/
540  IRPyro_sensor_device_type IRPyro_TO_can = {0}; // Instance of sensor
541  IRPyro_TO_can.read_mode = 1; // Polled mode reading
542  IRPyro_TO_can.address = 0x08; // I2C address to configure
543  IRPyro_TO_can.number_of_active_channels = 1; // configures channel 2 for streamming
544  /*-------------------------- board setup ---------------------------------*/
546  UART_PutString(USART2, (uint8_t*)"Single TO-CAN read \n");
547  for(;;)
548  {
549  ut03_single_sensor_read(&IRPyro_TO_can);
550  }
551 }
552 void ut_TO_CAN_read2(void)
553 {
554 
555  /*------------------- Memory allocation, initialization ------------------*/
556  IRPyro_devices IRPyro_device = {0};
557  /*----------------------- --- CONFIGURATION ----- -----------------------*/
558  AFE_reg_type IRPyro_AFE_Master =
559  {
560  .S7_S0 = 0,
561  .LP = LOW_POWER_DISABLE,
562  .HP = HP_DISABLE,
563  .C_LP = LOW_PASS_180,
564  .CLK_OUT = CLK_ENABLE,
565  .SYNC = MASTER,
566  .TEMP = 0,
567  .INT = INT_ENABLE
568  };
569  AFE_reg_type IRPyro_AFE_Slave =
570  {
571  .S7_S0 = 0,
572  .LP = LOW_POWER_DISABLE,
573  .HP = HP_DISABLE,
574  .C_LP = LOW_PASS_180,
575  .CLK_OUT = CLK_DISABLE,
576  .SYNC = SLAVE,
577  .TEMP = 0,
578  .INT = INT_ENABLE
579  };
580  /*----------------- ADDRESSES ------------*/
581  /* Assuming four sensors on an IRPyro Break out board or demo board*/
582  IRPyro_device[0].INT_Port = 1;
583  IRPyro_device[0].CS_Port = 2;
584  IRPyro_device[0].CS_Pin = 1;
585  IRPyro_device[0].INT_Pin = 4;
586  IRPyro_device[0].address = 0x0A;
587 
588  IRPyro_device[1].CS_Port = 2;
589  IRPyro_device[1].INT_Port = 1;
590  IRPyro_device[1].CS_Pin = 5;
591  IRPyro_device[1].INT_Pin = 5;
592  IRPyro_device[1].address = 0x0B;
593 
594  /*----------------- CONFIGURATION ------------*/
595  IRPyro_device[0].AFE_register = IRPyro_AFE_Master; // MASTER, INT, CLK DISABLED
596  IRPyro_device[0].read_mode = 1;
597  IRPyro_device[0].number_of_active_channels = 1;
598 
599  IRPyro_device[1].AFE_register = IRPyro_AFE_Slave; // MASTER, INT, CLK DISABLED
600  IRPyro_device[1].read_mode = 1;
601  IRPyro_device[1].number_of_active_channels = 1;
602 
603 
604  UART_PutString(USART2, (uint8_t*)"IRPyro TO: READ DATA FROM MULTIPLE SENSORS and detect frames missing with the sensors CONFIGURED FOR INTERRUPT\n");
606  ut04_multiple_sensor_read(IRPyro_device, 4);
607 
608 
609 }
610 /******************************************************************************/
611 /** @defgroup UT_10_IRPyro Unit testing support functions
612  * @brief assorted board manipulation and comparison functions
613  * @{
614  */
615 
616 /**
617  * @brief Changes the state of all the CS lines as used on the IRPyro backplane board
618  */
619 void IRPyro_demo_board(uint8_t value)
620 {
621  CS_pin_set(2,1,value);
622  CS_pin_set(2,3,value);
623  CS_pin_set(2,4,value);
624  CS_pin_set(2,5,value);
625 }
626 /**
627  * @brief Checks the results of a test for pass or fail by adding individual results
628  * @param test_results individual test result (0 fail / 1 sucess)
629  * @param number_of_tests success result
630  * @retval op_result 1 PASS/0 FAIL
631  */
632 static uint8_t check_results(uint8_t * test_results, uint8_t number_of_tests)
633 {
634  uint8_t op_result = 0;
635  for (uint8_t idx=0; idx< number_of_tests; ++idx)
636  {
637  if (test_results[idx] == 1)
638  {
639  ++ op_result;
640  }
641  else
642  {
643  op_result = test_results[idx];
644  break;
645  }
646  }
647  if (op_result == number_of_tests)
648  {
649  op_result = 1;
650  }
651  return op_result;
652 }
653 /**
654  * @brief Given a list of devices collects a number of samples and determines lost frames
655  * @param this_list group of IRPyro configuration data
656  * @param list_size number of devices on the list
657  * @retval number_of_frames_lost
658  */
659 static uint8_t IRPyro_test_multiple_sensor_read_sample(IRPyro_devices this_list, uint8_t list_size)
660 {
661  uint16_t number_of_frames_lost[4] = {0};
662  uint16_t previous_frame_count[4] = {0};
663  uint16_t present_frame_count[4] = {0};
664  uint8_t reading_attempt = 0;
665  uint8_t op_result = 0;
666 
667  for(uint8_t device=0; device<list_size; ++device)
668  {
669  op_result = FIFO_reset(&this_list[device]);
670  if (op_result != 1)
671  {
672  UART_PutString(USART2, (uint8_t*)"DEVICE NUMBER: ");
673  UART_PutNumber(USART2, (uint32_t) device);
674  UART_PutString(USART2, (uint8_t*)" FAILED TO RESET WITH CODE ");
675  UART_PutNumber(USART2, (uint32_t) op_result);
676  UART_PutString(USART2, (uint8_t*)" \n.");
677  }
678  }
679  op_result = IRPyro_read_devices(this_list, list_size);
680  if (op_result != 1)
681  {
682  UART_PutString(USART2, (uint8_t*)"FAILED TO READ WITH CODE ");
683  UART_PutNumber(USART2, (uint32_t) op_result);
684  UART_PutString(USART2, (uint8_t*)" \n.");
685  }
686  for(uint8_t device=0; device< IRPyro_LIST_SIZE; ++device)
687  {
688  present_frame_count[device] = this_list[device].channel_value[IRPyro_FRAME_COUNT_LOCATION]; // FRAME_COUNT
689  previous_frame_count[device] = this_list[device].channel_value[IRPyro_FRAME_COUNT_LOCATION]; // FRAME_COUNT
690  }
691  UART_PutString(USART2, (uint8_t*)"READING ");
692  UART_PutNumber(USART2, NUMBER_OF_FRAMES_TO_COUNT);
693  UART_PutString(USART2, (uint8_t*)" FRAMES \n");
694  int sample_counter=0;
695  while(sample_counter < NUMBER_OF_FRAMES_TO_COUNT)
696  {
697  op_result = IRPyro_read_devices(this_list, list_size);
698  if (op_result == 1)
699  {
700  ++sample_counter;
701  for(uint8_t device=0; device< IRPyro_LIST_SIZE; ++device)
702  {
703  uint16_t dif = 0;
704  present_frame_count[device] = this_list[device].channel_value[IRPyro_FRAME_COUNT_LOCATION]; // FRAME_COUNT
705  dif = present_frame_count[device] - previous_frame_count[device];
706  if (dif > 1)
707  {
708  ++number_of_frames_lost[device];
709  }
710  previous_frame_count[device] = present_frame_count[device];
711  }
712  }
713  else
714  {
715  if (reading_attempt < 3)
716  {
717  ++reading_attempt;
718  }
719  else
720  {
721  ++sample_counter;
722  for(uint8_t device=0; device< IRPyro_LIST_SIZE; ++device)
723  {
724  ++number_of_frames_lost[device];
725  }
726  reading_attempt=0;
727  }
728  }
729  }
730  UART_PutString(USART2, (uint8_t*)"TEST COMPLETE \n");
731  UART_PutString(USART2, (uint8_t*)"Frames lost \n");
732  int total;
733  for(uint8_t device=0; device< IRPyro_LIST_SIZE; ++device)
734  {
735  total =+number_of_frames_lost[device];
736  UART_PutString(USART2, (uint8_t*)"Device: ");
737  UART_PutNumber(USART2, device);
738  UART_PutString(USART2, (uint8_t*)" ");
739  UART_PutString(USART2, (uint8_t*)" frames lost: ");
740  UART_PutNumber(USART2, number_of_frames_lost[device]);
741  UART_PutString(USART2, (uint8_t*)"\n");
742  }
743  return (total == 0) ? 1 : 0; // 1 passed all / 0 fail;
744 }
745 /**
746  * @brief IRPyro data collection for a number samples
747  * @param this_device IRPyro configuration data
748  * @retval number_of_frames_lost
749  */
750 static uint8_t IRPyro_test_single_sensor_read_sample(IRPyro_sensor_device_type* this_device)
751 {
752  uint16_t number_of_frames_lost = 0;
753  uint16_t previous_frame_count = 0;
754  uint16_t present_frame_count = 0;
755  uint8_t reading_attempt = 0;
756  uint8_t op_result = 0;
757 
758  op_result = FIFO_reset(this_device);
759  if (op_result != 1)
760  {
761  UART_PutString(USART2, (uint8_t*)"FAILED TO RESET WITH CODE ");
762  UART_PutNumber(USART2, (uint32_t) op_result);
763  UART_PutString(USART2, (uint8_t*)" \n.");
764  }
765  op_result = IRPyro_read(this_device);
766  if (op_result != 1)
767  {
768  UART_PutString(USART2, (uint8_t*)"FAILED TO READ WITH CODE ");
769  UART_PutNumber(USART2, (uint32_t) op_result);
770  UART_PutString(USART2, (uint8_t*)" \n.");
771  }
772  previous_frame_count = this_device->channel_value[IRPyro_FRAME_COUNT_LOCATION]; // FRAME_COUNT
773  present_frame_count = this_device->channel_value[IRPyro_FRAME_COUNT_LOCATION]; // FRAME_COUNT
774 
775  UART_PutString(USART2, (uint8_t*)"READING ");
776  UART_PutNumber(USART2, NUMBER_OF_FRAMES_TO_COUNT);
777  UART_PutString(USART2, (uint8_t*)" FRAMES \n");
778  uint32_t sample_counter=0;
779  while(sample_counter < NUMBER_OF_FRAMES_TO_COUNT)
780  {
781  op_result = IRPyro_read(this_device);
782  if (op_result == 1)
783  {
784  ++sample_counter;
785  uint16_t dif = 0;
786  present_frame_count = this_device->channel_value[IRPyro_FRAME_COUNT_LOCATION]; // FRAME_COUNT
787  dif = present_frame_count - previous_frame_count;
788  if (dif > 1)
789  {
790  ++number_of_frames_lost;
791  }
792  previous_frame_count = present_frame_count;
793  }
794  else
795  {
796  if (reading_attempt < 3)
797  {
798  ++reading_attempt;
799  }
800  else
801  {
802  ++sample_counter;
803  ++number_of_frames_lost;
804  reading_attempt=0;
805  }
806  }
807  }
808  UART_PutString(USART2, (uint8_t*)"TEST COMPLETE \n");
809  UART_PutString(USART2, (uint8_t*)"Frames lost ");
810  UART_PutNumber(USART2, number_of_frames_lost);
811  UART_PutString(USART2, (uint8_t*)"\n");
812  return (number_of_frames_lost == 0) ? 1 : 0; // 1 passed all / 0 fail;
813 }
814 /**
815  * @brief Compares AFE registers for equality
816  * @param first First AFE
817  * @param second Second AFE
818  * @retval comparison 0 not equal / 1 equal
819  */
820 static uint8_t AFE_compare(AFE_reg_type first, AFE_reg_type second)
821 {
822  uint8_t i = 0, result_comparison = 1;
823  uint8_t *AFE_pointer_one = &(first.S7_S0);
824  uint8_t *AFE_pointer_two = &(second.S7_S0);
825  uint8_t AFE_size = sizeof(first);
826 
827  while (result_comparison && i<AFE_size)
828  {
829  if (AFE_pointer_one[i] != AFE_pointer_two[i] )
830  result_comparison = 0;
831  else
832  ++i;
833  }
834  return result_comparison;
835 }
836 /**
837  * @brief Compares CCP registers for equality
838  * @param first First CCP
839  * @param second Second CCP
840  * @retval comparison 0 not equal / 1 equal
841  */
842 static uint8_t CCP_compare(CCP_reg_type first, CCP_reg_type second)
843 {
844  uint8_t i = 0, result_comparison = 1;
845  uint8_t *CCP_pointer_one = &(first.Feedback_cap);
846  uint8_t *CCP_pointer_two = &(second.Feedback_cap);
847  uint8_t CCP_size = sizeof(first);
848 
849  while (result_comparison && i<CCP_size)
850  {
851  if (CCP_pointer_one[i] != CCP_pointer_two[i] )
852  result_comparison = 0;
853  else
854  ++i;
855  }
856  return result_comparison;
857 }
858 /**
859  * @brief Compares WUP registers for equality
860  * @param first First WUP
861  * @param second Second WUP
862  * @retval comparison 0 not equal / 1 equal
863  */
864 static uint8_t WUP_compare(WUP_reg_type first, WUP_reg_type second)
865 {
866  uint8_t i = 0, result_comparison = 1;
867  uint8_t *WUP_pointer_one = &(first.UHT);
868  uint8_t *WUP_pointer_two = &(second.UHT);
869  uint8_t WUP_size = sizeof(first);
870 
871  while (result_comparison && i<WUP_size)
872  {
873  if (WUP_pointer_one[i] != WUP_pointer_two[i] )
874  result_comparison = 0;
875  else
876  ++i;
877  }
878  return result_comparison;
879 }
880 /**
881  * @brief Clear the entire FIFO (Rd/Wr pointer reset with the Empty)
882  * @param this_device pointer to the IRPyro data structure
883  * @retval op_result 1 success / 0 error
884  */
885 static uint8_t FIFO_reset(IRPyro_sensor_device_type* this_device)
886 {
887  uint8_t op_result = 0;
888  uint8_t i2c_result = 0;
889 
890  i2c_result = i2c_Read(this_device->address, IRPyro_FIFO_RESET, &op_result ,1);
891  if ((i2c_result == 1) && (op_result == IRPyro_FIFO_RESET_OK))
892  {
893  op_result =1;
894  }
895  else
896  op_result = i2c_result;
897  return op_result;
898 }
899 /**
900  * @brief callback function
901  * @attention This function is called from an interrupt service request function
902  * and should be minimal.
903  */
904 static void wakeup_event_callback(void)
905 {
906 // add non blocking code
907 }
908 /** end of Unit testing support functions
909  * @}
910  */
911 /** end of Unit Test module
912  * @}
913  */
914 /* ********** Copyright (c) 2018 _KEMET, Ltd. **********END OF FILE************/
IOCTL_TEST_NUMBER
#define IOCTL_TEST_NUMBER
TIME_TO_WAIT
#define TIME_TO_WAIT
Definition: IRPyro_UT.h:39
FIFO_reset
static uint8_t FIFO_reset(IRPyro_sensor_device_type *this_device)
Clear the entire FIFO (Rd/Wr pointer reset with the Empty)
Definition: IRPyro_UT.c:885
ut06_IOCTL02
uint8_t ut06_IOCTL02(IRPyro_sensor_device_type *IRPyro_test_Sensor)
Definition: IRPyro_UT.c:417
ut03_single_sensor_read
uint8_t ut03_single_sensor_read(IRPyro_sensor_device_type *IRPyro_test_Sensor)
Definition: IRPyro_UT.c:165
ut_wake_up_event
uint8_t ut_wake_up_event(IRPyro_sensor_device_type *IRPyro_test_Sensor)
Wake up event.
Definition: IRPyro_UT.c:336
ut_TO_CAN_read2
void ut_TO_CAN_read2(void)
Definition: IRPyro_UT.c:552
IRPyro_test_multiple_sensor_read_sample
static uint8_t IRPyro_test_multiple_sensor_read_sample(IRPyro_devices this_list, uint8_t list_size)
Given a list of devices collects a number of samples and determines lost frames.
Definition: IRPyro_UT.c:659
NUMBER_OF_FRAMES_TO_COUNT
#define NUMBER_OF_FRAMES_TO_COUNT
Definition: IRPyro_UT.h:38
CCP_compare
static uint8_t CCP_compare(CCP_reg_type first, CCP_reg_type second)
Compares CCP registers for equality.
Definition: IRPyro_UT.c:842
ut06_IOCTL01
uint8_t ut06_IOCTL01(IRPyro_sensor_device_type *IRPyro_test_Sensor)
Test of IOCTL functions.
Definition: IRPyro_UT.c:269
ut02_multiple_sensor_init
uint8_t ut02_multiple_sensor_init(IRPyro_devices this_list, uint8_t list_size)
Definition: IRPyro_UT.c:121
ut01_single_sensor_init
uint8_t ut01_single_sensor_init(IRPyro_sensor_device_type *IRPyro_test_Sensor)
Definition: IRPyro_UT.c:65
IOCTL01_TEST_NUMBER
#define IOCTL01_TEST_NUMBER
AFE_compare
static uint8_t AFE_compare(AFE_reg_type first, AFE_reg_type second)
Compares AFE registers for equality.
Definition: IRPyro_UT.c:820
WAKE_UP_EVENT_TEST_NUMBER
#define WAKE_UP_EVENT_TEST_NUMBER
IRPyro_FRAME_COUNT_LOCATION
#define IRPyro_FRAME_COUNT_LOCATION
Definition: IRPyro_UT.h:37
IRPyro_demo_board
void IRPyro_demo_board(uint8_t value)
Changes the state of all the CS lines as used on the IRPyro backplane board.
Definition: IRPyro_UT.c:619
ut_TO_CAN_read
void ut_TO_CAN_read(void)
Single TO-CAN read.
Definition: IRPyro_UT.c:537
WUP_compare
static uint8_t WUP_compare(WUP_reg_type first, WUP_reg_type second)
Compares WUP registers for equality.
Definition: IRPyro_UT.c:864
IRPyro_UT.h
IRPyro_FIFO_RESET_OK
#define IRPyro_FIFO_RESET_OK
Definition: IRPyro_UT.h:33
ut04_multiple_sensor_read
uint8_t ut04_multiple_sensor_read(IRPyro_devices this_list, uint8_t list_size)
Definition: IRPyro_UT.c:211
check_results
static uint8_t check_results(uint8_t *test_results, uint8_t number_of_tests)
Checks the results of a test for pass or fail by adding individual results.
Definition: IRPyro_UT.c:632
IRPyro_CCP_SIZE
#define IRPyro_CCP_SIZE
Definition: IRPyro_UT.h:36
wakeup_event_callback
static void wakeup_event_callback(void)
callback function
Definition: IRPyro_UT.c:904
IRPyro_FIFO_RESET
#define IRPyro_FIFO_RESET
Definition: IRPyro_UT.h:34
IRPyro_test_single_sensor_read_sample
static uint8_t IRPyro_test_single_sensor_read_sample(IRPyro_sensor_device_type *this_device)
IRPyro data collection for a number samples.
Definition: IRPyro_UT.c:750