-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathsemtech_loramac_timer.c
94 lines (80 loc) · 2.05 KB
/
semtech_loramac_timer.c
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Copyright (C) 2017 Fundacion Inria Chile
* 2017 Inria
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @{
* @ingroup pkg_semtech-loramac
* @file
* @brief Compatibility functions for controlling the LoRaMAC timers
*
* @author Jose Ignacio Alamos <[email protected]>
* @author Alexandre Abadie <[email protected]>
* @author Francisco Molina <[email protected]>
* @}
*/
#include "ztimer.h"
#include "thread.h"
#include "semtech-loramac/timer.h"
extern kernel_pid_t semtech_loramac_pid;
void TimerInit(TimerEvent_t *obj, void (*cb)(void))
{
obj->dev = (ztimer_t) {
.base = {
.next = NULL,
.offset = 0,
},
.callback = NULL,
.arg = NULL,
};
obj->running = 0;
obj->cb = cb;
}
void TimerReset(TimerEvent_t *obj)
{
TimerStop(obj);
TimerStart(obj);
}
void TimerStart(TimerEvent_t *obj)
{
obj->running = 1;
ztimer_t *timer = &(obj->dev);
msg_t *msg = &(obj->msg);
msg->type = MSG_TYPE_MAC_TIMEOUT;
msg->content.value = (uintptr_t)obj->cb;
ztimer_set_msg(ZTIMER_MSEC, timer, obj->timeout, msg, semtech_loramac_pid);
}
void TimerStop(TimerEvent_t *obj)
{
obj->running = 0;
ztimer_remove(ZTIMER_MSEC, &(obj->dev));
}
void TimerSetValue(TimerEvent_t *obj, uint32_t value)
{
if (obj->running) {
ztimer_remove(ZTIMER_MSEC, &(obj->dev));
}
obj->timeout = value;
}
TimerTime_t TimerGetCurrentTime(void)
{
uint64_t CurrentTime = ztimer_now(ZTIMER_MSEC);
return (TimerTime_t)CurrentTime;
}
TimerTime_t TimerGetElapsedTime(TimerTime_t savedTime)
{
uint64_t CurrentTime = ztimer_now(ZTIMER_MSEC);
return (TimerTime_t)(CurrentTime - savedTime);
}
TimerTime_t TimerGetFutureTime(TimerTime_t eventInFuture)
{
uint64_t CurrentTime = ztimer_now(ZTIMER_MSEC);
return (TimerTime_t)(CurrentTime + eventInFuture);
}
void TimerLowPowerHandler( void )
{
}