mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-20 21:33:19 -07:00
Tidy up of SpinDelay
This commit is contained in:
parent
f7c64b570c
commit
5e6a0b2369
1 changed files with 20 additions and 35 deletions
|
@ -193,6 +193,8 @@ int BUTTON_HELD(int ms)
|
|||
return BUTTON_ERROR;
|
||||
}
|
||||
|
||||
// attempt at high resolution microsecond timer
|
||||
// beware: timer counts in 21.3uS increments (1024/48Mhz)
|
||||
void SpinDelayUs(int us)
|
||||
{
|
||||
int ticks = (48*us) >> 10;
|
||||
|
@ -207,29 +209,6 @@ void SpinDelayUs(int us)
|
|||
WORD start = (WORD)PWM_CH_COUNTER(0);
|
||||
|
||||
for(;;) {
|
||||
WORD now = (WORD)PWM_CH_COUNTER(0);
|
||||
if(now == (WORD)(start + ticks)) {
|
||||
return;
|
||||
}
|
||||
WDT_HIT();
|
||||
}
|
||||
}
|
||||
|
||||
void SpinDelay(int ms)
|
||||
{
|
||||
int ticks = (48000*ms) >> 10;
|
||||
|
||||
// Borrow a PWM unit for my real-time clock
|
||||
PWM_ENABLE = PWM_CHANNEL(0);
|
||||
// 48 MHz / 1024 gives 46.875 kHz
|
||||
PWM_CH_MODE(0) = PWM_CH_MODE_PRESCALER(10);
|
||||
PWM_CH_DUTY_CYCLE(0) = 0;
|
||||
PWM_CH_PERIOD(0) = 0xffff;
|
||||
|
||||
WORD start = (WORD)PWM_CH_COUNTER(0);
|
||||
|
||||
for(;;)
|
||||
{
|
||||
WORD now = (WORD)PWM_CH_COUNTER(0);
|
||||
if (now == (WORD)(start + ticks))
|
||||
return;
|
||||
|
@ -237,3 +216,9 @@ void SpinDelay(int ms)
|
|||
WDT_HIT();
|
||||
}
|
||||
}
|
||||
|
||||
void SpinDelay(int ms)
|
||||
{
|
||||
// convert to uS and call microsecond delay function
|
||||
SpinDelayUs(ms*1000);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue