Contiki-NG
contiki-main.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, George Oikonomou - http://www.spd.gr
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29  * OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 /*---------------------------------------------------------------------------*/
32 /**
33  * \addtogroup main
34  * @{
35  */
36 /*---------------------------------------------------------------------------*/
37 /**
38  * \file
39  *
40  * Implementation of \os's main routine
41  */
42 /*---------------------------------------------------------------------------*/
43 #include "contiki.h"
44 #include "contiki-net.h"
45 #include "sys/node-id.h"
46 #include "sys/platform.h"
47 #include "sys/energest.h"
48 #include "sys/stack-check.h"
49 #include "dev/watchdog.h"
50 
52 #include "services/rpl-border-router/rpl-border-router.h"
56 
57 #include <stdio.h>
58 #include <stdint.h>
59 /*---------------------------------------------------------------------------*/
60 /* Log configuration */
61 #include "sys/log.h"
62 #define LOG_MODULE "Main"
63 #define LOG_LEVEL LOG_LEVEL_MAIN
64 /*---------------------------------------------------------------------------*/
65 int
66 #if PLATFORM_MAIN_ACCEPTS_ARGS
67 main(int argc, char **argv)
68 {
69  platform_process_args(argc, argv);
70 #else
71 main(void)
72 {
73 #endif
75 
76  clock_init();
77  rtimer_init();
78  process_init();
79  process_start(&etimer_process, NULL);
80  ctimer_init();
81  watchdog_init();
82 
83  energest_init();
84 
85 #if STACK_CHECK_ENABLED
87 #endif
88 
90 
91  netstack_init();
92  node_id_init();
93 
94  LOG_INFO("Starting " CONTIKI_VERSION_STRING "\n");
95  LOG_INFO("- Routing: %s\n", NETSTACK_ROUTING.name);
96  LOG_INFO("- Net: %s\n", NETSTACK_NETWORK.name);
97  LOG_INFO("- MAC: %s\n", NETSTACK_MAC.name);
98  LOG_INFO("- 802.15.4 PANID: 0x%04x\n", IEEE802154_PANID);
99 #if MAC_CONF_WITH_TSCH
100  LOG_INFO("- 802.15.4 TSCH default hopping sequence length: %u\n", (unsigned)sizeof(TSCH_DEFAULT_HOPPING_SEQUENCE));
101 #else /* MAC_CONF_WITH_TSCH */
102  LOG_INFO("- 802.15.4 Default channel: %u\n", IEEE802154_DEFAULT_CHANNEL);
103 #endif /* MAC_CONF_WITH_TSCH */
104 
105  LOG_INFO("Node ID: %u\n", node_id);
106  LOG_INFO("Link-layer address: ");
107  LOG_INFO_LLADDR(&linkaddr_node_addr);
108  LOG_INFO_("\n");
109 
110 #if NETSTACK_CONF_WITH_IPV6
111  {
112  uip_ds6_addr_t *lladdr;
113  memcpy(&uip_lladdr.addr, &linkaddr_node_addr, sizeof(uip_lladdr.addr));
114  process_start(&tcpip_process, NULL);
115 
116  lladdr = uip_ds6_get_link_local(-1);
117  LOG_INFO("Tentative link-local IPv6 address: ");
118  LOG_INFO_6ADDR(lladdr != NULL ? &lladdr->ipaddr : NULL);
119  LOG_INFO_("\n");
120  }
121 #endif /* NETSTACK_CONF_WITH_IPV6 */
122 
124 
125 #if BUILD_WITH_RPL_BORDER_ROUTER
126  rpl_border_router_init();
127  LOG_DBG("With RPL Border Router\n");
128 #endif /* BUILD_WITH_RPL_BORDER_ROUTER */
129 
130 #if BUILD_WITH_ORCHESTRA
131  orchestra_init();
132  LOG_DBG("With Orchestra\n");
133 #endif /* BUILD_WITH_ORCHESTRA */
134 
135 #if BUILD_WITH_SHELL
137  LOG_DBG("With Shell\n");
138 #endif /* BUILD_WITH_SHELL */
139 
140 #if BUILD_WITH_COAP
141  coap_engine_init();
142  LOG_DBG("With CoAP\n");
143 #endif /* BUILD_WITH_SHELL */
144 
145 #if BUILD_WITH_SIMPLE_ENERGEST
147 #endif /* BUILD_WITH_SIMPLE_ENERGEST */
148 
149  autostart_start(autostart_processes);
150 
151  watchdog_start();
152 
153 #if PLATFORM_PROVIDES_MAIN_LOOP
155 #else
156  while(1) {
157  uint8_t r;
158  do {
159  r = process_run();
161  } while(r > 0);
162 
163  platform_idle();
164  }
165 #endif
166 
167  return 0;
168 }
169 /*---------------------------------------------------------------------------*/
170 /**
171  * @}
172  */
uip_lladdr_t uip_lladdr
Host L2 address.
Definition: uip6.c:107
Header file for the energy estimation mechanism
void platform_main_loop()
The platform&#39;s main loop, if provided.
Definition: platform.c:188
void platform_init_stage_two()
Stage 2 of platform driver initialisation.
Definition: platform.c:123
CoAP engine implementation.
void platform_idle()
The platform&#39;s idle/sleep function.
Definition: platform.c:185
void ctimer_init(void)
Initialize the callback timer library.
Definition: ctimer.c:91
Node-id (simple 16-bit identifiers) handling.
Header file for the Contiki-NG main routine.
Orchestra header file
A shell back-end for the serial port
void serial_shell_init(void)
Initializes Serial Shell module.
Definition: serial-shell.c:76
void platform_process_args(int argc, char **argv)
Allow the platform to process main&#39;s command line arguments.
Definition: platform.c:227
linkaddr_t linkaddr_node_addr
The link-layer address of the node.
Definition: linkaddr.c:48
void node_id_init(void)
Initialize the node ID.
Definition: node-id.c:47
#define IEEE802154_DEFAULT_CHANNEL
The default channel for IEEE 802.15.4 networks.
Definition: mac.h:52
void process_init(void)
Initialize the process module.
Definition: process.c:208
void watchdog_start(void)
Starts the WDT in watchdog mode if enabled by user configuration, maximum interval.
Definition: watchdog.c:72
A process that periodically prints out the time spent in radio tx, radio rx, total time and duty cycle.
Unicast address structure.
Definition: uip-ds6.h:204
void simple_energest_init(void)
Initialize the deployment module.
void stack_check_init(void)
Initialize the stack area with a known pattern.
Definition: stack-check.c:73
void platform_init_stage_three()
Final stage of platform driver initialisation.
Definition: platform.c:169
void watchdog_init(void)
Initialisation function for the WDT.
Definition: watchdog.c:63
Stack checker library header file.
void watchdog_periodic(void)
Writes the WDT clear sequence.
Definition: watchdog.c:85
Header file for the logging system
void rtimer_init(void)
Initialize the real-time scheduler.
Definition: rtimer.c:61
int process_run(void)
Run the system once - call poll handlers and process one event.
Definition: process.c:302
void clock_init(void)
Arch-specific implementation of clock_init for the cc2538.
Definition: clock.c:93
void platform_init_stage_one(void)
Basic (Stage 1) platform driver initialisation.
Definition: platform.c:114
void process_start(struct process *p, process_data_t data)
Start a process.
Definition: process.c:99