IRPyro TO unit test console using the IRPyro API
Functions for single and multiple sensor configurations in a Unit test format
IRPyro_UT_HL_for_TO.c
Go to the documentation of this file.
1 /**
2 ******************************************************************************
3 * @file IRPyro_UT_HL_for_TO.c
4 * @author _KEMET, Ltd
5 * @date March 2018
6 * @version Release 1.0.0
7 * @copyright (c) 2018 _KEMET, Ltd
8 * @brief High 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 /* Includes ------------------------------------------------------------------*/
30 #include "IRPyro_UT.h"
31 void TO_test01(void);
32 void TO_test02(void);
33 void TO_test03(void);
34 void TO_test04(void);
35 void TO_test05(void);
36 void TO_test06(void);
37 void TO_test07(void);
38 static void sensor_power_stabilize(void);
39 /** @defgroup IRPyroAPI_UnitTest_HL High level unit test module
40  * @brief Configure the IRPyro sensors to test and calls the functions defined in IRPyroUT.c
41  * @{
42  */
43 /** @defgroup UT_01_IRPyro Main function
44  * @brief Calls the product verification plan units
45  * Each function validates a point of the product verification plan
46  * @note Refer to PSVP017 (product verification specification) document on the engineering section.
47  * @{
48  */
49 /**
50  * @brief unit testing main program.
51  */
52 int main()
53 {
54  /*-------------------------- board setup ---------------------------------*/
55  Micro_controller_template_init();
57  // turn off all CS lines
59  /*-------------------------- start test ----------------------------------*/
60  /*Single Sensor Test */
61 // TO_test01(); // 01 Initialize a single device for POLLED CONFIGURATION
62 // TO_test03(); // 03 READ DATA FROM A SINGLE SENSOR and detect frames missing with the sensor CONFIGURED FOR POLLED
63 // TO_test05(); // 05 Change sensor POWER CONFIGURATION
64 // TO_test06(); // 06 Configure sensor WAKE UP EVENT, SEND TO SLEEP, DETECT WAKE UP
65 // TO_test07(); // 07 Change PARAMETERS on the fly
66 
67  /*Multiple Sensor Test */
68 // TO_test02(); // 02 Initialize multiple devices for POLLED CONFIGURATION
69  TO_test04(); // 04 READ DATA FROM MULTIPLE SENSORS and detect frames missing with the sensors CONFIGURED FOR POLLED
70 }
71 /** end of main program
72  * @}
73  */
74 /** @defgroup ver_plan Verification plan functions
75  * @brief each function configures the required data structures to pass to the
76  * unit test functions
77  * @{
78  */
79 /**
80  * @brief Configures the registers of a single IRPyro TO and then read back again.
81  * @attention Set your serial terminal console with the following parameters:
82  * @verbatim
83  * Baud Rate: 921600
84  * Parity: None
85  * Data Bits: 8
86  * Stop Bits: 1
87  * Hardware Flow Control: None
88  * Software Flow Control: None
89  * @endverbatim
90  * The function sends the result of the operation to the serial console
91  */
92 void TO_test01(void)
93 {
94  /*------------------ Memory allocation, initialization-------------------*/
95  IRPyro_sensor_device_type IRPyro_single_sensor = {0}; // Instance of sensor
96  /*-------------------Physical Location ----------------------------------*/
97  IRPyro_single_sensor.INT_Port = 1;
98  IRPyro_single_sensor.CS_Port = 2;
99  IRPyro_single_sensor.CS_Pin = 1;
100  IRPyro_single_sensor.INT_Pin = 4;
101  /*-------------------Test configuration ---------------------------------*/
102  IRPyro_single_sensor.number_of_active_channels = 1; // configures channel 2 for streaming
103  IRPyro_single_sensor.read_mode = 1; // POLLED CONFIGURATION
104  IRPyro_single_sensor.address = 0x08; // I2C address to configure
105  /*-------------------------- board setup ---------------------------------*/
108  UART_PutString(USART2, (uint8_t*)"01 IRPyro TO: Initialize a single device \n");
109  ut01_single_sensor_init(&IRPyro_single_sensor);
110 }
111 /**
112  * @brief Configures a list of IRPyro TO. The configuration data is read from the sensors and compared.
113  * @attention Set your serial terminal console with the following parameters:
114  * @verbatim
115  * Baud Rate: 921600
116  * Parity: None
117  * Data Bits: 8
118  * Stop Bits: 1
119  * Hardware Flow Control: None
120  * Software Flow Control: None
121  * @endverbatim
122  * The function sends the result of the operation to the serial console
123  */
124 void TO_test02(void)
125 {
126  /*------------------- Memory allocation, initialization ------------------*/
127  IRPyro_devices IRPyro_device = {0};
128  /*----------------------- --- CONFIGURATION ----- -----------------------*/
129  AFE_reg_type IRPyro_AFE_configuration =
130  {
131  .CLK_OUT = CLK_DISABLE,
132  .INT = INT_DISABLE
133  };
134  /*----------------- ADDRESSES ------------*/
135  /* Assuming four sensors on an IRPyro Break out board or demo board*/
136  IRPyro_device[0].INT_Port = 1;
137  IRPyro_device[0].CS_Port = 2;
138  IRPyro_device[0].CS_Pin = 1;
139  IRPyro_device[0].INT_Pin = 4;
140  IRPyro_device[0].address = 0x70;
141 
142  IRPyro_device[1].CS_Port = 2;
143  IRPyro_device[1].INT_Port = 1;
144  IRPyro_device[1].CS_Pin = 5;
145  IRPyro_device[1].INT_Pin = 5;
146  IRPyro_device[1].address = 0x69;
147 
148  IRPyro_device[2].CS_Port = 2;
149  IRPyro_device[2].INT_Port = 1;
150  IRPyro_device[2].CS_Pin = 4;
151  IRPyro_device[2].INT_Pin = 6;
152  IRPyro_device[2].address = 0x68;
153 
154  /*----------------- CONFIGURATION ------------*/
155  IRPyro_device[0].AFE_register = IRPyro_AFE_configuration; // MASTER, INT, CLK DISABLED
156  IRPyro_device[0].number_of_active_channels = 1; // configures channel 2 for streaming
157  IRPyro_device[0].read_mode = 1;
158  IRPyro_device[1].AFE_register = IRPyro_AFE_configuration; // MASTER, INT, CLK DISABLED
159  IRPyro_device[1].number_of_active_channels = 1; // configures channel 2 for streaming
160  IRPyro_device[1].read_mode = 1;
161  IRPyro_device[2].AFE_register = IRPyro_AFE_configuration; // MASTER, INT, CLK DISABLED
162  IRPyro_device[2].number_of_active_channels = 1; // configures channel 2 for streaming
163  IRPyro_device[2].read_mode = 1;
166  UART_PutString(USART2, (uint8_t*)"02 IRPyro TO: Initialize multiple devices \n");
167  ut02_multiple_sensor_init(IRPyro_device, 3);
168 }
169 /**
170  * @brief Configures a single IRPyro TO for data streaming and verifies if any frame is missing
171  * One hour of data is read from the sensor. Each frame counter received is compared
172  * with the previous. A missing frame is detected when both numbers are NOT CONSECUTIVE.
173  * This event is counted.
174  * @attention Set your serial terminal console with the following parameters:
175  * @verbatim
176  * Baud Rate: 921600
177  * Parity: None
178  * Data Bits: 8
179  * Stop Bits: 1
180  * Hardware Flow Control: None
181  * Software Flow Control: None
182  * @endverbatim
183  * The function sends the result of the operation to the serial console
184  */
185 void TO_test03(void)
186 {
187  /*------------------ Memory allocation, initialization-------------------*/
188  IRPyro_sensor_device_type IRPyro_single_sensor = {0}; // Instance of sensor
189  /*-------------------Physical Location ----------------------------------*/
190  IRPyro_single_sensor.INT_Port = 1;
191  IRPyro_single_sensor.CS_Port = 2;
192  IRPyro_single_sensor.CS_Pin = 1;
193  IRPyro_single_sensor.INT_Pin = 4;
194  /*-------------------Test configuration ---------------------------------*/
195  IRPyro_single_sensor.number_of_active_channels = 1; // configures channel 2 for streaming
196  IRPyro_single_sensor.read_mode = 1; // Polled mode reading
197  IRPyro_single_sensor.address = 0x08; // I2C address to configure
198  /*-------------------------- board setup ---------------------------------*/
201  UART_PutString(USART2, (uint8_t*)"03 IRPyro TO: READ DATA FROM A SINGLE IRPyro TO SENSOR and detect frames missing\n");
202  ut03_single_sensor_read(&IRPyro_single_sensor);
203 }
204 /**
205  * @brief A maximum of three IRPyro TO sensors are configured for data read with frame counter detection
206 configured. One hour of data is read from the sensors. Each frame counter received
207 is compared with the previous. A missing frame is detected when both numbers are
208 NOT CONSECUTIVE. This event is counted.
209  * @attention Set your serial terminal console with the following parameters:
210  * @verbatim
211  * Baud Rate: 921600
212  * Parity: None
213  * Data Bits: 8
214  * Stop Bits: 1
215  * Hardware Flow Control: None
216  * Software Flow Control: None
217  * @endverbatim
218  * The function sends the result of the operation to the serial console
219  */
220 void TO_test04(void)
221 {
222 
223  /*------------------- Memory allocation, initialization ------------------*/
224  IRPyro_devices IRPyro_device = {0};
225  /*----------------------- --- CONFIGURATION ----- -----------------------*/
226  AFE_reg_type IRPyro_AFE_Master =
227  {
228  .S7_S0 = 0,
229  .LP = LOW_POWER_DISABLE,
230  .HP = HP_DISABLE,
231  .C_LP = LOW_PASS_22_5,
232  .CLK_OUT = CLK_DISABLE,
233  .SYNC = MASTER,
234  .TEMP = 0,
235  .INT = INT_DISABLE
236  };
237  /*----------------- ADDRESSES ------------*/
238  /* Assuming four sensors on an IRPyro Break out board or demo board*/
239  IRPyro_device[0].INT_Port = 1;
240  IRPyro_device[0].CS_Port = 2;
241  IRPyro_device[0].CS_Pin = 1;
242  IRPyro_device[0].INT_Pin = 4;
243  IRPyro_device[0].address = 0x70;
244 
245  IRPyro_device[1].CS_Port = 2;
246  IRPyro_device[1].INT_Port = 1;
247  IRPyro_device[1].CS_Pin = 5;
248  IRPyro_device[1].INT_Pin = 5;
249  IRPyro_device[1].address = 0x69;
250 
251  IRPyro_device[2].CS_Port = 2;
252  IRPyro_device[2].INT_Port = 1;
253  IRPyro_device[2].CS_Pin = 4;
254  IRPyro_device[2].INT_Pin = 6;
255  IRPyro_device[2].address = 0x68;
256 
257  /*----------------- CONFIGURATION ------------*/
258  IRPyro_device[0].AFE_register = IRPyro_AFE_Master; // MASTER, INT, CLK DISABLED
259  IRPyro_device[0].read_mode = 1;
260  IRPyro_device[0].number_of_active_channels = 1;
261 
262  IRPyro_device[1].AFE_register = IRPyro_AFE_Master; // MASTER, INT, CLK DISABLED
263  IRPyro_device[1].read_mode = 1;
264  IRPyro_device[1].number_of_active_channels = 1;
265 
266  IRPyro_device[2].AFE_register = IRPyro_AFE_Master; // MASTER, INT, CLK DISABLED
267  IRPyro_device[2].read_mode = 1;
268  IRPyro_device[2].number_of_active_channels = 1;
269 
272  UART_PutString(USART2, (uint8_t*)"04 IRPyro TO: READ DATA FROM MULTIPLE SENSORS and detect frames missing\n");
273  ut04_multiple_sensor_read(IRPyro_device, 3);
274 }
275 /**
276  * @brief Change register settings of a single IRPyro TO
277 The following API commands are issued: sampling_rate_set, sampling_rate_get, high_pass_set,
278 high_pass_get, low_pass_set, low_pass_get, gain_set, and gain_get, power_off.
279 A sample of readings is taken and the behaviour of the sensor is observed.
280  * @attention Set your serial terminal console with the following parameters:
281  * @verbatim
282  * Baud Rate: 921600
283  * Parity: None
284  * Data Bits: 8
285  * Stop Bits: 1
286  * Hardware Flow Control: None
287  * Software Flow Control: None
288  * @endverbatim
289  * The function sends the result of the operation to the serial console
290 
291  */
292 void TO_test05(void)
293 {
294  /*------------------ Memory allocation, initialization-------------------*/
295  IRPyro_sensor_device_type IRPyro_single_sensor = {0}; // Instance of sensor
296  /*-------------------Physical Location ----------------------------------*/
297  IRPyro_single_sensor.INT_Port = 1;
298  IRPyro_single_sensor.CS_Port = 2;
299  IRPyro_single_sensor.CS_Pin = 1;
300  IRPyro_single_sensor.INT_Pin = 4;
301  /*-------------------Test configuration ---------------------------------*/
302  IRPyro_single_sensor.read_mode = 2; // DAISY CHAIN CONFIGURATION
303  IRPyro_single_sensor.address = 0x08; // I2C address to configure
304  IRPyro_single_sensor.number_of_active_channels = 1; // configures channel 2 for streaming
305  /*-------------------------- board setup ---------------------------------*/
308  UART_PutString(USART2, (uint8_t*)"05 IRPyro TO: Change sensor POWER CONFIGURATION\n");
309  ut06_IOCTL02(&IRPyro_single_sensor);
310 }
311 /**
312  * @brief Send a single IRPyro TO to sleep and then wake up by command
313 The following API commands are issued: power_sleep, and power_wakeup. A sample of
314 readings is taken and the behaviour of the sensor is observed.
315  * @attention Set your serial terminal console with the following parameters:
316  * @verbatim
317  * Baud Rate: 921600
318  * Parity: None
319  * Data Bits: 8
320  * Stop Bits: 1
321  * Hardware Flow Control: None
322  * Software Flow Control: None
323  * @endverbatim
324  * The function sends the result of the operation to the serial console
325  */
326 void TO_test06(void)
327 {
328 // wake command response
329  /* The sensor is configured to sleep and on a wake up event alerts the MCU and
330  * data is read a more elaborate scenario is putting the MCU to sleep and the
331  * sensor wakes the device up.
332  */
333  /*------------------ Memory allocation, initialization-------------------*/
334  IRPyro_sensor_device_type IRPyro_single_sensor = {0}; // Instance of sensor
335  /*-------------------Physical Location ----------------------------------*/
336  IRPyro_single_sensor.INT_Port = 1;
337  IRPyro_single_sensor.CS_Port = 2;
338  IRPyro_single_sensor.CS_Pin = 1;
339  IRPyro_single_sensor.INT_Pin = 4;
340  /*-------------------Test configuration ---------------------------------*/
341  IRPyro_single_sensor.read_mode = 2; // DAISY CHAIN CONFIGURATION
342  IRPyro_single_sensor.address = 0x70; // I2C address to configure
343  IRPyro_single_sensor.number_of_active_channels = 1; // configures channel 2 for streaming
344  /*------------------- Wake up event definition -------------------------*/
345  IRPyro_single_sensor.WUP_register.UHT = MAX_WUP_THRESHOLD;
346  IRPyro_single_sensor.WUP_register.ULT = SAFE_WUP_THRESHOLD;
347  IRPyro_single_sensor.WUP_register.LHT = MIN_WUP_THRESHOLD;
348  IRPyro_single_sensor.WUP_register.LLT = MIN_WUP_THRESHOLD;
349  IRPyro_single_sensor.WUP_register.WT_Threshold = DEFAULT_NO_EVENTS;
350  IRPyro_single_sensor.WUP_register.DP0_DP2 = SEL_CH_2;
351  IRPyro_single_sensor.WUP_register.CH0_CH2 = SEL_CH_2;
352  IRPyro_single_sensor.WUP_register.ST = SLEEP_MODE_ONE_CH; // Single channel selected
353  /*-------------------------- board setup --------------------------------*/
356  UART_PutString(USART2, (uint8_t*)"06 IRPyro TO: Configure sensor WAKE UP EVENT, SEND TO SLEEP, DETECT WAKE UP \n");
357  ut_wake_up_event(&IRPyro_single_sensor);
358 }
359 /**
360  * @brief Turn OFF and ON a single IRPyro TO with parameters restored
361 The following API commands are issued: power_off, power_normal, and power_low. A
362 sample of readings is taken and the behavior of the sensor is observed.
363  * @attention Set your serial terminal console with the following parameters:
364  * @verbatim
365  * Baud Rate: 921600
366  * Parity: None
367  * Data Bits: 8
368  * Stop Bits: 1
369  * Hardware Flow Control: None
370  * Software Flow Control: None
371  * @endverbatim
372  * The function sends the result of the operation to the serial console
373  */
374 void TO_test07(void)
375 {
376  /*------------------ Memory allocation, initialization-------------------*/
377  IRPyro_sensor_device_type IRPyro_single_sensor = {0}; // Instance of sensor
378  /*-------------------Physical Location ----------------------------------*/
379  IRPyro_single_sensor.INT_Port = 1;
380  IRPyro_single_sensor.CS_Port = 2;
381  IRPyro_single_sensor.CS_Pin = 1;
382  IRPyro_single_sensor.INT_Pin = 4;
383  /*-------------------Test configuration ---------------------------------*/
384  IRPyro_single_sensor.read_mode = 2; // DAISY CHAIN CONFIGURATION
385  IRPyro_single_sensor.address = 0x08; // I2C address to configure
386  IRPyro_single_sensor.number_of_active_channels = 1; // configures channel 2 for streaming
387  /*-------------------------- board setup ---------------------------------*/
390  UART_PutString(USART2, (uint8_t*)"07 IRPyro TO: Change PARAMETERS on the fly\n");
391  ut06_IOCTL01(&IRPyro_single_sensor);
392 }
393 /**
394  * @brief Changes the state of all the CS lines as used on the IRPyro backplane board
395  * @param state 0 disabled / 1 enabled
396  */
398 {
399  CS_pin_set(2,1,state);
400  CS_pin_set(2,3,state);
401  CS_pin_set(2,4,state);
402  CS_pin_set(2,5,state);
403 }
404 /**
405  * @brief power cycles the sensors on the board to assure stability
406 */
408 {
409  // toggle all CS lines
411  Micro_controller_delay_ms(30);
413  Micro_controller_delay_ms(30);
415 }
416 /** end of Verification plan functions
417  * @}
418  */
419 /** end of High Level Unit Test module
420  * @}
421  */
422 /* ********** Copyright (c) 2018 _KEMET, Ltd. **********END OF FILE************/
uint8_t ut02_multiple_sensor_init(IRPyro_devices this_list, uint8_t list_size)
Unit Testing module.
void TO_test02(void)
Configures a list of IRPyro TO. The configuration data is read from the sensors and compared...
uint8_t ut03_single_sensor_read(IRPyro_sensor_device_type *IRPyro_TEST_Sensor)
uint8_t ut01_single_sensor_init(IRPyro_sensor_device_type *IRPyro_TEST_Sensor)
uint8_t ut_wake_up_event(IRPyro_sensor_device_type *IRPyro_test_Sensor)
Wake up event.
void IRPyro_demo_board(uint8_t value)
Changes the state of all the CS lines as used on the IRPyro backplane board.
uint8_t ut06_IOCTL02(IRPyro_sensor_device_type *IRPyro_test_Sensor)
void TO_test06(void)
Send a single IRPyro TO to sleep and then wake up by command The following API commands are issued: p...
void demo_board_sensor_control(int state)
Changes the state of all the CS lines as used on the IRPyro backplane board.
uint8_t ut06_IOCTL01(IRPyro_sensor_device_type *IRPyro_test_Sensor)
Test of IOCTL functions.
static void sensor_power_stabilize(void)
power cycles the sensors on the board to assure stability
void TO_test03(void)
Configures a single IRPyro TO for data streaming and verifies if any frame is missing One hour of dat...
int main()
unit testing main program.
void TO_test04(void)
A maximum of three IRPyro TO sensors are configured for data read with frame counter detection config...
void TO_test05(void)
Change register settings of a single IRPyro TO The following API commands are issued: sampling_rate_s...
void TO_test01(void)
Configures the registers of a single IRPyro TO and then read back again.
uint8_t ut04_multiple_sensor_read(IRPyro_devices this_list, uint8_t list_size)
void TO_test07(void)
Turn OFF and ON a single IRPyro TO with parameters restored The following API commands are issued: po...