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 
51 #include "net/queuebuf.h"
54 #include "services/rpl-border-router/rpl-border-router.h"
59 
60 #include <stdio.h>
61 #include <stdint.h>
62 /*---------------------------------------------------------------------------*/
63 /* Log configuration */
64 #include "sys/log.h"
65 #define LOG_MODULE "Main"
66 #define LOG_LEVEL LOG_LEVEL_MAIN
67 /*---------------------------------------------------------------------------*/
68 int
69 #if PLATFORM_MAIN_ACCEPTS_ARGS
70 main(int argc, char **argv)
71 {
72  platform_process_args(argc, argv);
73 #else
74 main(void)
75 {
76 #endif
78 
79  clock_init();
80  rtimer_init();
81  process_init();
82  process_start(&etimer_process, NULL);
83  ctimer_init();
84  watchdog_init();
85 
86  energest_init();
87 
88 #if STACK_CHECK_ENABLED
90 #endif
91 
93 
94 #if QUEUEBUF_ENABLED
95  queuebuf_init();
96 #endif /* QUEUEBUF_ENABLED */
97  netstack_init();
98  node_id_init();
99 
100  LOG_INFO("Starting " CONTIKI_VERSION_STRING "\n");
101  LOG_INFO("- Routing: %s\n", NETSTACK_ROUTING.name);
102  LOG_INFO("- Net: %s\n", NETSTACK_NETWORK.name);
103  LOG_INFO("- MAC: %s\n", NETSTACK_MAC.name);
104  LOG_INFO("- 802.15.4 PANID: 0x%04x\n", IEEE802154_PANID);
105 #if MAC_CONF_WITH_TSCH
106  LOG_INFO("- 802.15.4 TSCH default hopping sequence length: %u\n", (unsigned)sizeof(TSCH_DEFAULT_HOPPING_SEQUENCE));
107 #else /* MAC_CONF_WITH_TSCH */
108  LOG_INFO("- 802.15.4 Default channel: %u\n", IEEE802154_DEFAULT_CHANNEL);
109 #endif /* MAC_CONF_WITH_TSCH */
110 
111  LOG_INFO("Node ID: %u\n", node_id);
112  LOG_INFO("Link-layer address: ");
113  LOG_INFO_LLADDR(&linkaddr_node_addr);
114  LOG_INFO_("\n");
115 
116 #if NETSTACK_CONF_WITH_IPV6
117  {
118  uip_ds6_addr_t *lladdr;
119  memcpy(&uip_lladdr.addr, &linkaddr_node_addr, sizeof(uip_lladdr.addr));
120  process_start(&tcpip_process, NULL);
121 
122  lladdr = uip_ds6_get_link_local(-1);
123  LOG_INFO("Tentative link-local IPv6 address: ");
124  LOG_INFO_6ADDR(lladdr != NULL ? &lladdr->ipaddr : NULL);
125  LOG_INFO_("\n");
126  }
127 #endif /* NETSTACK_CONF_WITH_IPV6 */
128 
130 
131 #if BUILD_WITH_RPL_BORDER_ROUTER
132  rpl_border_router_init();
133  LOG_DBG("With RPL Border Router\n");
134 #endif /* BUILD_WITH_RPL_BORDER_ROUTER */
135 
136 #if BUILD_WITH_ORCHESTRA
137  orchestra_init();
138  LOG_DBG("With Orchestra\n");
139 #endif /* BUILD_WITH_ORCHESTRA */
140 
141 #if BUILD_WITH_SHELL
143  LOG_DBG("With Shell\n");
144 #endif /* BUILD_WITH_SHELL */
145 
146 #if BUILD_WITH_COAP
147  coap_engine_init();
148  LOG_DBG("With CoAP\n");
149 #endif /* BUILD_WITH_SHELL */
150 
151 #if BUILD_WITH_SNMP
152  snmp_init();
153  LOG_DBG("With SNMP\n");
154 #endif /* BUILD_WITH_SNMP */
155 
156 #if BUILD_WITH_SIMPLE_ENERGEST
158 #endif /* BUILD_WITH_SIMPLE_ENERGEST */
159 
160 #if BUILD_WITH_TSCH_CS
161  /* Initialize the channel selection module */
163 #endif /* BUILD_WITH_TSCH_CS */
164 
165  autostart_start(autostart_processes);
166 
167  watchdog_start();
168 
169 #if PLATFORM_PROVIDES_MAIN_LOOP
171 #else
172  while(1) {
173  uint8_t r;
174  do {
175  r = process_run();
177  } while(r > 0);
178 
179  platform_idle();
180  }
181 #endif
182 
183  return 0;
184 }
185 /*---------------------------------------------------------------------------*/
186 /**
187  * @}
188  */
uip_lladdr_t uip_lladdr
Host L2 address.
Definition: uip6.c:107
An implementation of the Simple Network Management Protocol (RFC 3411-3418)
Header file for the energy estimation mechanism
void platform_main_loop()
The platform&#39;s main loop, if provided.
Definition: platform.c:195
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:233
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:48
#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 tsch_cs_adaptations_init(void)
Initializes the TSCH hopping sequence selection module.
Definition: tsch-cs.c:108
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.
Header file for the Packet queue buffer management
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:74
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.
Header file for TSCH adaptive channel selection
void watchdog_periodic(void)
Writes the WDT clear sequence.
Definition: watchdog.c:85
void snmp_init()
Initializes the SNMP engine.
Definition: snmp.c:86
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