amiro-os / unittests / periphery-lld / src / ut_alld_VL53L0X_v1.c @ a845d9eb
History | View | Annotate | Download (21.196 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, ®_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 | aosUtPassed(stream, &result); |
||
102 | } else {
|
||
103 | aosUtFailedMsg(stream, &result, "0x%08X; 0x%08X\n", status, reg_8[0]); |
||
104 | } |
||
105 | |||
106 | |||
107 | //validate I2C bus on 0xC1 0xAA
|
||
108 | 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, ®_8[0], 1, (((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.timeout ); |
||
109 | if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && reg_8[0]==0xAA) { |
||
110 | aosUtPassed(stream, &result); |
||
111 | } else {
|
||
112 | aosUtFailedMsg(stream, &result, "0x%08X; 0x%08X\n", status, reg_8[0]); |
||
113 | } |
||
114 | |||
115 | //validate I2C bus on 0xC2 0x10
|
||
116 | 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, ®_8[0], 1, (((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.timeout ); |
||
117 | if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && reg_8[0]==0x10) { |
||
118 | aosUtPassed(stream, &result); |
||
119 | } else {
|
||
120 | aosUtFailedMsg(stream, &result, "0x%08X; 0x%08X\n", status, reg_8[0]); |
||
121 | } |
||
122 | |||
123 | //validate I2C bus on 0x51 0x0099
|
||
124 | 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, ®_8[0], 2, (((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.timeout ); |
||
125 | if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && reg_8[0]==0x00 && reg_8[1]==0x99) { |
||
126 | aosUtPassed(stream, &result); |
||
127 | } else {
|
||
128 | aosUtFailedMsg(stream, &result, "0x%08X; 0x%08X\n", status, reg_8[0]); |
||
129 | } |
||
130 | |||
131 | //validate I2C bus on 0x61 0x0000
|
||
132 | 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, ®_8[0], 2, (((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.timeout ); |
||
133 | if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && reg_8[0]==0x00 && reg_8[1]==0x00) { |
||
134 | aosUtPassed(stream, &result); |
||
135 | } else {
|
||
136 | aosUtFailedMsg(stream, &result, "0x%08X; 0x%08X\n", status, reg_8[0]); |
||
137 | } |
||
138 | |||
139 | |||
140 | |||
141 | |||
142 | |||
143 | chprintf(stream, "reading register...\n");
|
||
144 | |||
145 | //read register 0x88 register has status 0x24
|
||
146 | 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, ®_8[0], 1, (((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.timeout ); |
||
147 | if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && reg_8[0]==0x24) { |
||
148 | aosUtPassed(stream, &result); |
||
149 | } else {
|
||
150 | aosUtFailedMsg(stream, &result, "0x%08X; 0x%08X\n", status, reg_8[0]); |
||
151 | } |
||
152 | |||
153 | |||
154 | chprintf(stream, "writing register...\n");
|
||
155 | |||
156 | //VL53L0X_WrByte(Dev, 0x88, 0x00);
|
||
157 | uint8_t tx_buf = 0x00;
|
||
158 | //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 );
|
||
159 | |||
160 | 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 );
|
||
161 | |||
162 | |||
163 | if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING)) {
|
||
164 | aosUtPassed(stream, &result); |
||
165 | } else {
|
||
166 | aosUtFailedMsg(stream, &result, "0x%08X; 0x%08X\n", status, reg_8[0]); |
||
167 | } |
||
168 | |||
169 | |||
170 | |||
171 | //read register 0x88
|
||
172 | 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, ®_8[0], 1, (((ut_vl53l0xdata_t*)(ut->data))->vl53d)->vl53l0x_dev.timeout ); |
||
173 | if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && reg_8[0]==0x00) { |
||
174 | aosUtPassed(stream, &result); |
||
175 | } else {
|
||
176 | aosUtFailedMsg(stream, &result, "0x%08X; 0x%08X\n", status, reg_8[0]); |
||
177 | } |
||
178 | |||
179 | |||
180 | |||
181 | |||
182 | chprintf(stream, "init sensor data...\n");
|
||
183 | |||
184 | status = vl53l0x_lld_init(((ut_vl53l0xdata_t*)(ut->data))->vl53d); |
||
185 | |||
186 | |||
187 | if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING)) {
|
||
188 | aosUtPassed(stream, &result); |
||
189 | } else {
|
||
190 | aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
||
191 | } |
||
192 | |||
193 | |||
194 | chprintf(stream, "set single mode...\n");
|
||
195 | |||
196 | status = vl53l0x_lld_set_mode(((ut_vl53l0xdata_t*)(ut->data))->vl53d, VL53L0X_DEVICEMODE_SINGLE_RANGING, |
||
197 | VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_DISABLED,0,0); |
||
198 | |||
199 | |||
200 | status |= VL53L0X_GetDeviceMode(&(((ut_vl53l0xdata_t*)(ut->data))->vl53d->vl53l0x_dev), &deviceMode); |
||
201 | |||
202 | |||
203 | if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && deviceMode == VL53L0X_DEVICEMODE_SINGLE_RANGING) {
|
||
204 | aosUtPassed(stream, &result); |
||
205 | } else {
|
||
206 | aosUtFailedMsg(stream, &result, "0x%08X; %u\n", status, deviceMode);
|
||
207 | } |
||
208 | |||
209 | chprintf(stream, "reading results...\n");
|
||
210 | |||
211 | status = vl53l0x_lld_perform_mesaurement(((ut_vl53l0xdata_t*)(ut->data))->vl53d, ®_16[0]);
|
||
212 | chprintf(stream, "\t\tdistance : %u\n", reg_16[0]); |
||
213 | int i = 0; |
||
214 | for (i = 0; i<4; i++){ |
||
215 | status |= vl53l0x_lld_perform_mesaurement(((ut_vl53l0xdata_t*)(ut->data))->vl53d, ®_16[0]);
|
||
216 | |||
217 | chprintf(stream, "\t\tdistance : %u\n", reg_16[0]); |
||
218 | } |
||
219 | |||
220 | if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING)) {
|
||
221 | aosUtPassed(stream, &result); |
||
222 | } else {
|
||
223 | aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
||
224 | } |
||
225 | |||
226 | |||
227 | |||
228 | chprintf(stream, "setting new address...\n");
|
||
229 | |||
230 | status = vl53l0x_lld_set_address(((ut_vl53l0xdata_t*)(ut->data))->vl53d, 0x49);
|
||
231 | |||
232 | |||
233 | if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING)) {
|
||
234 | aosUtPassed(stream, &result); |
||
235 | } else {
|
||
236 | aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
||
237 | |||
238 | } |
||
239 | |||
240 | |||
241 | //-----------------------------------------------------------------------
|
||
242 | |||
243 | |||
244 | |||
245 | chprintf(stream, "reading with interrupt ...\n");
|
||
246 | |||
247 | |||
248 | chprintf(stream, "\tgeneral information: eventmask VL53L0X: %lu and eventflag VL53L0X: %lu \n",
|
||
249 | EVENT_MASK(INTERRUPT_EVENT_ID), ((ut_vl53l0xdata_t*)(ut->data))->evtflags); |
||
250 | |||
251 | chprintf(stream, "set single mode and interrupt to VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY ...\n");
|
||
252 | |||
253 | status = vl53l0x_lld_set_mode(((ut_vl53l0xdata_t*)(ut->data))->vl53d, VL53L0X_DEVICEMODE_SINGLE_RANGING, |
||
254 | VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY,0,0); |
||
255 | /*
|
||
256 | same as
|
||
257 | |||
258 | status |= VL53L0X_SetDeviceMode(&(((ut_vl53l0xdata_t*)(ut->data))->vl53d->vl53l0x_dev), VL53L0X_DEVICEMODE_SINGLE_RANGING);
|
||
259 | status |= VL53L0X_SetGpioConfig(&(((ut_vl53l0xdata_t*)(ut->data))->vl53d->vl53l0x_dev), 0, VL53L0X_DEVICEMODE_SINGLE_RANGING,
|
||
260 | VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY, VL53L0X_INTERRUPTPOLARITY_LOW);
|
||
261 | */
|
||
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 | pFunctionality == VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY && pPolarity == VL53L0X_INTERRUPTPOLARITY_LOW) { |
||
269 | 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 | |||
280 | if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && pMeasurementDataReady == 0) { |
||
281 | aosUtPassed(stream, &result); |
||
282 | } else {
|
||
283 | aosUtFailedMsg(stream, &result, "0x%08X, there are blocking interrupts :%u\n", status, pMeasurementDataReady);
|
||
284 | chprintf(stream, "clear blocking interrupts...\n");
|
||
285 | |||
286 | status = vl53l0x_lld_getRangingData(((ut_vl53l0xdata_t*)(ut->data))->vl53d, pRangingMeasurementData); |
||
287 | |||
288 | if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING)) {
|
||
289 | aosUtPassed(stream, &result); |
||
290 | } else {
|
||
291 | aosUtFailedMsg(stream, &result, "0x%08X;\n", status);
|
||
292 | |||
293 | } |
||
294 | |||
295 | } |
||
296 | |||
297 | |||
298 | chprintf(stream, "start maeasurement ... \n");
|
||
299 | |||
300 | |||
301 | //set everything for eventshandler
|
||
302 | chEvtRegister(((ut_vl53l0xdata_t*)(ut->data))->evtsource, &event_listener, INTERRUPT_EVENT_ID); |
||
303 | aosSysGetUptime(&tend); |
||
304 | tend += 2 * MICROSECONDS_PER_SECOND;
|
||
305 | |||
306 | status = vl53l0x_lld_start_measurement(((ut_vl53l0xdata_t*)(ut->data))->vl53d); |
||
307 | |||
308 | if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING)) {
|
||
309 | aosUtPassed(stream, &result); |
||
310 | } else {
|
||
311 | aosUtFailedMsg(stream, &result, "0x%08X;\n", status);
|
||
312 | |||
313 | } |
||
314 | |||
315 | |||
316 | do {
|
||
317 | // read proximity data, interrupt event information and interrupt status
|
||
318 | const eventmask_t emask = chEvtWaitOneTimeout(EVENT_MASK(INTERRUPT_EVENT_ID), chTimeUS2I(10*MICROSECONDS_PER_MILLISECOND)); |
||
319 | const eventflags_t eflags = chEvtGetAndClearFlags(&event_listener);
|
||
320 | |||
321 | |||
322 | if (emask == EVENT_MASK(INTERRUPT_EVENT_ID) &&
|
||
323 | eflags == ((ut_vl53l0xdata_t*)(ut->data))->evtflags) { |
||
324 | // true positive (correct case)
|
||
325 | chprintf(stream, "EVENT\n");
|
||
326 | status |= VL53L0X_GetRangingMeasurementData(&(((ut_vl53l0xdata_t*)(ut->data))->vl53d->vl53l0x_dev), pRangingMeasurementData); |
||
327 | chprintf(stream, "\t\tinterrupt detected: prox = %i\n", RangingMeasurementData.RangeMilliMeter);
|
||
328 | status |= VL53L0X_ClearInterruptMask(&(((ut_vl53l0xdata_t*)(ut->data))->vl53d->vl53l0x_dev), |
||
329 | VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_LEVEL_HIGH); |
||
330 | }else if (eflags == ((ut_vl53l0xdata_t*)(ut->data))->evtflags){ |
||
331 | chprintf(stream, "mask: %lu\n", emask);
|
||
332 | chprintf(stream, "flag: %lu\n", eflags);
|
||
333 | }else if (emask == EVENT_MASK(INTERRUPT_EVENT_ID)){ |
||
334 | chprintf(stream, "first::mask: %lu and flag: %lu\n", emask, eflags);
|
||
335 | |||
336 | // read from GPIO
|
||
337 | status |= pcal6524_lld_read_group(((ut_vl53l0xdata_t*)ut->data)->gpio, PCAL6524_LLD_CMD_INPUT_P0, buffer, |
||
338 | ((ut_vl53l0xdata_t*)ut->data)->timeout); |
||
339 | |||
340 | status |= vl53l0x_lld_CheckRangingDataReady(((ut_vl53l0xdata_t*)(ut->data))->vl53d, &pMeasurementDataReady); |
||
341 | |||
342 | if ((pMeasurementDataReady == 0x01)) { |
||
343 | |||
344 | chprintf(stream, "\t\tRead input: 0x%04X 0x%04X 0x%04X\t",
|
||
345 | (((uint16_t)buffer[0]) << 8) | buffer[1], |
||
346 | (((uint16_t)buffer[2]) << 8) | buffer[3], |
||
347 | (((uint16_t)buffer[4]) << 8) | buffer[5]); |
||
348 | |||
349 | |||
350 | //get the measurement from VL53L0X
|
||
351 | status |= vl53l0x_lld_getRangingData(((ut_vl53l0xdata_t*)(ut->data))->vl53d, pRangingMeasurementData); |
||
352 | chprintf(stream, "distance: %i\n", RangingMeasurementData.RangeMilliMeter);
|
||
353 | |||
354 | } |
||
355 | |||
356 | |||
357 | } |
||
358 | |||
359 | |||
360 | aosSysGetUptime(&tcurrent); |
||
361 | } while (tcurrent < tend);
|
||
362 | |||
363 | if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING)) {
|
||
364 | aosUtPassed(stream, &result); |
||
365 | } else {
|
||
366 | aosUtFailedMsg(stream, &result, "0x%08X; 0x%08X\n", status, pRangingMeasurementData);
|
||
367 | |||
368 | } |
||
369 | |||
370 | chprintf(stream, "stop maeasurement ... \n");
|
||
371 | |||
372 | status = vl53l0x_lld_stop_measurement(((ut_vl53l0xdata_t*)(ut->data))->vl53d); |
||
373 | |||
374 | |||
375 | chEvtUnregister(((ut_vl53l0xdata_t*)(ut->data))->evtsource, &event_listener); |
||
376 | |||
377 | if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING)) {
|
||
378 | aosUtPassed(stream, &result); |
||
379 | } else {
|
||
380 | aosUtFailedMsg(stream, &result, "0x%08X;\n", status);
|
||
381 | |||
382 | } |
||
383 | |||
384 | |||
385 | |||
386 | |||
387 | |||
388 | //-----------------------------------------------------
|
||
389 | |||
390 | chprintf(stream, "set continuous mode and interrupt to VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_OUT_OF_WINDOW (80mm/150mm) ...\n");
|
||
391 | |||
392 | // wand a threshold of 80
|
||
393 | // 100 mm < max Threshold von 254 mm
|
||
394 | ThresholdHigh = 150;
|
||
395 | ThresholdLow = 80;
|
||
396 | |||
397 | status = vl53l0x_lld_set_mode(((ut_vl53l0xdata_t*)(ut->data))->vl53d, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING, |
||
398 | VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_OUT_OF_WINDOW,ThresholdLow,ThresholdHigh); |
||
399 | |||
400 | status |= VL53L0X_GetGpioConfig(&(((ut_vl53l0xdata_t*)(ut->data))->vl53d->vl53l0x_dev), 0, &deviceMode, &pFunctionality, &pPolarity);
|
||
401 | status |= VL53L0X_GetInterruptThresholds(&(((ut_vl53l0xdata_t*)(ut->data))->vl53d->vl53l0x_dev), |
||
402 | VL53L0X_DEVICEMODE_CONTINUOUS_RANGING, |
||
403 | &ThresholdLow, &ThresholdHigh); |
||
404 | |||
405 | if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && deviceMode == VL53L0X_DEVICEMODE_CONTINUOUS_RANGING &&
|
||
406 | pFunctionality == VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_OUT_OF_WINDOW && pPolarity == VL53L0X_INTERRUPTPOLARITY_LOW){ |
||
407 | //&& ThresholdLow == 80 * 65536 && ThresholdHigh == 150 * 65536) { not possible, only strange wrong values, e.g. Threshold low:1431655765;Threshold high:0
|
||
408 | aosUtPassed(stream, &result); |
||
409 | } else {
|
||
410 | aosUtFailedMsg(stream, &result, "0x%08X; mode:%u; Interrupt:%u; InterruptPolarity:%u; Threshold low:%lu"
|
||
411 | ";Threshold high:%lu\n", status, deviceMode, pFunctionality, pPolarity, ThresholdLow/65536.0, ThresholdHigh/65536.0); |
||
412 | } |
||
413 | |||
414 | chprintf(stream, "check for blocking interrupts...\n");
|
||
415 | |||
416 | status = vl53l0x_lld_CheckRangingDataReady(((ut_vl53l0xdata_t*)(ut->data))->vl53d, &pMeasurementDataReady); |
||
417 | |||
418 | |||
419 | if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && pMeasurementDataReady == 0) { |
||
420 | aosUtPassed(stream, &result); |
||
421 | } else {
|
||
422 | aosUtFailedMsg(stream, &result, "0x%08X, there are blocking interrupts :%u\n", status, pMeasurementDataReady);
|
||
423 | chprintf(stream, "clear blocking interrupts...\n");
|
||
424 | |||
425 | status = vl53l0x_lld_getRangingData(((ut_vl53l0xdata_t*)(ut->data))->vl53d, pRangingMeasurementData); |
||
426 | |||
427 | if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING)) {
|
||
428 | aosUtPassed(stream, &result); |
||
429 | } else {
|
||
430 | aosUtFailedMsg(stream, &result, "0x%08X;\n", status);
|
||
431 | |||
432 | } |
||
433 | |||
434 | } |
||
435 | |||
436 | |||
437 | |||
438 | |||
439 | chprintf(stream, "start maeasurement ... \n");
|
||
440 | |||
441 | |||
442 | //set everything for eventshandler
|
||
443 | chEvtRegister(((ut_vl53l0xdata_t*)(ut->data))->evtsource, &event_listener, INTERRUPT_EVENT_ID); |
||
444 | aosSysGetUptime(&tend); |
||
445 | tend += 10 * MICROSECONDS_PER_SECOND;
|
||
446 | |||
447 | status = vl53l0x_lld_start_measurement(((ut_vl53l0xdata_t*)(ut->data))->vl53d); |
||
448 | |||
449 | if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING)) {
|
||
450 | aosUtPassed(stream, &result); |
||
451 | } else {
|
||
452 | aosUtFailedMsg(stream, &result, "0x%08X;\n", status);
|
||
453 | |||
454 | } |
||
455 | |||
456 | |||
457 | do {
|
||
458 | // read proximity data, interrupt event information and interrupt status
|
||
459 | const eventmask_t emask = chEvtWaitOneTimeout(EVENT_MASK(INTERRUPT_EVENT_ID), chTimeUS2I(10*MICROSECONDS_PER_MILLISECOND)); |
||
460 | const eventflags_t eflags = chEvtGetAndClearFlags(&event_listener);
|
||
461 | |||
462 | if (emask == EVENT_MASK(INTERRUPT_EVENT_ID) &&
|
||
463 | eflags == ((ut_vl53l0xdata_t*)(ut->data))->evtflags) { |
||
464 | // true positive (correct case)
|
||
465 | chprintf(stream, "EVENT\n");
|
||
466 | status |= VL53L0X_GetRangingMeasurementData(&(((ut_vl53l0xdata_t*)(ut->data))->vl53d->vl53l0x_dev), pRangingMeasurementData); |
||
467 | |||
468 | |||
469 | chprintf(stream, "\t\tinterrupt detected: prox = %i\n", RangingMeasurementData.RangeMilliMeter);
|
||
470 | status |= VL53L0X_ClearInterruptMask(&(((ut_vl53l0xdata_t*)(ut->data))->vl53d->vl53l0x_dev),0);
|
||
471 | }else if (eflags == ((ut_vl53l0xdata_t*)(ut->data))->evtflags){ |
||
472 | chprintf(stream, "mask: %lu\n", emask);
|
||
473 | chprintf(stream, "flag: %lu\n", eflags);
|
||
474 | }else if (emask == EVENT_MASK(INTERRUPT_EVENT_ID)){ |
||
475 | chprintf(stream, "last::mask: %lu and flag: %lu\n", emask, eflags);
|
||
476 | |||
477 | // read from GPIO
|
||
478 | status |= pcal6524_lld_read_group(((ut_vl53l0xdata_t*)ut->data)->gpio, PCAL6524_LLD_CMD_INPUT_P0, buffer, |
||
479 | ((ut_vl53l0xdata_t*)ut->data)->timeout); |
||
480 | |||
481 | status |= vl53l0x_lld_CheckRangingDataReady(((ut_vl53l0xdata_t*)(ut->data))->vl53d, &pMeasurementDataReady); |
||
482 | |||
483 | if ((pMeasurementDataReady == 0x01)) { |
||
484 | |||
485 | chprintf(stream, "\t\tRead input: 0x%04X 0x%04X 0x%04X\t",
|
||
486 | (((uint16_t)buffer[0]) << 8) | buffer[1], |
||
487 | (((uint16_t)buffer[2]) << 8) | buffer[3], |
||
488 | (((uint16_t)buffer[4]) << 8) | buffer[5]); |
||
489 | |||
490 | |||
491 | //get the measurement from VL53L0X
|
||
492 | status |= vl53l0x_lld_getRangingData(((ut_vl53l0xdata_t*)(ut->data))->vl53d, pRangingMeasurementData); |
||
493 | chprintf(stream, "distance: %i\n", RangingMeasurementData.RangeMilliMeter);
|
||
494 | } |
||
495 | |||
496 | |||
497 | } |
||
498 | |||
499 | |||
500 | aosSysGetUptime(&tcurrent); |
||
501 | } while (tcurrent < tend);
|
||
502 | |||
503 | if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING)) {
|
||
504 | aosUtPassed(stream, &result); |
||
505 | } else {
|
||
506 | aosUtFailedMsg(stream, &result, "0x%08X; 0x%08X\n", status, pRangingMeasurementData);
|
||
507 | |||
508 | } |
||
509 | |||
510 | chprintf(stream, "stop maeasurement ... \n");
|
||
511 | |||
512 | status = vl53l0x_lld_stop_measurement(((ut_vl53l0xdata_t*)(ut->data))->vl53d); |
||
513 | |||
514 | |||
515 | chEvtUnregister(((ut_vl53l0xdata_t*)(ut->data))->evtsource, &event_listener); |
||
516 | |||
517 | if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING)) {
|
||
518 | aosUtPassed(stream, &result); |
||
519 | } else {
|
||
520 | aosUtFailedMsg(stream, &result, "0x%08X;\n", status);
|
||
521 | |||
522 | } |
||
523 | |||
524 | |||
525 | |||
526 | |||
527 | chprintf(stream, "setting default address...\n");
|
||
528 | |||
529 | status = vl53l0x_lld_set_address(((ut_vl53l0xdata_t*)(ut->data))->vl53d, 0x29);
|
||
530 | |||
531 | |||
532 | aosUtInfoMsg(stream, "driver object memory footprint: %u bytes\n", sizeof(VL53L0XDriver)); |
||
533 | |||
534 | return result;
|
||
535 | } |
||
536 | #endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_VL53L0X) && (AMIROLLD_CFG_VL53L0X == 1) */ |