tnt has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26908 )
Change subject: icE1usb fw: Add access functions for the 'time' hardware ......................................................................
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 --- M firmware/ice40-riscv/icE1usb/misc.c M firmware/ice40-riscv/icE1usb/misc.h 2 files changed, 33 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-e1-hardware refs/changes/08/26908/1
diff --git a/firmware/ice40-riscv/icE1usb/misc.c b/firmware/ice40-riscv/icE1usb/misc.c index 50aec43..b8419aa 100644 --- a/firmware/ice40-riscv/icE1usb/misc.c +++ b/firmware/ice40-riscv/icE1usb/misc.c @@ -122,6 +122,34 @@ 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) { diff --git a/firmware/ice40-riscv/icE1usb/misc.h b/firmware/ice40-riscv/icE1usb/misc.h index 76d5a7d..b72793f 100644 --- a/firmware/ice40-riscv/icE1usb/misc.h +++ b/firmware/ice40-riscv/icE1usb/misc.h @@ -36,4 +36,9 @@
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);
Hello Jenkins Builder,
I'd like you to reexamine a change. Please visit
https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26908
to look at the new patch set (#2).
Change subject: icE1usb fw: Add access functions for the 'time' hardware ......................................................................
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 --- M firmware/ice40-riscv/icE1usb/misc.c M firmware/ice40-riscv/icE1usb/misc.h 2 files changed, 33 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-e1-hardware refs/changes/08/26908/2
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26908 )
Change subject: icE1usb fw: Add access functions for the 'time' hardware ......................................................................
Patch Set 2: Code-Review+2
laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-e1-hardware/+/26908 )
Change subject: icE1usb fw: Add access functions for the 'time' hardware ......................................................................
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 --- M firmware/ice40-riscv/icE1usb/misc.c M firmware/ice40-riscv/icE1usb/misc.h 2 files changed, 33 insertions(+), 0 deletions(-)
Approvals: laforge: Looks good to me, approved Jenkins Builder: Verified
diff --git a/firmware/ice40-riscv/icE1usb/misc.c b/firmware/ice40-riscv/icE1usb/misc.c index 50aec43..b8419aa 100644 --- a/firmware/ice40-riscv/icE1usb/misc.c +++ b/firmware/ice40-riscv/icE1usb/misc.c @@ -122,6 +122,34 @@ 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) { diff --git a/firmware/ice40-riscv/icE1usb/misc.h b/firmware/ice40-riscv/icE1usb/misc.h index 76d5a7d..b72793f 100644 --- a/firmware/ice40-riscv/icE1usb/misc.h +++ b/firmware/ice40-riscv/icE1usb/misc.h @@ -36,4 +36,9 @@
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);