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 }
/******************************************************************************* * BEGHDR * Function: void StatusBlink_led1(int BlinkCount) * DESCRIPTION: Blinks LED 1 - Green based on specified delay * INPUTS: BlinkCount * PROCESSING: Turns on and off the Green LED with specified blink time * OUTPUTS: VOID *******************************************************************************/ void StatusBlink_led2(int BlinkCount) { BSP_TURN_ON_LED2(); delay(BlinkCount); BSP_TURN_OFF_LED2(); }
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(); } } } } }