// main program body int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT board_init(); // init oscilator and leds timer_init(); // init timer sht11_init(); // init sht sensor #ifdef DEBUG uart_init(); // init debug interface set_debug_value(0x0,0); // store value for debug interface set_debug_value(0x0,1); #endif while(1) { unsigned int Tval,Hval; int TvalC,HvalC; LED_GREEN_ON(); if ((sht_measure_check(&Tval,TEMP)==0) && (sht_measure_check(&Hval,HUMI)==0)) { sht2int(Tval,Hval,&TvalC,&HvalC); #ifdef DEBUG set_debug_value(int2bcd(TvalC),0); set_debug_value(int2bcd(HvalC),1); #endif } LED_GREEN_OFF(); __bis_SR_register(CPUOFF + GIE); // enter sleep mode (leave on timer interrupt) } return -1; }
void auto_init(void) { #ifdef MODULE_BOARD_DISPLAY extern void lcd_init(); lcd_init(); DEBUG("DISP OK"); #endif #ifdef MODULE_DISPLAY_PUTCHAR extern void init_display_putchar(); init_display_putchar(); DEBUG("DISP OK"); #endif #ifdef MODULE_HWTIMER DEBUG("Auto init hwtimer module.\n"); hwtimer_init(); #endif #ifdef MODULE_VTIMER DEBUG("Auto init vtimer module.\n"); vtimer_init(); #endif #ifdef MODULE_UART0 DEBUG("Auto init uart0 module.\n"); board_uart0_init(); #endif #ifdef MODULE_RTC DEBUG("Auto init rtc module.\n"); rtc_init(); rtc_enable(); #endif #ifdef MODULE_SHT11 DEBUG("Auto init SHT11 module.\n"); sht11_init(); #endif #ifdef MODULE_GPIOINT DEBUG("Auto init gpioint module.\n"); gpioint_init(); #endif #ifdef MODULE_CC110X DEBUG("Auto init CC1100 module.\n"); cc1100_init(); #endif #ifdef MODULE_LTC4150 DEBUG("Auto init ltc4150 module.\n"); ltc4150_init(); #endif #ifdef MODULE_MCI DEBUG("Auto init mci module.\n"); MCI_initialize(); #endif #ifdef MODULE_PROFILING extern void profiling_init(void); profiling_init(); #endif main(); }
PROCESS_THREAD(test_sht11_process, ev, data) { static unsigned rh; static struct etimer et; PROCESS_BEGIN(); sht11_init(); for(etimer_set(&et,CLOCK_SECOND*30);;etimer_reset(&et)){ PROCESS_YIELD(); printf("Temperature: %u degree Celsius\n", (-39.60 + 0.01 * sht11_temp())); rh = sht11_humidity(); printf("Relative Humidity: %u%%\n", (unsigned)(-4 + 0.0405*rh - 2.8e-6*(rh*rh))); } PROCESS_END(); }
PROCESS_THREAD(ptemperature_client, ev, data) { static struct etimer atimer; PROCESS_BEGIN(); SERVER_NODE(&server_ipaddr); PRINTF("Creating connection to server"); client_conn = udp_new(&server_ipaddr, UIP_HTONS(REMOTE_PORT), NULL); udp_bind(client_conn, UIP_HTONS(LOCAL_PORT)); sht11_init(); PRINTF("Starting ptemperature client timer"); etimer_set(&atimer, CLOCK_SECOND*POLL_INTERVAL); while(1) { PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&atimer)); PRINTF("Timer expired. Initiating temperature send."); send_data(); etimer_reset(&atimer); } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ static int configure(int type, int c) { switch(type) { case SENSORS_ACTIVE: if(c) { if(!status(SENSORS_ACTIVE)) { rtimer_clock_t t0; sht11_init(); state = ON; /* For for about 11 ms before the SHT11 can be used. */ t0 = RTIMER_NOW(); while(RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + RTIMER_SECOND / 100)); } } else { sht11_off(); state = OFF; } } return 0; }
void auto_init(void) { #ifdef MODULE_TINYMT32 random_init(0); #endif #ifdef MODULE_XTIMER DEBUG("Auto init xtimer module.\n"); xtimer_init(); #endif #ifdef MODULE_RTC DEBUG("Auto init rtc module.\n"); rtc_init(); #endif #ifdef MODULE_IO1_XPLAINED DEBUG("Auto init IO1 Xplained extension module.\n"); io1_xplained_auto_init(); #endif #ifdef MODULE_SHT11 DEBUG("Auto init SHT11 module.\n"); sht11_init(); #endif #ifdef MODULE_GPIOINT DEBUG("Auto init gpioint module.\n"); gpioint_init(); #endif #ifdef MODULE_LTC4150 DEBUG("Auto init ltc4150 module.\n"); ltc4150_init(); #endif #ifdef MODULE_MCI DEBUG("Auto init mci module.\n"); mci_initialize(); #endif #ifdef MODULE_PROFILING extern void profiling_init(void); profiling_init(); #endif #ifdef MODULE_GNRC_PKTBUF DEBUG("Auto init gnrc_pktbuf module\n"); gnrc_pktbuf_init(); #endif #ifdef MODULE_GNRC_PKTDUMP DEBUG("Auto init gnrc_pktdump module.\n"); gnrc_pktdump_init(); #endif #ifdef MODULE_GNRC_SIXLOWPAN DEBUG("Auto init gnrc_sixlowpan module.\n"); gnrc_sixlowpan_init(); #endif #ifdef MODULE_GNRC_IPV6 DEBUG("Auto init gnrc_ipv6 module.\n"); gnrc_ipv6_init(); #endif #ifdef MODULE_GNRC_UDP DEBUG("Auto init UDP module.\n"); gnrc_udp_init(); #endif #ifdef MODULE_DHT DEBUG("Auto init DHT devices.\n"); extern void dht_auto_init(void); dht_auto_init(); #endif #ifdef MODULE_LWIP DEBUG("Bootstraping lwIP.\n"); lwip_bootstrap(); #endif #ifdef MODULE_GCOAP DEBUG("Auto init gcoap module.\n"); gcoap_init(); #endif /* initialize network devices */ #ifdef MODULE_AUTO_INIT_GNRC_NETIF #ifdef MODULE_AT86RF2XX extern void auto_init_at86rf2xx(void); auto_init_at86rf2xx(); #endif #ifdef MODULE_ATA8510 extern void auto_init_ata8510(void); auto_init_ata8510(); #endif #ifdef MODULE_CC2420 extern void auto_init_cc2420(void); auto_init_cc2420(); #endif #ifdef MODULE_ENCX24J600 extern void auto_init_encx24j600(void); auto_init_encx24j600(); #endif #ifdef MODULE_ENC28J60 extern void auto_init_enc28j60(void); auto_init_enc28j60(); #endif #ifdef MODULE_ETHOS extern void auto_init_ethos(void); auto_init_ethos(); #endif #ifdef MODULE_GNRC_SLIP extern void auto_init_slip(void); auto_init_slip(); #endif #ifdef MODULE_CC110X extern void auto_init_cc110x(void); auto_init_cc110x(); #endif #ifdef MODULE_CC2538_RF extern void auto_init_cc2538_rf(void); auto_init_cc2538_rf(); #endif #ifdef MODULE_XBEE extern void auto_init_xbee(void); auto_init_xbee(); #endif #ifdef MODULE_KW2XRF extern void auto_init_kw2xrf(void); auto_init_kw2xrf(); #endif #ifdef MODULE_NETDEV2_TAP extern void auto_init_netdev2_tap(void); auto_init_netdev2_tap(); #endif #ifdef MODULE_NORDIC_SOFTDEVICE_BLE extern void gnrc_nordic_ble_6lowpan_init(void); gnrc_nordic_ble_6lowpan_init(); #endif #ifdef MODULE_NRFMIN extern void gnrc_nrfmin_init(void); gnrc_nrfmin_init(); #endif #ifdef MODULE_W5100 extern void auto_init_w5100(void); auto_init_w5100(); #endif #endif /* MODULE_AUTO_INIT_GNRC_NETIF */ #ifdef MODULE_GNRC_IPV6_NETIF gnrc_ipv6_netif_init_by_dev(); #endif #ifdef MODULE_GNRC_UHCPC extern void auto_init_gnrc_uhcpc(void); auto_init_gnrc_uhcpc(); #endif /* initialize sensors and actuators */ #ifdef MODULE_AUTO_INIT_SAUL DEBUG("auto_init SAUL\n"); #ifdef MODULE_SAUL_GPIO extern void auto_init_gpio(void); auto_init_gpio(); #endif #ifdef MODULE_SAUL_ADC extern void auto_init_adc(void); auto_init_adc(); #endif #ifdef MODULE_LSM303DLHC extern void auto_init_lsm303dlhc(void); auto_init_lsm303dlhc(); #endif #ifdef MODULE_LPS331AP extern void auto_init_lps331ap(void); auto_init_lps331ap(); #endif #ifdef MODULE_ISL29020 extern void auto_init_isl29020(void); auto_init_isl29020(); #endif #ifdef MODULE_L3G4200D extern void auto_init_l3g4200d(void); auto_init_l3g4200d(); #endif #ifdef MODULE_LIS3DH extern void auto_init_lis3dh(void); auto_init_lis3dh(); #endif #ifdef MODULE_MMA8652 extern void auto_init_mma8652(void); auto_init_mma8652(); #endif #ifdef MODULE_SI70XX extern void auto_init_si70xx(void); auto_init_si70xx(); #endif #ifdef MODULE_BMP180 extern void auto_init_bmp180(void); auto_init_bmp180(); #endif #ifdef MODULE_JC42 extern void auto_init_jc42(void); auto_init_jc42(); #endif #ifdef MODULE_HDC1000 extern void auto_init_hdc1000(void); auto_init_hdc1000(); #endif #endif /* MODULE_AUTO_INIT_SAUL */ #ifdef MODULE_AUTO_INIT_GNRC_RPL #ifdef MODULE_GNRC_RPL extern void auto_init_gnrc_rpl(void); auto_init_gnrc_rpl(); #endif #endif /* MODULE_AUTO_INIT_GNRC_RPL */ }
int main(void) { #if WITH_SD int r; #endif /* WITH_SD */ msp430_cpu_init(); watchdog_stop(); /* Platform-specific initialization. */ msb_ports_init(); adc_init(); clock_init(); rtimer_init(); sht11_init(); leds_init(); leds_on(LEDS_ALL); irq_init(); process_init(); /* serial interface */ rs232_set_input(serial_line_input_byte); rs232_init(); serial_line_init(); uart_lock(UART_MODE_RS232); uart_unlock(UART_MODE_RS232); #if WITH_UIP slip_arch_init(BAUD2UBR(115200)); #endif #if WITH_SD r = sd_initialize(); if(r < 0) { printf("Failed to initialize the SD driver: %s\n", sd_error_string(r)); } else { sd_offset_t capacity; printf("The SD driver was successfully initialized\n"); capacity = sd_get_capacity(); if(capacity < 0) { printf("Failed to get the SD card capacity: %s\n", sd_error_string(r)); } else { printf("SD card capacity: %u MB\n", (unsigned)(capacity / (1024UL * 1024))); } } #endif /* System services */ process_start(&etimer_process, NULL); ctimer_init(); node_id_restore(); init_net(); energest_init(); #if PROFILE_CONF_ON profile_init(); #endif /* PROFILE_CONF_ON */ leds_off(LEDS_ALL); printf(CONTIKI_VERSION_STRING " started. Node id %u, using %s.\n", node_id, rime_mac->name); autostart_start(autostart_processes); /* * This is the scheduler loop. */ ENERGEST_ON(ENERGEST_TYPE_CPU); while (1) { int r; #if PROFILE_CONF_ON profile_episode_start(); #endif /* PROFILE_CONF_ON */ do { /* Reset watchdog. */ watchdog_periodic(); r = process_run(); } while(r > 0); #if PROFILE_CONF_ON profile_episode_end(); #endif /* PROFILE_CONF_ON */ /* * Idle processing. */ int s = splhigh(); /* Disable interrupts. */ if (process_nevents() != 0) { splx(s); /* Re-enable interrupts. */ } else { static unsigned long irq_energest = 0; /* Re-enable interrupts and go to sleep atomically. */ ENERGEST_OFF(ENERGEST_TYPE_CPU); ENERGEST_ON(ENERGEST_TYPE_LPM); /* * We only want to measure the processing done in IRQs when we * are asleep, so we discard the processing time done when we * were awake. */ energest_type_set(ENERGEST_TYPE_IRQ, irq_energest); if (uart_edge) { _BIC_SR(LPM1_bits + GIE); } else { _BIS_SR(LPM1_bits + GIE); } /* * We get the current processing time for interrupts that was * done during the LPM and store it for next time around. */ dint(); irq_energest = energest_type_time(ENERGEST_TYPE_IRQ); eint(); ENERGEST_OFF(ENERGEST_TYPE_LPM); ENERGEST_ON(ENERGEST_TYPE_CPU); #if PROFILE_CONF_ON profile_clear_timestamps(); #endif /* PROFILE_CONF_ON */ } } return 0; }
void auto_init(void) { #ifdef MODULE_CONFIG DEBUG("Auto init loading config\n"); config_load(); #endif #ifdef MODULE_XTIMER DEBUG("Auto init xtimer module.\n"); xtimer_init(); #endif #ifdef MODULE_RTC DEBUG("Auto init rtc module.\n"); rtc_init(); #endif #ifdef MODULE_SHT11 DEBUG("Auto init SHT11 module.\n"); sht11_init(); #endif #ifdef MODULE_GPIOINT DEBUG("Auto init gpioint module.\n"); gpioint_init(); #endif #ifdef MODULE_LTC4150 DEBUG("Auto init ltc4150 module.\n"); ltc4150_init(); #endif #ifdef MODULE_MCI DEBUG("Auto init mci module.\n"); MCI_initialize(); #endif #ifdef MODULE_PROFILING extern void profiling_init(void); profiling_init(); #endif #ifdef MODULE_GNRC_PKTBUF DEBUG("Auto init gnrc_pktbuf module\n"); gnrc_pktbuf_init(); #endif #ifdef MODULE_GNRC_PKTDUMP DEBUG("Auto init gnrc_pktdump module.\n"); gnrc_pktdump_init(); #endif #ifdef MODULE_GNRC_SIXLOWPAN DEBUG("Auto init gnrc_sixlowpan module.\n"); gnrc_sixlowpan_init(); #endif #ifdef MODULE_GNRC_IPV6 DEBUG("Auto init gnrc_ipv6 module.\n"); gnrc_ipv6_init(); #endif #ifdef MODULE_GNRC_UDP DEBUG("Auto init UDP module.\n"); gnrc_udp_init(); #endif /* initialize network devices */ #ifdef MODULE_AUTO_INIT_GNRC_NETIF #ifdef MODULE_AT86RF2XX extern void auto_init_at86rf2xx(void); auto_init_at86rf2xx(); #endif #ifdef MODULE_ENCX24J600 extern void auto_init_encx24j600(void); auto_init_encx24j600(); #endif #ifdef MODULE_GNRC_SLIP extern void auto_init_slip(void); auto_init_slip(); #endif #ifdef MODULE_XBEE extern void auto_init_xbee(void); auto_init_xbee(); #endif #ifdef MODULE_KW2XRF extern void auto_init_kw2xrf(void); auto_init_kw2xrf(); #endif #ifdef MODULE_NETDEV2_TAP extern void auto_init_netdev2_tap(void); auto_init_netdev2_tap(); #endif #endif /* MODULE_AUTO_INIT_GNRC_NETIF */ #ifdef MODULE_GNRC_IPV6_NETIF gnrc_ipv6_netif_init_by_dev(); #endif }
void auto_init(void) { #ifdef MODULE_PRNG void auto_init_random(void); auto_init_random(); #endif #ifdef MODULE_XTIMER DEBUG("Auto init xtimer module.\n"); xtimer_init(); #endif #ifdef MODULE_SHT11 DEBUG("Auto init SHT11 module.\n"); sht11_init(); #endif #ifdef MODULE_MCI DEBUG("Auto init mci module.\n"); mci_initialize(); #endif #ifdef MODULE_PROFILING extern void profiling_init(void); profiling_init(); #endif #ifdef MODULE_GNRC_PKTBUF DEBUG("Auto init gnrc_pktbuf module\n"); gnrc_pktbuf_init(); #endif #ifdef MODULE_GNRC_PKTDUMP DEBUG("Auto init gnrc_pktdump module.\n"); gnrc_pktdump_init(); #endif #ifdef MODULE_GNRC_SIXLOWPAN DEBUG("Auto init gnrc_sixlowpan module.\n"); gnrc_sixlowpan_init(); #endif #ifdef MODULE_GNRC_IPV6 DEBUG("Auto init gnrc_ipv6 module.\n"); gnrc_ipv6_init(); #endif #ifdef MODULE_GNRC_UDP DEBUG("Auto init UDP module.\n"); gnrc_udp_init(); #endif #ifdef MODULE_GNRC_TCP DEBUG("Auto init TCP module\n"); gnrc_tcp_init(); #endif #ifdef MODULE_LWIP DEBUG("Bootstraping lwIP.\n"); lwip_bootstrap(); #endif #ifdef MODULE_OPENTHREAD extern void openthread_bootstrap(void); openthread_bootstrap(); #endif #ifdef MODULE_GCOAP DEBUG("Auto init gcoap module.\n"); gcoap_init(); #endif #ifdef MODULE_DEVFS DEBUG("Mounting /dev\n"); extern void auto_init_devfs(void); auto_init_devfs(); #endif #ifdef MODULE_GNRC_IPV6_NIB DEBUG("Auto init gnrc_ipv6_nib module.\n"); gnrc_ipv6_nib_init(); #endif #ifdef MODULE_SKALD DEBUG("Auto init Skald\n"); skald_init(); #endif #ifdef MODULE_RDCLI_COMMON DEBUG("Auto init rdcli_common module\n"); extern void rdcli_common_init(void); rdcli_common_init(); #endif #ifdef MODULE_RDCLI_SIMPLE_STANDALONE DEBUG("Auto init rdcli_simple module\n"); extern void rdcli_simple_run(void); rdcli_simple_run(); #endif /* initialize network devices */ #ifdef MODULE_AUTO_INIT_GNRC_NETIF #ifdef MODULE_AT86RF2XX extern void auto_init_at86rf2xx(void); auto_init_at86rf2xx(); #endif #ifdef MODULE_MRF24J40 extern void auto_init_mrf24j40(void); auto_init_mrf24j40(); #endif #ifdef MODULE_CC2420 extern void auto_init_cc2420(void); auto_init_cc2420(); #endif #ifdef MODULE_ENCX24J600 extern void auto_init_encx24j600(void); auto_init_encx24j600(); #endif #ifdef MODULE_ENC28J60 extern void auto_init_enc28j60(void); auto_init_enc28j60(); #endif #ifdef MODULE_ETHOS extern void auto_init_ethos(void); auto_init_ethos(); #endif #ifdef MODULE_SLIPDEV extern void auto_init_slipdev(void); auto_init_slipdev(); #endif #ifdef MODULE_CC110X extern void auto_init_cc110x(void); auto_init_cc110x(); #endif #ifdef MODULE_CC2538_RF extern void auto_init_cc2538_rf(void); auto_init_cc2538_rf(); #endif #ifdef MODULE_XBEE extern void auto_init_xbee(void); auto_init_xbee(); #endif #ifdef MODULE_KW2XRF extern void auto_init_kw2xrf(void); auto_init_kw2xrf(); #endif #ifdef MODULE_NETDEV_TAP extern void auto_init_netdev_tap(void); auto_init_netdev_tap(); #endif #ifdef MODULE_SOCKET_ZEP extern void auto_init_socket_zep(void); auto_init_socket_zep(); #endif #ifdef MODULE_NORDIC_SOFTDEVICE_BLE extern void gnrc_nordic_ble_6lowpan_init(void); gnrc_nordic_ble_6lowpan_init(); #endif #ifdef MODULE_NRFMIN extern void gnrc_nrfmin_init(void); gnrc_nrfmin_init(); #endif #ifdef MODULE_W5100 extern void auto_init_w5100(void); auto_init_w5100(); #endif #ifdef MODULE_SX127X extern void auto_init_sx127x(void); auto_init_sx127x(); #endif #endif /* MODULE_AUTO_INIT_GNRC_NETIF */ #ifdef MODULE_GNRC_UHCPC extern void auto_init_gnrc_uhcpc(void); auto_init_gnrc_uhcpc(); #endif /* initialize sensors and actuators */ #ifdef MODULE_AUTO_INIT_SAUL DEBUG("auto_init SAUL\n"); #ifdef MODULE_SAUL_GPIO extern void auto_init_gpio(void); auto_init_gpio(); #endif #ifdef MODULE_SAUL_ADC extern void auto_init_adc(void); auto_init_adc(); #endif #ifdef MODULE_LSM303DLHC extern void auto_init_lsm303dlhc(void); auto_init_lsm303dlhc(); #endif #ifdef MODULE_LPS331AP extern void auto_init_lps331ap(void); auto_init_lps331ap(); #endif #ifdef MODULE_ISL29020 extern void auto_init_isl29020(void); auto_init_isl29020(); #endif #ifdef MODULE_L3G4200D extern void auto_init_l3g4200d(void); auto_init_l3g4200d(); #endif #ifdef MODULE_LIS3DH extern void auto_init_lis3dh(void); auto_init_lis3dh(); #endif #ifdef MODULE_LIS3MDL extern void auto_init_lis3mdl(void); auto_init_lis3mdl(); #endif #ifdef MODULE_MAG3110 extern void auto_init_mag3110(void); auto_init_mag3110(); #endif #ifdef MODULE_MMA8X5X extern void auto_init_mma8x5x(void); auto_init_mma8x5x(); #endif #ifdef MODULE_MPL3115A2 extern void auto_init_mpl3115a2(void); auto_init_mpl3115a2(); #endif #ifdef MODULE_MPU9150 extern void auto_init_mpu9150(void); auto_init_mpu9150(); #endif #ifdef MODULE_GROVE_LEDBAR extern void auto_init_grove_ledbar(void); auto_init_grove_ledbar(); #endif #ifdef MODULE_SI70XX extern void auto_init_si70xx(void); auto_init_si70xx(); #endif #ifdef MODULE_BMP180 extern void auto_init_bmp180(void); auto_init_bmp180(); #endif #ifdef MODULE_BMX055 extern void auto_init_bmx055(void); auto_init_bmx055(); #endif #if defined(MODULE_BME280) || defined(MODULE_BMP280) extern void auto_init_bmx280(void); auto_init_bmx280(); #endif #ifdef MODULE_JC42 extern void auto_init_jc42(void); auto_init_jc42(); #endif #ifdef MODULE_TSL2561 extern void auto_init_tsl2561(void); auto_init_tsl2561(); #endif #ifdef MODULE_PULSE_COUNTER extern void auto_init_pulse_counter(void); auto_init_pulse_counter(); #endif #ifdef MODULE_HDC1000 extern void auto_init_hdc1000(void); auto_init_hdc1000(); #endif #ifdef MODULE_FXOS8700 extern void auto_init_fxos8700(void); auto_init_fxos8700(); #endif #ifdef MODULE_HTS221 extern void auto_init_hts221(void); auto_init_hts221(); #endif #ifdef MODULE_DHT extern void auto_init_dht(void); auto_init_dht(); #endif #ifdef MODULE_TMP006 extern void auto_init_tmp006(void); auto_init_tmp006(); #endif #ifdef MODULE_TCS37727 extern void auto_init_tcs37727(void); auto_init_tcs37727(); #endif #ifdef MODULE_VEML6070 extern void auto_init_veml6070(void); auto_init_veml6070(); #endif #ifdef MODULE_IO1_XPLAINED extern void auto_init_io1_xplained(void); auto_init_io1_xplained(); #endif #ifdef MODULE_ADXL345 extern void auto_init_adxl345(void); auto_init_adxl345(); #endif #ifdef MODULE_LSM6DSL extern void auto_init_lsm6dsl(void); auto_init_lsm6dsl(); #endif #ifdef MODULE_ADCXX1C extern void auto_init_adcxx1c(void); auto_init_adcxx1c(); #endif #ifdef MODULE_ADS101X extern void auto_init_ads101x(void); auto_init_ads101x(); #endif #ifdef MODULE_LIS2DH12 extern void auto_init_lis2dh12(void); auto_init_lis2dh12(); #endif #ifdef MODULE_SI114X extern void auto_init_si114x(void); auto_init_si114x(); #endif #endif /* MODULE_AUTO_INIT_SAUL */ #ifdef MODULE_AUTO_INIT_GNRC_RPL #ifdef MODULE_GNRC_RPL extern void auto_init_gnrc_rpl(void); auto_init_gnrc_rpl(); #endif #endif /* MODULE_AUTO_INIT_GNRC_RPL */ /* initialize storage devices */ #ifdef MODULE_AUTO_INIT_STORAGE DEBUG("auto_init STORAGE\n"); #ifdef MODULE_SDCARD_SPI extern void auto_init_sdcard_spi(void); auto_init_sdcard_spi(); #endif #endif /* MODULE_AUTO_INIT_STORAGE */ #ifdef MODULE_AUTO_INIT_CAN DEBUG("auto_init CAN\n"); extern void auto_init_candev(void); auto_init_candev(); #endif /* MODULE_AUTO_INIT_CAN */ }
/*---------------------------------------------------数据采集上传模考---------------------------------------------*/ static void udp_send_data(struct udp_tx *udp_tx_info) { static char pdata_buf[20]; char data_buf[3]; #if sht11 float tc,hc; sht11_init(); unsigned int tempera = sht11_temp(); unsigned int humidity = sht11_humidity(); tc=sht11_TemperatureC(tempera); hc=sht11_Humidity(tempera,humidity); printf("sorce Tc:%d;Hc:%d\n",(int)tc,(int)hc); // tc=25.5; // hc=57.2; printf("Tc:%d;Hc:%d\n",(int)tc,(int)hc); pdata_buf[0]=0x02; sprintf(data_buf,"%d",(int)tc); memcpy(&pdata_buf[1],data_buf,3); pdata_buf[4]=0x03; sprintf(data_buf,"%d",(int)hc); memcpy(&pdata_buf[5],data_buf,3); // sprintf(temp_data_buf,"%d.%d",(int)hc,((int)(hc*10))%10); printf("temp_data:%s\n",pdata_buf); #endif #if sensor int16_t temperature; temperature = sensor_temp_get(TEMP_UNIT_CELCIUS); pdata_buf[0]=0x02; sprintf(data_buf,"%d",temperature); memcpy(&pdata_buf[1],data_buf,3); printf("temp_data:%s\n",pdata_buf); #endif #if light_sensor int16_t illumination; illumination=60; // modbus_init(); // illumination= modbus_get(); printf("illumination_data:%d\n",illumination); data_buf[0]=0x00; data_buf[1]=0xff&(illumination>>8); data_buf[2]=0xff&illumination; pdata_buf[0]=0x04; memcpy(&pdata_buf[1],data_buf,3); printf("temp_data:%s\n",pdata_buf); #endif #if bh1750_sensor int16_t illumination; illumination=60; bh1750_init(); illumination= bh1750_light(); printf("illumination_data:%d\n",illumination); data_buf[0]=0x00; data_buf[1]=0xff&(illumination>>8); data_buf[2]=0xff&illumination; pdata_buf[0]=0x04; memcpy(&pdata_buf[1],data_buf,3); printf("temp_data:%s\n",pdata_buf); #endif uint8_t sum = 0; udp_tx_info->buf[0] = udp_header[0]; udp_tx_info->buf[1] = udp_header[1]; udp_tx_info->buf[2] =version[0]; udp_tx_info->buf[3] = DATA_SEND ; //0x01 udp_tx_info->buf[4]=user.userid[3]; udp_tx_info->buf[5]=user.userid[2]; udp_tx_info->buf[6]=user.userid[1]; udp_tx_info->buf[7]=user.userid[0]; udp_tx_info->buf[8] = K-8; memcpy(&udp_tx_info->buf[9],udp_id,K-8); memcpy(&udp_tx_info->buf[K+1],device_type,4); udp_tx_info->buf[K+5] = 0x00; udp_tx_info->buf[K+6] = 0x14; memcpy(&udp_tx_info->buf[K+7],pdata_buf,20); sum = calac_checksum(udp_tx_info); udp_tx_info->buf[K+27] = sum; udp_tx_info->buf[K+28] = 0x0D; udp_tx_info->buf[K+29] = 0x0A; udp_tx_info->len = K+30; }
void auto_init(void) { #ifdef MODULE_CONFIG DEBUG("Auto init loading config\n"); config_load(); #endif #ifdef MODULE_XTIMER DEBUG("Auto init xtimer module.\n"); xtimer_init(); #endif #ifdef MODULE_RTC DEBUG("Auto init rtc module.\n"); rtc_init(); #endif #ifdef MODULE_SHT11 DEBUG("Auto init SHT11 module.\n"); sht11_init(); #endif #ifdef MODULE_GPIOINT DEBUG("Auto init gpioint module.\n"); gpioint_init(); #endif #ifdef MODULE_LTC4150 DEBUG("Auto init ltc4150 module.\n"); ltc4150_init(); #endif #ifdef MODULE_MCI DEBUG("Auto init mci module.\n"); MCI_initialize(); #endif #ifdef MODULE_PROFILING extern void profiling_init(void); profiling_init(); #endif #ifdef MODULE_GNRC_PKTBUF DEBUG("Auto init gnrc_pktbuf module\n"); gnrc_pktbuf_init(); #endif #ifdef MODULE_GNRC_PKTDUMP DEBUG("Auto init gnrc_pktdump module.\n"); gnrc_pktdump_init(); #endif #ifdef MODULE_GNRC_SIXLOWPAN DEBUG("Auto init gnrc_sixlowpan module.\n"); gnrc_sixlowpan_init(); #endif #ifdef MODULE_GNRC_IPV6 DEBUG("Auto init gnrc_ipv6 module.\n"); gnrc_ipv6_init(); #endif #ifdef MODULE_GNRC_UDP DEBUG("Auto init UDP module.\n"); gnrc_udp_init(); #endif /* initialize network devices */ #ifdef MODULE_AUTO_INIT_GNRC_NETIF #ifdef MODULE_AT86RF2XX extern void auto_init_at86rf2xx(void); auto_init_at86rf2xx(); #endif #ifdef MODULE_ENCX24J600 extern void auto_init_encx24j600(void); auto_init_encx24j600(); #endif #ifdef MODULE_ENC28J60 extern void auto_init_enc28j60(void); auto_init_enc28j60(); #endif #ifdef MODULE_GNRC_SLIP extern void auto_init_slip(void); auto_init_slip(); #endif #ifdef MODULE_CC110X extern void auto_init_cc110x(void); auto_init_cc110x(); #endif #ifdef MODULE_XBEE extern void auto_init_xbee(void); auto_init_xbee(); #endif #ifdef MODULE_KW2XRF extern void auto_init_kw2xrf(void); auto_init_kw2xrf(); #endif #ifdef MODULE_NETDEV2_TAP extern void auto_init_netdev2_tap(void); auto_init_netdev2_tap(); #endif #endif /* MODULE_AUTO_INIT_GNRC_NETIF */ #ifdef MODULE_GNRC_IPV6_NETIF gnrc_ipv6_netif_init_by_dev(); #endif /* initialize sensors and actuators */ #ifdef MODULE_AUTO_INIT_SAUL DEBUG("auto_init SAUL\n"); #ifdef MODULE_SAUL_GPIO extern void auto_init_gpio(void); auto_init_gpio(); #endif #ifdef MODULE_LSM303DLHC extern void auto_init_lsm303dlhc(void); auto_init_lsm303dlhc(); #endif #ifdef MODULE_LPS331AP extern void auto_init_lps331ap(void); auto_init_lps331ap(); #endif #ifdef MODULE_ISL29020 extern void auto_init_isl29020(void); auto_init_isl29020(); #endif #ifdef MODULE_L3G4200D extern void auto_init_l3g4200d(void); auto_init_l3g4200d(); #endif #endif /* MODULE_AUTO_INIT_SAUL */ }
/*---------------------------------------------------------------------------*/ int main(int argc, char **argv) { /* * Initalize hardware. */ msp430_cpu_init(); clock_init(); leds_init(); leds_on(LEDS_RED); uart1_init(BAUD2UBR(115200)); /* Must come before first printf */ #if WITH_UIP slip_arch_init(BAUD2UBR(115200)); #endif /* WITH_UIP */ leds_on(LEDS_GREEN); ds2411_init(); /* XXX hack: Fix it so that the 802.15.4 MAC address is compatible with an Ethernet MAC address - byte 0 (byte 2 in the DS ID) cannot be odd. */ ds2411_id[2] &= 0xfe; leds_on(LEDS_BLUE); xmem_init(); leds_off(LEDS_RED); rtimer_init(); /* * Hardware initialization done! */ /* Restore node id if such has been stored in external mem */ node_id_restore(); random_init(ds2411_id[0] + node_id); leds_off(LEDS_BLUE); /* * Initialize Contiki and our processes. */ process_init(); process_start(&etimer_process, NULL); process_start(&sensors_process, NULL); /* * Initialize light and humidity/temp sensors. */ sensors_light_init(); battery_sensor.activate(); sht11_init(); ctimer_init(); cc2420_init(); cc2420_set_pan_addr(IEEE802154_PANID, 0 /*XXX*/, ds2411_id); cc2420_set_channel(RF_CHANNEL); printf(CONTIKI_VERSION_STRING " started. "); if(node_id > 0) { printf("Node id is set to %u.\n", node_id); } else { printf("Node id is not set.\n"); } set_rime_addr(); printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", ds2411_id[0], ds2411_id[1], ds2411_id[2], ds2411_id[3], ds2411_id[4], ds2411_id[5], ds2411_id[6], ds2411_id[7]); #if WITH_UIP6 memcpy(&uip_lladdr.addr, ds2411_id, sizeof(uip_lladdr.addr)); sicslowpan_init(sicslowmac_init(&cc2420_driver)); process_start(&tcpip_process, NULL); printf(" %s channel %u\n", sicslowmac_driver.name, RF_CHANNEL); #if UIP_CONF_ROUTER rime_init(rime_udp_init(NULL)); uip_router_register(&rimeroute); #endif /* UIP_CONF_ROUTER */ #else /* WITH_UIP6 */ rime_init(MAC_DRIVER.init(&cc2420_driver)); printf(" %s channel %u\n", rime_mac->name, RF_CHANNEL); #endif /* WITH_UIP6 */ #if !WITH_UIP && !WITH_UIP6 uart1_set_input(serial_line_input_byte); serial_line_init(); #endif #if PROFILE_CONF_ON profile_init(); #endif /* PROFILE_CONF_ON */ leds_off(LEDS_GREEN); #if WITH_FTSP ftsp_init(); #endif /* WITH_FTSP */ #if TIMESYNCH_CONF_ENABLED timesynch_init(); timesynch_set_authority_level(rimeaddr_node_addr.u8[0]); #endif /* TIMESYNCH_CONF_ENABLED */ #if WITH_UIP process_start(&tcpip_process, NULL); process_start(&uip_fw_process, NULL); /* Start IP output */ process_start(&slip_process, NULL); slip_set_input_callback(set_gateway); { uip_ipaddr_t hostaddr, netmask; uip_init(); uip_ipaddr(&hostaddr, 172,16, rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]); uip_ipaddr(&netmask, 255,255,0,0); uip_ipaddr_copy(&meshif.ipaddr, &hostaddr); uip_sethostaddr(&hostaddr); uip_setnetmask(&netmask); uip_over_mesh_set_net(&hostaddr, &netmask); /* uip_fw_register(&slipif);*/ uip_over_mesh_set_gateway_netif(&slipif); uip_fw_default(&meshif); uip_over_mesh_init(UIP_OVER_MESH_CHANNEL); printf("uIP started with IP address %d.%d.%d.%d\n", uip_ipaddr_to_quad(&hostaddr)); } #endif /* WITH_UIP */ button_sensor.activate(); energest_init(); ENERGEST_ON(ENERGEST_TYPE_CPU); print_processes(autostart_processes); autostart_start(autostart_processes); /* * This is the scheduler loop. */ #if DCOSYNCH_CONF_ENABLED timer_set(&mgt_timer, DCOSYNCH_PERIOD * CLOCK_SECOND); #endif watchdog_start(); /* watchdog_stop();*/ while(1) { int r; #if PROFILE_CONF_ON profile_episode_start(); #endif /* PROFILE_CONF_ON */ do { /* Reset watchdog. */ watchdog_periodic(); r = process_run(); } while(r > 0); #if PROFILE_CONF_ON profile_episode_end(); #endif /* PROFILE_CONF_ON */ /* * Idle processing. */ int s = splhigh(); /* Disable interrupts. */ /* uart1_active is for avoiding LPM3 when still sending or receiving */ if(process_nevents() != 0 || uart1_active()) { splx(s); /* Re-enable interrupts. */ } else { static unsigned long irq_energest = 0; #if DCOSYNCH_CONF_ENABLED /* before going down to sleep possibly do some management */ if (timer_expired(&mgt_timer)) { timer_reset(&mgt_timer); msp430_sync_dco(); } #endif /* Re-enable interrupts and go to sleep atomically. */ ENERGEST_OFF(ENERGEST_TYPE_CPU); ENERGEST_ON(ENERGEST_TYPE_LPM); /* We only want to measure the processing done in IRQs when we are asleep, so we discard the processing time done when we were awake. */ energest_type_set(ENERGEST_TYPE_IRQ, irq_energest); watchdog_stop(); _BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This statement will block until the CPU is woken up by an interrupt that sets the wake up flag. */ /* We get the current processing time for interrupts that was done during the LPM and store it for next time around. */ dint(); irq_energest = energest_type_time(ENERGEST_TYPE_IRQ); eint(); watchdog_start(); ENERGEST_OFF(ENERGEST_TYPE_LPM); ENERGEST_ON(ENERGEST_TYPE_CPU); } } return 0; }