⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 phy.c

📁 802.15.4协议的物理层和mac层的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
	result_t ok;
	
	disableFIFOP();  


    call HPLCC2420.cmd(CC2420_SXOSCOFF); 

    call HPL_Control.stop();

    TOSH_CLR_CC_RSTN_PIN();
    ok &= VREFOff();
    TOSH_SET_CC_RSTN_PIN();

    return SUCCESS;
  }
   
/*****************************************************************************************************/  
/**************************************PD-DATA********************************************************/
/*****************************************************************************************************/  


async command result_t PD_DATA.request(uint8_t psduLength, uint8_t* psdu) {

	//atomic{
		
		call HPLCC2420FIFO.writeTXFIFO(psduLength,(uint8_t *)psdu);
		call HPLCC2420.cmd(CC2420_STXON);
	//}
	signal PD_DATA.confirm(PHY_SUCCESS);
	return SUCCESS;
}

/*****************************************************************************************************/  
/********************************************PLME-ED**************************************************/
/*****************************************************************************************************/  

command result_t PLME_ED.request(){
	//MAC asking for energy detection
	//signal PLME_ED.confirm(PHY_SUCCESS,GetRFPower());
	uint8_t rssi;
	rssi =  (uint8_t) call HPLCC2420.read(CC2420_RSSI);
	//verify how to do the energy detection
	
	////printfUART("ED: %i\n", rssi);
	signal PLME_ED.confirm(PHY_SUCCESS,rssi);
	
	return SUCCESS;
}

/*****************************************************************************************************/  
/********************************************PLME-CCA*************************************************/
/*****************************************************************************************************/

command result_t PLME_CCA.request(){
//MAC asking for CCA
	if ( TOSH_READ_CC_CCA_PIN() == CCA_BUSY )
		signal PLME_CCA.confirm(PHY_BUSY);
	else
		signal PLME_CCA.confirm(PHY_IDLE);
		
	
	return SUCCESS;
}

/*****************************************************************************************************/  
/********************************************PLME-GET*************************************************/
/*****************************************************************************************************/

command result_t PLME_GET.request(uint8_t PIBAttribute){
//MAC asking for PIBAttribute value
  switch(PIBAttribute)
		{
			case PHYCURRENTCHANNEL:
				signal PLME_GET.confirm(PHY_SUCCESS, PIBAttribute, phy_PIB.phyCurrentChannel);
				break;

			case PHYCHANNELSSUPPORTED:
				signal PLME_GET.confirm(PHY_SUCCESS, PIBAttribute, phy_PIB.phyChannelsSupported);
				break;

			case PHYTRANSMITPOWER:
				signal PLME_GET.confirm(PHY_SUCCESS, PIBAttribute, phy_PIB.phyTransmitPower);
				break;
			case PHYCCAMODE:
				signal PLME_GET.confirm(PHY_SUCCESS, PIBAttribute, phy_PIB.phyCcaMode);
				break;
			default:
				signal PLME_GET.confirm(PHY_UNSUPPORTED_ATTRIBUTE, PIBAttribute, 0x00);
				break;
		}
		
  
  return SUCCESS;
  }
  
/*****************************************************************************************************/  
/********************************************PLME-SET*************************************************/
/*****************************************************************************************************/
command result_t PLME_SET.request(uint8_t PIBAttribute, uint8_t PIBAttributeValue){
  

	  //MAC is demanding for PHY to write the indicated PIB value
	  switch(PIBAttribute)
			{
				case PHYCURRENTCHANNEL:
					
					phy_PIB.phyCurrentChannel = PIBAttributeValue;
					TunePreset(phy_PIB.phyCurrentChannel);
					signal PLME_SET.confirm(PHY_SUCCESS, PIBAttribute);
					break;
	
				case PHYCHANNELSSUPPORTED:
					phy_PIB.phyChannelsSupported = PIBAttributeValue;
					signal PLME_SET.confirm(PHY_SUCCESS, PIBAttribute);
					break;
	
				case PHYTRANSMITPOWER:
					phy_PIB.phyTransmitPower= PIBAttributeValue;
					SetRFPower(phy_PIB.phyTransmitPower);
					signal PLME_SET.confirm(PHY_SUCCESS, PIBAttribute);
					break;
				case PHYCCAMODE:
					phy_PIB.phyCcaMode= PIBAttributeValue;
					signal PLME_SET.confirm(PHY_SUCCESS, PIBAttribute);
					break;
				default:
					signal PLME_SET.confirm(PHY_UNSUPPORTED_ATTRIBUTE, PIBAttribute);
					break;
			}
	  return SUCCESS;
} 
  
