From 64b55e7e1236121ea4197d9a37cfec43b196cfe8 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Wed, 2 Feb 2022 06:40:10 +0100 Subject: moved ecp, platform -> src --- ecp/src/platform/fe310/time.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 ecp/src/platform/fe310/time.c (limited to 'ecp/src/platform/fe310/time.c') diff --git a/ecp/src/platform/fe310/time.c b/ecp/src/platform/fe310/time.c new file mode 100644 index 0000000..3c74933 --- /dev/null +++ b/ecp/src/platform/fe310/time.c @@ -0,0 +1,35 @@ +#include +#include + +#include +#include +#include +#include + +extern ECPSocket *_ecp_tr_sock; + +static void timer_handler(unsigned char type) { + ecp_cts_t next = ecp_timer_exe(_ecp_tr_sock); + if (next) { + eos_timer_set(next, EOS_TIMER_ETYPE_ECP); + } +} + +int ecp_tm_init(ECPContext *ctx) { + eos_timer_set_handler(EOS_TIMER_ETYPE_ECP, timer_handler); + eos_net_acquire_for_evt(EOS_EVT_TIMER | EOS_TIMER_ETYPE_ECP, 1); + return ECP_OK; +} + +ecp_cts_t ecp_tm_abstime_ms(ecp_cts_t msec) { + return eos_time_get_tick() * 1000 / EOS_TIMER_RTC_FREQ + msec; +} + +void ecp_tm_sleep_ms(ecp_cts_t msec) { + eos_time_sleep(msec); +} + +void ecp_tm_timer_set(ecp_cts_t next) { + uint32_t _next = eos_timer_get(EOS_TIMER_ETYPE_ECP); + if ((_next == EOS_TIMER_NONE) || (next < _next)) eos_timer_set(next, EOS_TIMER_ETYPE_ECP); +} -- cgit v1.2.3