1
0
mirror of https://github.com/mist-devel/mist-firmware.git synced 2026-03-10 04:11:17 +00:00
Files
mist-devel.mist-firmware/usb/timer.c
Eugene Azarov 7930c18d52 mcp2221: i2c state change waiting loop is improved
* ds3231: 12h to 24h time convertion fix
* pcf85263: small fix for get/set time
2026-02-02 01:06:21 +03:00

41 lines
710 B
C

#include "timer.h"
// this is a 32 bit counter which overflows after 2^32 milliseconds
// -> after 46 days
void timer_init() {
// reprogram the realtime timer to run at 1Khz
InitRTTC();
}
msec_t timer_get_msec() {
return GetRTTC();
}
bool timer_check(msec_t ref, msec_t delay) {
msec_t now = GetRTTC();
return ((now-ref) >= delay);
}
void timer_delay_msec(msec_t t) {
msec_t now = GetRTTC();
while(GetRTTC() - now < t);
}
RAMFUNC void delay_usec(unsigned int delay)
{
unsigned int count = (delay * (MCLK / 1000000 / 4));
if (count > 2) count -= 2;
else if (count == 0) return;
asm volatile (
"1: sub %0, %0, #1 \n\t"
"bne 1b"
: "+l" (count)
:
: "cc"
);
}