blob: 4bf530c2c42ee4bc760b835ec76fa5eb07db433f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#include <stdlib.h>
#include <ecp/core.h>
#include <ecp/tm.h>
#include <eos/eos.h>
#include <eos/event.h>
#include <eos/soc/timer.h>
#include <eos/dev/net.h>
extern ECPSocket *_ecp_tr_sock;
static void timer_handler(unsigned char type) {
ecp_sts_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_sts_t ecp_tm_get_s(void) {
return eos_time_get_tick() / EOS_TIMER_RTC_FREQ;
}
ecp_sts_t ecp_tm_get_ms(void) {
return eos_time_get_tick() * 1000 / EOS_TIMER_RTC_FREQ;
}
void ecp_tm_sleep(ecp_sts_t msec) {
eos_time_sleep(msec);
}
void ecp_tm_timer_set(ecp_sts_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);
}
|