/** * \brief Main routine for the cc2538dk platform */ int main(void) { nvic_init(); ioc_init(); sys_ctrl_init(); clock_init(); lpm_init(); rtimer_init(); gpio_init(); leds_init(); fade(LEDS_YELLOW); process_init(); watchdog_init(); button_sensor_init(); /* * Character I/O Initialisation. * When the UART receives a character it will call serial_line_input_byte to * notify the core. The same applies for the USB driver. * * If slip-arch is also linked in afterwards (e.g. if we are a border router) * it will overwrite one of the two peripheral input callbacks. Characters * received over the relevant peripheral will be handled by * slip_input_byte instead */ #if UART_CONF_ENABLE uart_init(0); uart_init(1); uart_set_input(SERIAL_LINE_CONF_UART, serial_line_input_byte); #endif #if USB_SERIAL_CONF_ENABLE usb_serial_init(); usb_serial_set_input(serial_line_input_byte); #endif serial_line_init(); INTERRUPTS_ENABLE(); fade(LEDS_GREEN); PUTS(CONTIKI_VERSION_STRING); PUTS(BOARD_STRING); PRINTF(" Net: "); PRINTF("%s\n", NETSTACK_NETWORK.name); PRINTF(" MAC: "); PRINTF("%s\n", NETSTACK_MAC.name); PRINTF(" RDC: "); PRINTF("%s\n", NETSTACK_RDC.name); /* Initialise the H/W RNG engine. */ random_init(0); udma_init(); process_start(&etimer_process, NULL); ctimer_init(); set_rf_params(); #if CRYPTO_CONF_INIT crypto_init(); crypto_disable(); #endif netstack_init(); #if NETSTACK_CONF_WITH_IPV6 memcpy(&uip_lladdr.addr, &linkaddr_node_addr, sizeof(uip_lladdr.addr)); queuebuf_init(); process_start(&tcpip_process, NULL); #endif /* NETSTACK_CONF_WITH_IPV6 */ adc_init(); process_start(&sensors_process, NULL); energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); autostart_start(autostart_processes); watchdog_start(); fade(LEDS_ORANGE); while(1) { uint8_t r; do { /* Reset watchdog and handle polls and events */ watchdog_periodic(); r = process_run(); } while(r > 0); /* We have serviced all pending events. Enter a Low-Power mode. */ lpm_enter(); } }
/** * \brief Main routine for the cc2538dk platform */ int main(void) { // Just for test purposes uint16_t temperature = 0; uint16_t humidity = 0; float* temperature_f; float* humidity_f; unsigned char* checksum; unsigned char status; unsigned char temp_data = 0xff; /* unsigned char err = 0; SHT11 disabled */ nvic_init(); sys_ctrl_init(); clock_init(); lpm_init(); rtimer_init(); gpio_init(); ioc_init(); i2c_init(); leds_init(); fade(LEDS_YELLOW); process_init(); watchdog_init(); button_sensor_init(); /* * Character I/O Initialisation. * When the UART receives a character it will call serial_line_input_byte to * notify the core. The same applies for the USB driver. * * If slip-arch is also linked in afterwards (e.g. if we are a border router) * it will overwrite one of the two peripheral input callbacks. Characters * received over the relevant peripheral will be handled by * slip_input_byte instead */ #if UART_CONF_ENABLE uart_init(); uart_set_input(serial_line_input_byte); #endif #if USB_SERIAL_CONF_ENABLE usb_serial_init(); usb_serial_set_input(serial_line_input_byte); #endif serial_line_init(); INTERRUPTS_ENABLE(); fade(LEDS_GREEN); PUTS(CONTIKI_VERSION_STRING);PUTS(BOARD_STRING); PRINTF(" Net: ");PRINTF("%s\n", NETSTACK_NETWORK.name);PRINTF(" MAC: ");PRINTF("%s\n", NETSTACK_MAC.name);PRINTF(" RDC: ");PRINTF("%s\n", NETSTACK_RDC.name); /* Initialise the H/W RNG engine. */ random_init(0); udma_init(); process_start(&etimer_process, NULL); ctimer_init(); set_rime_addr(); netstack_init(); cc2538_rf_set_addr(IEEE802154_PANID); #if UIP_CONF_IPV6 memcpy(&uip_lladdr.addr, &rimeaddr_node_addr, sizeof(uip_lladdr.addr)); queuebuf_init(); process_start(&tcpip_process, NULL); #endif /* UIP_CONF_IPV6 */ process_start(&sensors_process, NULL); energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); autostart_start(autostart_processes); watchdog_start(); fade(LEDS_ORANGE); while (1) { uint8_t r; do { /* Reset watchdog and handle polls and events */ watchdog_periodic(); r = process_run(); /* err = s_measure(&temperature, checksum, TEMP); if (err == 0) { PRINTF("Temperature (ADC value) = 0x%4x\n", temperature); err = s_measure(&humidity, checksum, HUMI); if (err == 0) { PRINTF("Humidity (ADC value) = 0x%4x\n", humidity); float tc=sht11_TemperatureC(temperature); float hc=sht11_Humidity(temperature,humidity); printf("temp:%u.%u\nhumidity:%u.%u\n",(int)tc,((int)(tc*10))%10 , (int)hc,((int)(hc*10))%10); } else PRINTF("SHT11 error - could not read humidity!\n"); } else PRINTF("SHT11 error - could not read temperature!\n"); */ /*err = s_write_statusreg(&temp_data); if (err == 0) { err = s_read_statusreg(&status, checksum); if (err == 0) PRINTF("STATUS REGISTER = 0x%2x", status); else PRINTF("SHT11 error - could not read status register!\n"); }*/ } while (r > 0); /* We have serviced all pending events. Enter a Low-Power mode. */ lpm_enter(); } }
/** * \brief Main routine for the cc2538dk platform */ int main(void) { nvic_init(); sys_ctrl_init(); clock_init(); dint(); /*Init Watchdog*/ watchdog_init();//Need to check the watchdog on 123gxl rtimer_init(); lpm_init(); gpio_init(); ioc_init(); leds_init(); fade(LEDS_YELLOW); button_sensor_init(); /* * Character I/O Initialisation. * When the UART receives a character it will call serial_line_input_byte to * notify the core. The same applies for the USB driver. * * If slip-arch is also linked in afterwards (e.g. if we are a border router) * it will overwrite one of the two peripheral input callbacks. Characters * received over the relevant peripheral will be handled by * slip_input_byte instead */ #if UART_CONF_ENABLE uart_init(0); uart_init(1); uart_set_input(SERIAL_LINE_CONF_UART, serial_line_input_byte); #endif #if USB_SERIAL_CONF_ENABLE usb_serial_init(); usb_serial_set_input(serial_line_input_byte); #endif serial_line_init(); /*Enable EA*/ eint(); INTERRUPTS_ENABLE(); fade(LEDS_GREEN); PRINTF("=================================\r\n"); PUTS(CONTIKI_VERSION_STRING); PRINTF("======================\r\n"); PRINTF("\r\n"); PUTS(BOARD_STRING); PRINTF("\r\n"); #ifdef NODEID node_id = NODEID; #ifdef BURN_NODEID node_id_burn(node_id); node_id_restore(); /* also configures node_mac[] */ #endif /* BURN_NODEID */ #else node_id_restore(); /* also configures node_mac[] */ #endif /* NODE_ID */ /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */ #ifdef MAC_1 { uint8_t ieee[] = { MAC_1, MAC_2, MAC_3, MAC_4, MAC_5, MAC_6, MAC_7, MAC_8 }; memcpy(node_mac, ieee, sizeof(uip_lladdr.addr)); } #endif /* * Initialize Contiki and our processes. */ process_init(); process_start(&sensors_process, NULL); button_sensor_init(); process_start(&etimer_process, NULL); ctimer_init(); set_rime_addr(); printf("finish addr seting\r\n"); /* Initialise the H/W RNG engine. */ random_init(0); udma_init(); if(node_id > 0) { printf("Node id %u.\r\n", node_id); } else { printf("Node id not set.\r\n"); } #if WITH_UIP6 memcpy(&uip_lladdr.addr, node_mac, sizeof(uip_lladdr.addr)); /* Setup nullmac-like MAC for 802.15.4 */ queuebuf_init(); netstack_init(); PRINTF("CC2538 IEEE802154 PANID %d\r\n", IEEE802154_PANID); cc2538_rf_set_addr(IEEE802154_PANID); printf("%s/%s %lu %u\r\n", NETSTACK_RDC.name, NETSTACK_MAC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1: NETSTACK_RDC.channel_check_interval()), RF_CHANNEL); process_start(&tcpip_process, NULL); printf("IPv6 "); { uip_ds6_addr_t *lladdr; 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\r\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]); } if(1) { uip_ipaddr_t ipaddr; int i; uip_ip6addr(&ipaddr, 0xfc00, 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\r\n", ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]); } #else /* WITH_UIP6 */ netstack_init(); PRINTF("CC2538 IEEE802154 PANID %d\r\n", IEEE802154_PANID); cc2538_rf_set_addr(IEEE802154_PANID); printf("%s %lu %u\r\n", NETSTACK_RDC.name, CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1: NETSTACK_RDC.channel_check_interval()), RF_CHANNEL); #endif /* WITH_UIP6 */ #if !WITH_UIP6 uart1_set_input(serial_line_input_byte); serial_line_init(); #endif #ifdef NETSTACK_AES_H #ifndef NETSTACK_AES_KEY #error Please define NETSTACK_AES_KEY! #endif /* NETSTACK_AES_KEY */ { const uint8_t key[] = NETSTACK_AES_KEY; netstack_aes_set_key(key); } /*printf("AES encryption is enabled: '%s'\n", NETSTACK_AES_KEY);*/ printf("AES encryption is enabled\r\n"); #else /* NETSTACK_AES_H */ printf("Warning: AES encryption is disabled\r\n"); #endif /* NETSTACK_AES_H */ #if TIMESYNCH_CONF_ENABLED timesynch_init(); timesynch_set_authority_level(rimeaddr_node_addr.u8[0]); #endif /* TIMESYNCH_CONF_ENABLED */ energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); simple_rpl_init(); /*Watch dog configuration*/ watchdog_periodic(); watchdog_start(); autostart_start(autostart_processes); //duty_cycle_scroller_start(CLOCK_SECOND * 2); #if IP64_CONF_UIP_FALLBACK_INTERFACE_SLIP && WITH_SLIP /* Start the SLIP */ printf("Initiating SLIP: my IP is 172.16.0.2...\r\n"); slip_arch_init(0); { uip_ip4addr_t ipv4addr, netmask; uip_ipaddr(&ipv4addr, 172, 16, 0, 2); uip_ipaddr(&netmask, 255, 255, 255, 0); ip64_set_ipv4_address(&ipv4addr, &netmask); } uart1_set_input(slip_input_byte); #endif /* IP64_CONF_UIP_FALLBACK_INTERFACE_SLIP */ fade(LEDS_ORANGE); /* * This is the scheduler loop. */ while(1) { uint8_t r; do { /* Reset watchdog and handle polls and events */ // printf("reset watchdog\r\n"); watchdog_periodic(); r = process_run(); } while(r > 0); /* We have serviced all pending events. Enter a Low-Power mode. */ lpm_enter(); } }