44#include "contiki-net.h"
51#include "dev/watchdog.h"
57#include "services/rpl-border-router/rpl-border-router.h"
68#define LOG_MODULE "Main"
69#define LOG_LEVEL LOG_LEVEL_MAIN
71#if PLATFORM_MAIN_ACCEPTS_ARGS
79static const char *prog;
80static const char *help_usage;
81static const char *help_suffix;
84contiki_set_usage(
const char *msg)
90contiki_set_extra_help(
const char *msg)
96contiki_add_option(
struct contiki_callback_option *option)
98 static bool initialized =
false;
109 printf(
"usage: %s [options]%s", prog, help_usage ? help_usage :
"\n");
110 printf(
"Options are:\n");
111 for(
struct contiki_callback_option *r =
list_head(contiki_options);
112 r != NULL; r = r->next) {
116 int short_len = r->opt_struct.flag == NULL && r->opt_struct.val ? 6 : 0;
118 printf(
" -%c, ", (
char)r->opt_struct.val);
120 int has_arg = r->opt_struct.has_arg;
121 const char *arg_desc = has_arg == no_argument ?
"" :
122 has_arg == optional_argument ?
" [value]" :
" value ";
123 printf(
" %c-%s%s%s\t%s", strlen(r->opt_struct.name) == 1 ?
' ' :
'-',
124 r->opt_struct.name, arg_desc,
126 short_len + 3 + strlen(r->opt_struct.name) + strlen(arg_desc) < 8
131 printf(
"%s", help_suffix);
136help_callback(
const char *optarg)
141CONTIKI_OPTION(CONTIKI_MAX_INIT_PRIO + 1, {
"help", no_argument, NULL,
'h' },
142 help_callback,
"display this help and exit\n");
145parse_argv(
int *argc,
char ***argv)
148 const int num_options =
list_length(contiki_options);
149 struct contiki_callback_option options[num_options];
150 struct option long_options[num_options + 1];
153 for(
struct contiki_callback_option *r =
list_head(contiki_options);
154 r != NULL; ++i, r = r->next) {
155 memcpy(&long_options[i], &r->opt_struct,
sizeof(
struct option));
156 memcpy(&options[i], r,
sizeof(
struct contiki_callback_option));
159 memset(&long_options[i], 0,
sizeof(
struct option));
163 int c = getopt_long_only(*argc, *argv,
"", long_options, &ix);
171 if(options[ix].callback) {
173 if((rv = options[ix].callback(optarg)) != 0) {
184main(
int argc,
char **argv)
187 if((rv = parse_argv(&argc, &argv)) != 0) {
209#if STACK_CHECK_ENABLED
219 NETSTACK_RADIO.init();
225 NETSTACK_NETWORK.init();
232 LOG_INFO(
"Starting " CONTIKI_VERSION_STRING
"\n");
233 LOG_DBG(
"TARGET=%s", CONTIKI_TARGET_STRING);
234#ifdef CONTIKI_BOARD_STRING
235 LOG_DBG_(
", BOARD=%s", CONTIKI_BOARD_STRING);
238 LOG_INFO(
"- Routing: %s\n", NETSTACK_ROUTING.name);
239 LOG_INFO(
"- Net: %s\n", NETSTACK_NETWORK.name);
240 LOG_INFO(
"- MAC: %s\n", NETSTACK_MAC.name);
241 LOG_INFO(
"- 802.15.4 PANID: 0x%04x\n", IEEE802154_PANID);
242#if MAC_CONF_WITH_TSCH
243 LOG_INFO(
"- 802.15.4 TSCH default hopping sequence length: %u\n", (
unsigned)
sizeof(TSCH_DEFAULT_HOPPING_SEQUENCE));
248 LOG_INFO(
"Node ID: %u\n", node_id);
249 LOG_INFO(
"Link-layer address: ");
253#if NETSTACK_CONF_WITH_IPV6
259 lladdr = uip_ds6_get_link_local(-1);
260 LOG_INFO(
"Tentative link-local IPv6 address: ");
261 LOG_INFO_6ADDR(lladdr != NULL ? &lladdr->ipaddr : NULL);
268#if BUILD_WITH_RPL_BORDER_ROUTER
269 rpl_border_router_init();
270 LOG_DBG(
"With RPL Border Router\n");
273#if BUILD_WITH_ORCHESTRA
275 LOG_DBG(
"With Orchestra\n");
280 LOG_DBG(
"With Shell\n");
285 LOG_DBG(
"With CoAP\n");
290 LOG_DBG(
"With SNMP\n");
293#if BUILD_WITH_SIMPLE_ENERGEST
297#if BUILD_WITH_TSCH_CS
302 autostart_start(autostart_processes);
306#if PLATFORM_PROVIDES_MAIN_LOOP
310 process_num_events_t r;
void serial_shell_init(void)
Initializes Serial Shell module.
#define CC_NORETURN
Configure if the C compiler supports functions that are not meant to return e.g.
CoAP engine implementation.
Header file for the energy estimation mechanism.
802.15.4 frame creation and parsing functions
void snmp_init()
Initializes the SNMP engine.
void clock_init(void)
Arch-specific implementation of clock_init for the cc2538.
void watchdog_start(void)
Starts the WDT in watchdog mode if enabled by user configuration, maximum interval.
void watchdog_periodic(void)
Writes the WDT clear sequence.
void watchdog_init(void)
Initialisation function for the WDT.
void platform_init_stage_three()
Final stage of platform driver initialisation.
void platform_init_stage_one(void)
Basic (Stage 1) platform driver initialisation.
void platform_idle()
The platform's idle/sleep function.
void platform_init_stage_two()
Stage 2 of platform driver initialisation.
void ctimer_init(void)
Initialize the callback timer library.
linkaddr_t linkaddr_node_addr
The link-layer address of the node.
static void list_init(list_t list)
Initialize a list.
#define LIST(name)
Declare a linked list.
int list_length(const_list_t list)
Get the length of a list.
void list_add(list_t list, void *item)
Add an item at the end of a list.
static void * list_head(const_list_t list)
Get a pointer to the first element of a list.
void platform_main_loop(void)
The platform's main loop, if provided.
#define CONTIKI_OPTION(prio,...)
Add a command line option when the compilation unit is present.
static void node_id_init(void)
Initialize the node ID.
process_num_events_t process_run(void)
Run the system once - call poll handlers and process one event.
void process_start(struct process *p, process_data_t data)
Start a process.
void process_init(void)
Initialize the process module.
#define rtimer_init()
Initialize the real-time scheduler.
void simple_energest_init(void)
Initialize the deployment module.
void stack_check_init(void)
Initialize the stack area with a known pattern.
uip_lladdr_t uip_lladdr
Host L2 address.
Linked list manipulation routines.
Header file for the logging system.
#define IEEE802154_DEFAULT_CHANNEL
The default channel for IEEE 802.15.4 networks.
Node-id (simple 16-bit identifiers) handling.
Header file for the Packet queue buffer management.
Header file for generating non-cryptographic random numbers.
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.
void(* init)(void)
Initialize the MAC driver.
Unicast address structure.
void tsch_cs_adaptations_init(void)
Initializes the TSCH hopping sequence selection module.
Header file for TSCH adaptive channel selection.