onewire basic impl + fixed a bug in usec delays

This commit is contained in:
2018-01-29 22:37:12 +01:00
parent 9e65c8409a
commit eca8319820
5 changed files with 320 additions and 218 deletions
+12 -5
View File
@@ -95,17 +95,24 @@ uint64_t PTIM_GetMicrotime(void)
}
vPortExitCritical();
return (uint64_t)uwMillis*1000 + uwMicros;
return (uint64_t) uwMillis * 1000 + uwMicros;
}
/** microsecond delay */
void PTIM_MicroDelay(uint16_t usec)
{
usec++; // rounding up
assert_param(usec < 1000);
uint16_t end = (uint16_t) (TIMEBASE_TIMER->CNT + usec);
if (end > 999) end -= 1000;
const uint16_t start = (uint16_t) TIMEBASE_TIMER->CNT;
const uint16_t remain = (uint16_t) (999 - start);
while (TIMEBASE_TIMER->CNT != end);
if (remain > usec) {
// timer still has enough space going forward to pass the required wait time
for (; TIMEBASE_TIMER->CNT < start + usec;);
}
else {
// timer is too close to the end
usec -= remain;
for (; TIMEBASE_TIMER->CNT >= start || TIMEBASE_TIMER->CNT < usec;);
}
}