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"
53 #include "services/rpl-border-router/rpl-border-router.h"
58 
59 #include <stdio.h>
60 #include <stdint.h>
61 /*---------------------------------------------------------------------------*/
62 /* Log configuration */
63 #include "sys/log.h"
64 #define LOG_MODULE "Main"
65 #define LOG_LEVEL LOG_LEVEL_MAIN
66 /*---------------------------------------------------------------------------*/
67 int
68 #if PLATFORM_MAIN_ACCEPTS_ARGS
69 main(int argc, char **argv)
70 {
71  platform_process_args(argc, argv);
72 #else
73 main(void)
74 {
75 #endif
77 
78  clock_init();
79  rtimer_init();
80  process_init();
81  process_start(&etimer_process, NULL);
82  ctimer_init();
83  watchdog_init();
84 
85  energest_init();
86 
87 #if STACK_CHECK_ENABLED
89 #endif
90 
92 
93 #if QUEUEBUF_ENABLED
94  queuebuf_init();
95 #endif /* QUEUEBUF_ENABLED */
96  netstack_init();
97  node_id_init();
98 
99  LOG_INFO("Starting " CONTIKI_VERSION_STRING "\n");
100  LOG_INFO("- Routing: %s\n", NETSTACK_ROUTING.name);
101  LOG_INFO("- Net: %s\n", NETSTACK_NETWORK.name);
102  LOG_INFO("- MAC: %s\n", NETSTACK_MAC.name);
103  LOG_INFO("- 802.15.4 PANID: 0x%04x\n", IEEE802154_PANID);
104 #if MAC_CONF_WITH_TSCH
105  LOG_INFO("- 802.15.4 TSCH default hopping sequence length: %u\n", (unsigned)sizeof(TSCH_DEFAULT_HOPPING_SEQUENCE));
106 #else /* MAC_CONF_WITH_TSCH */
107  LOG_INFO("- 802.15.4 Default channel: %u\n", IEEE802154_DEFAULT_CHANNEL);
108 #endif /* MAC_CONF_WITH_TSCH */
109 
110  LOG_INFO("Node ID: %u\n", node_id);
111  LOG_INFO("Link-layer address: ");
112  LOG_INFO_LLADDR(&linkaddr_node_addr);
113  LOG_INFO_("\n");
114 
115 #if NETSTACK_CONF_WITH_IPV6
116  {
117  uip_ds6_addr_t *lladdr;
118  memcpy(&uip_lladdr.addr, &linkaddr_node_addr, sizeof(uip_lladdr.addr));
119  process_start(&tcpip_process, NULL);
120 
121  lladdr = uip_ds6_get_link_local(-1);
122  LOG_INFO("Tentative link-local IPv6 address: ");
123  LOG_INFO_6ADDR(lladdr != NULL ? &lladdr->ipaddr : NULL);
124  LOG_INFO_("\n");
125  }
126 #endif /* NETSTACK_CONF_WITH_IPV6 */
127 
129 
130 #if BUILD_WITH_RPL_BORDER_ROUTER
131  rpl_border_router_init();
132  LOG_DBG("With RPL Border Router\n");
133 #endif /* BUILD_WITH_RPL_BORDER_ROUTER */
134 
135 #if BUILD_WITH_ORCHESTRA
136  orchestra_init();
137  LOG_DBG("With Orchestra\n");
138 #endif /* BUILD_WITH_ORCHESTRA */
139 
140 #if BUILD_WITH_SHELL
142  LOG_DBG("With Shell\n");
143 #endif /* BUILD_WITH_SHELL */
144 
145 #if BUILD_WITH_COAP
146  coap_engine_init();
147  LOG_DBG("With CoAP\n");
148 #endif /* BUILD_WITH_SHELL */
149 
150 #if BUILD_WITH_SIMPLE_ENERGEST
152 #endif /* BUILD_WITH_SIMPLE_ENERGEST */
153 
154 #if BUILD_WITH_TSCH_CS
155  /* Initialize the channel selection module */
157 #endif /* BUILD_WITH_TSCH_CS */
158 
159  autostart_start(autostart_processes);
160 
161  watchdog_start();
162 
163 #if PLATFORM_PROVIDES_MAIN_LOOP
165 #else
166  while(1) {
167  uint8_t r;
168  do {
169  r = process_run();
171  } while(r > 0);
172 
173  platform_idle();
174  }
175 #endif
176 
177  return 0;
178 }
179 /*---------------------------------------------------------------------------*/
180 /**
181  * @}
182  */
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: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
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