/*****************************************************************************************************/  
/**********************************PLME_SET_TRX_STATE*************************************************/
/*****************************************************************************************************/


async command result_t PLME_SET_TRX_STATE.request(uint8_t state){
	////printfUART("PLME_SET_TRX_STATE.request\n","");

  //MAC is demanding for PHY to change to the requested transceiver radio state
atomic{ 
		switch(state)
		{
			case PHY_RX_ON:
				switch(currentRxTxState)
				{
					//transceiver state already on
					case PHY_RX_ON: signal PLME_SET_TRX_STATE.confirm(PHY_RX_ON);
									break;
					case PHY_TRX_OFF:call HPLCC2420.cmd(CC2420_SRXON);
									currentRxTxState = PHY_RX_ON;
									signal PLME_SET_TRX_STATE.confirm(SUCCESS);
									break;
					case PHY_TX_ON:
									signal PLME_SET_TRX_STATE.confirm(PHY_BUSY_TX);
									break;
				}
				break;

			case PHY_TRX_OFF:
				switch(currentRxTxState)
				{
					//transceiver state already on
					case PHY_RX_ON:call HPLCC2420.cmd(CC2420_SRFOFF);
									 currentRxTxState = PHY_TRX_OFF; 
									signal PLME_SET_TRX_STATE.confirm(PHY_BUSY_RX);
									break;
					case PHY_TRX_OFF: signal PLME_SET_TRX_STATE.confirm(PHY_TRX_OFF);
									break;
					case PHY_TX_ON: call HPLCC2420.cmd(CC2420_SRFOFF);
									 currentRxTxState = PHY_TRX_OFF;
									signal PLME_SET_TRX_STATE.confirm(PHY_BUSY_TX);
									break;
				}
				break;

			case PHY_FORCE_TRX_OFF:
				call HPLCC2420.cmd(CC2420_SRFOFF);
				 currentRxTxState = PHY_TRX_OFF;

				break;
			case PHY_TX_ON:
			
				switch(currentRxTxState)
				{
					//transceiver state already on
					case PHY_RX_ON: signal PLME_SET_TRX_STATE.confirm(PHY_BUSY_RX);
									break;
					case PHY_TRX_OFF:
									//call HPLCC2420.cmd(CC2420_SXOSCON);
									call HPLCC2420.cmd(CC2420_STXON);
									 currentRxTxState = PHY_TX_ON;
									signal PLME_SET_TRX_STATE.confirm(SUCCESS);
									break;
					case PHY_TX_ON:
									signal PLME_SET_TRX_STATE.confirm(PHY_TX_ON);
									break;
				}
			break;
		}
		}
 //printfUART("set tx%i\n",currentRxTxState);	
  return SUCCESS;
} 
 
/*****************************************************************************************************/ 
/*******************Physical Events CC2420************************************************************/
/*****************************************************************************************************/ 

async event result_t FIFOP.fired() {
		uint8_t rssi;
		
		call HPLCC2420FIFO.readRXFIFO(100,(uint8_t*)rxmpdu_ptr);
		rssi =  (uint8_t) call HPLCC2420.read(CC2420_RSSI);
		//post process_received_packet();
		signal PD_DATA.indication(rxmpdu_ptr->length,(uint8_t*)rxmpdu_ptr, rssi);
		
		call HPLCC2420.cmd(CC2420_SFLUSHRX);
    
	return SUCCESS;
  }
    
  task void process_received_packet()
  {
		signal PD_DATA.indication(rxmpdu_ptr->length,(uint8_t*)rxmpdu_ptr, 1);

	return;
  }


  async event result_t HPLCC2420RAM.readDone(uint16_t addr, uint8_t length, uint8_t* buffer) {
     return SUCCESS;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -