Statistics
| Branch: | Tag: | Revision:

amiro-os / unittests / periphery-lld / src / ut_alld_VL53L0X_v1.c @ bf8ca9aa

History | View | Annotate | Download (21.511 KB)

1 a845d9eb Andre Raming
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  Thomas Schöpping et al.
4

5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14

15
You should have received a copy of the GNU General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#include <amiroos.h>
20
#include <ut_alld_VL53L0X_v1.h>
21
22
#if ((AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_VL53L0X) && (AMIROLLD_CFG_VL53L0X == 1)) || defined(__DOXYGEN__)
23
24
/******************************************************************************/
25
/* LOCAL DEFINITIONS                                                          */
26
/******************************************************************************/
27
28
#define INTERRUPT_EVENT_ID            1
29
30
/******************************************************************************/
31
/* EXPORTED VARIABLES                                                         */
32
/******************************************************************************/
33
34
/******************************************************************************/
35
/* LOCAL TYPES                                                                */
36
/******************************************************************************/
37
38
/******************************************************************************/
39
/* LOCAL VARIABLES                                                            */
40
/******************************************************************************/
41
42
/******************************************************************************/
43
/* LOCAL FUNCTIONS                                                            */
44
/******************************************************************************/
45
46
/******************************************************************************/
47
/* EXPORTED FUNCTIONS                                                         */
48
/******************************************************************************/
49
50
/**
51
 * @brief utAlldVL53L0XFunc
52
 * @param stream
53
 * @param ut
54
 * @return
55
 *
56
 *
57
 * debug:
58
 *  chprintf(stream, "timeout %lu\n", MyDevice.timeout); or chprintf((BaseSequentialStream*)&SD1, "%s: %d\n", __FILE__, __LINE__);
59
 *  aosThdMSleep(100);
60
 *
61
 *
62
 */
