mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-22 06:13:51 -07:00
Merge pull request #1908 from lnv42/master
fix infinity loop in SpinDelayUs() and SpinDelayUsPrecision()
This commit is contained in:
commit
6df86578c7
1 changed files with 10 additions and 5 deletions
|
@ -35,11 +35,14 @@ void SpinDelayUsPrecision(int us) {
|
||||||
AT91C_BASE_PWMC_CH0->PWMC_CDTYR = 0; // Channel Duty Cycle Register
|
AT91C_BASE_PWMC_CH0->PWMC_CDTYR = 0; // Channel Duty Cycle Register
|
||||||
AT91C_BASE_PWMC_CH0->PWMC_CPRDR = 0xFFFF; // Channel Period Register
|
AT91C_BASE_PWMC_CH0->PWMC_CPRDR = 0xFFFF; // Channel Period Register
|
||||||
|
|
||||||
uint16_t start = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
|
uint16_t end = AT91C_BASE_PWMC_CH0->PWMC_CCNTR + ticks;
|
||||||
|
if (end == 0) // AT91C_BASE_PWMC_CH0->PWMC_CCNTR is never == 0
|
||||||
|
end++; // so we have to end++ to avoid inivity loop
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
uint16_t now = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
|
uint16_t now = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
|
||||||
if (now == (uint16_t)(start + ticks))
|
|
||||||
|
if (now == end)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
WDT_HIT();
|
WDT_HIT();
|
||||||
|
@ -59,13 +62,15 @@ void SpinDelayUs(int us) {
|
||||||
AT91C_BASE_PWMC_CH0->PWMC_CDTYR = 0; // Channel Duty Cycle Register
|
AT91C_BASE_PWMC_CH0->PWMC_CDTYR = 0; // Channel Duty Cycle Register
|
||||||
AT91C_BASE_PWMC_CH0->PWMC_CPRDR = 0xffff; // Channel Period Register
|
AT91C_BASE_PWMC_CH0->PWMC_CPRDR = 0xffff; // Channel Period Register
|
||||||
|
|
||||||
uint16_t start = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
|
uint16_t end = AT91C_BASE_PWMC_CH0->PWMC_CCNTR + ticks;
|
||||||
|
if (end == 0) // AT91C_BASE_PWMC_CH0->PWMC_CCNTR is never == 0
|
||||||
|
end++; // so we have to end++ to avoid inivity loop
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
uint16_t now = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
|
uint16_t now = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
|
||||||
if (now == (uint16_t)(start + ticks))
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
if (now == end)
|
||||||
|
return;
|
||||||
WDT_HIT();
|
WDT_HIT();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue