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

📄 mftmac.h

📁 motorola jw32 usb 源码
💻 H
📖 第 1 页 / 共 2 页
字号:
/*********************************************************************
 *
 *                  MFT MAC layer
 *
 *********************************************************************
 * FileName:        mftMAC.h
 * Processor:       c51
 * Company:         chengdu MFT, Inc.
 *
 * Software License Agreement
 *
 *
 * Author               Date    Comment
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * jiangchao    				5/09/05 Rel 0.1
 ********************************************************************/

 #include "public.h"
  #include "mft.h"
#include "mftPHY.h"
#include "Tick.h"

//******************************************************************************

/*
 *******************************************
 * Frame Type MSB fields - END
 *******************************************
 */

#define    MAC_ACK_KEYBOARD           0x04
#define MAC_ACK_JK1               		0x01
#define MAC_ACK_JK2              			0x02
#define MAC_JKTRSLENGTH          				5     //jk key transfer buffer length
//----------------------------------------------
#define  PRESSED                			0x01
#define  LOOSE                  			0x00
#define  AUTOBD                       0x02  //auto bound
 //-------------------------------------------------
 #define MACGAMEMODE_Switch  0x28			 //k6 and k4
#define MACLGAMEMODE_Switch  0x30		 //k6 and k5
//--------------------------------------------
#define  FORCE_WRITE         0x01
#define  NORMAL_WRITE        0x00
//---------------------------------------------------
#define MAC_MSMAPHEAD        0x00
#define MAC_KBMAPHEAD        0x01
#define MAC_JK0MAPHEAD        0x04
#define MAC_JK1MAPHEAD        0x05

//----------------------------------------------------
// Constants used to build a an Association Request (CMD frame 0x01)
#if defined(I_AM_COORDINATOR)
    #define IS_COORDINATOR      (0x01)      // 1 is yes, 0 if no.
#else
    #define IS_COORDINATOR      (0x00)
#endif
#define MAC_MODE_BEACON              0
#define MAC_MODE_NORMAL            1
#define MAC_FRAME_LENGTH              (0x10)
#define MAC_FRAME_HEAD                (0x04)//1 fralength+1 daddr+frame head+device address
#define  MAC_MODE_NUMBER               (0x04)
#define  MAC_JKMODE_NUMBER               (0x03)

#define MAC_SCAN_MAX_CHANNEL        	(32)

///#define MAC_KEY_DATASI ZE        	    (1)//FIVE KEY *12=60 BYTE.LESS THAN DATASIZE =64
#define MAC_MSKEY_NUMBER        	    (6)//five key
//-------------------------------------------------------------
#define mouse_right_key  (2)
#define mouse_left_key   (1)
#define RJK  (0xA0)
#define LJK  (0xA1)
#define MAC_JKKEY_NUMBER        	    (38)//five keyfine MAC_MODE_NUMBER        	    (5)//mode four mode
#define MAC_KEYMAPLEN        	    (60)//mode four mode
#define MAC_KMDSTART              0x04  //headid+kbid+modify+reserve+data...
#define KbLength 6
#define KbPassLength 3
//---------------------------------
#define Joystick_mode (0)
#define Dir4_mode   (1)
#define Mouse_mode  (2)
#define Key_mode    (3)
#define Dir8_mode   (4)
//---------------------------------

#define Hat_mode (5)
#define Hat4_mode (6)
#define Hat8_mode (7)

//---------------------------------
#define Macro_Mode (9)
#define CAPJK_INDEX 0x00
#define LJK_INDEX 0x01
#define RJK_INDEX 0x02
//-----------------------------------------------------------
#define LJK_NUMBER   20					    
#define RJK_NUMBER   28
#define HAT_NUMBER   13
#define JK_MSTART    0x02
//--------------------------------------------------------
#define MAC_PAN_ID                 0x00  //PANID
#define MAC_CHNL_ID                 0x01 //CHANNEL 
#define MAC_GAMELPW_MODE                2
#define MAC_GAME_MODE                 3
#define MAC_MEDIA_MODE               1
#define MAC_NORMAL_MODE               0
#define MAC_WFLASH_MODE               10
//beacon control
#define  BI              				(16)//(aNumSuperframeSlots*BISLOT)=16ms
#define  BIREADY              			(14)  //2ms ready for send beacon
#define GKBOVERIME                     400 //after 400MS .NO KEYBOARD DATA.AUTO BOUNCE KEY
#define TICK_JKOverTime               5000 //5 second
#define TICK_WARNTime               5000 //10 second
//--------------------------------------------------------
#define BROADADDRESS                  0x00
// MAP flag
//----------------------------------------------------------
//warn code define
#define  WARN_NETLOST               1   
#define  WARN_PWRLOW                2     
#define  WARN_PWRFULL                4 
#define  WARN_PWRCHAG                8 
#define  WARN_CHANLOST                0x10
#define  WARN_PANIDLOST                0x20
//------------------------------------------------------------
//download device id
#define MOUSEID                  0x06
#define JK1MODEID                  40
#define JK2MODEID                    50

//----------------------------------------------------------------
typedef enum _MAC_DEVICE_ID
{
		MAC_DEVICE_CONTROLER    = 0x00,
	 	MAC_DEVICE_MICROPHONE  	= 0x01,
    MAC_DEVICE_MOUSE   			= 0x02,
    MAC_DEVICE_KEYBOARD   	= 0x03,
    MAC_DEVICE_JOYSTICK0   	= 0x04,
    MAC_DEVICE_JOYSTICK1   	= 0x05,

    MAC_DEVICE_CENSOR   	  = 0x0f,

} MAC_DEVICE_ID;
//-----------------------------------------------------------------
#define  LED_LIGHT          0
#define  LED_CLOSE          1
#define  BUZZ_OPEN          0
#define  BUZZ_CLOSE         1
//------------------------------------------------------------------
//LED TYPE DEFINE
#define  LED_ALL          5
#define  LED_RED          1
#define  LED_BLUE          2
#define  LED_GREEN          3
#define  LED_DA          4
//------------------------------------------
#define KEY_CALL          PTA_PTA7 
#define LED_PWRLOW         PTD_PTD0 
#define LED_PWRCHG         PTD_PTD1
#define LED_FULL           PTD_PTD2
//#define LED_DATA           PTD_PTD3 
#define LED_DATA           PTD_PTD0

#define WARN_BUZZER        PTC_PTC3

//-----------------------------------------------------------------
#define LED_REA0           PTD_PTD4  
#define LED_REA1           PTD_PTD5 

#define LED_BLU0           PTD_PTD6 
#define LED_BLU1           PTD_PTD7   

#define LED_GRN0           PTB_PTB0   
#define LED_GRN1           PTB_PTB1
//-----------------------------------------------------------------
//this should change with device
//------------------------------------------------------------
#if defined I_AM_RFD
		#if defined I_AM_MICE
				#define   MY_DEVICEID  					MAC_DEVICE_MOUSE
		#elif defined I_AM_JOYSTICK0
				#define   MY_DEVICEID  					MAC_DEVICE_JOYSTICK0

		#elif defined I_AM_JOYSTICK1
				#define   MY_DEVICEID  					MAC_DEVICE_JOYSTICK1

		#elif defined I_AM_KEYBOARD
				#define   MY_DEVICEID  					MAC_DEVICE_KEYBOARD

		#elif defined I_AM_MICROPHONE
				#define   MY_DEVICEID  					MAC_DEVICE_MICROPHONE
		#endif
//-------------------------------------------------------------
#else
		#define   MY_DEVICEID               MAC_DEVICE_CONTROLER
#endif
//--------------------------------------------------------------
#ifndef   MY_DEVICEID
			#error "device must be defined as either a RFD device."
#endif
#define 	MAC_PHY_ADDRESS      (MY_DEVICEID)

//******************************************************************************
// Data Structures
//******************************************************************************
// NWK Beacon Payload, second byte

#pragma DATA_SEG  MY_ZEROPAGE
// mac head structure
typedef struct FRAME_CONTROL
{
    union
    {
        struct
        {
        	uchar    devId               		: 4; //high bit device id.
        	uchar    type               		: 4; //low bit fame type

        } fields;
        uchar    Val;
    } Control;
} FRAME_CONTROL;

typedef struct FRAME_JNCTRL
{
    union
    {
        struct
        {
        	//uchar    reserve               		  : 1; //
        	uchar    mode               		  : 1; //high bit work mode
        	uchar    power               		  : 2; //high bit send power
        	uchar    channel               		: 5; //low bit channel

        } fields;
        uchar    Val;
    } Control;
} JNCTRL;

typedef struct _NET_STATE
{
    union
    {
        struct
        {
        	uchar    reserve               		  :3; //
        	uchar    mode               		  : 1; //high bit work mode
        	uchar    bReserve               : 4; //low bit send power
        } fields;
        uchar    Val;
    } Control;
} NET_STATE;

typedef struct _NODE_INFO
{
   uchar      	devId;
   uchar      	panId;
   uchar        devAddress;
} NODE_INFO;

//MAC JK ADDRESS INDEX
typedef struct _MAC_JKID
{
	 	uchar      	devAddress;
	  uchar      	devID;
}MAC_JKDev;