63
aos_utresult_t utAlldVL53L0XFunc(BaseSequentialStream* stream, aos_unittest_t* ut)
64
{
65
66
  // Check if the different things are here from the module.c
67
  aosDbgCheck((ut->data != NULL) &&
68
                (((ut_vl53l0xdata_t*)(ut->data))->vl53d != NULL) && (((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.i2cd != NULL);
69
70
  // local variables
71
  aos_utresult_t result = {0, 0};
72
  uint32_t status = APAL_STATUS_OK;
73
  uint8_t reg_buf[4] = {0,0,0,0};
74
  uint8_t* reg_8 = (uint8_t*)(reg_buf);
75
  uint16_t* reg_16 = (uint16_t*)(reg_buf);
76
  event_listener_t event_listener;
77
  aos_timestamp_t tcurrent, tend;
78
79
  VL53L0X_DeviceModes deviceMode;
80
  VL53L0X_GpioFunctionality pFunctionality;
81
  VL53L0X_InterruptPolarity pPolarity;
82
  uint8_t pMeasurementDataReady=0;
83
  VL53L0X_RangingMeasurementData_t    RangingMeasurementData;
84
  VL53L0X_RangingMeasurementData_t   *pRangingMeasurementData    = &RangingMeasurementData;
85
86
  uint32_t ThresholdLow;
87
  uint32_t ThresholdHigh;
88
89
  uint8_t buffer[24];
90
  memset(buffer, 0xAA, sizeof(buffer));
91
92
93
  chprintf(stream, "validate I2C bus...\n");
94
95
96
  // check I2C communication after fresh reset, without API loaded (before VL53L0X_DataInit() is called)
97
98
  //validate I2C bus on 0xC0 0xEE
99
  status = VL53L0X_read_multi((((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.i2cd, (apalI2Caddr_t)(((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.I2cDevAddr , 0xc0, &reg_8[0], 1, (((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.timeout );
100
  if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && reg_8[0]==0xEE) {
101
102 bf8ca9aa Andre Raming
      //validate I2C bus on 0xC1 0xAA
103
      status = VL53L0X_read_multi((((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.i2cd, (apalI2Caddr_t)(((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.I2cDevAddr , 0xc1, &reg_8[0], 1, (((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.timeout );
104
      if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && reg_8[0]==0xAA) {
105
106
          //validate I2C bus on 0xC2 0x10
107
          status = VL53L0X_read_multi((((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.i2cd, (apalI2Caddr_t)(((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.I2cDevAddr , 0xc2, &reg_8[0], 1, (((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.timeout );
108
          if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && reg_8[0]==0x10) {
109
110
              //validate I2C bus on  0x51 0x0099
111
              status = VL53L0X_read_multi((((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.i2cd, (apalI2Caddr_t)(((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.I2cDevAddr , 0x51, &reg_8[0], 2, (((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.timeout );
112
              if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && reg_8[0]==0x00 && reg_8[1]==0x99) {
113
                  //validate I2C bus on  0x61 0x0000
114
                  status = VL53L0X_read_multi((((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.i2cd, (apalI2Caddr_t)(((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.I2cDevAddr , 0x61, &reg_8[0], 2, (((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.timeout );
115
                  if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && reg_8[0]==0x00 && reg_8[1]==0x00) {
116
                    aosUtPassed(stream, &result);
117
                  } else {
118
                    aosUtFailedMsg(stream, &result, "0x%08X; 0x%08X\n", status, reg_8[0]);
119
                  }
120
              } else {
121
                aosUtFailedMsg(stream, &result, "0x%08X; 0x%08X\n", status, reg_8[0]);
122
              }
123
124
          } else {
125
            aosUtFailedMsg(stream, &result, "0x%08X; 0x%08X\n", status, reg_8[0]);
126
          }
127
128
      } else {
129
        aosUtFailedMsg(stream, &result, "0x%08X; 0x%08X\n", status, reg_8[0]);
130
      }
131 a845d9eb Andre Raming
132
  } else {
133
    aosUtFailedMsg(stream, &result, "0x%08X; 0x%08X\n", status, reg_8[0]);
134
  }
135
136
137
138 bf8ca9aa Andre Raming
139
140
141
142
143
144 a845d9eb Andre Raming
145
146
147
148
149
  chprintf(stream, "reading register...\n");
150
151
  //read register 0x88 register has status 0x24
152
  status = VL53L0X_read_multi((((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.i2cd, (apalI2Caddr_t)(((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.I2cDevAddr , 0x88, &reg_8[0], 1, (((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.timeout );
153
  if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && reg_8[0]==0x24) {
154
    aosUtPassed(stream, &result);
155
  } else {
156
    aosUtFailedMsg(stream, &result, "0x%08X; 0x%08X\n", status, reg_8[0]);
157
  }
158
159
160 bf8ca9aa Andre Raming
  chprintf(stream, "writing register (Byte)...\n");
161 a845d9eb Andre Raming
162
  //VL53L0X_WrByte(Dev, 0x88, 0x00);
163
  uint8_t tx_buf = 0x00;
164
  //status = VL53L0X_write_multi((((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.i2cd, (apalI2Caddr_t)(((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.I2cDevAddr, 0x88, (uint8_t*)&tx_buf, 1 ,(((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.timeout );
165
166
  status = VL53L0X_write_byte((((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.i2cd, (apalI2Caddr_t)(((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.I2cDevAddr, 0x88, tx_buf,(((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.timeout );
167
168
169
  if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING)) {
170
    aosUtPassed(stream, &result);
171
  } else {
172
    aosUtFailedMsg(stream, &result, "0x%08X; 0x%08X\n", status, reg_8[0]);
173
  }
174
175
176 bf8ca9aa Andre Raming
  chprintf(stream, "writing register (multi)...\n");
177 a845d9eb Andre Raming
178
  //read register 0x88
179
  status = VL53L0X_read_multi((((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.i2cd, (apalI2Caddr_t)(((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.I2cDevAddr , 0x88, &reg_8[0], 1, (((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.timeout );
180
  if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && reg_8[0]==0x00) {
181
    aosUtPassed(stream, &result);
182
  } else {
183
    aosUtFailedMsg(stream, &result, "0x%08X; 0x%08X\n", status, reg_8[0]);
184
  }
185
186
187
188
189
  chprintf(stream, "init sensor data...\n");
190
191
  status = vl53l0x_lld_init(((ut_vl53l0xdata_t*)(ut->data))->vl53d);
192
193
194
  if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING)) {
195
    aosUtPassed(stream, &result);
196
  } else {
197
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
198
  }
199
200
201
  chprintf(stream, "set single mode...\n");
202
203
  status = vl53l0x_lld_set_mode(((ut_vl53l0xdata_t*)(ut->data))->vl53d, VL53L0X_DEVICEMODE_SINGLE_RANGING,
204
                                VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_DISABLED,0,0);
205
206
207
  status |= VL53L0X_GetDeviceMode(&(((ut_vl53l0xdata_t*)(ut->data))->vl53d->vl53l0x_dev), &deviceMode);
208
209
210
  if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && deviceMode == VL53L0X_DEVICEMODE_SINGLE_RANGING) {
211
    aosUtPassed(stream, &result);
212
  } else {
213
    aosUtFailedMsg(stream, &result, "0x%08X; %u\n", status, deviceMode);
214
  }
215
216
  chprintf(stream, "reading results...\n");
217
218
  status = vl53l0x_lld_perform_mesaurement(((ut_vl53l0xdata_t*)(ut->data))->vl53d, &reg_16[0]);
219 bf8ca9aa Andre Raming
  chprintf(stream, "\t\tdistance : %u mm\n", reg_16[0]);
220 a845d9eb Andre Raming
  int i = 0;
221
  for (i = 0; i<4; i++){
222
      status |= vl53l0x_lld_perform_mesaurement(((ut_vl53l0xdata_t*)(ut->data))->vl53d, &reg_16[0]);
223
224 bf8ca9aa Andre Raming
      chprintf(stream, "\t\tdistance : %u mm\n", reg_16[0]);
225 a845d9eb Andre Raming
  }
226
227
  if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING)) {
228
    aosUtPassed(stream, &result);
229
  } else {
230
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
231
  }
232
233
234
235
  chprintf(stream, "setting new address...\n");
236
237
  status = vl53l0x_lld_set_address(((ut_vl53l0xdata_t*)(ut->data))->vl53d, 0x49);
238
239
240
  if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING)) {
241
    aosUtPassed(stream, &result);
242
  } else {
243
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
244
245
  }
246
  
247
  
248
  //-----------------------------------------------------------------------
249
250
251
252
  chprintf(stream, "reading with interrupt ...\n");
253
254
255
  chprintf(stream, "\tgeneral information: eventmask VL53L0X: %lu and eventflag VL53L0X: %lu \n",
256
           EVENT_MASK(INTERRUPT_EVENT_ID), ((ut_vl53l0xdata_t*)(ut->data))->evtflags);
257
258
  chprintf(stream, "set single mode and interrupt to VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY ...\n");
259
260
  status = vl53l0x_lld_set_mode(((ut_vl53l0xdata_t*)(ut->data))->vl53d, VL53L0X_DEVICEMODE_SINGLE_RANGING,
261
                                VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY,0,0);
262
263
264
265
  status |= VL53L0X_GetGpioConfig(&(((ut_vl53l0xdata_t*)(ut->data))->vl53d->vl53l0x_dev), 0, &deviceMode, &pFunctionality, &pPolarity);
266
267
  if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && deviceMode == VL53L0X_DEVICEMODE_SINGLE_RANGING &&
268 bf8ca9aa Andre Raming
          pFunctionality == VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY && pPolarity == VL53L0X_INTERRUPTPOLARITY_HIGH) {
269 a845d9eb Andre Raming
    aosUtPassed(stream, &result);
270
  } else {
271
    aosUtFailedMsg(stream, &result, "0x%08X; mode:%u; Interrupt:%u; InterruptPolarity: %u\n", status, deviceMode, pFunctionality, pPolarity);
272
  }
273
274
275
  chprintf(stream, "check for blocking interrupts...\n");
276
277
  status = vl53l0x_lld_CheckRangingDataReady(((ut_vl53l0xdata_t*)(ut->data))->vl53d, &pMeasurementDataReady);
278
279 bf8ca9aa Andre Raming
  status |= pcal6524_lld_read_group(((ut_vl53l0xdata_t*)ut->data)->gpio, PCAL6524_LLD_CMD_INPUT_P0, buffer,
280
                                  ((ut_vl53l0xdata_t*)ut->data)->timeout);
281
  switch (pcal6524_lld_cmd_groupsize(PCAL6524_LLD_CMD_INPUT_P0)) {
282
  case 1:
283
284
      break;
285
  case 2:
286
      break;
287
  case 3:
288
      chprintf(stream, "\t\tRead input: 0x%02X 0x%02X 0x%02X\t", buffer[0], buffer[1], buffer[2]);
289
      break;
290
  case 6:
291
      chprintf(stream, "\t\tRead input: 0x%04X 0x%04X 0x%04X\t",
292
               (((uint16_t)buffer[0]) << 8) | buffer[1],
293
               (((uint16_t)buffer[2]) << 8) | buffer[3],
294
               (((uint16_t)buffer[4]) << 8) | buffer[5]);
295
      break;
296
  default:
297
      break;
298
  }
299
300 a845d9eb Andre Raming
301
  if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && pMeasurementDataReady == 0) {
302
    aosUtPassed(stream, &result);
303
  } else {
304
    aosUtFailedMsg(stream, &result, "0x%08X, there are blocking interrupts :%u\n", status, pMeasurementDataReady);
305
    chprintf(stream, "clear blocking interrupts...\n");
306
307
    status = vl53l0x_lld_getRangingData(((ut_vl53l0xdata_t*)(ut->data))->vl53d, pRangingMeasurementData);
308
309
    if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING)) {
310
      aosUtPassed(stream, &result);
311
    } else {
312
      aosUtFailedMsg(stream, &result, "0x%08X;\n", status);
313
314
    }
315
316
  }
317
318
319
  chprintf(stream, "start maeasurement ... \n");
320
321
  //set everything for eventshandler
322
  chEvtRegister(((ut_vl53l0xdata_t*)(ut->data))->evtsource, &event_listener, INTERRUPT_EVENT_ID);
323
  aosSysGetUptime(&tend);
324
  tend += 2 * MICROSECONDS_PER_SECOND;
325
326
  status = vl53l0x_lld_start_measurement(((ut_vl53l0xdata_t*)(ut->data))->vl53d);
327
328
  if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING)) {
329
    aosUtPassed(stream, &result);
330
  } else {
331
    aosUtFailedMsg(stream, &result, "0x%08X;\n", status);
332
333
  }
334
335 bf8ca9aa Andre Raming
chprintf(stream, "Check for interrupts ... \n");
336 a845d9eb Andre Raming
  do {
337
    // read proximity data, interrupt event information and interrupt status
338 bf8ca9aa Andre Raming
    const eventmask_t emask = chEvtWaitOneTimeout(EVENT_MASK(INTERRUPT_EVENT_ID), chTimeUS2I(MICROSECONDS_PER_SECOND));
339 a845d9eb Andre Raming
    const eventflags_t eflags = chEvtGetAndClearFlags(&event_listener);
340
341
342
    if (emask == EVENT_MASK(INTERRUPT_EVENT_ID) &&
343
        eflags == ((ut_vl53l0xdata_t*)(ut->data))->evtflags) {
344
      // true positive (correct case)
345 bf8ca9aa Andre Raming
      chprintf(stream, "\t\tEVENT");
346
      status |= pcal6524_lld_read_group(((ut_vl53l0xdata_t*)ut->data)->gpio, PCAL6524_LLD_CMD_INPUT_P0, buffer,
347
                                      ((ut_vl53l0xdata_t*)ut->data)->timeout);
348
      status |= vl53l0x_lld_getRangingData(((ut_vl53l0xdata_t*)(ut->data))->vl53d, pRangingMeasurementData);
349 a845d9eb Andre Raming
350
351 bf8ca9aa Andre Raming
      switch (pcal6524_lld_cmd_groupsize(PCAL6524_LLD_CMD_INPUT_P0)) {
352
      case 1:
353 a845d9eb Andre Raming
354 bf8ca9aa Andre Raming
          break;
355
      case 2:
356
          break;
357
      case 3:
358
          chprintf(stream, "\tRead input: 0x%02X 0x%02X 0x%02X", buffer[0], buffer[1], buffer[2]);
359
          break;
360
      case 6:
361
          chprintf(stream, "\t\tRead input: 0x%04X 0x%04X 0x%04X",
362
                   (((uint16_t)buffer[0]) << 8) | buffer[1],
363
                   (((uint16_t)buffer[2]) << 8) | buffer[3],
364
                   (((uint16_t)buffer[4]) << 8) | buffer[5]);
365
          break;
366
      default:
367
          break;
368
      }
369
      chprintf(stream, "\tdistance = %i mm\n", RangingMeasurementData.RangeMilliMeter);
370 a845d9eb Andre Raming
371
372
373 bf8ca9aa Andre Raming
    }else{
374
        chprintf(stream, "\tNo Interrupt, last measurement = %i mm\n", (((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.Data.LastRangeMeasure.RangeMilliMeter);
375 a845d9eb Andre Raming
376
    }
377
378
379
    aosSysGetUptime(&tcurrent);
380
  } while (tcurrent < tend);
381
382
  if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING)) {
383
    aosUtPassed(stream, &result);
384
  } else {
385
    aosUtFailedMsg(stream, &result, "0x%08X; 0x%08X\n", status, pRangingMeasurementData);
386
387
  }
388
389
  chprintf(stream, "stop maeasurement ... \n");
390
391
  status = vl53l0x_lld_stop_measurement(((ut_vl53l0xdata_t*)(ut->data))->vl53d);
392
393
394
  chEvtUnregister(((ut_vl53l0xdata_t*)(ut->data))->evtsource, &event_listener);
395
396
  if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING)) {
397
    aosUtPassed(stream, &result);
398
  } else {
399
    aosUtFailedMsg(stream, &result, "0x%08X;\n", status);
400
401
  }
402
403
404
405
406
407
//-----------------------------------------------------
408
409
  chprintf(stream, "set continuous mode and interrupt to VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_OUT_OF_WINDOW (80mm/150mm) ...\n");
410
411
  // wand a threshold of 80
412
  // 100 mm < max Threshold von 254 mm
413
  ThresholdHigh = 150;
414
  ThresholdLow = 80;
415
416
  status = vl53l0x_lld_set_mode(((ut_vl53l0xdata_t*)(ut->data))->vl53d, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING,
417
                                VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_OUT_OF_WINDOW,ThresholdLow,ThresholdHigh);
418
419
  status |= VL53L0X_GetGpioConfig(&(((ut_vl53l0xdata_t*)(ut->data))->vl53d->vl53l0x_dev), 0, &deviceMode, &pFunctionality, &pPolarity);
420
  status |= VL53L0X_GetInterruptThresholds(&(((ut_vl53l0xdata_t*)(ut->data))->vl53d->vl53l0x_dev),
421
      VL53L0X_DEVICEMODE_CONTINUOUS_RANGING,
422
      &ThresholdLow, &ThresholdHigh);
423
424
  if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && deviceMode == VL53L0X_DEVICEMODE_CONTINUOUS_RANGING &&
425 bf8ca9aa Andre Raming
          pFunctionality == VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_OUT_OF_WINDOW && pPolarity == VL53L0X_INTERRUPTPOLARITY_HIGH){
426 a845d9eb Andre Raming
          //&& ThresholdLow == 80 * 65536 && ThresholdHigh == 150 * 65536) { not possible, only strange wrong values, e.g. Threshold low:1431655765;Threshold high:0
427
    aosUtPassed(stream, &result);
428
  } else {
429
    aosUtFailedMsg(stream, &result, "0x%08X; mode:%u; Interrupt:%u; InterruptPolarity:%u; Threshold low:%lu"
430
                                    ";Threshold high:%lu\n", status, deviceMode, pFunctionality, pPolarity, ThresholdLow/65536.0, ThresholdHigh/65536.0);
431
  }
432
433
  chprintf(stream, "check for blocking interrupts...\n");
434
435
  status = vl53l0x_lld_CheckRangingDataReady(((ut_vl53l0xdata_t*)(ut->data))->vl53d, &pMeasurementDataReady);
436
437 bf8ca9aa Andre Raming
  status |= pcal6524_lld_read_group(((ut_vl53l0xdata_t*)ut->data)->gpio, PCAL6524_LLD_CMD_INPUT_P0, buffer,
438
                                  ((ut_vl53l0xdata_t*)ut->data)->timeout);
439
  switch (pcal6524_lld_cmd_groupsize(PCAL6524_LLD_CMD_INPUT_P0)) {
440
  case 1:
441
442
      break;
443
  case 2:
444
      break;
445
  case 3:
446
      chprintf(stream, "\t\tRead input: 0x%02X 0x%02X 0x%02X\t", buffer[0], buffer[1], buffer[2]);
447
      break;
448
  case 6:
449
      chprintf(stream, "\t\tRead input: 0x%04X 0x%04X 0x%04X\t",
450
               (((uint16_t)buffer[0]) << 8) | buffer[1],
451
               (((uint16_t)buffer[2]) << 8) | buffer[3],
452
               (((uint16_t)buffer[4]) << 8) | buffer[5]);
453
      break;
454
  default:
455
      break;
456
  }
457 a845d9eb Andre Raming
458
  if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && pMeasurementDataReady == 0) {
459
    aosUtPassed(stream, &result);
460
  } else {
461
    aosUtFailedMsg(stream, &result, "0x%08X, there are blocking interrupts :%u\n", status, pMeasurementDataReady);
462
    chprintf(stream, "clear blocking interrupts...\n");
463
464 bf8ca9aa Andre Raming
465 a845d9eb Andre Raming
    status = vl53l0x_lld_getRangingData(((ut_vl53l0xdata_t*)(ut->data))->vl53d, pRangingMeasurementData);
466
467
    if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING)) {
468
      aosUtPassed(stream, &result);
469
    } else {
470
      aosUtFailedMsg(stream, &result, "0x%08X;\n", status);
471
472
    }
473
474
  }
475
476
  chprintf(stream, "start maeasurement ... \n");
477
478
479
  //set everything for eventshandler
480
  chEvtRegister(((ut_vl53l0xdata_t*)(ut->data))->evtsource, &event_listener, INTERRUPT_EVENT_ID);
481
  aosSysGetUptime(&tend);
482
  tend += 10 * MICROSECONDS_PER_SECOND;
483
484
  status = vl53l0x_lld_start_measurement(((ut_vl53l0xdata_t*)(ut->data))->vl53d);
485
486
  do {
487
    // read proximity data, interrupt event information and interrupt status
488 bf8ca9aa Andre Raming
    const eventmask_t emask = chEvtWaitOneTimeout(EVENT_MASK(INTERRUPT_EVENT_ID), chTimeUS2I(MICROSECONDS_PER_SECOND));
489 a845d9eb Andre Raming
    const eventflags_t eflags = chEvtGetAndClearFlags(&event_listener);
490
491
    if (emask == EVENT_MASK(INTERRUPT_EVENT_ID) &&
492
        eflags == ((ut_vl53l0xdata_t*)(ut->data))->evtflags) {
493
      // true positive (correct case)
494 bf8ca9aa Andre Raming
      chprintf(stream, "\t\tEVENT");
495
      // read from GPIO
496
      status |= pcal6524_lld_read_group(((ut_vl53l0xdata_t*)ut->data)->gpio, PCAL6524_LLD_CMD_INPUT_P0, buffer,
497
                                      ((ut_vl53l0xdata_t*)ut->data)->timeout);
498
      switch (pcal6524_lld_cmd_groupsize(PCAL6524_LLD_CMD_INPUT_P0)) {
499
      case 1:
500
501
          break;
502
      case 2:
503
          break;
504
      case 3:
505
          chprintf(stream, "\tRead input: 0x%02X 0x%02X 0x%02X\t", buffer[0], buffer[1], buffer[2]);
506
          break;
507
      case 6:
508
          chprintf(stream, "\t\tRead input: 0x%04X 0x%04X 0x%04X\t",
509
                   (((uint16_t)buffer[0]) << 8) | buffer[1],
510
                   (((uint16_t)buffer[2]) << 8) | buffer[3],
511
                   (((uint16_t)buffer[4]) << 8) | buffer[5]);
512
          break;
513
      default:
514
          break;
515
      }
516
      status |= vl53l0x_lld_getRangingData(((ut_vl53l0xdata_t*)(ut->data))->vl53d, pRangingMeasurementData);
517
518
519
      chprintf(stream, "distance = %i mm\n", RangingMeasurementData.RangeMilliMeter);
520 a845d9eb Andre Raming
      status |= VL53L0X_ClearInterruptMask(&(((ut_vl53l0xdata_t*)(ut->data))->vl53d->vl53l0x_dev),0);
521 bf8ca9aa Andre Raming
    }else{
522
      chprintf(stream, "\tNo Interrupt, last measurement = %i mm\n", (((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.Data.LastRangeMeasure.RangeMilliMeter);
523 a845d9eb Andre Raming
    }
524
525
    aosSysGetUptime(&tcurrent);
526
  } while (tcurrent < tend);
527
528
  if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING)) {
529
    aosUtPassed(stream, &result);
530
  } else {
531
    aosUtFailedMsg(stream, &result, "0x%08X; 0x%08X\n", status, pRangingMeasurementData);
532
533
  }
534
535
  chprintf(stream, "stop maeasurement ... \n");
536
537
  status = vl53l0x_lld_stop_measurement(((ut_vl53l0xdata_t*)(ut->data))->vl53d);
538
539
540
  chEvtUnregister(((ut_vl53l0xdata_t*)(ut->data))->evtsource, &event_listener);
541
542
  if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING)) {
543
    aosUtPassed(stream, &result);
544
  } else {
545
    aosUtFailedMsg(stream, &result, "0x%08X;\n", status);
546
547
  }
548
549
550
551
  chprintf(stream, "setting default address...\n");
552
553
  status = vl53l0x_lld_set_address(((ut_vl53l0xdata_t*)(ut->data))->vl53d, 0x29);
554
555
556
  aosUtInfoMsg(stream, "driver object memory footprint: %u bytes\n", sizeof(VL53L0XDriver));
557
558
  return result;
559
}
560
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_VL53L0X) && (AMIROLLD_CFG_VL53L0X == 1) */