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

📄 mftphy2500.c.bak

📁 motorola jw32 usb 源码
💻 BAK
📖 第 1 页 / 共 2 页
字号:
/*********************************************************************
 *
 *                  MFT MAC layer
 *
 *********************************************************************
 * FileName:        mftPHY2500.c
 * Dependencies:
 * Processor:       c51
 * Company:         chengdu MFT, Inc.
 *
 * Software License Agreement
 *
 *
 * Author               Date    Comment
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *     				10/14/2005 Rel 0.1
 ********************************************************************/
//#include "mftPHY2500.h"
//#include "mft.h"
//----------------------------------------------------------------------------------------
extern  void MACPhyDataReady(void);
extern BYTE MACMsIsGameMode(void);
extern BYTE MACWaitGdo(void);
#pragma DATA_SEG DEFAULT
extern  BYTE   macRandom;
#define  ECHNUMBER  30 //exclude channel number
BYTE  PHYOccupyChl[ECHNUMBER]; //record exclude channel
BYTE  phychCount=0;
#pragma DATA_SEG  MY_ZEROPAGE

BYTE PHYChannel=0;
BYTE PHYPower=0;
BYTE PHYRvLength=0;
 BYTE PHYSendFlag=0;
//#pragma CONST_SEG ConstData
//BYTE   const paTable[1] ={0xFB};

/*RF_SETTINGS  const rfSettings = {
0x07,    //FSCTRL1  Frequency synthesizer control.
0x00,    //FSCTRL0  Frequency synthesizer control.
0x5D,    //FREQ2  Frequency control word, high byte.
0x93,    //FREQ1  Frequency control word, middle byte.
0xB1,    //FREQ0  Frequency control word, low byte.
0x2D,    //MDMCFG4  Modem configuration.
0x3B,    //MDMCFG3  Modem configuration.
0x73,    //MDMCFG2  Modem configuration.
0xA2,    //MDMCFG1  Modem configuration.
0xF8,    //MDMCFG0  Modem configuration.
0x00,    //CHANNR  Channel number.
0x01,    //DEVIATN  Modem deviation setting (when FSK modulation is enabled).
0xB6,    //FREND1  Front end RX configuration.
0x10,    //FREND0  Front end RX configuration.  //0x17->0x10 no power table
0x08,    //MCSM0  Main Radio Control State Machine configuration.//0x18 to 0x08 jc
0x1D,    //FOCCFG  Frequency Offset Compensation Configuration.
0x1C,    //BSCFG  Bit synchronization Configuration.
0xC7,    //AGCCTRL2  AGC control.
0xB2,    //AGCCTRL0  AGC control.
0xEA,    //FSCAL3  Frequency synthesizer calibration.
0x0A,    //FSCAL2  Frequency synthesizer calibration.
0x11,    //FSCAL0  Frequency synthesizer calibration.
0x59,    //FSTEST  Frequency synthesizer calibration.
0x88,    //TEST2  Various test settings.
0x31,    //TEST1  Various test settings.
0x0B,    //TEST0  Various test settings.
0x46,    //IOCFG2  GDO2 output pin configuration.0x47->0x06->46
0x2E,    //IOCFG0D  GDO0 output pin configuration. Refer to SmartRF?Studio User Manual for detailed pseudo register explanation.//jc 0x06->0x46->0x2e
0x06,    //PKTCTRL1  Packet automation control.
0x05,    //PKTCTRL0  Packet automation control.
0x00,    //ADDR  Device address.
0x40,    //PKTLEN  Packet length.
};
				 */
 #pragma CONST_SEG DEFAULT
//---------------------------------------------------------------------------------------
void PHYCaliberateOsc()
{
	 //  while(GDO2_PIN)
   //  	_nop_();
  // delayms(8);
  //  halSpiStrobe(CCxxx0_SIDLE);
    halSpiStrobe(CCxxx0_SCAL);
  	 delayms(1);
  //	halSpiStrobe(CCxxx0_SRX);

}
//check phy whether is in rx state.1 ok.0 error
/*BYTE PHYSelfCheck()
{
//	BYTE bstatus=0;
    if(GDO2_PIN)
    {
  			return FALSE;
    }
	 PHYRvLength = halSpiReadStatus(CCxxx0_MARCSTATE);
	 if(PHYRvLength<0x0d||PHYRvLength>0x0f) //rx state
	 {
	 		return FALSE;
	 }
	return TRUE;
}*/
//jump occupied channel
void PHYJumpExChannel()
{
	BYTE i;
  for(i=0;i<phychCount;i++)
  {
  	if(PHYOccupyChl[i]==PHYChannel)
  	{
  		PHYChannel++;
  		i=0;
  		if(PHYChannel>=MAXCHAN)
  		{
  				PHYChannel=FIRSTCHAN;
  		}
  	}
  }
}
//record occupy channel
void PhyRecordExChannel()
{
	  PHYOccupyChl[phychCount]=PHYChannel; //record exclude channel
		phychCount++;
		if(phychCount>ECHNUMBER)
		{
		  phychCount=0;
		}
}
void PHYClearExChannel()
{
	BYTE i;
	    	phychCount = 0;
	for(i=0;i<ECHNUMBER;i++)
		 PHYOccupyChl[i]=0xff;

}
 /**********************************************************************
 * 函数: void PHYSetChannel(BYTE chanNel)
 * 功能:设置无线收发器的频道
 * 输入:channel 逻辑频道,由RF 无线收发器支持的频道决定.
 * 描述:此函数用于在频道扫描或频道冲突时,上层可以改变当前的物理频道
 **********************************************************************/
