/*---------------------------------------------------------------------------*/ static void set_rime_addr(void) { int i; union { uint8_t u8[8]; } eui64; uint8_t *stm32w_eui64 = ST_RadioGetEui64(); { uint8_t c; /* Copy the EUI-64 to lladdr converting from Little-Endian to Big-Endian. */ for(c = 0; c < 8; c++) { eui64.u8[c] = stm32w_eui64[7 - c]; } } #if UIP_CONF_IPV6 memcpy(&uip_lladdr.addr, &eui64, sizeof(uip_lladdr.addr)); #endif #if UIP_CONF_IPV6 linkaddr_set_node_addr((linkaddr_t *)&eui64); #else linkaddr_set_node_addr((linkaddr_t *)&eui64.u8[8 - LINKADDR_SIZE]); #endif printf("Rime started with address "); for(i = 0; i < sizeof(linkaddr_t) - 1; i++) { printf("%d.", linkaddr_node_addr.u8[i]); } printf("%d\n", linkaddr_node_addr.u8[i]); }
/*---------------------------------------------------------------------------*/ #ifndef NODE_ID #define NODE_ID 0x03 #endif /* NODE_ID */ static void set_rime_addr(void) { linkaddr_t n_addr; int i; memset(&n_addr, 0, sizeof(linkaddr_t)); // Set node address #if NETSTACK_CONF_WITH_IPV6 //memcpy(addr.u8, ds2411_id, sizeof(addr.u8)); n_addr.u8[7] = node_id & 0xff; n_addr.u8[6] = node_id >> 8; #else /* if(node_id == 0) { for(i = 0; i < sizeof(linkaddr_t); ++i) { addr.u8[i] = ds2411_id[7 - i]; } } else { addr.u8[0] = node_id & 0xff; addr.u8[1] = node_id >> 8; }*/ n_addr.u8[0] = node_id & 0xff; n_addr.u8[1] = node_id >> 8; #endif linkaddr_set_node_addr(&n_addr); printf("Rime started with address "); for(i = 0; i < sizeof(n_addr.u8) - 1; i++) { printf("%d.", n_addr.u8[i]); } printf("%d\n", n_addr.u8[i]); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(eth_drv_process, ev, data) { PROCESS_BEGIN(); #if !CETIC_6LBR_ONE_ITF if(!sixlbr_config_use_raw_ethernet) { //We must create our own Ethernet MAC address while(!radio_ready) { PROCESS_PAUSE(); } mac_createEthernetAddr((uint8_t *) eth_mac_addr, &wsn_mac_addr); eth_mac_addr[0] &= ~TRANSLATE_BIT_MASK; eth_mac_addr_ready = 1; } #else //TODO: Ethernet Bridge bullshit ! eth_mac_addr[5] += 1; mac_createSicslowpanLongAddr((uint8_t *)eth_mac_addr, &wsn_mac_addr); memcpy(uip_lladdr.addr, wsn_mac_addr.addr, sizeof(uip_lladdr.addr)); linkaddr_set_node_addr((linkaddr_t *) &wsn_mac_addr); #endif LOG6LBR_ETHADDR(INFO, ð_mac_addr, "Eth MAC address : "); ethernet_ready = 1; PROCESS_END(); }
int net_set_mac(uint8_t *mac, uint8_t len) { if ((len > UIP_LLADDR_LEN) || (len != 6 && len != 8)) { NET_ERR("Wrong ll addr len, len %d, max %d\n", len, UIP_LLADDR_LEN); return -EINVAL; } linkaddr_set_node_addr((linkaddr_t *)mac); #ifdef CONFIG_NETWORKING_WITH_IPV6 { uip_ds6_addr_t *lladdr; uip_ds6_set_lladdr((uip_lladdr_t *)mac); lladdr = uip_ds6_get_link_local(-1); NET_DBG("Tentative link-local IPv6 address "); PRINT6ADDR(&lladdr->ipaddr); PRINTF("\n"); lladdr->state = ADDR_AUTOCONF; } #endif return 0; }
/*---------------------------------------------------------------------------*/ static void set_rime_addr(void) { linkaddr_t addr; int i; memset(&addr, 0, sizeof(linkaddr_t)); #if UIP_CONF_IPV6 memcpy(addr.u8, ds2411_id, sizeof(addr.u8)); #else if(node_id == 0) { for(i = 0; i < sizeof(linkaddr_t); ++i) { addr.u8[i] = ds2411_id[7 - i]; } } else { addr.u8[0] = node_id & 0xff; addr.u8[1] = node_id >> 8; } #endif linkaddr_set_node_addr(&addr); printf("Rime started with address "); for(i = 0; i < sizeof(addr.u8) - 1; i++) { printf("%d.", addr.u8[i]); } printf("%d\n", addr.u8[i]); }
/*---------------------------------------------------------------------------*/ static void set_linkaddr(void) { int i; linkaddr_t addr; memset(&addr, 0, LINKADDR_SIZE); #if NETSTACK_CONF_WITH_IPV6 memcpy(addr.u8, node_mac, sizeof(addr.u8)); #else if(node_id == 0) { for(i = 0; i < LINKADDR_SIZE; ++i) { addr.u8[i] = node_mac[LINKADDR_SIZE - 1 - i]; } } else { addr.u8[0] = node_id & 0xff; addr.u8[1] = node_id >> 8; } #endif linkaddr_set_node_addr(&addr); #if DEBUG PRINTF("Link-layer address: "); for(i = 0; i < sizeof(addr.u8) - 1; i++) { PRINTF("%d.", addr.u8[i]); } PRINTF("%d\n", addr.u8[i]); #endif }
/*---------------------------------------------------------------------------*/ static void set_rime_addr(void) { linkaddr_t addr; int i; memset(&addr, 0, sizeof(linkaddr_t)); #if NETSTACK_CONF_WITH_IPV6 memcpy(addr.u8, node_mac, sizeof(addr.u8)); #else if(node_id == 0) { for(i = 0; i < sizeof(linkaddr_t); ++i) { addr.u8[i] = node_mac[7 - i]; } } else { addr.u8[0] = node_id & 0xff; addr.u8[1] = node_id >> 8; } #endif linkaddr_set_node_addr(&addr); printf("Rime addr "); for(i = 0; i < sizeof(addr.u8) - 1; i++) { printf("%u.", addr.u8[i]); } printf("%u\n", addr.u8[i]); }
int cmd_handler_cc2420(const uint8_t *data, int len) { if(data[0] == '!') { if(data[1] == 'C' && len == 3) { printf("cc2420_cmd: setting channel: %d\n", data[2]); cc2420_set_channel(data[2]); return 1; } else if(data[1] == 'M' && len == 10) { printf("cc2420_cmd: Got MAC\n"); memcpy(uip_lladdr.addr, data+2, sizeof(uip_lladdr.addr)); linkaddr_set_node_addr((linkaddr_t *) uip_lladdr.addr); uint16_t shortaddr = (linkaddr_node_addr.u8[0] << 8) + linkaddr_node_addr.u8[1]; cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, linkaddr_node_addr.u8); return 1; } } else if(data[0] == '?') { if(data[1] == 'C' && len == 2) { uint8_t buf[4]; printf("cc2420_cmd: getting channel: %d\n", data[2]); buf[0] = '!'; buf[1] = 'C'; buf[2] = cc2420_get_channel(); cmd_send(buf, 3); return 1; } } return 0; }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(example_unicast_process, ev, data) { linkaddr_t node_addr; node_addr.u8[0] = 140; node_addr.u8[1] = 165; linkaddr_set_node_addr(&node_addr); PROCESS_EXITHANDLER(unicast_close(&uc);)
void slip_got_mac(const uint8_t * data) { memcpy(uip_lladdr.addr, data, sizeof(uip_lladdr.addr)); linkaddr_set_node_addr((linkaddr_t *) uip_lladdr.addr); linkaddr_copy((linkaddr_t *) & wsn_mac_addr, &linkaddr_node_addr); LOG6LBR_LLADDR(INFO, &uip_lladdr, "Got MAC: "); radio_mac_addr_ready = 1; }
int cmd_handler_cooja(const uint8_t *data, int len) { if(data[0] == '!') { if(data[1] == 'C' && len == 3) { printf("cooja_cmd: setting channel: %d\n", data[2]); radio_set_channel(data[2]); //Enable radio NETSTACK_RDC.off(1); return 1; } else if(data[1] == 'M' && len == 10) { if(!linkaddr_cmp((linkaddr_t *)(data+2), &linkaddr_null)) { printf("cooja_cmd: Got MAC\n"); if(linkaddr_cmp(&default_link_addr, &linkaddr_null)) { linkaddr_copy(&default_link_addr, &linkaddr_node_addr); } memcpy(uip_lladdr.addr, data+2, sizeof(uip_lladdr.addr)); linkaddr_set_node_addr((linkaddr_t *) uip_lladdr.addr); } else { printf("cooja_cmd: Clear MAC disabled\n"); if(!linkaddr_cmp(&default_link_addr, &linkaddr_null)) { memcpy(uip_lladdr.addr, &default_link_addr, sizeof(uip_lladdr.addr)); linkaddr_set_node_addr(&default_link_addr); } //Stop radio NETSTACK_RDC.off(0); } return 1; } } else if(data[0] == '?') { if(data[1] == 'C' && len == 2) { uint8_t buf[4]; printf("cooja_cmd: getting channel: %d\n", data[2]); buf[0] = '!'; buf[1] = 'C'; buf[2] = 0; cmd_send(buf, 3); return 1; } } return 0; }
/*---------------------------------------------------------------------------*/ void border_router_set_mac(const uint8_t *data) { memcpy(uip_lladdr.addr, data, sizeof(uip_lladdr.addr)); linkaddr_set_node_addr((linkaddr_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; }
/*---------------------------------------------------------------------------*/ static void set_rime_addr(void) { linkaddr_t addr; unsigned int i; /* memset(&addr, 0x65, sizeof(linkaddr_t)); */ memcpy(addr.u8, id.u8, sizeof(addr.u8)); linkaddr_set_node_addr(&addr); PRINTF("Rime started with address "); PRINTF("%d", addr.u8[0]); for(i = 1; i < sizeof(addr.u8); i++) { PRINTF(".%d", addr.u8[i]); } PRINTF("\n"); }
/*---------------------------------------------------------------------------*/ static void set_mac_addr(void) { linkaddr_t addr; int i; memset(&addr, 0, sizeof(linkaddr_t)); for(i = 0; i < sizeof(uip_lladdr.addr); i += 2) { addr.u8[i + 1] = node_id & 0xff; addr.u8[i + 0] = node_id >> 8; } linkaddr_set_node_addr(&addr); printf("MAC address "); for(i = 0; i < sizeof(addr.u8) - 1; i++) { printf("%d.", addr.u8[i]); } printf("%d\n", addr.u8[i]); }
int main_minimal_net(void) { // TODO: Pegar MAC Address do Microchip MRF24J40MA clock_init(); linkaddr_set_node_addr((linkaddr_t*) &addr); memcpy(&uip_lladdr.addr, &linkaddr_node_addr.u8, sizeof(uip_lladdr.addr)); #if 1 queuebuf_init(); netstack_init(); #endif process_init(); /* procinit_init initializes RPL which sets a ctimer for the first DIS */ /* We must start etimers and ctimers,before calling it */ process_start(&etimer_process, NULL); ctimer_init(); procinit_init(); #if AUTOSTART_ENABLE autostart_start(autostart_processes); #endif OSSemBinaryCreate(0, &Contiki_Sem); PRINTF("\n*******%s online*******\n\r", CONTIKI_VERSION_STRING); while (1) { int n; //char c; //INT8U ret,poll; //clock_time_t next_event; do { n = process_run(); //mrf24j40_get_rssi(); } while (n > 0); OSSemPend(Contiki_Sem, 0); } }
static void set_rime_addr(void) { linkaddr_t addr; uint8_t i; memset(&addr, 0, sizeof(linkaddr_t)); #if NETSTACK_CONF_WITH_IPV6 memcpy(&uip_lladdr.addr, mac_address, sizeof(uip_lladdr.addr)); memcpy(addr.u8, mac_address, sizeof(addr.u8)); #endif linkaddr_set_node_addr(&addr); #ifdef FILTERED_BORDER_ROUTER linkaddr_copy((linkaddr_t *) & wsn_mac_addr, &linkaddr_node_addr); #endif printf("Rime started with address "); for(i = 0; i < sizeof(addr.u8) - 1; i++) { printf("%02X:", addr.u8[i]); } printf("%02X\n", addr.u8[i]); mac_set =1; }
/*---------------------------------------------------------------------------*/ static void set_rime_addr(void) { linkaddr_t addr; int i; memset(&addr, 0, sizeof(linkaddr_t)); #if WITH_UIP6 for(i = 0; i < sizeof(uip_lladdr.addr); i += 2) { addr.u8[i + 1] = node_id & 0xff; addr.u8[i + 0] = node_id >> 8; } #else /* WITH_UIP6 */ addr.u8[0] = node_id & 0xff; addr.u8[1] = node_id >> 8; #endif /* WITH_UIP6 */ linkaddr_set_node_addr(&addr); printf("Rime started with address "); for(i = 0; i < sizeof(addr.u8) - 1; i++) { printf("%d.", addr.u8[i]); } printf("%d\n", addr.u8[i]); }
/*-----------------------------Low level initialization--------------------*/ static void initialize(void) { watchdog_init(); watchdog_start(); #if CONFIG_STACK_MONITOR /* Simple stack pointer highwater monitor. The 'm' command in cdc_task.c * looks for the first overwritten magic number. */ { extern uint16_t __bss_end; uint16_t p=(uint16_t)&__bss_end; do { *(uint16_t *)p = 0x4242; p+=100; } while (p<SP-100); //don't overwrite our own stack } #endif /* Initialize hardware */ // Checks for "finger", jumps to DFU if present. init_lowlevel(); /* Clock */ clock_init(); /* Leds are referred to by number to prevent any possible confusion :) */ /* Led0 Blue Led1 Red Led2 Green Led3 Yellow */ Leds_init(); Led1_on(); /* Get a random (or probably different) seed for the 802.15.4 packet sequence number. * Some layers will ignore duplicates found in a history (e.g. Contikimac) * causing the initial packets to be ignored after a short-cycle restart. */ ADMUX =0x1E; //Select AREF as reference, measure 1.1 volt bandgap reference. ADCSRA=1<<ADEN; //Enable ADC, not free running, interrupt disabled, fastest clock ADCSRA|=1<<ADSC; //Start conversion while (ADCSRA&(1<<ADSC)); //Wait till done PRINTD("ADC=%d\n",ADC); random_init(ADC); ADCSRA=0; //Disable ADC #if USB_CONF_RS232 /* Use rs232 port for serial out (tx, rx, gnd are the three pads behind jackdaw leds */ rs232_init(RS232_PORT_0, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Redirect stdout to second port */ rs232_redirect_stdout(RS232_PORT_0); #if ANNOUNCE PRINTA("\n\n*******Booting %s*******\n",CONTIKI_VERSION_STRING); #endif #endif /* rtimer init needed for low power protocols */ rtimer_init(); /* Process subsystem. */ process_init(); /* etimer process must be started before USB or ctimer init */ process_start(&etimer_process, NULL); Led2_on(); /* Now we can start USB enumeration */ process_start(&usb_process, NULL); /* Start CDC enumeration, bearing in mind that it may fail */ /* Hopefully we'll get a stdout for startup messages, if we don't already */ #if USB_CONF_SERIAL process_start(&cdc_process, NULL); {unsigned short i; for (i=0;i<65535;i++) { process_run(); watchdog_periodic(); if (stdout) break; } #if !USB_CONF_RS232 PRINTA("\n\n*******Booting %s*******\n",CONTIKI_VERSION_STRING); #endif } #endif if (!stdout) Led3_on(); #if RF230BB #if JACKDAW_CONF_USE_SETTINGS PRINTA("Settings manager will be used.\n"); #else {uint8_t x[2]; *(uint16_t *)x = eeprom_read_word((uint16_t *)&eemem_channel); if((uint8_t)x[0]!=(uint8_t)~x[1]) { PRINTA("Invalid EEPROM settings detected. Rewriting with default values.\n"); get_channel_from_eeprom(); } } #endif ctimer_init(); /* Start radio and radio receive process */ /* Note this starts RF230 process, so must be done after process_init */ NETSTACK_RADIO.init(); /* Set addresses BEFORE starting tcpip process */ memset(&tmp_addr, 0, sizeof(linkaddr_t)); if(get_eui64_from_eeprom(tmp_addr.u8)); //Fix MAC address init_net(); #if NETSTACK_CONF_WITH_IPV6 memcpy(&uip_lladdr.addr, &tmp_addr.u8, 8); #endif rf230_set_pan_addr( get_panid_from_eeprom(), get_panaddr_from_eeprom(), (uint8_t *)&tmp_addr.u8 ); rf230_set_channel(get_channel_from_eeprom()); rf230_set_txpower(get_txpower_from_eeprom()); linkaddr_set_node_addr(&tmp_addr); /* Initialize stack protocols */ queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); #if ANNOUNCE PRINTA("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n\r",tmp_addr.u8[0],tmp_addr.u8[1],tmp_addr.u8[2],tmp_addr.u8[3],tmp_addr.u8[4],tmp_addr.u8[5],tmp_addr.u8[6],tmp_addr.u8[7]); PRINTA("%s %s, channel %u",NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel()); if (NETSTACK_RDC.channel_check_interval) { unsigned short tmp; tmp=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\ NETSTACK_RDC.channel_check_interval()); if (tmp<65535) PRINTA(", check rate %u Hz",tmp); } PRINTA("\n"); #endif #if UIP_CONF_IPV6_RPL #if RPL_BORDER_ROUTER process_start(&tcpip_process, NULL); process_start(&border_router_process, NULL); PRINTD ("RPL Border Router Started\n"); #else process_start(&tcpip_process, NULL); PRINTD ("RPL Started\n"); #endif #if RPL_HTTPD_SERVER extern struct process httpd_process; process_start(&httpd_process, NULL); PRINTD ("Webserver Started\n"); #endif #endif /* UIP_CONF_IPV6_RPL */ #else /* RF230BB */ /* The order of starting these is important! */ process_start(&mac_process, NULL); #if NETSTACK_CONF_WITH_IPV6 || NETSTACK_CONF_WITH_IPV4 process_start(&tcpip_process, NULL); #endif #endif /* RF230BB */ /* Start ethernet network and storage process */ process_start(&usb_eth_process, NULL); #if USB_CONF_STORAGE process_start(&storage_process, NULL); #endif /* Autostart other processes */ /* There are none in the default build so autostart_processes will be unresolved in the link. */ /* The AUTOSTART_PROCESSES macro which defines it can only be used in the .co module. */ /* See /examples/ravenusbstick/ravenusb.c for an autostart template. */ #if 0 autostart_start(autostart_processes); #endif #if ANNOUNCE #if USB_CONF_RS232 PRINTA("Online.\n"); #else PRINTA("Online. Type ? for Jackdaw menu.\n"); #endif #endif Leds_off(); }
/*---------------------------------------------------------------------------*/ void init_net(uint8_t node_id) { uint16_t shortaddr; uint64_t longaddr; linkaddr_t addr; #if WITH_UIP6 uip_ds6_addr_t *lladdr; uip_ipaddr_t ipaddr; #endif uint8_t i; memset(&shortaddr, 0, sizeof(shortaddr)); memset(&longaddr, 0, sizeof(longaddr)); *((uint8_t *)&shortaddr) = node_id >> 8; *((uint8_t *)&shortaddr + 1) = node_id; *((uint8_t *)&longaddr) = node_id >> 8; *((uint8_t *)&longaddr + 1) = node_id; for(i = 2; i < sizeof(longaddr); ++i) { ((uint8_t *)&longaddr)[i] = random_rand(); } PRINTF("SHORT MAC ADDRESS %02x:%02x\n", *((uint8_t *) & shortaddr), *((uint8_t *) & shortaddr + 1)); PRINTF("EXTENDED MAC ADDRESS %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", *((uint8_t *)&longaddr), *((uint8_t *)&longaddr + 1), *((uint8_t *)&longaddr + 2), *((uint8_t *)&longaddr + 3), *((uint8_t *)&longaddr + 4), *((uint8_t *)&longaddr + 5), *((uint8_t *)&longaddr + 6), *((uint8_t *)&longaddr + 7)); memset(&addr, 0, sizeof(linkaddr_t)); for(i = 0; i < sizeof(addr.u8); ++i) { addr.u8[i] = ((uint8_t *)&longaddr)[i]; } linkaddr_set_node_addr(&addr); PRINTF("Rime started with address: "); for(i = 0; i < sizeof(addr.u8) - 1; ++i) { PRINTF("%d.", addr.u8[i]); } PRINTF("%d\n", addr.u8[i]); queuebuf_init(); NETSTACK_RADIO.init(); mrf24j40_set_channel(RF_CHANNEL); mrf24j40_set_panid(IEEE802154_PANID); mrf24j40_set_short_mac_addr(shortaddr); mrf24j40_set_extended_mac_addr(longaddr); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); PRINTF("%s %s, channel check rate %d Hz, radio channel %u\n", NETSTACK_MAC.name, NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1 : NETSTACK_RDC.channel_check_interval()), RF_CHANNEL); #if WITH_UIP6 #if LINKADDR_CONF_SIZE == 2 memset(&uip_lladdr.addr, 0, sizeof(uip_lladdr.addr)); uip_lladdr.addr[3] = 0xff; uip_lladdr.addr[4]= 0xfe; memcpy(&uip_lladdr.addr[6], &shortaddr, sizeof(shortaddr)); #else memcpy(&uip_lladdr.addr, &longaddr, sizeof(uip_lladdr.addr)); #endif process_start(&tcpip_process, NULL); lladdr = uip_ds6_get_link_local(-1); PRINTF("Tentative link-local IPv6 address "); 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_ip6addr(&ipaddr, 0x2001, 0x1418, 0x100, 0x823c, 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 }
void serial_data_handler(void) { if (data_length == 0) { /* No data to process, read the stream IO */ //rx_index = 0; data_length = sio2host_rx(data, 156); /* @ToDo 20 ?, * different * values for * USB and * UART ? */ } else { /* Data has been received, process the data */ printf("Receiving file..\n"); data_length--; rx_index++; if(rx_index ==99) { printf("Received File!!!!!!!!!!\n"); } } #endif void configure_gclock_generator(void) { //! [setup_1] struct system_gclk_gen_config gclock_gen_conf; //! [setup_1] //! [setup_2] system_gclk_gen_get_config_defaults(&gclock_gen_conf); //! [setup_2] //! [setup_3] gclock_gen_conf.source_clock = SYSTEM_CLOCK_SOURCE_ULP32K; gclock_gen_conf.division_factor = 128; //! [setup_3] //! [setup_4] system_gclk_gen_set_config(GCLK_GENERATOR_4, &gclock_gen_conf); //! [setup_4] //! [setup_5] system_gclk_gen_enable(GCLK_GENERATOR_4); //! [setup_5] } /*---------------------------------------------------------------------------*/ static void set_link_addr(void) { linkaddr_t addr; unsigned int i; memset(&addr, 0, sizeof(linkaddr_t)); #if UIP_CONF_IPV6 #if SAMR21 memcpy(addr.u8, eui64, sizeof(addr.u8)); #else memcpy(addr.u8, node_mac, sizeof(addr.u8)); #endif #else /* UIP_CONF_IPV6 */ if(node_id == 0) { for(i = 0; i < sizeof(linkaddr_t); ++i) { #if SAMR21 addr.u8[i] = eui64 [7 - i]; #else addr.u8[i] = node_mac [7 - i]; #endif } } else { addr.u8[0] = node_id & 0xff; addr.u8[1] = node_id >> 8; } #endif /* UIP_CONF_IPV6 */ linkaddr_set_node_addr(&addr); printf("Link layer addr "); for(i = 0; i < sizeof(addr.u8) - 1; i++) { printf("%u:", addr.u8[i]); } printf("%u, ", addr.u8[i]); for(i = 0; i < sizeof(addr.u8) - 1; i++) { printf("%02x:", addr.u8[i]); } printf("%02x\n", addr.u8[i]); }
void init_lowlevel(void) { /* Second rs232 port for debugging */ rs232_init(RS232_PORT_1, USART_BAUD_115200, USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Redirect stdout to second port */ rs232_redirect_stdout(RS232_PORT_1); /* Clock */ clock_init(); /* rtimers needed for radio cycling */ rtimer_init(); /* Initialize process subsystem */ process_init(); /* etimers must be started before ctimer_init */ process_start(&etimer_process, NULL); #if RF230BB ctimer_init(); /* Start radio and radio receive process */ NETSTACK_RADIO.init(); /* Set addresses BEFORE starting tcpip process */ linkaddr_t addr; memset(&addr, 0, sizeof(linkaddr_t)); eeprom_read_block ((void *)&addr.u8, &mac_address, 8); #if UIP_CONF_IPV6 memcpy(&uip_lladdr.addr, &addr.u8, 8); #endif rf230_set_pan_addr(IEEE802154_PANID, 0, (uint8_t *)&addr.u8); #ifdef CHANNEL_802_15_4 rf230_set_channel(CHANNEL_802_15_4); #else rf230_set_channel(26); #endif linkaddr_set_node_addr(&addr); PRINTF("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n",addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7]); /* Initialize stack protocols */ queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); #if ANNOUNCE_BOOT printf_P(PSTR("%s %s, channel %u"),NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel()); if (NETSTACK_RDC.channel_check_interval) {//function pointer is zero for sicslowmac unsigned short tmp; tmp=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\ NETSTACK_RDC.channel_check_interval()); if (tmp<65535) printf_P(PSTR(", check rate %u Hz"),tmp); } printf_P(PSTR("\n")); #endif #if UIP_CONF_ROUTER #if ANNOUNCE_BOOT printf_P(PSTR("Routing Enabled\n")); #endif rime_init(rime_udp_init(NULL)); uip_router_register(&rimeroute); #endif process_start(&tcpip_process, NULL); #else /* mac process must be started before tcpip process! */ process_start(&mac_process, NULL); process_start(&tcpip_process, NULL); #endif /*RF230BB*/ }
/** * \brief Main function for nRF52dk platform. * \note This function doesn't return. */ int main(void) { board_init(); leds_init(); clock_init(); rtimer_init(); watchdog_init(); process_init(); // Seed value is ignored since hardware RNG is used. random_init(0); #ifdef UART0_ENABLED uart0_init(); #if SLIP_ARCH_CONF_ENABLE slip_arch_init(0); #else uart0_set_input(serial_line_input_byte); serial_line_init(); #endif #endif PRINTF("Starting " CONTIKI_VERSION_STRING "\n"); process_start(&etimer_process, NULL); ctimer_init(); #if ENERGEST_CONF_ON energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); #endif #ifdef SOFTDEVICE_PRESENT ble_stack_init(); ble_advertising_init(DEVICE_NAME); #if NETSTACK_CONF_WITH_IPV6 netstack_init(); linkaddr_t linkaddr; ble_get_mac(linkaddr.u8); /* Set link layer address */ linkaddr_set_node_addr(&linkaddr); /* Set device link layer address in uip stack */ memcpy(&uip_lladdr.addr, &linkaddr, sizeof(uip_lladdr.addr)); process_start(&ble_iface_observer, NULL); process_start(&tcpip_process, NULL); #endif /* NETSTACK_CONF_WITH_IPV6 */ #endif /* SOFTDEVICE_PRESENT */ process_start(&sensors_process, NULL); autostart_start(autostart_processes); watchdog_start(); #ifdef SOFTDEVICE_PRESENT ble_advertising_start(); PRINTF("Advertising name [%s]\n", DEVICE_NAME); #endif while(1) { uint8_t r; do { r = process_run(); watchdog_periodic(); } while(r > 0); lpm_drop(); } }
void init_lowlevel(void) { uint8_t i; unsigned char ds2411_id[6]; /* Second rs232 port for debugging */ rs232_init(RS232_PORT_1, USART_BAUD_38400, USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Redirect stdout to second port */ rs232_redirect_stdout(RS232_PORT_1); /* Clock */ clock_init(); /* rtimers needed for radio cycling */ rtimer_init(); /* Initialize process subsystem */ process_init(); /* etimers must be started before ctimer_init */ process_start(&etimer_process, NULL); #if RF230BB ctimer_init(); /* Start radio and radio receive process */ NETSTACK_RADIO.init(); if(ds2411_read(ds2411_id)) { /* if serial available, modify adress in EPROM */ mac_address[0] = 0x02; mac_address[1] = 0; mac_address[2] = ds2411_id[0]; mac_address[3] = ds2411_id[1]; mac_address[4] = ds2411_id[2]; mac_address[5] = ds2411_id[3]; mac_address[6] = ds2411_id[4]; mac_address[7] = ds2411_id[5]; } /* Set addresses BEFORE starting tcpip process */ linkaddr_t addr; memset(&addr, 0, sizeof(linkaddr_t)); memcpy((void *)&addr.u8, &mac_address, 8); #if UIP_CONF_IPV6 memcpy(&uip_lladdr.addr, &addr.u8, 8); #endif /* UIP_CONF_IPV6 */ rf230_set_pan_addr(IEEE802154_PANID, 0, (uint8_t *) & addr.u8); #ifdef CHANNEL_802_15_4 rf230_set_channel(CHANNEL_802_15_4); #else /* CHANNEL_802_15_4 */ rf230_set_channel(26); #endif /* CHANNEL_802_15_4 */ linkaddr_set_node_addr(&addr); //calibrate_rc_osc_32k(); //CO: Had to comment this out /* Initialize hardware */ PRINTF("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n", addr.u8[0], addr.u8[1], addr.u8[2], addr.u8[3], addr.u8[4], addr.u8[5], addr.u8[6], addr.u8[7]); /* Initialize stack protocols */ queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); #if ANNOUNCE_BOOT printf_P(PSTR("%s %s, channel %u"), NETSTACK_MAC.name, NETSTACK_RDC.name, rf230_get_channel()); if(NETSTACK_RDC.channel_check_interval) { //function pointer is zero for sicslowmac unsigned short tmp; tmp = CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1 : NETSTACK_RDC.channel_check_interval()); if(tmp < 65535) printf_P(PSTR(", check rate %u Hz"), tmp); } printf_P(PSTR("\n")); #endif /* ANNOUNCE_BOOT */ #if UIP_CONF_ROUTER #if ANNOUNCE_BOOT printf_P(PSTR("Routing Enabled\n")); #endif /* ANNOUNCE_BOOT */ rime_init(rime_udp_init(NULL)); uip_router_register(&rimeroute); #endif /* UIP_CONF_ROUTER */ #if UIP_CONF_IPV6 process_start(&tcpip_process, NULL); #endif /* UIP_CONF_IPV6 */ #else /*RF230BB */ #if UIP_CONF_IPV6 /* mac process must be started before tcpip process! */ process_start(&mac_process, NULL); process_start(&tcpip_process, NULL); #endif /* UIP_CONF_IPV6 */ #endif /* RF230BB */ }
void platform_set_wsn_mac(linkaddr_t * mac_addr) { linkaddr_set_node_addr(mac_addr); slip_set_mac(mac_addr); }
/*============================================================================== LOCAL FUNCTIONS ==============================================================================*/ static int8_t _fradio_init(void) { uint32_t env_s_ip; uint32_t env_s_port; uint32_t env_c_ip; uint32_t env_c_port; linkaddr_t un_addr; env_s_ip = inet_addr(FRADIO_S_IP); env_c_ip = inet_addr(FRADIO_C_IP); if (!env_s_ip || !env_c_ip) { LOG_ERR("%s\n\r","FRADIO_S_IP or FRADIO_C_IP not found"); exit(1); } LOG_INFO("serv ip is: %s\n", FRADIO_S_IP); LOG_INFO("cli ip is: %s\n", FRADIO_C_IP); #if CLIENT & !SERVER env_s_port = atoi(FRADIO_OUTPORT_CLIENT); env_c_port = atoi(FRADIO_INPORT_CLIENT); #elif SERVER & !CLIENT env_s_port = atoi(FRADIO_OUTPORT_SERVER); env_c_port = atoi(FRADIO_INPORT_SERVER); #endif if (!env_s_port || !env_c_port) { LOG_ERR("%s\n\r","OUTPORT or INPORT not found"); exit(1); } LOG_INFO("serv port is: %d\n", env_s_port); LOG_INFO("cli port is: %d\n", env_c_port); // LOG_INFO("initial ll addr = %02X:%02X:%02X:%02X:%02X:%02X\n",uip_lladdr.addr[0],uip_lladdr.addr[1],uip_lladdr.addr[2],uip_lladdr.addr[3],uip_lladdr.addr[4],uip_lladdr.addr[5]); sockfd=socket(AF_INET,SOCK_DGRAM,0); memset(&servaddr,0,sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr=env_s_ip; servaddr.sin_port=htons(env_s_port); if (bind(sockfd,(struct sockaddr *)&servaddr,sizeof(servaddr)) < 0) { LOG_ERR("fail to create a socket: error %d\n",errno); exit(1); } memset(&cliaddr,0,sizeof(cliaddr)); cliaddr.sin_family = AF_INET; cliaddr.sin_addr.s_addr=env_c_ip; cliaddr.sin_port=htons(env_c_port); int flags = fcntl(sockfd, F_GETFL, 0); if (flags < 0) { LOG_ERR("%s\n\r","fcntl error"); exit(1); } flags = (flags|O_NONBLOCK); fcntl(sockfd, F_SETFL, flags); LOG_INFO("%s\n\r","fake_radio driver was initialized"); memcpy((void *)&un_addr.u8, &mac_address, 8); memcpy(&uip_lladdr.addr, &un_addr.u8, 8); linkaddr_set_node_addr(&un_addr); LOG_INFO("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n", \ un_addr.u8[0],un_addr.u8[1],\ un_addr.u8[2],un_addr.u8[3],\ un_addr.u8[4],un_addr.u8[5],\ un_addr.u8[6],un_addr.u8[7]); /* Start the packet receive process */ etimer_set(&tmr, 10, _fradio_handler); printf("set %p for %p callback\n\r",&tmr, &_fradio_handler); return 0; } /* _fradio_init() */