1 /*
2 * Copyright (c) 2020 O.S.Systems
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/logging/log.h>
8 LOG_MODULE_DECLARE(updatehub, CONFIG_UPDATEHUB_LOG_LEVEL);
9
10 #include <zephyr/kernel.h>
11 #include "updatehub_timer.h"
12
13 static int blk_vars[UPDATEHUB_BLK_MAX_VARS];
14
timer_expire(struct k_timer * timer)15 static void timer_expire(struct k_timer *timer)
16 {
17 LOG_DBG("tmr_expire");
18 blk_vars[UPDATEHUB_BLK_TX_AVAILABLE] = 1;
19 }
20
21 K_TIMER_DEFINE(uhu_packet_down_tmr, timer_expire, NULL);
22
updatehub_blk_get(enum updatehub_blk_vars var)23 int updatehub_blk_get(enum updatehub_blk_vars var)
24 {
25 LOG_DBG("blk_get[%d] = %d", var, blk_vars[var]);
26 return blk_vars[var];
27 }
28
updatehub_blk_inc(enum updatehub_blk_vars var)29 void updatehub_blk_inc(enum updatehub_blk_vars var)
30 {
31 blk_vars[var]++;
32 LOG_DBG("blk_inc[%d] = %d", var, blk_vars[var]);
33 }
34
updatehub_blk_set(enum updatehub_blk_vars var,int val)35 void updatehub_blk_set(enum updatehub_blk_vars var, int val)
36 {
37 LOG_DBG("blk_set[%d] = %d", var, val);
38 blk_vars[var] = val;
39 }
40
updatehub_tmr_start(void)41 void updatehub_tmr_start(void)
42 {
43 LOG_DBG("tmr_start");
44 k_timer_start(&uhu_packet_down_tmr,
45 K_SECONDS(CONFIG_UPDATEHUB_COAP_CONN_TIMEOUT),
46 K_NO_WAIT);
47 }
48
updatehub_tmr_stop(void)49 void updatehub_tmr_stop(void)
50 {
51 LOG_DBG("tmr_stop");
52 k_timer_stop(&uhu_packet_down_tmr);
53 }
54