Commit 0d252f92 authored by galberding's avatar galberding
Browse files

Replace apalGetTime() with rtcGetTime()

parent 3781ba84
......@@ -537,6 +537,8 @@ VL53L1_Error VL53L1_GpioInterruptDisable(void)
return VL53L1_ERROR_NOT_SUPPORTED;
}
/**
* @brief Retrieve the current system tick count.
*
......@@ -546,7 +548,9 @@ VL53L1_Error VL53L1_GpioInterruptDisable(void)
*/
VL53L1_Error VL53L1_GetTickCount(uint32_t *ptime_ms)
{
*ptime_ms = apalGetTime() / 1000;
static RTCDateTime time;
rtcGetTime(&RTCD1, &time);
*ptime_ms = time.millisecond;
return VL53L1_ERROR_NONE;
}
......@@ -573,7 +577,10 @@ VL53L1_Error VL53L1_WaitValueMaskEx(VL53L1_Dev_t *pdev, uint32_t timeout_ms, uin
apalDbgAssert(mask != 0x00);
// local variables
const apalTime_t starttime = apalGetTime();
static RTCDateTime time;
rtcGetTime(&RTCD1, &time);
const apalTime_t starttime = time.millisecond;
apalTime_t transmissionstartoffset, transmissionendoffset;
apalTime_t remaintime = timeout_ms * 1000;
uint8_t txbuf[sizeof(uint16_t)] = {index >> 8, index & 0xFF};
......@@ -581,8 +588,9 @@ VL53L1_Error VL53L1_WaitValueMaskEx(VL53L1_Dev_t *pdev, uint32_t timeout_ms, uin
// infinite loop will return from within
for(;;) {
rtcGetTime(&RTCD1, &time);
// measure time before transmission
transmissionstartoffset = apalGetTime() - starttime;
transmissionstartoffset = time.millisecond - starttime;
// try transmission
if (apalI2CMasterTransmit(pdev->Interface.i2cd, pdev->Interface.addr, txbuf, sizeof(txbuf), rxbuf, sizeof(rxbuf), (remaintime < VL53L1X_LLD_I2C_TIMEOUT) ? remaintime : VL53L1X_LLD_I2C_TIMEOUT) < 0) {
......@@ -595,7 +603,8 @@ VL53L1_Error VL53L1_WaitValueMaskEx(VL53L1_Dev_t *pdev, uint32_t timeout_ms, uin
}
// measure time after transmission
transmissionendoffset = apalGetTime() - starttime;
rtcGetTime(&RTCD1, &time);
transmissionendoffset = time.millisecond - starttime;
// check for timeout and recalculate remaining time
if (transmissionendoffset < timeout_ms * 1000) {
......@@ -613,7 +622,8 @@ VL53L1_Error VL53L1_WaitValueMaskEx(VL53L1_Dev_t *pdev, uint32_t timeout_ms, uin
}
// recalculate remaining time
remaintime = apalGetTime() - starttime;
rtcGetTime(&RTCD1, &time);
remaintime = time.millisecond - starttime;
if (remaintime < timeout_ms * 1000) {
remaintime = (timeout_ms * 1000) - remaintime;
} else {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment