Example #1
0
/***********************************************************************************
* @fn          basicRfInit
*
* @brief       Initialise basic RF datastructures. Sets channel, short address and
*              PAN id in the chip and configures interrupt on packet reception
*
* @param       pRfConfig - pointer to BASIC_RF_CONFIG struct.
*                          This struct must be allocated by higher layer
*              txState - file scope variable that keeps tx state info
*              rxi - file scope variable info extracted from the last incoming
*                    frame
*
* @return      none
*/
uint8 basicRfInit(basicRfCfg_t* pRfConfig)
{
    if (halRfInit()==FAILED)
        return FAILED;

    halIntOff();

    // Set the protocol configuration
    pConfig = pRfConfig;
    rxi.pPayload   = NULL;

    txState.receiveOn = TRUE;
    txState.frameCounter = 0;

    // Set channel
    halRfSetChannel(pConfig->channel);

    // Write the short address and the PAN ID to the CC2520 RAM
    halRfSetShortAddr(pConfig->myAddr);
    halRfSetPanId(pConfig->panId);

    // if security is enabled, write key and nonce
    #ifdef SECURITY_CCM
    basicRfSecurityInit(pConfig);
    #endif

    // Set up receive interrupt (received data or acknowlegment)
    halRfRxInterruptConfig(basicRfRxFrmDoneIsr);

    halIntOn();

    return SUCCESS;
}
Example #2
0
/***********************************************************************************
* @fn          main
*
* @brief       This is the main entry of the "Light Switch" application.
*              After the application modes are chosen the switch can
*              send toggle commands to a light device.
*
* @param       basicRfConfig - file scope variable. Basic RF configuration
*              data
*              appState - file scope variable. Holds application state
*
* @return      none
*/
void main(void)
{
    uint8 appMode = NONE;

    // Config basicRF
    basicRfConfig.panId = PAN_ID;
    basicRfConfig.channel = RF_CHANNEL;
    basicRfConfig.ackRequest = TRUE;
#ifdef SECURITY_CCM
    basicRfConfig.securityKey = key;
#endif

    // Initalise board peripherals
    halBoardInit();
 //   halJoystickInit();

    // Initalise hal_rf
    if(halRfInit()==FAILED) {
      HAL_ASSERT(FALSE);
    }

    // Indicate that device is powered
    halLedSet(2);//*****************by boo LED2(P1_1=1)
    halLedClear(1);//***************by boo LED1(P1_0=0)
    
    /************Select one and shield to another***********by boo*/
    appSwitch();        //½ÚµãΪ°´¼üS1       P0_4    
    // Role is undefined. This code should not be reached
    HAL_ASSERT(FALSE);
}
Example #3
0
File: main.c Project: liyanfeng/WSN
void main(void)
{
    halMcuInit();

    hal_led_init();
    
    hal_uart_init();
    
    //Uart0Init(0, 0); 
    printf("s rssi: d\r\n");
    //Uart0Init(unsigned char StopBits,unsigned char Parity)
    if (FAILED == halRfInit()) {
        HAL_ASSERT(FALSE);
    }

    // Config basicRF
    basicRfConfig.panId = PAN_ID;
    basicRfConfig.channel = RF_CHANNEL;
    basicRfConfig.ackRequest = TRUE;
#ifdef SECURITY_CCM
    basicRfConfig.securityKey = key;
#endif

    
    // Initialize BasicRF
#if NODE_TYPE
    basicRfConfig.myAddr = SEND_ADDR;
#else
    basicRfConfig.myAddr = RECV_ADDR; 
#endif
    
    if(basicRfInit(&basicRfConfig)==FAILED) {
      HAL_ASSERT(FALSE);
    }
    
#if NODE_TYPE
    //uWaveInit();
    dht11_io_init();
    rfSendData();
#else
    rfRecvData();   
#endif
}
Example #4
0
/* ------------------------------------------------------------------------------------------------------
 *												mac_init()
 *
 * Description : MAC layer init.
 *
 */
void mac_init(void)
{
	
	/* Initialise RF radio.*/
	halRfInit();
	
#if (0)
	pib.coord_addr.mode			= SHORT_ADDR;
	pib.coord_addr.short_addr	= 0x0000;		// Net coord short address is 0x0000;
	pib.coord					= true;
	pib.short_addr				= 0x0000;		// Default node short address is 0xFFFF.
	pib.pan_id					= 0xFFFF;		// Default PAN ID is 0xFFFF.
	
	// Read MAC address in FALSH.
	HalFlashRead(HAL_FLASH_IEEE_PAGE, HAL_FLASH_IEEE_OSET, pib.ext_addr, Z_EXTADDR_LEN);
	pib.assoc_permit			= false;		// Node's association is permit.
//	pcb.mac_state				= MLME_SCAN;

	pib.curr_channel			= 20;								/* channel 20.*/
	pib.rx_on_when_idle			= true;
	pib.max_csma_backoffs		= 3;
	pib.min_be					= 3;
	pib.dsn						= (U8)halRfGetChipId(); // Random value as frame number.
	pib.tmp_pan_id				= 0xFFFF;
	
    /* Write the short address and the PAN ID to the CC2520 RAM*/
	halRfSetExtAddr(pib.ext_addr);
	halRfSetShortAddr(pib.short_addr);
	halRfSetPanId(pib.pan_id);
#endif
	pib.curr_channel			= 20;								/* channel 20.*/
	
	// Set channel
	halRfSetChannel(pib.curr_channel);
	
	halRfRxInterruptConfig(RfRxFrmDoneIsr);
	
	mac_buf_init();
	
	halRfReceiveOn();
}
Example #5
0
void main(void)
{
    halMcuInit();

    hal_led_init();
    
    hal_uart_init();
    printf("你知道串口是正常的.....\r\n");
    if (FAILED == halRfInit()) {
        HAL_ASSERT(FALSE);
    }

    // Config basicRF
    basicRfConfig.panId = PAN_ID;
    basicRfConfig.channel = RF_CHANNEL;
    basicRfConfig.ackRequest = TRUE;
#ifdef SECURITY_CCM
    basicRfConfig.securityKey = key;
#endif

    
    // Initialize BasicRF
#if NODE_TYPE
    basicRfConfig.myAddr = SEND_ADDR;
#else
    basicRfConfig.myAddr = RECV_ADDR; 
#endif
    
    if(basicRfInit(&basicRfConfig)==FAILED) {
      HAL_ASSERT(FALSE);
    }
#if NODE_TYPE
    dht11_io_init();
    InitialT1test();
  rfSendData();
#else
  printf("接收数据\r\n");
  rfRecvData();   
#endif
}
Example #6
0
/***********************************************************************************
* @fn          main
*
* @brief
*
* @param
*
*
* @return      none
*/
void main (void)
{
    int8 minRssi, maxRssi, rssiOffset;
    int16 barValue;
    int16 txtValue;
    uint8 barHeight, n;

    appShowText=FALSE;
    barHeight=  3;
    txtChannel= 0;

    // Initalise board peripherals
    halBoardInit();

    // Initalise hal_rf
    if(halRfInit()==FAILED) {
      HAL_ASSERT(FALSE);
    }
    // Indicate that device is powered
    halLedSet(1);

    // Print Logo and splash screen on LCD
    utilPrintLogo("Spectrum Anl");
    halMcuWaitMs(3000);

    // Calculate RSSI offset and range (must be done after setting gain mode)
    halRfSetGain(HAL_RF_GAIN_HIGH);

    rssiOffset= halRfGetRssiOffset();
    minRssi=    MIN_RSSI_DBM + rssiOffset;
    maxRssi=    MAX_RSSI_DBM + rssiOffset;

    // Config IO interrupt
    appConfigIO();

    // Set chip in RX scan mode
    halSetRxScanMode();

    // Load bar graph symbols to LCD
    utilLoadBarGraph();

    while(1) {
    	uint8 sample;
    	
        // For each RSSI sample record
        for (sample = 0; sample < SAMPLE_COUNT; sample++) {
        	uint8 channel;
            // Sample channel 11-26
            for(channel = 0; channel < CHANNELS; channel++ ) {
                ppRssi[channel][sample] = halSampleED(channel+CHANNEL_11, SAMPLE_TIME);
            }

            // Update the display with the latest graph values
            for(channel = 0; channel < CHANNELS; channel++ ) {
			
                barValue = -128;
                for (n = 0; n < SAMPLE_COUNT; n++) {
                    barValue = MAX((int8) barValue, ppRssi[channel][n]);
                }
                barValue -= minRssi;

                // Saturate
                if (barValue < 0)
                    barValue = 0;
                if (barValue > ((int16) maxRssi - (int16) minRssi))
                    barValue = (int16) maxRssi - (int16) minRssi;
                // Scale
                barValue *= (barHeight == 2) ? (8 + 1 + 8) : (8 + 1 + 8 + 1 + 8);
                barValue /= maxRssi - minRssi;

                // Display the bar
                for (n = 0; n < barHeight; n++) {
                    utilDisplayBarGraph(n + 1, channel, (barHeight - 1 - n) * 9, barValue);
                }
            }
        }

        // Show RSSI in text form on display
        if(appShowText) {
            txtValue = -128;
            barHeight=2;
            // find peak value
            for (n = 0; n < SAMPLE_COUNT; n++) {
                txtValue = MAX((int8) txtValue, ppRssi[txtChannel][n]);
            }
            txtValue -= rssiOffset;
            utilLcdDisplayValue(3, (char*)channelText[txtChannel], txtValue, " dBm");
        }
        else
            barHeight=3;
    }
}
Example #7
0
/***********************************************************************************
* @fn          main
*/
void main(void)
{
  // Initalise board peripherals
  halBoardInit();
  
  basicRfSetUp();
  
  // Initalise hal_rf
  if(halRfInit()==FAILED)
  {
    HAL_ASSERT(FALSE);
  }
  
  // Indicate that device is powered
  halLedSet(1);
  halMcuWaitMs(350);
  
  configureUSART0forUART_ALT1();
  uartStartRxForIsr();
  
  
  while(TRUE)
  {
    //----------------------
    // INITIALIZE
    //----------------------
    if(initFlag)
    {
      while(!start); //waiting for 'a' key from PC 
      //respond to PC -- going to try to start up WRS 
      start=0;
      pTxData[0] = INIT_COMM_CMD;
      basicRfReceiveOff();
      if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)
      {
        state=1;
      }
      basicRfReceiveOn();
      //wait for ACK from WRS
      
      pTxData[0] = INIT_COEF_CMD;
      basicRfReceiveOff();
      if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)
      {
        basicRfReceiveOn();
        
        //WAIT FOR COEFFICIENTS FROM WRS
        while(!basicRfPacketIsReady());//wait to receive acknowledgement
        
        if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, NULL)>0) 
        {
          if(pRxData[0] == 'C') 
          {  
            //Pass to PC
            for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++)
            {
              U0CSR &= ~0x02; //SET U0TX_BYTE to 0
              U0DBUF = pRxData[uartTxIndex];      
              while (!(U0CSR&0x02));
            }
          }    
        }
      }
      
      //finished sending coefficients to PC 
      
      basicRfReceiveOn();
      initFlag=0;
    }
    
    
    
    if(turnOnMotorFlag){
      if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)//send command to WRS
      {
        turnOnMotorFlag=0;
      }
    }
    
    if(sendInitFlag){
      if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)//send command to WRS
      {
        initFlag=1;
        sendInitFlag=0;
        //Pass to PC
        for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++)
        {
          pRxData[0] == 'R';
          U0CSR &= ~0x02; //SET U0TX_BYTE to 0
          U0DBUF = pRxData[uartTxIndex];      
          while (!(U0CSR&0x02));
        }
      }
    }
    //Receive package from WRS
    if(basicRfPacketIsReady())
    { 
      
      if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, myRSSI)>0) {
        getRSSI = basicRfGetRssi();
        pRxData[104]=getRSSI;
        if(pRxData[0] == 'D')//||(pRxData[0] == 'I'))
        {          
          //SEND DATA TO PC 
          for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++)
          {
            U0CSR &= ~0x02; //SET U0TX_BYTE to 0
            U0DBUF = pRxData[uartTxIndex];      
            while (!(U0CSR&0x02));
          }
        }
      }
      
    }    
  }
}
Example #8
0
/***********************************************************************************
* @fn          main
*/
void main(void)
{
  // Initalise board peripherals
  halBoardInit();
  
  
  basicRfSetUp();
  
  // Initalise hal_rf
  if(halRfInit()==FAILED)
  {
    HAL_ASSERT(FALSE);
  }
  
  // Indicate that device is powered
  halLedSet(1);
  halMcuWaitMs(350);
  
  configureUSART0forUART_ALT1();
  uartStartRxForIsr();
  
  while(!start); //waiting for 'a' key from PC 
  //respond to PC -- going to try to start up WRS 
  
  pTxData[0] = INIT_COMM_CMD;
  basicRfReceiveOff();
  if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)
  {
    state=1;
  }
  basicRfReceiveOn();
  //wait for ACK from WRS
  
  pTxData[0] = INIT_COEF_CMD;
  basicRfReceiveOff();
  if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)
  {
    basicRfReceiveOn();
    
    state=2;//continuous?
    
    //WAIT FOR COEFFICIENTS FROM WRS
    while(!basicRfPacketIsReady());//wait to receive acknowledgement
    
    if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, NULL)>0) 
    {
      if(pRxData[0] == 'C') 
      {  
        //Pass to PC
        for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++)
        {
          U0CSR &= ~0x02; //SET U0TX_BYTE to 0
          U0DBUF = pRxData[uartTxIndex];      
          while (!(U0CSR&0x02));
        }
        // while(!ACK);//waiting for acknowledgement
      }    
    }
  }
  
  //finished sending coefficients to PC 
  
  basicRfReceiveOn();
  
  while(TRUE)
  {
    //Receive package from WRS
    if(basicRfPacketIsReady())
    { 
      
      if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, myRSSI)>0) {
        getRSSI = basicRfGetRssi();
        pRxData[104]=getRSSI;
        if((pRxData[0] == 'P')||(pRxData[0] == 'A'))
        {          
          //SEND DATA TO PC 
          for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++)
          {
            U0CSR &= ~0x02; //SET U0TX_BYTE to 0
            U0DBUF = pRxData[uartTxIndex];      
            while (!(U0CSR&0x02));
          }
        }
      }
      
    }
    
    //Receive CMD from PC 
    if(changePWMflag)//have this be set in interrupt 
    {
      //basicRfReceiveOff();
      
      if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)//send PWM info to WRS
      {
        
        changePWMflag=0;
      }
      //basicRfReceiveOn();
        
        //        while(changePWMflag)//Keep receiving until PWM acknowledge is sent
        //        {
        //          while(!basicRfPacketIsReady());//waiting for acknowledgement -- important here i think
        //          
        //          if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, NULL)>0) 
        //          {
        //            if(pRxData[0] == 'Z')
        //            {
        //              //receive current duty cycle and send back to PC 
        //              for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++)
        //              {
        //                U0CSR &= ~0x02; //SET U0TX_BYTE to 0
        //                U0DBUF = pRxData[uartTxIndex];      
        //                while (!(U0CSR&0x02));
        //              }
        //              changePWMflag = 0;
        //            }
        //            //else send pressure?
        //          }
        //        }
        //      }
      
    }
  }//END OF MAIN WHILE LOOP
}