void PHYSetChannel(BYTE channel)
{
    PHYChannel=channel;
     halSpiStrobe(CCxxx0_SIDLE);
   halSpiWriteReg(CCxxx0_CHANNR,PHYChannel);
     PHYCaliberateOsc();
}
void PHY_IntInit()
{
	  //DisableInterrupts;
	 /// GDO2_PIN = 0x01;
    KBSCR = 0x02; //imaskk=1.disable keyboard int
    KBIER = 0x10 ;//allow kba4 interrupt
   //KBIER = 0x08 ;//allow kba3 interrupt
    KBSCR =  0x00 ;//mak 0,allow keyboard interrupt
    //KBSCR |=  0x10 ;//mak 0,clear keyfKBSCR |=  0x10 ;//mak 0,clear keyf
   // KBSCR &=0xfb;
    //EnableInterrupts;
		//GDO2_PIN = 0x00;
}
 /**********************************************************************
 	函数: Bool PHYSetNextChannel(void)
	功能:设置无线收发器的频道为下一个频道
	输出:如果设置成功,则返回TRUE,否则返回FALSE.
	描述:在当前频道的基础上加1,切换到下一个频道,如果下一个频道超出了RF支
	持的物理频道的数量,则返回失败,否则设置下一个频道为当前频道,返回TRUE.
 **********************************************************************/
BYTE PHYSetNextChannel(byte nextStep)
{
//	BYTE i;
   // if(PHYChannel>=max_channr)
    //        return FALSE;
    BYTE tempchan=0;
    
    if(nextStep)
    {
    		tempchan=(macRandom&0x03)+1;
    		PHYChannel+=tempchan;
    		if(PHYChannel>=MAXCHAN)
    				PHYChannel= 	tempchan+FIRSTCHAN;
		    PHYJumpExChannel();
    }
    else
    {
    		PHYChannel++;
    }
    halSpiStrobe(CCxxx0_SIDLE);
    halSpiWriteReg(CCxxx0_CHANNR,PHYChannel);
    PHYCaliberateOsc();
    return TRUE;
}
void PHYSetPHYAddress(BYTE PhyAddress)
{
 //   BYTE macAddress;
	PHYSetTRXState(PHY_TRX_TX_ON) ;
    halSpiWriteReg(CCxxx0_ADDR, PhyAddress);
    /*macAddress=halSpiReadReg(CCxxx0_ADDR);
    while(macAddress!=PhyAddress)
    {
        halSpiWriteReg(CCxxx0_ADDR, PhyAddress);
         __RESET_WATCHDOG();
   }			 */
}
/**********************************************************************
 	函数: void PHYSetFirstChannel(void)
	功能:设置无线收发器的第一个频道

	描述:
 **********************************************************************/
void PHYSetFirstChannel(byte tryflag)
{
	if(tryflag==0)
    PHYChannel=FIRSTCHAN;
  else {															  

  	PHYChannel=(macRandom&0x1F)+FIRSTCHAN;
  //	PHYChannel=0x01;
  }

  PHYJumpExChannel();
    halSpiStrobe(CCxxx0_SIDLE);
    halSpiWriteReg(CCxxx0_CHANNR,PHYChannel);
    PHYCaliberateOsc();
}
/**********************************************************************
 	函数: void PHYClearRxBuffer()
	功能:clear rx fifo.in case of 2500 buffer error

	描述:
 **********************************************************************/
void PHYClearRxBuffer() {

   //  if(halSpiReadReg(CCxxx0_RXFIFO)) ;
    	 halSpiStrobe(CCxxx0_SFRX);//clear rx fifo
}
//-------------------------------------------------------------------------------------------------------
//void PHYClearRXFifo()
//
//  DESCRIPTION: clear rx fifo

/*void PHYClearRXFifo()
{
    BYTE static gdoLowTimes =0;
    if(!GDO2_PIN)
    {
        if(gdoLowTimes>2)
        {
                 gdoLowTimes =0;
                // if ((halSpiReadStatus(CCxxx0_RXBYTES) & BYTES_IN_RXFIFO))
             		 PHYClearRxBuffer();
                return;
        }
        gdoLowTimes++;
    }
    else
    {
        gdoLowTimes =0;

    }
}*/
 /**********************************************************************
 	函数: void PHYSetTRXState(PHY_TRX_STATE state)
	功能: 设置RF 的状态.
	输入: state 表示RF 新的状态.接收状态PHY_TRX_RX_ON,发送状态
				PHY_TRX_TX_ON,或者关闭状态PHY_TRX_OFF,PHY_TRX_FORCE_OFF.

⌨️ 快捷键说明

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