icE1usb fw: Add access functions for the 'time' hardware

The hardware has a tick counter (constantly incremented every
cycle) and a pps counter (which is the tick counter captured
at the pps edge).

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I2122ea3d636c8a430c6eb945b0c11e26e02fee43
This commit is contained in:
Sylvain Munaut 2022-01-11 11:10:49 +01:00
parent be5a53a4fe
commit 00b57625bc
2 changed files with 33 additions and 0 deletions

View File

@ -122,6 +122,34 @@ e1_tick_read(int port)
return misc_regs->e1_tick[port].tx;
}
bool
time_elapsed(uint32_t ref, unsigned int tick)
{
return ((misc_regs->time.now - ref) & 0x7fffffff) >= tick;
}
void
delay(unsigned int ms)
{
uint32_t ref = misc_regs->time.now;
ms *= SYS_CLK_FREQ / 1000;
while (!time_elapsed(ref, ms));
}
uint32_t
time_pps_read(void)
{
return misc_regs->time.pps;
}
uint32_t
time_now_read(void)
{
return misc_regs->time.now;
}
void
reboot(int fw)
{

View File

@ -36,4 +36,9 @@ void e1_led_set(bool enable, uint8_t cfg);
uint16_t e1_tick_read(int port);
bool time_elapsed(uint32_t ref, unsigned int tick);
void delay(unsigned int ms);
uint32_t time_pps_read(void);
uint32_t time_now_read(void);
void reboot(int fw);