void tcpip_init() { #if UIP_TCP { static unsigned char i; for(i = 0; i < UIP_LISTENPORTS; ++i) { s.listenports[i].port = 0; } s.p = PROCESS_CURRENT(); } #endif //tcpip_event = process_alloc_event(); // etimer_set(&periodic, tcpip_process, CLOCK_SECOND/2); etimer_set(&periodic, CLOCK_SECOND/2); uip_init(); /* initialize RPL if configured for using RPL */ #if UIP_CONF_IPV6_RPL rpl_init(); #endif /* UIP_CONF_IPV6_RPL */ }
/*---------------------------------------------------------------------------*/ void tcpip_init(void) { #if UIP_TCP { static unsigned char i; for(i = 0; i < UIP_LISTENPORTS; ++i) { s.listenports[i].port = 0; } } #endif evproc_regCallback(EVENT_TYPE_TCP_POLL,eventhandler); evproc_regCallback(EVENT_TYPE_UDP_POLL,eventhandler); evproc_regCallback(EVENT_TYPE_PCK_INPUT,eventhandler); #if UIP_CONF_ICMP6 evproc_regCallback(EVENT_TYPE_ICMP6,eventhandler); // it is neede to register callback #endif /* UIP_CONF_ICMP6 */ etimer_set(&periodic, bsp_get(E_BSP_GET_TRES) / 2, eventhandler); uip_init(); #ifdef UIP_FALLBACK_INTERFACE UIP_FALLBACK_INTERFACE.init(); #endif /* initialize RPL if configured for using RPL */ #if UIP_CONF_IPV6_RPL rpl_init(); #endif /* UIP_CONF_IPV6_RPL */ }
void stack_init_rpl(int iface, const ipv6_addr_t *dodag_id) { (void)iface; rpl_init(); #ifdef STACK_RPL_ROOT rpl_set_root(0, (uip_ipaddr_t *)dodag_id); #else (void)dodag_id; #endif }
int main(void) { rpl_init(NULL, 0); printf("%llu\n", rpl_clock_get()); // printf("%lu\n", rpl_clock_get_monotonic()); rpl_exit(); return 0; }
/*---------------------------------------------------------------------------*/ void border_router_set_mac(const uint8_t *data) { memcpy(uip_lladdr.addr, data, sizeof(uip_lladdr.addr)); rimeaddr_set_node_addr((rimeaddr_t *)uip_lladdr.addr); /* is this ok - should instead remove all addresses and add them back again - a bit messy... ?*/ uip_ds6_init(); rpl_init(); mac_set = 1; }
int main(int argc, char** argv) { rpl_dll_t dll = NULL; rpl_init(NULL, 0); dll = rpl_dll_new(); if (!rpl_dll_open(dll, "/")) fprintf(stderr, "%s\n", rpl_error_translate_last()); rpl_exit(); return 0; }
int main(void) { puts("Smart Environment Actor Application"); // initialize RNG random_init(time(NULL)); // Message Queue for receiving potentially fast incoming networking packets msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE); // Initialize GPIO gpio_init(LEDRED_PIN, GPIO_OUT); gpio_init(LEDYELLOW_PIN, GPIO_OUT); gpio_init(LEDGREEN_PIN, GPIO_OUT); iface_pid = get_first_interface(); if (iface_pid < 0) { puts("Unable to find an interface to use for wireless communication"); return 1; } if (!rpl_init(iface_pid)) { puts("error: unable to initialize RPL"); return 1; } puts("Joining multicast group on addr " MULTICAST_ADDR); add_multicast_address(MULTICAST_ADDR, iface_pid); puts("Launching coap server"); thread_create(_rcv_stack_buf, THREAD_STACKSIZE_DEFAULT, THREAD_PRIORITY_MAIN - 1, 0, _coap_server_thread, NULL , "_coap_server_thread"); // Taken from the hello world example! printf("You are running RIOT on a(n) %s board.\n", RIOT_BOARD); printf("This board features a(n) %s MCU.\n", RIOT_MCU); char line_buf[SHELL_DEFAULT_BUFSIZE]; shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE); return 0; }
int main(int argc, char **argv) { uint32 retval; kprintf("main: calling getlocalip\n"); retval = getlocalip(); if (retval == SYSERR) { kprintf("I'm here to stop!\n"); } else { kprintf("I'm here to continue!\n"); kprintf("\n\n###########################################################\n\n"); kprintf("IP address is %d.%d.%d.%d %08x\n\r", (retval>>24)&0xff, (retval>>16)&0xff, (retval>>8)&0xff, retval&0xff,retval); kprintf("Subnet mask is %d.%d.%d.%d and router is %d.%d.%d.%d\n\r", (NetData.addrmask>>24)&0xff, (NetData.addrmask>>16)&0xff, (NetData.addrmask>> 8)&0xff, NetData.addrmask&0xff, (NetData.routeraddr>>24)&0xff, (NetData.routeraddr>>16)&0xff, (NetData.routeraddr>> 8)&0xff, NetData.routeraddr&0xff); } dot2ip(RPL_FORWARDING_GATEWAY, &retval); if(retval == NetData.ipaddr){ kprintf("I am the simulator gateway\r\n"); } rpl_init(); resume(create(shell, 4096, INITPRIO, "Shell", 1, CONSOLE)); receive(); getlocalip(); resume(create(shell, 4096, INITPRIO, "Shell", 1, CONSOLE)); return OK; }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(tcpip_process, ev, data) { PROCESS_BEGIN(); #if UIP_TCP { static unsigned char i; for(i = 0; i < UIP_LISTENPORTS; ++i) { s.listenports[i].port = 0; } s.p = PROCESS_CURRENT(); } #endif tcpip_event = process_alloc_event(); #if UIP_CONF_ICMP6 tcpip_icmp6_event = process_alloc_event(); #endif /* UIP_CONF_ICMP6 */ etimer_set(&periodic, CLOCK_SECOND); ctimer_set(&reset_input,WINDOW_SIZE_DATA_RATE, reset_packet_input, 0); uip_init(); #ifdef UIP_FALLBACK_INTERFACE UIP_FALLBACK_INTERFACE.init(); #endif /* initialize RPL if configured for using RPL */ #if UIP_CONF_IPV6 && UIP_CONF_IPV6_RPL rpl_init(); #endif /* UIP_CONF_IPV6_RPL */ #if FORWARDER define_mobile_nodes(); #endif while(1) { PROCESS_YIELD(); eventhandler(ev, data); } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(tcpip_process, ev, data) { PROCESS_BEGIN(); tcpip_set_inputfunc(tcpip_inputfunc); #if UIP_TCP { static unsigned char i; for(i = 0; i < UIP_LISTENPORTS; ++i) { s.listenports[i].port = 0; } s.p = PROCESS_CURRENT(); } #endif tcpip_event = process_alloc_event(); #if UIP_CONF_ICMP6 tcpip_icmp6_event = process_alloc_event(); #endif /* UIP_CONF_ICMP6 */ etimer_set(&periodic, CLOCK_SECOND / 2); uip_init(); #ifdef UIP_FALLBACK_INTERFACE UIP_FALLBACK_INTERFACE.init(); #endif /* initialize RPL if configured for using RPL */ #if NETSTACK_CONF_WITH_IPV6 && UIP_CONF_IPV6_RPL rpl_init(); #endif /* UIP_CONF_IPV6_RPL */ while(1) { PROCESS_YIELD(); eventhandler(ev, data); } PROCESS_END(); }
void rpl_udp_init(int argc, char **argv) { transceiver_command_t tcmd; msg_t m; int32_t chan = UNASSIGNED_CHANNEL; if (argc != 2) { printf("Usage: %s (r|n|h)\n", argv[0]); printf("\tr\tinitialize as root\n"); printf("\tn\tinitialize as node router\n"); printf("\th\tinitialize as non-routing node (host-mode)\n"); return; } char command = argv[1][0]; if ((command == 'n') || (command == 'r') || (command == 'h')) { printf("INFO: Initialize as %srouting %s on address %d\n", ((command == 'h') ? "non-" : ""), (((command == 'n') || (command == 'h')) ? "node" : "root"), id); #if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY) || defined(MODULE_CC110X_LEGACY_CSMA)) if (!id || (id > 255)) { printf("ERROR: address not a valid 8 bit integer\n"); return; } #endif DEBUGF("Setting HW address to %u\n", id); net_if_set_hardware_address(0, id); tcmd.transceivers = TRANSCEIVER; tcmd.data = &chan; m.type = GET_CHANNEL; m.content.ptr = (void *) &tcmd; msg_send_receive(&m, &m, transceiver_pid); if( chan == UNASSIGNED_CHANNEL ) { DEBUGF("The channel has not been set yet."); /* try to set the channel to 10 (RADIO_CHANNEL) */ chan = RADIO_CHANNEL; } m.type = SET_CHANNEL; msg_send_receive(&m, &m, transceiver_pid); if( chan == UNASSIGNED_CHANNEL ) { puts("ERROR: channel NOT set! Aborting initialization."); return; } printf("Channel set to %" PRIi32 "\n", chan); /* global address */ ipv6_addr_t global_addr, global_prefix; ipv6_addr_init(&global_prefix, 0xabcd, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0); ipv6_addr_set_by_eui64(&global_addr, 0, &global_prefix); if (command != 'h') { DEBUGF("Initializing RPL for interface 0\n"); uint8_t state = SIXLOWERROR_VALUE; if (command == 'n') { /* * no global address specified, we'll use auto address config * initiated by the root node */ state = rpl_init(0, NULL); } else if (command == 'r') { rpl_options_t rpl_opts = { .instance_id = 0, .prefix = global_prefix, .prefix_len = 64, .prefix_flags = RPL_PREFIX_INFO_AUTO_ADDR_CONF, /* autonomous address-configuration */ }; /* use specific global address */ state = rpl_init(0, &global_addr); rpl_init_root(&rpl_opts); is_root = 1; } if (state != SIXLOWERROR_SUCCESS) { puts("Error initializing RPL"); } else { puts("6LoWPAN and RPL initialized."); } ipv6_iface_set_routing_provider(rpl_get_next_hop); }
void init(char *str) { transceiver_command_t tcmd; msg_t m; uint8_t chan = RADIO_CHANNEL; char command; int res = sscanf(str, "init %c", &command); if (res < 1) { printf("Usage: init (r|n)\n"); printf("\tr\tinitialize as root\n"); printf("\tn\tinitialize as node router\n"); } uint8_t state; if ((command == 'n') || (command == 'r')) { printf("INFO: Initialize as %s on address %d\n", ((command == 'n') ? "node" : "root"), id); if (!id || (id > 255)) { printf("ERROR: address not a valid 8 bit integer\n"); return; } state = rpl_init(TRANSCEIVER, id); if (state != SIXLOWERROR_SUCCESS) { printf("Error initializing RPL\n"); } else { puts("6LoWPAN and RPL initialized."); } if (command == 'r') { rpl_init_root(); is_root = 1; } else { ipv6_iface_set_routing_provider(rpl_get_next_hop); } int monitor_pid = thread_create(monitor_stack_buffer, MONITOR_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, monitor, "monitor"); transceiver_register(TRANSCEIVER, monitor_pid); ipv6_register_packet_handler(monitor_pid); //sixlowpan_lowpan_register(monitor_pid); } else { printf("ERROR: Unknown command '%c'\n", command); return; } /* TODO: check if this works as intended */ ipv6_addr_t prefix, tmp; ipv6_addr_init(&std_addr, 0xABCD, 0xEF12, 0, 0, 0x1034, 0x00FF, 0xFE00, id); ipv6_addr_init_prefix(&prefix, &std_addr, 64); plist_add(&prefix, 64, NDP_OPT_PI_VLIFETIME_INFINITE, 0, 1, ICMPV6_NDP_OPT_PI_FLAG_AUTONOM); ipv6_init_iface_as_router(); /* add global address */ ipv6_addr_set_by_eui64(&tmp, &std_addr); ipv6_iface_add_addr(&tmp, IPV6_ADDR_TYPE_GLOBAL, NDP_ADDR_STATE_PREFERRED, 0, 0); /* set channel to 10 */ tcmd.transceivers = TRANSCEIVER; tcmd.data = &chan; m.type = SET_CHANNEL; m.content.ptr = (void *) &tcmd; msg_send_receive(&m, &m, transceiver_pid); printf("Channel set to %u\n", RADIO_CHANNEL); destiny_init_transport_layer(); puts("Destiny initialized"); /* start transceiver watchdog */ }
void rpl_udp_init(int argc, char **argv) { transceiver_command_t tcmd; msg_t m; uint8_t chan = RADIO_CHANNEL; if (argc != 2) { printf("Usage: %s (r|n)\n", argv[0]); printf("\tr\tinitialize as root\n"); printf("\tn\tinitialize as node router\n"); return; } uint8_t state; char command = argv[1][0]; if ((command == 'n') || (command == 'r')) { printf("INFO: Initialize as %s on address %d\n", ((command == 'n') ? "node" : "root"), id); if (!id || (id > 255)) { printf("ERROR: address not a valid 8 bit integer\n"); return; } DEBUGF("Setting HW address to %u\n", id); net_if_set_hardware_address(0, id); DEBUGF("Initializing RPL for interface 0\n"); state = rpl_init(0); if (state != SIXLOWERROR_SUCCESS) { printf("Error initializing RPL\n"); } else { puts("6LoWPAN and RPL initialized."); } if (command == 'r') { rpl_init_root(); is_root = 1; } else { ipv6_iface_set_routing_provider(rpl_get_next_hop); } DEBUGF("Start monitor\n"); int monitor_pid = thread_create( monitor_stack_buffer, sizeof(monitor_stack_buffer), PRIORITY_MAIN - 2, CREATE_STACKTEST, rpl_udp_monitor, NULL, "monitor"); DEBUGF("Register at transceiver %02X\n", TRANSCEIVER); transceiver_register(TRANSCEIVER, monitor_pid); ipv6_register_packet_handler(monitor_pid); //sixlowpan_lowpan_register(monitor_pid); } else { printf("ERROR: Unknown command '%c'\n", command); return; } /* TODO: check if this works as intended */ ipv6_addr_t prefix, tmp; ipv6_addr_init(&std_addr, 0xABCD, 0xEF12, 0, 0, 0x1034, 0x00FF, 0xFE00, id); ipv6_addr_init_prefix(&prefix, &std_addr, 64); ndp_add_prefix_info(0, &prefix, 64, NDP_OPT_PI_VLIFETIME_INFINITE, NDP_OPT_PI_PLIFETIME_INFINITE, 1, ICMPV6_NDP_OPT_PI_FLAG_AUTONOM); ipv6_init_as_router(); /* add global address */ ipv6_addr_set_by_eui64(&tmp, 0, &std_addr); ipv6_net_if_add_addr(0, &tmp, NDP_ADDR_STATE_PREFERRED, 0, 0, 0); /* set channel to 10 */ tcmd.transceivers = TRANSCEIVER; tcmd.data = &chan; m.type = SET_CHANNEL; m.content.ptr = (void *) &tcmd; msg_send_receive(&m, &m, transceiver_pid); printf("Channel set to %u\n", RADIO_CHANNEL); puts("Destiny initialized"); /* start transceiver watchdog */ }
/* ----------------------------------------------------------------------------- * Initialise the uip_server * -------------------------------------------------------------------------- */ void uip_server_init(chanend xtcp[], int num_xtcp, xtcp_ipconfig_t *ipconfig, unsigned char *mac_address) { if (ipconfig != NULL) memcpy(&uip_static_ipconfig, ipconfig, sizeof(xtcp_ipconfig_t)); /* set the mac_adress */ memcpy(&uip_lladdr, mac_address, 6); #if 0 //XXX CHSC: not necessary? Be carefully with erasing the mac address... /* The following line sets the uIP's link-layer address. This must be done * before the tcpip_process is started since in its initialisation * routine the function uip_netif_init() will be called from inside * uip_init()and there the default IPv6 address will be set by combining * the link local prefix (fe80::/64)and the link layer address. */ rimeaddr_copy((rimeaddr_t*) &uip_lladdr.addr, &rimeaddr_node_addr); #endif //TODO chsc: port the rtimer module (if really needed) // /* rtimers needed for radio cycling */ // rtimer_init(); /* Initialise the process module */ process_init(); /* etimers must be started before ctimer_init */ process_start(&etimer_process, NULL); ctimer_init(); /* this calls have to be made before the uip_init * not exactely proved why. CHSC * */ etimer_request_poll(); process_run(); uip_init(); #if UIP_CONF_IPV6 && UIP_CONF_IPV6_RPL rpl_init(); #endif /* UIP_CONF_IPV6_RPL */ #if UIP_IGMP igmp_init(); #endif /* UIP_IGMP */ if (ipconfig != NULL && (*((int*)ipconfig->ipaddr.u8) != 0)) { uip_static_ip = 1; } if (ipconfig == NULL) { uip_ipaddr_t ipaddr; #if UIP_CONF_IPV4 uip_ipaddr(&ipaddr, 0, 0, 0, 0); uip_sethostaddr(&ipaddr); uip_setdraddr(&ipaddr); uip_setnetmask(&ipaddr); #elif UIP_CONF_IPV6 uip_ip6addr(&ipaddr, 0, 0, 0, 0 , 0, 0, 0, 0); #endif /* UIP_CONF_IPVx */ } else { #if UIP_CONF_IPV4 uip_sethostaddr(&ipconfig->ipaddr); uip_setdraddr(&ipconfig->gateway); uip_setnetmask(&ipconfig->netmask); #ifdef XTCP_VERBOSE_DEBUG printf("Address: ");uip_printip4(uip_hostaddr);printf("\n"); printf("Gateway: ");uip_printip4(uip_draddr);printf("\n"); printf("Netmask: ");uip_printip4(uip_netmask);printf("\n"); #endif /* XTCP_VERBOSE_DEBUG */ #elif UIP_CONF_IPV6 #endif /* UIP_CONF_IPVx */ } #if UIP_CONF_IPV4 { #if UIP_USE_AUTOIP int hwsum = mac_address[0] + mac_address[1] + mac_address[2] + mac_address[3] + mac_address[4] + mac_address[5]; autoip_init(hwsum + (hwsum << 16) + (hwsum << 24)); #endif #if UIP_USE_DHCP dhcpc_init(uip_lladdr.addr, 6); #endif } #endif /* UIP_CONF_IPV4 */ xtcpd_init(xtcp, num_xtcp); }
/*---------------------------------------------------------------------------*/ void uip_ds6_periodic(void) { #if CONF_6LOWPAN_ND_OPTI_START && UIP_CONF_6L_ROUTER /* Start RPL only when the device has global IPv6 */ if(!rpl_started && uip_ds6_get_global(ADDR_PREFERRED)) { rpl_init(); rpl_started = 1; } #endif /* CONF_6LOWPAN_ND_OPTI_START && UIP_CONF_6L_ROUTER */ /* Periodic processing on unicast addresses */ for(locaddr = uip_ds6_if.addr_list; locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) { if(locaddr->isused) { if((!locaddr->isinfinite) && (stimer_expired(&locaddr->vlifetime))) { uip_ds6_addr_rm(locaddr); #if UIP_ND6_DEF_MAXDADNS > 0 } else if((locaddr->state == ADDR_TENTATIVE) && (locaddr->dadnscount <= uip_ds6_if.maxdadns) && (timer_expired(&locaddr->dadtimer)) && (uip_len == 0)) { uip_ds6_dad(locaddr); #endif /* UIP_ND6_DEF_MAXDADNS > 0 */ } } } /* Periodic processing on default routers */ uip_ds6_defrt_periodic(); /* for(locdefrt = uip_ds6_defrt_list; locdefrt < uip_ds6_defrt_list + UIP_DS6_DEFRT_NB; locdefrt++) { if((locdefrt->isused) && (!locdefrt->isinfinite) && (stimer_expired(&(locdefrt->lifetime)))) { uip_ds6_defrt_rm(locdefrt); } }*/ #if CONF_6LOWPAN_ND /* Periodic processing on context prefixes */ for(loccontext = uip_ds6_context_pref_list; loccontext < uip_ds6_context_pref_list + UIP_DS6_CONTEXT_PREF_NB; loccontext++) { if(loccontext->state != CONTEXT_PREF_ST_FREE) { #if UIP_CONF_6LBR if(stimer_expired(&loccontext->lifetime) && loccontext->br->state != BR_ST_NEW_VERSION) { switch(loccontext->state) { case CONTEXT_PREF_ST_RM: /* Valid lifetime expired, so remove */ loccontext->state = CONTEXT_PREF_ST_FREE; break; case CONTEXT_PREF_ST_ADD: /* before c=0, now c=1 */ loccontext->state = CONTEXT_PREF_ST_COMPRESS; stimer_set(&loccontext->lifetime, loccontext->vlifetime * 60); break; } } #else /* UIP_CONF_6LBR */ if(stimer_expired(&loccontext->lifetime)) { switch(loccontext->state) { case CONTEXT_PREF_ST_UNCOMPRESSONLY: case CONTEXT_PREF_ST_RM: /* Valid lifetime expired, so remove */ loccontext->state = CONTEXT_PREF_ST_FREE; break; case CONTEXT_PREF_ST_SENDING: /* receive-only mode for a period of twice the default Router Lifetime */ loccontext->state = CONTEXT_PREF_ST_UNCOMPRESSONLY; stimer_set(&loccontext->lifetime, loccontext->router_lifetime * 2); break; case CONTEXT_PREF_ST_ADD: /* before c=0, now c=1 */ loccontext->state = CONTEXT_PREF_ST_COMPRESS; stimer_set(&loccontext->lifetime, loccontext->vlifetime * 60); break; } } else if(is_timeout_percent(&loccontext->lifetime, UIP_DS6_RS_PERCENT_LIFETIME_RETRAN, UIP_DS6_RS_MINLIFETIME_RETRAN) && loccontext->state == CONTEXT_PREF_ST_COMPRESS) { if(loccontext->br->state != BR_ST_SENDING_RS) { loccontext->br->state = BR_ST_MUST_SEND_RS; } loccontext->state = CONTEXT_PREF_ST_SENDING; } #endif /* UIP_CONF_6LBR */ } } #endif /* CONF_6LOWPAN_ND */ #if !UIP_CONF_ROUTER /* Periodic processing on prefixes */ for(locprefix = uip_ds6_prefix_list; locprefix < uip_ds6_prefix_list + UIP_DS6_PREFIX_NB; locprefix++) { if(locprefix->isused && !locprefix->isinfinite) { if(stimer_expired(&(locprefix->vlifetime))) { uip_ds6_prefix_rm(locprefix); #if UIP_CONF_6LR || UIP_CONF_6LN } else if(is_timeout_percent(&locprefix->vlifetime, UIP_DS6_RS_PERCENT_LIFETIME_RETRAN, UIP_DS6_RS_MINLIFETIME_RETRAN)) { if(locprefix->br->state != BR_ST_SENDING_RS) { locprefix->br->state = BR_ST_MUST_SEND_RS; } #endif /* UIP_CONF_6LR || UIP_CONF_6LN */ } } } #endif /* !UIP_CONF_ROUTER */ /* Periodic processing on border router */ #if CONF_6LOWPAN_ND uip_ds6_br_periodic(); #endif /* CONF_6LOWPAN_ND */ /* Periodic processing on Duplication Address*/ #if UIP_CONF_6LBR for(locdad = uip_ds6_dup_addr_list; locdad < uip_ds6_dup_addr_list + UIP_DS6_DUPADDR_NB; locdad++) { if(locdad->isused && stimer_expired(&locdad->lifetime)) { uip_ds6_dup_addr_rm(locdad); } } #endif /* UIP_CONF_6LBR */ uip_ds6_neighbor_periodic(); #if UIP_CONF_ROUTER & UIP_ND6_SEND_RA #if !CONF_6LOWPAN_ND || UIP_ND6_RA_PERIODIC /* Periodic RA sending */ if(stimer_expired(&uip_ds6_timer_ra) && (uip_len == 0)) { uip_ds6_send_ra_periodic(); } #endif /* !CONF_6LOWPAN_ND || UIP_ND6_RA_PERIODIC */ #endif /* UIP_CONF_ROUTER & UIP_ND6_SEND_RA */ etimer_reset(&uip_ds6_timer_periodic); return; }
void mainfunc(cyg_addrword_t data) { /******************** lock the Scheduler ************************/ cyg_scheduler_lock(); /****************************************************************/ printf("Hello, eCos mainfunc!\n"); ds2411_id[0] = 0x00; ds2411_id[1] = 0x12; ds2411_id[2] = 0x75; ds2411_id[3] = 0x00; ds2411_id[4] = 0x0c; ds2411_id[5] = 0x59; //ds2411_id[6] = 0x57; //ds2411_id[7] = 0x3d; ds2411_id[6] = 0x10; ds2411_id[7] = 0x17; ds2411_id[2] &= 0xfe; /* ds2411_id[0] = 0x02; ds2411_id[1] = 0x00; ds2411_id[2] = 0x00; ds2411_id[3] = 0x00; ds2411_id[4] = 0x00; ds2411_id[5] = 0x00; //ds2411_id[6] = 0x57; //ds2411_id[7] = 0x3d; ds2411_id[6] = 0x00; ds2411_id[7] = 0x00; */ /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */ #ifdef IEEE_802154_MAC_ADDRESS { uint8_t ieee[] = IEEE_802154_MAC_ADDRESS; memcpy(ds2411_id, ieee, sizeof(uip_lladdr.addr)); ds2411_id[7] = node_id & 0xff; } #endif random_init(5); set_rime_addr(); NETSTACK_RADIO.init(); { cyg_uint8 longaddr[8]; cyg_uint16 shortaddr; shortaddr = (rimeaddr_node_addr.u8[0] << 8) + rimeaddr_node_addr.u8[1]; memset(longaddr, 0, sizeof(longaddr)); rimeaddr_copy((rimeaddr_t *)&longaddr, &rimeaddr_node_addr); printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ", longaddr[0], longaddr[1], longaddr[2], longaddr[3], longaddr[4], longaddr[5], longaddr[6], longaddr[7]); uz2400_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr); } uz2400_set_channel(RF_CHANNEL);/////////////////////////////////////////// #if WITH_UIP6 memcpy(&uip_lladdr.addr, ds2411_id, sizeof(uip_lladdr.addr)); /* Setup nullmac-like MAC for 802.15.4 */ /* sicslowpan_init(sicslowmac_init(&cc2420_driver)); */ /* printf(" %s channel %u\n", sicslowmac_driver.name, RF_CHANNEL); */ /* Setup X-MAC for 802.15.4 */ queuebuf_init(); //NETSTACK_RADIO.init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); printf("%s %s, channel check rate %lu Hz, radio channel %u\n", NETSTACK_MAC.name, NETSTACK_RDC.name, CLOCK_CONF_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1: NETSTACK_RDC.channel_check_interval()), RF_CHANNEL); //================ uip_init(); rpl_init(); //============= printf("Tentative link-local IPv6 address "); { uip_ds6_addr_t *lladdr=NULL; int i; lladdr = uip_ds6_get_link_local(-1); for(i = 0; i < 7; ++i) { printf("%02x%02x:", lladdr->ipaddr.u8[i * 2], lladdr->ipaddr.u8[i * 2 + 1]); } printf("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]); } if(!UIP_CONF_IPV6_RPL) { uip_ipaddr_t ipaddr; int i; uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE); printf("Tentative global IPv6 address "); for(i = 0; i < 7; ++i) { printf("%02x%02x:", ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]); } printf("%02x%02x\n", ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]); } #endif /* WITH_UIP6 */ static cyg_uint32 GLedPinspec; GLedPinspec = CYGHWR_HAL_STM32_GPIO( C, 6, OUT_50MHZ , OUT_PUSHPULL ); volatile static cyg_uint8 blink=0; /******************** unlock the Scheduler ************************/ cyg_scheduler_unlock(); /****************************************************************/ while(1){ /* blink=~blink; CYGHWR_HAL_STM32_GPIO_OUT(GLedPinspec,blink); cyg_thread_delay(500); */ cyg_thread_yield(); } }