// MAC Frame header information in decoded manner.
typedef struct _MAC_HEADER
{
    FRAME_CONTROL     frameCtrl;
    uchar 						sndAddress;
    uchar 						frameLength;
} MAC_HEADER;


/*typedef  struct _MAC_STATE
{
        struct
        {
            BYTE    bIsAssociated           : 1; // '1' if this node is associated
            BYTE  	bIsEnabled							:	1; // '1' if current tx packet should be put in stage
            BYTE		bIsTest								:	1;//'1' if current state is in test mode
            BYTE		bmode								    :	1;//'1' no beacon 0 becon
            BYTE  	bIsScan                 : 1; //1 now is scan channel
            BYTE    bIsGetReady             : 1; //mac received data
            BYTE    bPhyGetReady            : 1;//phy  receive data
            BYTE    bIsMap                  : 1;//map mouse key to keyboard

        } bits;
} MAC_STATE;*/

typedef  struct _MAC_BEACON
{
      union
      {
        struct
        {
        	 //  BYTE  	bBeaconReady									:1; // reserve for mac
            BYTE  	bAck									:3; // reserve for mac

            BYTE  	devId											:	3; // device receive data
            BYTE  	bData									:	1; // beacon with data
            BYTE	  bmode									:	1;//'1': device is normal work mode.0 beacon mode
        } bits;
        BYTE Val;

      }Control;

} MAC_BEACON;


// PAN descriptor in decoded manner - this is used by end device to determine whom to associate
typedef struct _PAN_DESC
{
    BYTE  			CoordPANId;
    BYTE        LogicalChannel;
    BYTE        Lqi;
} PAN_DESC;



//******************************************************************************
// External Variables
//******************************************************************************

extern   MAC_HEADER   macCurrentFrame;
//extern    MAC_STATE    macState;
extern 	 NODE_INFO    macInfo;
//extern   PAN_DESC     PANDesc;
extern 	BYTE         currentBuffer;
extern 	BYTE PANDescCount;
extern  BYTE    bIsAssociated ; // '1' if this node is associated
extern BYTE    bIsGetReady           ;
//------------------------------------------------
#define   KEYMAPMAXSIZE        	    (250) //RAMSIZE-DATA_HEAD
#pragma DATA_SEG DEFAULT
#define MSMAPSIZE  KEYMAPMAXSIZE-2
typedef struct _keybuffer{
		BYTE      keylength;
		BYTE      keymode;
    BYTE      keybuffer[MSMAPSIZE];
}keybuffer;
#define JKMAPSIZE  PAGESIZE-2
typedef struct _jkbuffer{
		BYTE      keylength;
		BYTE      keymode;
    BYTE      keybuffer[JKMAPSIZE];
}jkbuffer;
//RAM key map struct define
//----------------------------------------------------

#define          JOYSTICK_MAP  0x01
#define          MOUSE_MAP  		0x02
#define          KEYBOARD_MAP  0x04
#define 					NOMAP                  0x10
#define 					DISMAP                 0x00
typedef struct  _keyMapIndex{
//BYTE keyNumber; //表示键号  delet for reduce ram room
BYTE  *address;//保存键在FLASH中数据部分的地址,不包括长度
BYTE length;//保存键映射数据的长度
}RamMapIndex;
/*typedef struct  _msMapIndex{
RamMapIndex msRamMapIndex[MAC_MSKEY_NUMBER];
}msRamMap;
*/
keybuffer *macKeyMap=(keybuffer *)&Ram_Key[DATA_HEAD];
RamMapIndex jk1RamMapIndex[MAC_JKKEY_NUMBER];
RamMapIndex jk2RamMapIndex[MAC_JKKEY_NUMBER];
RamMapIndex msRamMapIndex[MAC_MSKEY_NUMBER];
//mouse  key map
//----------------------------------------------------

#define   PAN_MAP_POSITION    	   3+DATA_HEAD

//#define   PAN_MAP    	    					Ram_Buffer[3]//Ram_Buffer.only in mode 0.
//msRamMap *macKeyMap=(msRamMap *)(Ram_Key+200);//head+length +mode
//---------------------------------------------
/*********************************************************************
 * Function:        void MACInit(void)
 *
 * PreCondition:    macInfo.longAddr is set as required.
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        Initializes data variables used by MAC module.
 *
 * Note:            None
 ********************************************************************/
extern void MACInit(void);


/*********************************************************************
 * Function:        void MACEnable(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        Enables PHY regulator and registers.
 *
 * Note:            None
 ********************************************************************/
extern void MACEnable(void);


/*********************************************************************
 * Macro:           void MACDisable(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *

⌨️ 快捷键说明

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