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 gradient_Init(uint8_t is_sink) { P1OUT &= ~0x03; print_debug("\r\nRESTART",9); //serial communication P3SEL |= 0x30; // P3.4,5 = USCI_A0 TXD/RXD UCA0CTL1 = UCSSEL_2; // SMCLK UCA0BR0 = 0x41; // 9600 from 8Mhz UCA0BR1 = 0x3; UCA0MCTL = UCBRS_2; UCA0CTL1 &= ~UCSWRST; // Initialize USCI state machine IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt __enable_interrupt(); //button P1DIR &= ~0x04; // P1.3 input P1OUT = 0x04; P1REN |= 0x04; // P1.3 pullup P1IE |= 0x04; // P1.3 interrupt enabled P1IES |= 0x04; // P1.3 Hi/lo edge P1IFG &= ~0x04; // P1.3 IFG cleared //extension pins used for debugging P4SEL &= ~0x20; // P4.5 generic I/O pin P2DIR |= 0x02; // P2.1 output @ extension pin P4 P2DIR |= 0x08; // P2.3 output @ extension pin P6 P4DIR |= 0x08; // P4.3 output @ extension pin P8 P4DIR |= 0x20; // P4.5 output @ extension pin P10 //set myAddr if(Flash_Addr == 0xFF) // no address set before { myAddr = MRFI_RandomByte(); FCTL2 = FWKEY + FSSEL0 + FN1; // MCLK/3 for Flash Timing Generator FCTL3 = FWKEY + LOCKA; // Clear LOCK & LOCKA bits FCTL1 = FWKEY + WRT; // Set WRT bit for write operation Flash_Addr = myAddr; FCTL1 = FWKEY; // Clear WRT bit FCTL3 = FWKEY + LOCKA + LOCK; // Set LOCK & LOCKA bit } else { myAddr=Flash_Addr; } //set height and start clock if (is_sink) { myHeight = 0; BSP_TOGGLE_LED1(); } else { myHeight = 255; //timer A BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO TACCTL0 = CCIE; // TACCR0 interrupt enabled TACCR0 = 1500*WAKEUP_PERIOD_S_FIXED; // 1500=1 second TACTL = TASSEL_1 + MC_1 + ID_3; // ACLK/8, upmode } gradient_set_state(GRADIENT_IDLE); mrfiSpiWriteReg(PATABLE, TX_POWER); print_cc2500_registers(); MRFI_WakeUp(); wor_start(IS_SINK_NODE); }
void MRFI_RxCompleteISR() { BSP_TOGGLE_LED1(); MRFI_Receive(&inBuffer); uint8_t pkt_type = GET_FROM_FRAME(MRFI_P_PAYLOAD(&inBuffer), F_TYPE); switch (pkt_type) { case (F_TYPE_UF): #ifdef PRINT_UF print_time(); print_UF(&inBuffer); #endif break; case (F_TYPE_CW): #ifdef PRINT_CW print_time(); print_CW(&inBuffer); #endif break; case (F_TYPE_ACK): #ifdef PRINT_ACK print_time(); print_ACK(&inBuffer); #endif break; case (F_TYPE_DATA): #ifdef PRINT_DATA print_time(); print_DATA(&inBuffer); #endif break; case (F_TYPE_FIN): #ifdef PRINT_FIN print_time(); print_FIN(&inBuffer); #endif break; default: print_time(); print_debug("\r\nError: Unrecognized packet format",35); } BSP_TOGGLE_LED1(); }
void toggleLED(uint8_t which) { if (1 == which) { BSP_TOGGLE_LED1(); } else if (2 == which) { BSP_TOGGLE_LED2(); } return; }
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() { BSP_Init(); // Initialisation de la librairie BSP NWK_DELAY(500); SMPL_Init(0); // Initialisation de la librairie SimpliciTI SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, 0); // Initialisation Timer A BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO TACCTL0 = CCIE; // TACCR0 interrupt enabled msg[0] = '#'; msg[1] = REPERE_ID; msg[2] = ':'; msg[3] = 'V'; msg[4] = 0; msg[5] = 0xFF; timeCounter = 250; unsyncRepere(); while (1) { SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SLEEP, 0); __bis_SR_register(LPM3_bits + GIE); SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, 0); SMPL_SendOpt(SMPL_LINKID_USER_UUD, msg, sizeof(msg), SMPL_TXOPTION_NONE); BSP_TOGGLE_LED1(); if (timeCounter >= 300) // Quand timeCounter a été incrémenté depuis 1 minute (0.2sec x 300) { voltAction(); msg[4] = ((uint8_t*)&volt)[3]; timeCounter = 0; } } }
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 ... */ }
// 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 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(); } } } } }