- /**
- * @brief Inner function, not available outside this file. This function is used
- * to wait for an answer from VL53L5CX sensor.
- */
- static uint8_t _vl53l5cx_poll_for_answer(
- VL53L5CX_Configuration *p_dev,
- uint8_t size,
- uint8_t pos,
- uint16_t address,
- uint8_t mask,
- uint8_t expected_value)
- {
- uint8_t status = VL53L5CX_STATUS_OK;
- uint8_t timeout = 0;
- do {
- status |= RdMulti(&(p_dev->platform), address,
- p_dev->temp_buffer, size);
- status |= WaitMs(&(p_dev->platform), 10);
- if(timeout >= (uint8_t)200) /* 2s timeout */
- {
- status |= p_dev->temp_buffer[2];
- }else if((size >= (uint8_t)4)
- && (p_dev->temp_buffer[2] >= (uint8_t)0x7f))
- {
- status |= VL53L5CX_MCU_ERROR;
- }
- else
- {
- timeout++;
- }
- }while ((p_dev->temp_buffer[pos] & mask) != expected_value);
- return status;
- }
如果超过 200(2 秒超时),则变量超时会递增并进行测试,但没有超时值条件来打破 while 循环。
如果下面的 while 条件永远不为真,这可能会导致无限循环。
- (p_dev->temp_buffer[pos] & mask) != expected_value
你能仔细检查代码吗?