Contiki-NG
Toggle main menu visibility
Loading...
Searching...
No Matches
border-router-embedded.c
Go to the documentation of this file.
1
/*
2
* Redistribution and use in source and binary forms, with or without
3
* modification, are permitted provided that the following conditions
4
* are met:
5
* 1. Redistributions of source code must retain the above copyright
6
* notice, this list of conditions and the following disclaimer.
7
* 2. Redistributions in binary form must reproduce the above copyright
8
* notice, this list of conditions and the following disclaimer in the
9
* documentation and/or other materials provided with the distribution.
10
* 3. Neither the name of the Institute nor the names of its contributors
11
* may be used to endorse or promote products derived from this software
12
* without specific prior written permission.
13
*
14
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
15
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
18
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
* SUCH DAMAGE.
25
*
26
* This file is part of the Contiki operating system.
27
*
28
*/
29
/**
30
* \file
31
* border-router
32
* \author
33
* Niclas Finne <nfi@sics.se>
34
* Joakim Eriksson <joakime@sics.se>
35
* Nicolas Tsiftes <nvt@sics.se>
36
*/
37
38
#include "contiki.h"
39
#include "
net/routing/routing.h
"
40
#if PLATFORM_SUPPORTS_BUTTON_HAL
41
#include "
dev/button-hal.h
"
42
#else
43
#include "dev/button-sensor.h"
44
#endif
45
#include "dev/slip.h"
46
#include "rpl-border-router.h"
47
48
/*---------------------------------------------------------------------------*/
49
/* Log configuration */
50
#include "
sys/log.h
"
51
#define LOG_MODULE "BR"
52
#define LOG_LEVEL LOG_LEVEL_INFO
53
54
void
request_prefix(
void
);
55
56
/*---------------------------------------------------------------------------*/
57
PROCESS
(border_router_process,
"Border router process"
);
58
/*---------------------------------------------------------------------------*/
59
PROCESS_THREAD
(border_router_process, ev, data)
60
{
61
static
struct
etimer
et;
62
63
PROCESS_BEGIN
();
64
65
/* While waiting for the prefix to be sent through the SLIP connection, the future
66
* border router can join an existing DAG as a parent or child, or acquire a default
67
* router that will later take precedence over the SLIP fallback interface.
68
* Prevent that by turning the radio off until we are initialized as a DAG root.
69
*/
70
prefix_set = 0;
71
NETSTACK_MAC.off();
72
73
PROCESS_PAUSE
();
74
75
#if !PLATFORM_SUPPORTS_BUTTON_HAL
76
SENSORS_ACTIVATE(button_sensor);
77
#endif
78
79
LOG_INFO(
"RPL-Border router started\n"
);
80
81
/* Request prefix until it has been received */
82
while
(!prefix_set) {
83
etimer_set
(&et,
CLOCK_SECOND
);
84
request_prefix();
85
PROCESS_WAIT_EVENT_UNTIL
(
etimer_expired
(&et));
86
LOG_INFO(
"Waiting for prefix\n"
);
87
}
88
89
NETSTACK_MAC.on();
90
91
print_local_addresses();
92
93
while
(1) {
94
PROCESS_YIELD
();
95
#if PLATFORM_SUPPORTS_BUTTON_HAL
96
if
(ev ==
button_hal_release_event
) {
97
#else
98
if
(ev == sensors_event && data == &button_sensor) {
99
#endif
100
LOG_INFO(
"Initiating global repair\n"
);
101
NETSTACK_ROUTING.global_repair(
"Button press"
);
102
}
103
}
104
105
PROCESS_END
();
106
}
107
/*---------------------------------------------------------------------------*/
button-hal.h
Header file for the button HAL.
button_hal_release_event
process_event_t button_hal_release_event
A broadcast event generated when a button gets released.
Definition
button-hal.c:54
CLOCK_SECOND
#define CLOCK_SECOND
A second, measured in system clock time.
Definition
clock.h:105
etimer_expired
static bool etimer_expired(struct etimer *et)
Check if an event timer has expired.
Definition
etimer.h:201
etimer_set
void etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
Definition
etimer.c:177
PROCESS
#define PROCESS(name, strname)
Declare a process.
Definition
process.h:309
PROCESS_PAUSE
#define PROCESS_PAUSE()
Yield the process for a short while.
Definition
process.h:223
PROCESS_BEGIN
#define PROCESS_BEGIN()
Define the beginning of a process.
Definition
process.h:122
PROCESS_WAIT_EVENT_UNTIL
#define PROCESS_WAIT_EVENT_UNTIL(c)
Wait for an event to be posted to the process, with an extra condition.
Definition
process.h:159
PROCESS_END
#define PROCESS_END()
Define the end of a process.
Definition
process.h:133
PROCESS_THREAD
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
Definition
process.h:275
PROCESS_YIELD
#define PROCESS_YIELD()
Yield the currently running process.
Definition
process.h:166
log.h
Header file for the logging system.
routing.h
Routing driver header file.
etimer
A timer.
Definition
etimer.h:79
os
services
rpl-border-router
embedded
border-router-embedded.c
Generated on
for Contiki-NG by
1.17.0