?? mftmac.c.bak
字號:
tkey+=JK_MSTART;
if(bdevtrans==MAC_DEVICE_JOYSTICK0)
tmode = jk1RamMapIndex[tkey].address[0];
else if(bdevtrans==MAC_DEVICE_JOYSTICK1)
tmode = jk2RamMapIndex[tkey].address[0];
if(tmode == MAC_DEVICE_KEYBOARD)
{
tmode=Key_mode;
}
else if(tmode == MAC_DEVICE_MOUSE)
{
tmode=Mouse_mode;
if(bdevtrans==MAC_DEVICE_JOYSTICK0)
*bkey = jk1RamMapIndex[tkey].address[1];//mouse key data
else if(bdevtrans==MAC_DEVICE_JOYSTICK1)
*bkey = jk2RamMapIndex[tkey].address[1];
}
else if(tmode==MAC_DEVICE_JOYSTICK0||tmode==MAC_DEVICE_JOYSTICK1)
{
tmode=Joystick_mode;
}
else
{
return 0;
}
}
if(tmode==Key_mode)//KEYBOARD MAP
{
if(bdevtrans==MAC_DEVICE_JOYSTICK0)
{
tlength = jk1RamMapIndex[tkey].length;
tdata = jk1RamMapIndex[tkey].address[2]; //keyboard modify
}
else if(bdevtrans==MAC_DEVICE_JOYSTICK1)
{
tlength = jk2RamMapIndex[tkey].length;
tdata = jk2RamMapIndex[tkey].address[2]; //keyboard modify
}
if(tlength==0)
return 0;
if((tlength>(KEYBOARDLENGTH+2))||(tlength<KEYBOARDLENGTH))//||(tdata!=0))
{
tmode = Macro_Mode;
if(*bflag==LOOSE)
return 0;
}
else//GET First scan code
{
*bkey = tdata ;
}
}
*bmode =tmode;
return 1 ;
}
//first come first serve.we only load two jk device.others share channel 0.
/*void MACChkJkAddr()
{
if(macJkDev[0].devAddress== macCurrentFrame.sndAddress)
return;
if(macJkDev[1].devAddress== macCurrentFrame.sndAddress)
return;
if(macJkDev[0].devAddress==0xff)//channel 0 free
{
if((macCurrentFrame.sndAddress&0x01)==0)//really should occupy channel 0??
macJkDev[0].devAddress=macCurrentFrame.sndAddress;
else if(macJkDev[1].devAddress==0xff) //channel 1 free
{
macJkDev[1].devAddress=macCurrentFrame.sndAddress;
}
}
else if(macJkDev[1].devAddress==0xff) //channel 1 free
{
if(macCurrentFrame.sndAddress&0x01)//really should occupy channel 1??
macJkDev[1].devAddress=macCurrentFrame.sndAddress;
}
}*/
/*********************************************************************
* Function: MACProcessJkData()
*
* Input: None
*
* Output: if jk data is legal return 1.else return 0
*
* Overview: this function is very important.deal with josytick data
then set map mode.and map data.
*
* Note: None
********************************************************************/
BYTE MACProcessJkData()
{
BYTE keylength;
BYTE i,bkey;
BYTE bscankey;
BYTE bkmode;
// BYTE bexmap;
BYTE bmkl;
BYTE bmapKey;
BYTE bmapout;
BYTE bkFlag=PRESSED;
JkeyMapId = DISMAP;
keylength = MAC_JKTRSLENGTH-1;//in case of Joystick_KeyFilter() overflow
//MACChkJkAddr();
bdevtrans=MACGetJkChannelId();
bmkl=Joystick_KeyFilter(&RXBuffer[0].databuffer[macRecLen],macCurrentFrame.frameLength,JKeyBuffer,&keylength);
if(keylength==0||bmkl==0)
{
return 0;
}
else
{
bIsMap = TRUE;
}
for(i=0;i<keylength;i++)
{
bkey = JKeyBuffer[i];
bkmode = 0;
bmapKey = GetKeyMapNumber(bkey);
if(!GetJkeyMode(&bkey,&bkmode,&bkFlag))
{
bIsMap = FALSE;
return 0;
}
if(bkmode==Key_mode&&bmkl==2) //especial key map
continue;
if(bkmode==Key_mode)
{
//first map modify key
for(bmkl=0;bmkl<3;bmkl++)//only fill 3 modify keys
{
bscankey=MACGetBitNumber1(bkey);
bkey&= ~(1<<bscankey) ;
if(bscankey!=NODATA)
{
bscankey+=0xE0;//transfer to key code
bmapout=DeviceData_output(bkmode,bscankey,bkFlag,&RXBuffer[0].databuffer[macRecLen],macCurrentFrame.frameLength);
}
else
{
break;
}
}
//map other data key
for(bmkl=MAC_KMDSTART;bmkl<KEYBOARDLENGTH;bmkl++)
{
if(bdevtrans==MAC_DEVICE_JOYSTICK0)
{
bscankey = jk1RamMapIndex[bmapKey].address[bmkl]; //keyboard DATA
}
else if(bdevtrans==MAC_DEVICE_JOYSTICK1)
{
bscankey = jk2RamMapIndex[bmapKey].address[bmkl]; //keyboard DATA
}
if(bscankey!=0)
{
bmapout=DeviceData_output(bkmode,bscankey,bkFlag,&RXBuffer[0].databuffer[macRecLen],macCurrentFrame.frameLength);
}
else break;
}
}
else if(bkmode==Macro_Mode)
{
JmacroKey = bmapKey;
}
else
{
bmapout=DeviceData_output(bkmode,bkey,bkFlag,&RXBuffer[0].databuffer[macRecLen],macCurrentFrame.frameLength);
if(bmapout!=0)
{
JkeyMapId|=bmapout;
}
}
if(bmapout!=0)
{
JkeyMapId|=bmapout;
}
}
return 1;
}
/*********************************************************************
* Function: BYTE MACSendTimeJudge()
* Description : before send data,judge device system time,whether is synchoronous
* with Coordinator.if now is cca time,device can send data now.or wait syn with beacon
*
*********************************************************************/
/*BYTE MACSendTimeJudge()
{
macTickDiff = TickGetDiff(TickGet(), macStartTick);
if(macTickDiff>=JNAWTIME&&macTickDiff<=(JNAWTIME+2))
return TRUE;
else
return FALSE;
}*/
//judge device gts is occupied or free.if occupied return 0.else return 1
/*static BYTE MACGtsEnable(BYTE device)
{
if(device==MAC_DEVICE_KEYBOARD)
{
if(macGts.Control.bits.bkey)
return FALSE;
//macGts.Control.bits.bkey = 1;
return TRUE;
}
else if(device==MAC_DEVICE_MOUSE)
{
if(macGts.Control.bits.bms0&&macGts.Control.bits.bms1)
{
return FALSE;
}
else
{
// macGts.Control.bits.bms0 =1;
// macGts.Control.bits.bms1 =1;
return TRUE;
}
}
return FALSE;
} */
/*static void TransmitIt(void)
{
// if(MACSendTimeJudge())
{
//macState.bits.bIsTest = FALSE;
PHYDataRequest(MACSndDataLength,TXBUFFER);
}
}*/
/*********************************************************************
* Function: BYTE GetMACMaxChannelNumber()
*
*
* Input: None
*
* Output: number of physical channel supported by rf chip
*
* Note: None
********************************************************************/
/*BYTE GetMACMaxChannelNumber(void)
{
return (phyChannelMaxSupport);
}*/
/*********************************************************************
* Function: void MACStart()
*
*
* Input: None
*
* Output:
*
* Note: begin into job.coordinator begin receive datga
device begin send data
********************************************************************/
void MACStart()
{
#if defined(I_AM_COORDINATOR)
BYTE phyParameter=0;
// Select unique random network
BYTE wflash;
bIsScan = FALSE;
// bIsTest = FALSE;
//------------------------------------------------
wflash=0;
phyParameter =macInfo.devAddress;
if(phyParameter==0x00) //first time
{
phyParameter =macCurrentChannel+macRandom;
phyParameter^= macRandom;
phyParameter+= RANDOM_LSB;
Ram_Key[PAN_MAP_POSITION]= phyParameter;
Ram_Key[PAN_MAP_POSITION+1]= macCurrentChannel;
wflash=1;
bchanlost=0;
MACSetDeviceAddress(phyParameter);
//delayms(5);
}
if(bchanlost)
{
Ram_Key[PAN_MAP_POSITION+1]= macCurrentChannel;
wflash=1;
bchanlost=0;
}
else
{
macCurrentChannel=msRamMapIndex[0].address[MAC_CHNL_ID];
}
if(wflash)
{
if(Ram_Key[PAN_MAP_POSITION]==0xff)
{
Ram_Key[PAN_MAP_POSITION]-=macRandom;
phyParameter=Ram_Key[PAN_MAP_POSITION];
}
WriteFlash((byte const *)FLASH_ADDRESS[0],KEYMAPMAXSIZE,Ram_Key,NORMAL_WRITE); //for debug
if( Modify_KeyMapIndex((BYTE const *)FLASH_ADDRESS[0],KEYMAPMAXSIZE,msRamMapIndex,MAC_MSKEY_NUMBER)) ;
}
MACSetPANId(phyParameter);
//----------------------------------------------
// MACSetDeviceAddress(phyParameter);
//-------------------------------------------------
PHYSetPHYAddress(phyParameter); //set address
//---------------------------------------------------
PHYSetChannel(macCurrentChannel); //set channel
///-------------------------------------------------
//-------------------------------------------------
//initialize variable
bIsAssociated = TRUE;
//when build pan,read flash ,load mouse configure data.
macStartTick = TickGet();
PHYSetTRXState(PHY_TRX_RX_ON); //open rx channel.begin receive data
#else
MACAcceptCurrentPAN();
MACStartAssociation();
//PHYSetTRXState(PHY_TRX_OFF); //close rx channel
#endif
}
BYTE MACWaitGdo(void)
{
unsigned int macWaitTick;
macWaitTick = TickGet();
while(GDO2_PIN)
{
//_nop_();
macTickDiff = TickGetDiff(TickGet(), macWaitTick);
if (macTickDiff>=4)
{
PHYSetTRXState(PHY_TRX_RX_ON);
return 1;
}
}
return 0;
}
/*********************************************************************
* Function: void MACISR(void)
*
* PreCondition: MACInit() is previously called.
*
* Input: None
*
* Output: None
*
* Side Effects: None
*
* Overview: Determines if a frame has completed transmission
* or not.
*
* Note: None
********************************************************************/
void MACISR(void)
{
// byte i;
if (bPhyGetReady)
{
/* got a packet for me */
if(MACWaitGdo()){
;
}
MACBufferPacket();
// See if it has a valid header.
if (MACGetHeader())
{
// Mark that we have a valid frame.
bIsGetReady = TRUE;
LED_DATA=LED_LIGHT;
ledDataFlag = 0;
macMsTick = TickGet();
}
bPhyGetReady=FALSE ;
}
}
BYTE MACMsIsGameMode()
{
return(MsMode==MAC_GAME_MODE);
}
/*********************************************************************
* Function: BYTE MACGet(void)
*
* PreCondition: MACIsGetReady() == TRUE
*
* Input: None
*
* Output: Byte that was read
*
* Side Effects: None
*
* Overview: Retrives one bytes from RF RX buffer.
*
* Note: Caller must make sure that RX buffer contains
* at least one byte calling MACIsGetReady()
********************************************************************/
BYTE MACGet(void)
{
if( macCurrentFrame.frameLength>0)
macCurrentFrame.frameLength--;
else
return RXBuffer[0].databuffer[macRecLen-1];
return RXBuffer[0].databuffer[macRecLen++];
}
/*********************************************************************
* Function: void MACPut(BYTE v)
*
* PreCondition: MACIsPutReady() == TRUE
*
* Input: v - A byte to put
*
* Output: None
*
* Side Effects: None
*
* Overview: Copies given byte into RF TX buffer and increments
* write pointer.
*
* Note: None
********************************************************************/
void MACPut(BYTE v)
{
// Put given byte into TXFIFO
TXBUFFER[macPacketLen]=v;
// Maintain length so that we update header.
macPacketLen++;
if(macPacketLen>=(MAXDEVLENGTH-1))
{
macPacketLen =MAXDEVLENGTH-1;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -