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