summaryrefslogtreecommitdiff
path: root/code/ecp
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2020-03-11 16:28:27 +0100
committerUros Majstorovic <majstor@majstor.org>2020-03-11 16:28:27 +0100
commitab1006d27417cc831150877ec46fbc13ffeddb53 (patch)
tree21a45e41483b84443f57a68360dae78e7fcabecc /code/ecp
parentc4dfa25d8d30f2812ae48dea1ffb0f326d46ae9f (diff)
timer fix
Diffstat (limited to 'code/ecp')
-rw-r--r--code/ecp/Makefile.fe3102
-rw-r--r--code/ecp/fe310/time.c15
-rw-r--r--code/ecp/timer.c26
3 files changed, 19 insertions, 24 deletions
diff --git a/code/ecp/Makefile.fe310 b/code/ecp/Makefile.fe310
index f921f33..5b670c1 100644
--- a/code/ecp/Makefile.fe310
+++ b/code/ecp/Makefile.fe310
@@ -5,4 +5,4 @@ vconn=vconn
rbuf_obj=
include $(FE310_HOME)/common.mk
-CFLAGS += -DECP_WITH_VCONN=1 -DECP_DEBUG=1 -I$(FE310_HOME) -I$(FE310_HOME)/include
+CFLAGS += -DECP_WITH_VCONN=1 -DECP_DEBUG=1 -I$(FE310_HOME)
diff --git a/code/ecp/fe310/time.c b/code/ecp/fe310/time.c
index 8458a2d..3c74933 100644
--- a/code/ecp/fe310/time.c
+++ b/code/ecp/fe310/time.c
@@ -6,15 +6,12 @@
#include <eos/event.h>
#include <eos/timer.h>
-#include "encoding.h"
-#include "platform.h"
-
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, 0);
+ eos_timer_set(next, EOS_TIMER_ETYPE_ECP);
}
}
@@ -25,16 +22,14 @@ int ecp_tm_init(ECPContext *ctx) {
}
ecp_cts_t ecp_tm_abstime_ms(ecp_cts_t msec) {
- volatile uint64_t *mtime = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIME);
-
- uint64_t now_ms = *mtime * 1000 / RTC_FREQ;
- return now_ms + msec;
+ return eos_time_get_tick() * 1000 / EOS_TIMER_RTC_FREQ + msec;
}
void ecp_tm_sleep_ms(ecp_cts_t msec) {
- eos_timer_sleep(msec);
+ eos_time_sleep(msec);
}
void ecp_tm_timer_set(ecp_cts_t next) {
- eos_timer_set(next, EOS_TIMER_ETYPE_ECP, 1);
+ 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);
}
diff --git a/code/ecp/timer.c b/code/ecp/timer.c
index 695d42a..f091464 100644
--- a/code/ecp/timer.c
+++ b/code/ecp/timer.c
@@ -9,7 +9,7 @@ int ecp_timer_create(ECPTimer *timer) {
rv = pthread_mutex_init(&timer->mutex, NULL);
if (rv) return ECP_ERR;
#endif
-
+
return ECP_OK;
}
@@ -21,17 +21,17 @@ void ecp_timer_destroy(ECPTimer *timer) {
int ecp_timer_item_init(ECPTimerItem *ti, ECPConnection *conn, unsigned char mtype, short cnt, ecp_cts_t timeout) {
if ((mtype & ECP_MTYPE_MASK) >= ECP_MAX_MTYPE) return ECP_ERR_MAX_MTYPE;
-
+
if (ti == NULL) return ECP_ERR;
if (conn == NULL) return ECP_ERR;
-
+
ti->conn = conn;
ti->mtype = mtype;
ti->cnt = cnt-1;
ti->timeout = timeout;
ti->abstime = 0;
ti->retry = NULL;
-
+
return ECP_OK;
}
@@ -39,7 +39,7 @@ int ecp_timer_push(ECPTimerItem *ti) {
int i, is_reg, rv = ECP_OK;
ECPConnection *conn = ti->conn;
ECPTimer *timer = &conn->sock->timer;
-
+
ti->abstime = ecp_tm_abstime_ms(ti->timeout);
#ifdef ECP_WITH_PTHREAD
@@ -51,12 +51,11 @@ int ecp_timer_push(ECPTimerItem *ti) {
#ifdef ECP_WITH_PTHREAD
pthread_mutex_unlock(&conn->mutex);
#endif
-
+
if (timer->head == ECP_MAX_TIMER-1) rv = ECP_ERR_MAX_TIMER;
if (!rv && !is_reg) rv = ECP_ERR_CLOSED;
if (!rv) {
- ecp_tm_timer_set(ti->timeout);
for (i=timer->head; i>=0; i--) {
if (ECP_CTS_LTE(ti->abstime, timer->item[i].abstime)) {
if (i != timer->head) memmove(timer->item+i+2, timer->item+i+1, sizeof(ECPTimerItem) * (timer->head-i));
@@ -70,8 +69,9 @@ int ecp_timer_push(ECPTimerItem *ti) {
timer->item[0] = *ti;
timer->head++;
}
+ ecp_tm_timer_set(ti->timeout);
}
-
+
#ifdef ECP_WITH_PTHREAD
pthread_mutex_unlock(&timer->mutex);
#endif
@@ -98,11 +98,11 @@ void ecp_timer_pop(ECPConnection *conn, unsigned char mtype) {
}
#ifdef ECP_WITH_PTHREAD
pthread_mutex_lock(&conn->mutex);
-#endif
+#endif
conn->refcount--;
#ifdef ECP_WITH_PTHREAD
pthread_mutex_unlock(&conn->mutex);
-#endif
+#endif
timer->head--;
break;
}
@@ -111,7 +111,7 @@ void ecp_timer_pop(ECPConnection *conn, unsigned char mtype) {
#ifdef ECP_WITH_PTHREAD
pthread_mutex_unlock(&timer->mutex);
#endif
-
+
}
void ecp_timer_remove(ECPConnection *conn) {
@@ -145,7 +145,7 @@ void ecp_timer_remove(ECPConnection *conn) {
#ifdef ECP_WITH_PTHREAD
pthread_mutex_unlock(&timer->mutex);
#endif
-
+
}
ecp_cts_t ecp_timer_exe(ECPSocket *sock) {
@@ -185,7 +185,7 @@ ecp_cts_t ecp_timer_exe(ECPSocket *sock) {
unsigned char mtype = to_exec[i].mtype;
ecp_timer_retry_t *retry = to_exec[i].retry;
ecp_conn_handler_msg_t *handler = conn->sock->ctx->handler[conn->type] ? conn->sock->ctx->handler[conn->type]->msg[mtype & ECP_MTYPE_MASK] : NULL;
-
+
if (to_exec[i].cnt > 0) {
ssize_t _rv = 0;
to_exec[i].cnt--;