2017-10-14 18:06:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* 3. Neither the name of the copyright holder nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* \addtogroup main
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
*
|
2017-10-15 16:57:01 +00:00
|
|
|
* Implementation of \os's main routine
|
2017-10-14 18:06:37 +00:00
|
|
|
*/
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
#include "contiki.h"
|
|
|
|
#include "contiki-net.h"
|
2018-05-16 18:25:14 +00:00
|
|
|
#include "sys/node-id.h"
|
2017-10-14 18:06:37 +00:00
|
|
|
#include "sys/platform.h"
|
2017-10-31 21:12:47 +00:00
|
|
|
#include "sys/energest.h"
|
2017-11-22 17:48:39 +00:00
|
|
|
#include "sys/stack-check.h"
|
2017-10-14 18:06:37 +00:00
|
|
|
#include "dev/watchdog.h"
|
|
|
|
|
2018-10-27 09:31:28 +00:00
|
|
|
#include "net/queuebuf.h"
|
2018-04-05 09:17:05 +00:00
|
|
|
#include "net/app-layer/coap/coap-engine.h"
|
2017-12-19 17:02:21 +00:00
|
|
|
#include "services/rpl-border-router/rpl-border-router.h"
|
2017-11-21 15:13:57 +00:00
|
|
|
#include "services/orchestra/orchestra.h"
|
|
|
|
#include "services/shell/serial-shell.h"
|
2018-05-17 09:56:34 +00:00
|
|
|
#include "services/simple-energest/simple-energest.h"
|
2017-11-28 14:58:42 +00:00
|
|
|
#include "services/tsch-cs/tsch-cs.h"
|
2017-10-14 18:06:37 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2017-10-17 23:17:12 +00:00
|
|
|
/* Log configuration */
|
|
|
|
#include "sys/log.h"
|
|
|
|
#define LOG_MODULE "Main"
|
|
|
|
#define LOG_LEVEL LOG_LEVEL_MAIN
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2017-10-14 18:06:37 +00:00
|
|
|
int
|
2017-10-15 16:33:05 +00:00
|
|
|
#if PLATFORM_MAIN_ACCEPTS_ARGS
|
|
|
|
main(int argc, char **argv)
|
2017-10-15 17:00:20 +00:00
|
|
|
{
|
|
|
|
platform_process_args(argc, argv);
|
2017-10-15 16:33:05 +00:00
|
|
|
#else
|
2017-10-14 18:06:37 +00:00
|
|
|
main(void)
|
|
|
|
{
|
2017-10-15 17:00:20 +00:00
|
|
|
#endif
|
2017-10-14 18:06:37 +00:00
|
|
|
platform_init_stage_one();
|
|
|
|
|
|
|
|
clock_init();
|
|
|
|
rtimer_init();
|
|
|
|
process_init();
|
|
|
|
process_start(&etimer_process, NULL);
|
|
|
|
ctimer_init();
|
2017-10-14 18:51:48 +00:00
|
|
|
watchdog_init();
|
2017-10-14 18:06:37 +00:00
|
|
|
|
|
|
|
energest_init();
|
|
|
|
|
2017-11-22 17:48:39 +00:00
|
|
|
#if STACK_CHECK_ENABLED
|
|
|
|
stack_check_init();
|
|
|
|
#endif
|
|
|
|
|
2017-10-14 18:06:37 +00:00
|
|
|
platform_init_stage_two();
|
|
|
|
|
2018-10-27 09:31:28 +00:00
|
|
|
#if QUEUEBUF_ENABLED
|
|
|
|
queuebuf_init();
|
|
|
|
#endif /* QUEUEBUF_ENABLED */
|
2018-05-16 18:25:14 +00:00
|
|
|
netstack_init();
|
|
|
|
node_id_init();
|
|
|
|
|
2017-10-17 23:17:12 +00:00
|
|
|
LOG_INFO("Starting " CONTIKI_VERSION_STRING "\n");
|
2018-04-13 09:54:16 +00:00
|
|
|
LOG_INFO("- Routing: %s\n", NETSTACK_ROUTING.name);
|
|
|
|
LOG_INFO("- Net: %s\n", NETSTACK_NETWORK.name);
|
|
|
|
LOG_INFO("- MAC: %s\n", NETSTACK_MAC.name);
|
|
|
|
LOG_INFO("- 802.15.4 PANID: 0x%04x\n", IEEE802154_PANID);
|
2018-04-24 16:04:01 +00:00
|
|
|
#if MAC_CONF_WITH_TSCH
|
2018-04-13 09:54:16 +00:00
|
|
|
LOG_INFO("- 802.15.4 TSCH default hopping sequence length: %u\n", (unsigned)sizeof(TSCH_DEFAULT_HOPPING_SEQUENCE));
|
2018-04-24 16:04:01 +00:00
|
|
|
#else /* MAC_CONF_WITH_TSCH */
|
|
|
|
LOG_INFO("- 802.15.4 Default channel: %u\n", IEEE802154_DEFAULT_CHANNEL);
|
|
|
|
#endif /* MAC_CONF_WITH_TSCH */
|
2017-10-14 18:06:37 +00:00
|
|
|
|
2018-05-16 18:25:14 +00:00
|
|
|
LOG_INFO("Node ID: %u\n", node_id);
|
|
|
|
LOG_INFO("Link-layer address: ");
|
2017-10-17 23:17:12 +00:00
|
|
|
LOG_INFO_LLADDR(&linkaddr_node_addr);
|
|
|
|
LOG_INFO_("\n");
|
|
|
|
|
2017-10-18 16:21:26 +00:00
|
|
|
#if NETSTACK_CONF_WITH_IPV6
|
|
|
|
{
|
|
|
|
uip_ds6_addr_t *lladdr;
|
|
|
|
memcpy(&uip_lladdr.addr, &linkaddr_node_addr, sizeof(uip_lladdr.addr));
|
|
|
|
process_start(&tcpip_process, NULL);
|
|
|
|
|
|
|
|
lladdr = uip_ds6_get_link_local(-1);
|
2018-05-16 18:25:14 +00:00
|
|
|
LOG_INFO("Tentative link-local IPv6 address: ");
|
2017-10-18 16:21:26 +00:00
|
|
|
LOG_INFO_6ADDR(lladdr != NULL ? &lladdr->ipaddr : NULL);
|
|
|
|
LOG_INFO_("\n");
|
|
|
|
}
|
2017-10-14 18:06:37 +00:00
|
|
|
#endif /* NETSTACK_CONF_WITH_IPV6 */
|
|
|
|
|
2017-10-18 16:22:01 +00:00
|
|
|
platform_init_stage_three();
|
2017-10-17 23:17:12 +00:00
|
|
|
|
2017-12-19 17:02:21 +00:00
|
|
|
#if BUILD_WITH_RPL_BORDER_ROUTER
|
|
|
|
rpl_border_router_init();
|
|
|
|
LOG_DBG("With RPL Border Router\n");
|
|
|
|
#endif /* BUILD_WITH_RPL_BORDER_ROUTER */
|
|
|
|
|
2017-10-14 18:06:37 +00:00
|
|
|
#if BUILD_WITH_ORCHESTRA
|
|
|
|
orchestra_init();
|
2017-10-17 23:17:12 +00:00
|
|
|
LOG_DBG("With Orchestra\n");
|
2017-10-14 18:06:37 +00:00
|
|
|
#endif /* BUILD_WITH_ORCHESTRA */
|
|
|
|
|
|
|
|
#if BUILD_WITH_SHELL
|
|
|
|
serial_shell_init();
|
2017-10-17 23:17:12 +00:00
|
|
|
LOG_DBG("With Shell\n");
|
2017-10-14 18:06:37 +00:00
|
|
|
#endif /* BUILD_WITH_SHELL */
|
|
|
|
|
2018-04-05 09:17:05 +00:00
|
|
|
#if BUILD_WITH_COAP
|
|
|
|
coap_engine_init();
|
|
|
|
LOG_DBG("With CoAP\n");
|
|
|
|
#endif /* BUILD_WITH_SHELL */
|
|
|
|
|
2018-05-17 09:56:34 +00:00
|
|
|
#if BUILD_WITH_SIMPLE_ENERGEST
|
|
|
|
simple_energest_init();
|
|
|
|
#endif /* BUILD_WITH_SIMPLE_ENERGEST */
|
|
|
|
|
2017-11-28 14:58:42 +00:00
|
|
|
#if BUILD_WITH_TSCH_CS
|
|
|
|
/* Initialize the channel selection module */
|
|
|
|
tsch_cs_adaptations_init();
|
|
|
|
#endif /* BUILD_WITH_TSCH_CS */
|
|
|
|
|
2017-10-14 18:06:37 +00:00
|
|
|
autostart_start(autostart_processes);
|
|
|
|
|
|
|
|
watchdog_start();
|
|
|
|
|
2017-10-15 16:08:43 +00:00
|
|
|
#if PLATFORM_PROVIDES_MAIN_LOOP
|
|
|
|
platform_main_loop();
|
|
|
|
#else
|
2017-10-14 18:06:37 +00:00
|
|
|
while(1) {
|
|
|
|
uint8_t r;
|
|
|
|
do {
|
|
|
|
r = process_run();
|
|
|
|
watchdog_periodic();
|
|
|
|
} while(r > 0);
|
|
|
|
|
|
|
|
platform_idle();
|
|
|
|
}
|
2017-10-15 16:08:43 +00:00
|
|
|
#endif
|
2017-10-15 17:10:43 +00:00
|
|
|
|
|
|
|
return 0;
|
2017-10-14 18:06:37 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|