void main (void) { BSP_Init( ); SET_MAIN_CLOCK_SOURCE(CRYSTAL); initUART(); printf( "Start iwsn system...\n" ); InitRFIO(); /* set io as normal io, not uart */ //P0DIR &= ~0x03; /* Set button as input */ EnableRecv(); SMPL_Init( NULL ); /* turn on the radio so we are always able to receive data asynchronously */ SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RXON, NULL ); /* turn on LED. */ BSP_TURN_ON_LED1( ); BSP_TURN_ON_LED2( ); /* never coming back... */ framework_entry(); /* but in case we do... */ while (1) ; }
void main() { BSP_Init( ); SET_MAIN_CLOCK_SOURCE(CRYSTAL); initUART(); initOuterRF(); enableOuterRF(); enableOuterRFData(); /* turn on LED. */ BSP_TURN_ON_LED1( ); BSP_TURN_ON_LED2( ); running(); return; }
__interrupt void Port_1(void) { if((P3IN & 0x20)) // /Charge=1; battery, Blink Red { BSP_TURN_ON_LED1(); __delay_cycles(10000); BSP_TURN_OFF_LED1(); } else // /Charge=0; Solar, blink green { BSP_TURN_ON_LED2(); __delay_cycles(10000); BSP_TURN_OFF_LED2(); } // If successful link, change timer state. if(status == status_six || status == status_five) { if(timer_state >= timer_state_6) // If transmit time is == 6, { // Set timer_state = 1 timer_state = timer_state_1; display_mode(); // Change GUI display time } else { timer_state++; // Change transmit time state display_mode(); // Change GUI display time } if(in_delay) // If in transmit delay, exit and { // send a new packet with new time __bic_SR_register_on_exit(LPM4_bits); // Clear LPM3 bit from 0(SR) } } __delay_cycles(150000); // Debounce software delay while(!(P1IN & 0x04)); // Loop if button is still pressed P1IFG &= ~0x04; // P1.2 IFG cleared key interuped }
void main(void) { sensor.cadc = 'A'; sensor.iadc = 125; trigger(0x5 + (0x6 << 3) + (0x1 << 6) + (0x7 << 9)); BSP_Init(); // init bsp first, then simpliciti BCSCTL3 = LFXT1S_2; // aclk = vlo // address check and creation Flash_Addr = (char *)0x10F0; // RF Address = 0x10F0 if( Flash_Addr[0] == 0xFF && // Check if device Address is missing Flash_Addr[1] == 0xFF && Flash_Addr[2] == 0xFF && Flash_Addr[3] == 0xFF ) { createRandomAddress(); // Create Random device address at } // initial startup if missing lAddr.addr[0] = Flash_Addr[0]; lAddr.addr[1] = Flash_Addr[1]; lAddr.addr[2] = Flash_Addr[2]; lAddr.addr[3] = Flash_Addr[3]; // load address SMPL_Ioctl(IOCTL_OBJ_ADDR, IOCTL_ACT_SET, &lAddr); SMPL_Init(NULL); // null callback for TX Init_ADC10(); Init_TIMER0A0(); do { // wait for button if (BSP_BUTTON1()) { break; } } while (1); while (SMPL_SUCCESS != SMPL_Link(&linkIDTemp)) // link to Rx { BSP_TOGGLE_LED1(); // toggle red for not linked } BSP_TURN_OFF_LED1(); // red off BSP_Delay(2000); // for 2 seconds BSP_TURN_ON_LED1(); _EINT(); // Enable Global Interupts while (1) { BSP_TOGGLE_LED2(); // adc with dtc in use ADC10CTL0 &= ~ENC; // turn off adc10 while (ADC10CTL1 & BUSY); // wait if adc10 core is active ADC10SA = (unsigned int)ADCdata; // data buffer start ADC10CTL0 |= ENC + ADC10SC; // sampling and conversion start LPM3; // insert sensor calculations here // or // send raw adc data from P1.0 sensor.iadc = ADCdata[0]; // turn on radio and tx sensor struct SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, 0); SMPL_Send(linkIDTemp, (uint8_t *)&sensor, sizeof( my_sensors )); } }
void main1 (void) { /* holds length of current message */ uint8_t len; /* the link token */ linkID_t LinkID = 0; /* the transmit and receive buffers */ uint8_t rx[MAX_APP_PAYLOAD], tx[MAX_APP_PAYLOAD]; /* holds led indicator time out counts */ uint16_t led_tmr; int8_t rssi_value; BSP_Init( ); SMPL_Init( NULL ); uart_intfc_init( ); /* turn on the radio so we are always able to receive data asynchronously */ SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RXON, NULL ); /* turn on LED. */ BSP_TURN_ON_LED1( ); #ifdef LINK_TO { uint8_t cnt = 0; tx_send_wait( "Linking to...\r\n", 15 ); while (SMPL_SUCCESS != SMPL_Link(&LinkID)) if( cnt++ == 0 ) { /* blink LED until we link successfully */ BSP_TOGGLE_LED1( ); } } #else // ifdef LINK_LISTEN tx_send_wait( "Listening for Link...\r\n", 23 ); while (SMPL_SUCCESS != SMPL_LinkListen(&LinkID)) { /* blink LED until we link successfully */ BSP_TOGGLE_LED1( ); } #endif tx_send_wait( "Link Established!\r\nReady...\r\n", 29 ); /* turn off the led */ BSP_TURN_OFF_LED1( ); main_loop: /* Check to see if we received any characters from the other radio * and if we have send them out the uart and reset indicator timeout. * Prioritize on radio received links as that buffer is the most time * critical with respect to the UART buffers. */ if( SMPL_Receive( LinkID, tx, &len ) == SMPL_SUCCESS ) { /* blocking call but should be ok if both ends have same uart buad rate */ //tx_send_wait( tx, len ); led_tmr = INDICATOR_TIME_OUT; /* update activity time out */ /* int8_t dbm; SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RSSI, (void *)&dbm); sSample= dbm; tx_send_wait(&char2send, 1 );//input only (unsigned char) tx_send_wait("\n", 1 );*/ unsigned char Test2; //unsigned char Test; rssi_value = 0 ; ioctlRadioSiginfo_t sigInfo1; sigInfo1.lid=LinkID; smplStatus_t SMPL_SUCCESS = SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SIGINFO, (void *)&sigInfo1); //if( SMPL_SUCCESS == SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RSSI,(void*)&rssi_value) ) { //transmitData( i, (signed char)sigInfo.sigInfo.rssi, (char*)msg ); //MRFI_Rssi() //Test2=RSSI; //Test=rssi_value; //int8_t i =-127; //int i =-127; unsigned char rssi_tmp[10]; int8_t rssi_int = sigInfo1.sigInfo.rssi; itoa(rssi_int,rssi_tmp); //tx_send_wait("This is Test :", sizeof("This is Test :") ); //tx_send_wait(&Test2, strlen(&Test2)); tx_send_wait(&rssi_tmp, strlen(rssi_tmp)); //tx_send_wait("\r\n", sizeof("\r\n") ); int8_t mk=0x01,bitshift=0; tx_send_wait("=",1); for (bitshift=0;bitshift<8;bitshift++) { if( (mk<<bitshift) & rssi_int ) tx_send_wait("1",1); else tx_send_wait("0",1); //tx_send_wait("x",1); MRFI_DelayMs( 5 ); } tx_send_wait("\r\n", sizeof("\r\n") ); /* tx_send_wait("This is Test2 :", sizeof("This is Test2 :") ); tx_send_wait( &Test2, sizeof(Test2) ); tx_send_wait("\n", sizeof("\n") ); */ } } FHSS_ACTIVE( if( nwk_pllBackgrounder( false ) != false ) ); { /* check to see if the host has sent any characters and if it has * then send them over the radio link and reset indicator timeout. */ len = rx_receive( rx, MAX_APP_PAYLOAD ); if( len != 0 ) { while( SMPL_Send( LinkID, rx, len ) != SMPL_SUCCESS ) ; /* if( SMPL_SUCCESS == SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RSSI,&rssi_value ) ){ SMPL_Send( LinkID, &rssi_value, sizeof(rssi_value) ); }*/ led_tmr = INDICATOR_TIME_OUT; /* update activity time out */ /* By forcing a minimum delay between transmissions we guarantee * a window for receiving packets. This is necessary as the radio * link is half duplex while the UART is full duplex. Without this * delay mechanism, packets can get lost as both ends may attempt to * transmit at the same time which the CCA algorithm fails to handle. */ MRFI_DelayMs( 5 ); } } /* manage led indicator */ if( led_tmr != 0 ) { led_tmr--; BSP_TURN_ON_LED1( ); } else BSP_TURN_OFF_LED1( ); goto main_loop; /* do it again and again and again and ... */ }
/******************************************************************************* * BEGHDR * Function: void StatusBlink_led1(int BlinkCount) * DESCRIPTION: Blinks LED 1 - Red based on specified delay * INPUTS: BlinkCount * PROCESSING: Turns on and off the RED LED with specified blink time * OUTPUTS: VOID *******************************************************************************/ void StatusBlink_led1(int BlinkCount) { BSP_TURN_ON_LED1(); delay(BlinkCount); BSP_TURN_OFF_LED1(); }
// AP main routine void simpliciti_main(void) { bspIState_t intState; uint8_t j; uint8_t len; uint32_t led_toggle = 0; uint8_t pwr; // Init variables simpliciti_flag = SIMPLICITI_STATUS_LINKING; // Init SimpliciTI SMPL_Init(sCB); // Set output power to +1.1dBm (868MHz) / +1.3dBm (915MHz) pwr = IOCTL_LEVEL_2; SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SETPWR, &pwr); // LED off BSP_TURN_OFF_LED1(); /* main work loop */ while (1) { // Wait for the Join semaphore to be set by the receipt of a Join frame from a //device that supports an End Device. if (sJoinSem && !sNumCurrentPeers) { /* listen for a new connection */ while (1) { if (SMPL_SUCCESS == SMPL_LinkListen(&linkID0)) { // We have a connection simpliciti_flag = SIMPLICITI_STATUS_LINKED; BSP_TURN_ON_LED1(); break; } /* Implement fail-to-link policy here. otherwise, listen again. */ } sNumCurrentPeers++; BSP_ENTER_CRITICAL_SECTION(intState); sJoinSem--; BSP_EXIT_CRITICAL_SECTION(intState); } /* Have we received a frame on one of the ED connections? * No critical section -- it doesn't really matter much if we miss a poll */ if (sPeerFrameSem) { // Continuously try to receive end device packets if (SMPL_SUCCESS == SMPL_Receive(linkID0, ed_data, &len)) { // Acceleration / ppt data packets are 4 byte long if (len == 4) { BSP_TOGGLE_LED1(); memcpy(simpliciti_data, ed_data, 4); setFlag(simpliciti_flag, SIMPLICITI_TRIGGER_RECEIVED_DATA); #ifdef EMBEDDED_UART uart_analyze_packet(simpliciti_data[0],simpliciti_data[1],simpliciti_data[2],simpliciti_data[3]); #endif } // Sync packets are either R2R (2 byte) or data (19 byte) long else if ((len == 2) || (len == 19)) { // Indicate received packet BSP_TOGGLE_LED1(); // Decode end device packet switch (ed_data[0]) { case SYNC_ED_TYPE_R2R: // Send reply if (getFlag(simpliciti_flag, SIMPLICITI_TRIGGER_SEND_CMD)) { // Clear flag clearFlag(simpliciti_flag, SIMPLICITI_TRIGGER_SEND_CMD); // Command data was set by USB buffer previously len = BM_SYNC_DATA_LENGTH; } else // No command currently available { simpliciti_data[0] = SYNC_AP_CMD_NOP; simpliciti_data[1] = 0x55; len = 2; } // Send reply packet to end device SMPL_Send(linkID0, simpliciti_data, len); break; case SYNC_ED_TYPE_MEMORY: case SYNC_ED_TYPE_STATUS: // If buffer is empty, copy received end device data to intermediate buffer if (!simpliciti_sync_buffer_status) { for (j=0; j<BM_SYNC_DATA_LENGTH; j++) simpliciti_data[j] = ed_data[j]; simpliciti_sync_buffer_status = 1; } // Set buffer status to full break; } } } } // Exit function if SIMPLICITI_TRIGGER_STOP flag bit is set in USB driver if (getFlag(simpliciti_flag, SIMPLICITI_TRIGGER_STOP)) { // Immediately turn off RF interrupt IEN2 &= ~BIT0; RFIM = 0; RFIF = 0; // Clean up after SimpliciTI and enable restarting the stack linkID0 = 0; sNumCurrentPeers = 0; sJoinSem = 0; sPeerFrameSem = 0; sInit_done = 0; // LED off BSP_TURN_OFF_LED1(); return; } // Blink slowly to indicate that access point is on if (!sNumCurrentPeers) { if (led_toggle++>150000) { BSP_TOGGLE_LED1(); led_toggle = 0; } } } }
void main (void) { ioctlScanChan_t scan; freqEntry_t freq[NWK_FREQ_TBL_SIZE]; uint8_t firstTimeThru = 1; BSP_Init(); /* Keep trying to join (a side effect of successful initialization) until * successful. Toggle LEDS to indicate that joining has not occurred. */ while (SMPL_SUCCESS != SMPL_Init(0)) { toggleLED(1); toggleLED(2); SPIN_ABOUT_A_SECOND; } scan.freq = freq; while (1) { SPIN_ABOUT_A_QUARTER_SECOND; SMPL_Ioctl(IOCTL_OBJ_FREQ, IOCTL_ACT_SCAN, &scan); if (1 == scan.numChan) { if (firstTimeThru) { BSP_TURN_OFF_LED1(); BSP_TURN_ON_LED2(); { uint8_t i=15; while (i--) { toggleLED(1); toggleLED(2); SPIN_ABOUT_A_QUARTER_SECOND; } } firstTimeThru = 0; } switch(freq[0].logicalChan) { case 0: /* GREEN OFF */ /* RED OFF */ BSP_TURN_OFF_LED1(); BSP_TURN_OFF_LED2(); break; case 1: /* GREEN OFF */ /* RED ON */ BSP_TURN_OFF_LED1(); BSP_TURN_ON_LED2(); break; case 2: /* GREEN ON */ /* RED OFF */ BSP_TURN_ON_LED1(); BSP_TURN_OFF_LED2(); break; case 3: /* GREEN ON */ /* RED ON */ BSP_TURN_ON_LED1(); BSP_TURN_ON_LED2(); break; case 4: /* blink them both... */ BSP_TURN_OFF_LED1(); BSP_TURN_OFF_LED2(); SPIN_ABOUT_A_QUARTER_SECOND; BSP_TURN_ON_LED1(); BSP_TURN_ON_LED2(); SPIN_ABOUT_A_QUARTER_SECOND; BSP_TURN_OFF_LED1(); BSP_TURN_OFF_LED2(); } } } }
void main (void) { addr_t lAddr; bspIState_t intState; char *Flash_Addr; // Initialize radio address location Flash_Addr = (char *)0x10F0; WDTCTL = WDTPW + WDTHOLD; // Stop WDT // delay loop to ensure proper startup before SimpliciTI increases DCO // This is typically tailored to the power supply used, and in this case // is overkill for safety due to wide distribution. __delay_cycles(65000); if( CALBC1_8MHZ == 0xFF && CALDCO_8MHZ == 0xFF )// Do not run if cal values { P1DIR |= 0x03; BSP_TURN_ON_LED1(); BSP_TURN_OFF_LED2(); while(1) { __delay_cycles(65000); BSP_TOGGLE_LED2(); BSP_TOGGLE_LED1(); } } BSP_Init(); if( Flash_Addr[0] == 0xFF && Flash_Addr[1] == 0xFF && Flash_Addr[2] == 0xFF && Flash_Addr[3] == 0xFF ) { createRandomAddress(); // Create Random device address at } // initial startup if missing lAddr.addr[0]=Flash_Addr[0]; lAddr.addr[1]=Flash_Addr[1]; lAddr.addr[2]=Flash_Addr[2]; lAddr.addr[3]=Flash_Addr[3]; //SMPL_Init(); SMPL_Ioctl(IOCTL_OBJ_ADDR, IOCTL_ACT_SET, &lAddr); MCU_Init(); //Transmit splash screen and network init notification TXString( (char*)splash, sizeof splash); TXString( "\r\nInitializing Network....", 26 ); SMPL_Init(sCB); // network initialized TXString( "Done\r\n", 6); // main work loop while(1) { // Wait for the Join semaphore to be set by the receipt of a Join frame from a // device that supports and End Device. if (sJoinSem && (sNumCurrentPeers < NUM_CONNECTIONS)) { // listen for a new connection SMPL_LinkListen(&sLID[sNumCurrentPeers]); sNumCurrentPeers++; BSP_ENTER_CRITICAL_SECTION(intState); if (sJoinSem) { sJoinSem--; } BSP_EXIT_CRITICAL_SECTION(intState); } // if it is time to measure our own temperature... if(sSelfMeasureSem) { // TXString("\r\n...", 5); BSP_TOGGLE_LED1(); sSelfMeasureSem = 0; } // Have we received a frame on one of the ED connections? // No critical section -- it doesn't really matter much if we miss a poll if (sPeerFrameSem) { uint8_t msg[MESSAGE_LENGTH], len, i; // process all frames waiting for (i=0; i<sNumCurrentPeers; ++i) { if (SMPL_Receive(sLID[i], msg, &len) == SMPL_SUCCESS) { ioctlRadioSiginfo_t sigInfo; sigInfo.lid = sLID[i]; SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SIGINFO, (void *)&sigInfo); transmitData( i, (signed char)sigInfo.sigInfo.rssi, (char*)msg ); BSP_TURN_ON_LED2(); // Toggle LED2 when received packet BSP_ENTER_CRITICAL_SECTION(intState); sPeerFrameSem--; BSP_EXIT_CRITICAL_SECTION(intState); __delay_cycles(10000); BSP_TURN_OFF_LED2(); } } } } }