Contiki-NG
Loading...
Searching...
No Matches
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/*---------------------------------------------------------------------------*/
68int
69#if PLATFORM_MAIN_ACCEPTS_ARGS
70main(int argc, char **argv)
71{
72 platform_process_args(argc, argv);
73#else
74main(void)
75{
76#endif
78
79 clock_init();
82 process_start(&etimer_process, NULL);
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();
99
100 LOG_INFO("Starting " CONTIKI_VERSION_STRING "\n");
101 LOG_DBG("TARGET=%s", CONTIKI_TARGET_STRING);
102#ifdef CONTIKI_BOARD_STRING
103 LOG_DBG_(", BOARD=%s", CONTIKI_BOARD_STRING);
104#endif
105 LOG_DBG_("\n");
106 LOG_INFO("- Routing: %s\n", NETSTACK_ROUTING.name);
107 LOG_INFO("- Net: %s\n", NETSTACK_NETWORK.name);
108 LOG_INFO("- MAC: %s\n", NETSTACK_MAC.name);
109 LOG_INFO("- 802.15.4 PANID: 0x%04x\n", IEEE802154_PANID);
110#if MAC_CONF_WITH_TSCH
111 LOG_INFO("- 802.15.4 TSCH default hopping sequence length: %u\n", (unsigned)sizeof(TSCH_DEFAULT_HOPPING_SEQUENCE));
112#else /* MAC_CONF_WITH_TSCH */
113 LOG_INFO("- 802.15.4 Default channel: %u\n", IEEE802154_DEFAULT_CHANNEL);
114#endif /* MAC_CONF_WITH_TSCH */
115
116 LOG_INFO("Node ID: %u\n", node_id);
117 LOG_INFO("Link-layer address: ");
118 LOG_INFO_LLADDR(&linkaddr_node_addr);
119 LOG_INFO_("\n");
120
121#if NETSTACK_CONF_WITH_IPV6
122 {
123 uip_ds6_addr_t *lladdr;
124 memcpy(&uip_lladdr.addr, &linkaddr_node_addr, sizeof(uip_lladdr.addr));
125 process_start(&tcpip_process, NULL);
126
127 lladdr = uip_ds6_get_link_local(-1);
128 LOG_INFO("Tentative link-local IPv6 address: ");
129 LOG_INFO_6ADDR(lladdr != NULL ? &lladdr->ipaddr : NULL);
130 LOG_INFO_("\n");
131 }
132#endif /* NETSTACK_CONF_WITH_IPV6 */
133
135
136#if BUILD_WITH_RPL_BORDER_ROUTER
137 rpl_border_router_init();
138 LOG_DBG("With RPL Border Router\n");
139#endif /* BUILD_WITH_RPL_BORDER_ROUTER */
140
141#if BUILD_WITH_ORCHESTRA
142 orchestra_init();
143 LOG_DBG("With Orchestra\n");
144#endif /* BUILD_WITH_ORCHESTRA */
145
146#if BUILD_WITH_SHELL
148 LOG_DBG("With Shell\n");
149#endif /* BUILD_WITH_SHELL */
150
151#if BUILD_WITH_COAP
152 coap_engine_init();
153 LOG_DBG("With CoAP\n");
154#endif /* BUILD_WITH_COAP */
155
156#if BUILD_WITH_SNMP
157 snmp_init();
158 LOG_DBG("With SNMP\n");
159#endif /* BUILD_WITH_SNMP */
160
161#if BUILD_WITH_SIMPLE_ENERGEST
163#endif /* BUILD_WITH_SIMPLE_ENERGEST */
164
165#if BUILD_WITH_TSCH_CS
166 /* Initialize the channel selection module */
168#endif /* BUILD_WITH_TSCH_CS */
169
170 autostart_start(autostart_processes);
171
173
174#if PLATFORM_PROVIDES_MAIN_LOOP
176#else
177 while(1) {
178 uint8_t r;
179 do {
180 r = process_run();
182 } while(r > 0);
183
185 }
186#endif
187
188 return 0;
189}
190/*---------------------------------------------------------------------------*/
191/**
192 * @}
193 */
CoAP engine implementation.
Header file for the energy estimation mechanism.
void snmp_init()
Initializes the SNMP engine.
Definition snmp.c:57
void clock_init(void)
Arch-specific implementation of clock_init for the cc2538.
Definition clock.c:93
void watchdog_start(void)
Starts the WDT in watchdog mode if enabled by user configuration, maximum interval.
Definition watchdog.c:72
void watchdog_periodic(void)
Writes the WDT clear sequence.
Definition watchdog.c:85
void watchdog_init(void)
Initialisation function for the WDT.
Definition watchdog.c:63
void platform_init_stage_three()
Final stage of platform driver initialisation.
Definition platform.c:169
void platform_init_stage_one(void)
Basic (Stage 1) platform driver initialisation.
Definition platform.c:114
void platform_idle()
The platform's idle/sleep function.
Definition platform.c:185
void platform_init_stage_two()
Stage 2 of platform driver initialisation.
Definition platform.c:123
void ctimer_init(void)
Initialize the callback timer library.
Definition ctimer.c:86
linkaddr_t linkaddr_node_addr
The link-layer address of the node.
Definition linkaddr.c:48
void platform_main_loop(void)
The platform's main loop, if provided.
Definition tz-normal.c:95
void platform_process_args(int argc, char **argv)
Allow the platform to process main's command line arguments.
Definition platform.c:237
static void node_id_init(void)
Initialize the node ID.
Definition node-id.h:61
int process_run(void)
Run the system once - call poll handlers and process one event.
Definition process.c:305
void process_start(struct process *p, process_data_t data)
Start a process.
Definition process.c:107
void process_init(void)
Initialize the process module.
Definition process.c:218
#define rtimer_init()
Initialize the real-time scheduler.
Definition rtimer.h:123
void serial_shell_init(void)
Initializes Serial Shell module.
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
uip_lladdr_t uip_lladdr
Host L2 address.
Definition uip6.c:107
Header file for the logging system.
#define IEEE802154_DEFAULT_CHANNEL
The default channel for IEEE 802.15.4 networks.
Definition mac.h:52
Node-id (simple 16-bit identifiers) handling.
Orchestra header file.
Header file for the Contiki-NG main routine.
Header file for the Packet queue buffer management.
A shell back-end for the serial port.
A process that periodically prints out the time spent in radio tx, radio rx, total time and duty cycl...
SNMP Implementation of the process.
Stack checker library header file.
Unicast address structure.
Definition uip-ds6.h:205
void tsch_cs_adaptations_init(void)
Initializes the TSCH hopping sequence selection module.
Definition tsch-cs.c:116
Header file for TSCH adaptive channel selection.