void running(void) { uint8 len; struct AppFrame* appFrame; uint16 count = 0xffff; while(1) { len = recvRf((uint8**)&appFrame); if(len > 0) { if(!isValidData(appFrame)) continue; if(!isMyAddress(appFrame)) { } else { BSP_TOGGLE_LED2(); doCommand(appFrame); } } count--; if(count == 0) { BSP_TOGGLE_LED1(); count = 0xffff; } } }
void toggleLED(uint8_t which) { if (1 == which) { BSP_TOGGLE_LED1(); } else if (2 == which) { BSP_TOGGLE_LED2(); } return; }
void unsyncRepere() { uint8_t msgTemp[10] = {0,0,0,0,0,0,0,0,0,0}; uint8_t msgLen = 0; SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RXON, 0); // Activation de la radio pour permettre la réception des messages NWK_DELAY(10); while((SMPL_Receive(SMPL_LINKID_USER_UUD, msgTemp, &msgLen)) == SMPL_SUCCESS) // Boucle de désynchronisation des repères { BSP_TOGGLE_LED2(); NWK_DELAY(10); } if(BSP_LED2_IS_ON()) BSP_TOGGLE_LED2(); TACCR0 = 2280; // ~ 0.2sec - 10 msec TACTL = TASSEL_1 + MC_1; // ACLK, upmode __bis_SR_register(LPM3_bits + GIE); TACCR0 = 2400; // ~ 0.2sec TACTL = TASSEL_1 + MC_1; // ACLK, upmode SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RXIDLE, 0); // Désactivation de la réception des messages }
void toggleLED(uint8_t which) { switch(which) { case 1 : BSP_TOGGLE_LED1(); break; case 2 : BSP_TOGGLE_LED2(); break; case 3 : BSP_TOGGLE_LED3(); break; } return; }
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 toggleLED(uint8_t which) { if (1 == which) BSP_TOGGLE_LED1(); else if (2 == which) BSP_TOGGLE_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(); } } } } }
__interrupt void Timer_A0 (void) { BSP_TOGGLE_LED2(); }