/** * Initialize the main hardware parameters. */ static void prvSetupHardware(void) { /* Stop the watchdog timer. */ WDTCTL = WDTPW + WDTHOLD; /* Setup MCLK 8MHz and SMCLK 1MHz */ set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz(); LEDS_INIT(); LEDS_OFF(); uart0_init(UART0_CONFIG_1MHZ_115200); uart0_register_callback(char_rx); /* Enable Interrupts */ eint(); }
int main( void ) { // Stop the watchdog timer. WDTCTL = WDTPW + WDTHOLD; // Clock settings set_mcu_speed_xt2_mclk_8MHz_smclk_8MHz(); // used by CDMA set_aclk_div(1); // ACKL is at 32768Hz // used for clock synchronization // Initialize the UART0 uart0_init(UART0_CONFIG_8MHZ_115200); // 115kbaud, SMCLK is at 8MHz uart0_register_callback(char_rx); // Set the UART callback function // Initialize random number ds2411_init(); rnd = (((uint16_t)ds2411_id.serial0) << 8) + (uint16_t)ds2411_id.serial1; // Timer settings time_1w = 0; timerA_init(); timerA_start_ACLK_div(TIMERA_DIV_1); // timerA period = 2s timerA_register_cb(TIMERA_ALARM_OVER, timer_overflow); // timerA overflow event timerA_register_cb(TIMERA_ALARM_CCR0, run_algorithm); // run algorithm at CCR0 timerA_register_cb(TIMERA_ALARM_CCR1, skew_correction); // compensate skew error at CCR1 timerA_set_alarm_from_now(TIMERA_ALARM_CCR0, rnd, 54983); // same period 1.678s, different phase timerA_set_alarm_from_now(TIMERA_ALARM_CCR1, 35000, skew); // skew compensation happens every 'skew' ticks // Initialize the MAC layer (radio) mac_init(11); mac_set_rx_cb(frame_rx); mac_set_error_cb(frame_error); mac_set_sent_cb(frame_sent); // Enable Interrupts eint(); while (1) { } return 0; }
/** * The main function. */ int main( void ) { /* Stop the watchdog timer. */ WDTCTL = WDTPW + WDTHOLD; /* Setup MCLK 8MHz and SMCLK 1MHz */ set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz(); /* Enable Interrupts */ eint(); uart0_init(UART0_CONFIG_1MHZ_115200); uart0_register_callback(char_cb); printf("CC1100 RXTX test program\r\n"); LEDS_INIT(); LEDS_OFF(); cc1100_init(); cc1100_cfg_append_status(CC1100_APPEND_STATUS_ENABLE); cc1100_cfg_crc_autoflush(CC1100_CRC_AUTOFLUSH_DISABLE); cc1100_cfg_white_data(CC1100_DATA_WHITENING_ENABLE); cc1100_cfg_crc_en(CC1100_CRC_CALCULATION_ENABLE); cc1100_cfg_freq_if(0x0C); cc1100_cfg_fs_autocal(CC1100_AUTOCAL_NEVER); cc1100_cfg_mod_format(CC1100_MODULATION_MSK); cc1100_cfg_sync_mode(CC1100_SYNCMODE_30_32); cc1100_cfg_manchester_en(CC1100_MANCHESTER_DISABLE); printf("CC1100 initialized\r\nType 's' to send a message\r\n"); while(1) { // Enter RX LED_RED_ON(); cc1100_cmd_idle(); cc1100_cmd_flush_rx(); cc1100_cmd_calibrate(); cc1100_cmd_rx(); cc1100_cfg_gdo0(CC1100_GDOx_SYNC_WORD); cc1100_gdo0_int_set_falling_edge(); cc1100_gdo0_int_clear(); cc1100_gdo0_int_enable(); cc1100_gdo0_register_callback(rx_ok); // Low Power Mode LPM0; // Check for send flag if (send == 1) { send = 0; LED_RED_OFF(); cc1100_cmd_idle(); cc1100_cmd_flush_tx(); cc1100_cmd_calibrate(); cc1100_gdo0_int_disable(); frameseq ++; length = sprintf((char *)frame, "Hello World #%i", frameseq); printf("Sent : %s \r\n", frame); cc1100_fifo_put(&length, 1); cc1100_fifo_put(frame, length); cc1100_cmd_tx(); // Wait for SYNC word sent while (cc1100_gdo0_read() == 0); // Wait for end of packet while (cc1100_gdo0_read() != 0); } // Check for receive flag if (receive == 1) { receive = 0; uint8_t i; // verify CRC result if ( !(cc1100_status_crc_lqi() & 0x80) ) { continue; } cc1100_fifo_get(&length, 1); if (length > 60) { continue; } cc1100_fifo_get(frame, length+2); uint16_t rssi = (uint16_t)frame[length]; int16_t rssi_d; if (rssi >= 128) rssi_d = (rssi-256)-140; else rssi_d = rssi-140; printf("Frame received with RSSI=%d.%d dBm: ", rssi_d, 5*(rssi_d&0x1)); for (i=0; i<length; i++) { printf("%c",frame[i]); } printf("\r\n"); LED_GREEN_TOGGLE(); } } return 0; }
int main(void) { WDTCTL = WDTPW+WDTHOLD; set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz(); set_aclk_div(1); LEDS_INIT(); LEDS_OFF(); ds2411_init(); nodeaddr = (((uint16_t)ds2411_id.serial1)<<8) + (ds2411_id.serial0); uart0_init(UART0_CONFIG_1MHZ_115200); uart0_register_callback(char_rx); eint(); printf("[APP];BOOTING;%.4x\n",nodeaddr); //check if this node is the sink if (nodeaddr == sink_nodes) { type = SINK; level = DEFAULT_LEVEL; } else { //retrieve father for (idx=0; idx<NUMBER_NODES; idx++) { if (list_nodes[idx] == nodeaddr) { if(father_nodes1[idx] != 0x0000) { parent_id = father_nodes1[idx]; level = 12; break; } } } } //hack for mobile /*if(nodeaddr == 0x1f5d) { parent_id = 0x0000; mac_set_mobile(1); level = 12; }*/ mac_init(10); mac_set_rx_cb(packet_received); mac_set_error_cb(packet_error); mac_set_sent_cb(packet_sent); timerB_set_alarm_from_now(TIMERB_ALARM_CCR6, 32768, 32768); timerB_register_cb(TIMERB_ALARM_CCR6, inc_clock); while (1) { LPM1; if (state == SM_TX) { if (level != UNDEF_LEVEL && type != SINK) { seq_max = NUM_SEQ_MAX; delay = rand(); delay &= 0xCFFF; delay += 12000; //(369ms < delay < 1991ms) timerB_set_alarm_from_now(TIMERB_ALARM_CCR5, delay, 0); timerB_register_cb(TIMERB_ALARM_CCR5, next_send); } else { printf("[APP];NOROUTE\n"); } state = SM_IDLE; } else if (state == SM_LOOP_TX) { if (level != UNDEF_LEVEL) { sprintf(sourceaddr,"%.4x",nodeaddr); data_txframe[0] = DATA; data_txframe[1] = level-1; data_txframe[2] = sourceaddr[0]; data_txframe[3] = sourceaddr[1]; data_txframe[4] = sourceaddr[2]; data_txframe[5] = sourceaddr[3]; data_txframe[6] = seq; //sequence data_txframe[7] = 1; //hops txlength = 8; stat_add(STAT_APP_TX); printf("[APP];NODE_TX;%.4x;%.4x;%u;%u-%u\n", nodeaddr, parent_id, seq, global_clock, timerB_time()/32); seq++; mac_send(data_txframe, txlength, parent_id); if (DEBUG_LEDS == 1) { LED_GREEN_ON(); } if (seq < seq_max) { timerB_set_alarm_from_now(TIMERB_ALARM_CCR5, SEND_DATA_PERIOD, 0); timerB_register_cb(TIMERB_ALARM_CCR5, next_send); } } state = SM_IDLE; } } return 0; }
/** * The main function. */ int main( void ) { // Stop the watchdog timer. WDTCTL = WDTPW + WDTHOLD; // Setup MCLK 8MHz and SMCLK 1MHz set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz(); set_aclk_div(8); // ACKL is at 4096Hz // Initialize the LEDs LEDS_INIT(); LEDS_OFF(); // Initialize the temperature sensor ds1722_init(); ds1722_set_res(12); ds1722_sample_cont(); // Initialier the Luminosity sensor tsl2550_init(); tsl2550_powerup(); tsl2550_set_standard(); tsl2550_read_adc0(); // Initialize the UART0 uart0_init(UART0_CONFIG_1MHZ_115200); // We want 115kbaud, // and SMCLK is running at 1MHz uart0_register_callback(char_rx); // Set the UART callback function // it will be called every time a // character is received. // Print first message printf("Senslab TP Ex2: UART\n"); // Enable Interrupts eint(); // Print information printf("Type command\n"); printf("\tt:\ttemperature measure\n"); printf("\tl:\tluminosity measure\n"); // Declare 2 variables for storing the different values int16_t value_0, value_1; while (1) { printf("cmd > "); cmd = 0; while (cmd==0) { LPM1; // Low Power Mode 1: SMCLK remains active for UART } switch (cmd) { case 't': value_0 = ds1722_read_MSB(); value_1 = ds1722_read_LSB(); value_1 >>= 5; value_1 *= 125; printf("Temperature measure: %i.%i\n", value_0, value_1); break; case 'l': tsl2550_init(); value_0 = tsl2550_read_adc0(); value_1 = tsl2550_read_adc1(); uart0_init(UART0_CONFIG_1MHZ_115200); uart0_register_callback(char_rx); printf("Luminosity measure: %i:%i\n", value_0, value_1); break; default: break; } } return 0; }
/** * The main function. */ int main( void ) { /* Stop the watchdog timer */ WDTCTL = WDTPW + WDTHOLD; /* Setup the MSP430 micro-controller clock frequency: MCLK, SMCLK and ACLK */ /* Set MCLK at 8MHz and SMCLK at 1MHz */ set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz(); /* Set ACKL at 4096Hz (32 768Hz / 8) */ set_aclk_div(8); /* Initialize the LEDs */ LEDS_INIT(); LEDS_OFF(); /* Initialize the temperature sensor */ ds1722_init(); ds1722_set_res(12); ds1722_sample_cont(); /* Initialize the Luminosity sensor */ tsl2550_init(); tsl2550_powerup(); tsl2550_set_standard(); tsl2550_read_adc0(); /* Initialize the UART0 */ /* We want 115kbaud, and SMCLK is running at 1MHz */ uart0_init(UART0_CONFIG_1MHZ_115200); /* Set the UART callback function it will be called every time a character is received. */ uart0_register_callback(char_rx); /* Print first message */ printf("\n\nSenslab Simple Demo program\n"); /* Enable Interrupts */ eint(); /* Print information */ printf("Type command\n"); printf("\tt:\ttemperature measure\n"); printf("\tl:\tluminosity measure\n"); /* Initialize the timer for the LEDs */ timerA_init(); /* TimerA clock is at 512Hz (4096Hz / 8) */ timerA_start_ACLK_div(TIMERA_DIV_8); /* Configure the first timerA period to 1s (periodic) */ timerA_set_alarm_from_now(TIMERA_ALARM_CCR0, 512, 512); /* Set the first timerA callback */ timerA_register_cb(TIMERA_ALARM_CCR0, alarm); // Declare 2 variables for storing the different values int16_t value_0=0, value_1=1; while (1) { printf("cmd > "); cmd = 0; while (cmd==0) { LPM0; // Low Power Mode 1: SMCLK remains active for UART } switch (cmd) { case 't': value_0 = ds1722_read_MSB(); value_1 = ds1722_read_LSB(); value_1 >>= 5; value_1 *= 125; printf("Temperature measure: %i.%i\n", value_0, value_1); break; case 'l': tsl2550_init(); value_0 = tsl2550_read_adc0(); value_1 = tsl2550_read_adc1(); uart0_init(UART0_CONFIG_1MHZ_115200); uart0_register_callback(char_rx); printf("Luminosity measure: %i:%i\n", value_0, value_1); break; default: break; } } return 0; }