-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
61 lines (48 loc) · 1.42 KB
/
main.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
/* main.c - KNoT Application Client */
/*
* Copyright (c) 2018, CESAR. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* The knot client application is acting as a client that is run in Zephyr OS,
* The client sends sensor data encapsulated using KNoT protocol.
*/
#include <zephyr.h>
#include <net/net_core.h>
#include <net/net_app.h>
#include <logging/log.h>
#include "proto.h"
#include "net.h"
LOG_MODULE_REGISTER(knot, LOG_LEVEL_DBG);
K_PIPE_DEFINE(p2n_pipe, 128, 4);
K_PIPE_DEFINE(n2p_pipe, 128, 4);
static struct k_sem quit_lock;
void main(void)
{
LOG_DBG("*** Welcome to KNoT! %s\n", CONFIG_ARCH);
k_sem_init(&quit_lock, 0, UINT_MAX);
/* Guarantees NET and PROTO threads will be created */
k_sched_lock();
/*
* KNoT state thread: manage device registration, detects
* sensor data changes acting like a proxy forwarding data
* from sensors to network layer (and oposite). Proto is
* consumer of ipdu fifo and producer of opdu.
*/
if (proto_start(&p2n_pipe, &n2p_pipe) < 0)
return;
/*
* Network thread: manage traffic from TCP or non-ip wireless
* technologies. Each technology(thread) is responsible for
* managing incoming and outgoing data. Net is consumer of
* opdu fifo and producer of ipdu.
*/
if (net_start(&p2n_pipe, &n2p_pipe) < 0)
return;
/* Allows NET and PROTO thread scheduling */
k_sched_unlock();
k_sem_take(&quit_lock, K_FOREVER);
net_stop();
proto_stop();
}