📄 iai_ezmac_plus_internal.h
字号:
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* *
* FILE NAME: IAI_EZMac_Plus_Internal.h *
* *
* DESIGNER: Kovacs, Krisztian; Lukacs, Miklos *
* PROGRAMMER: Kovacs, Krisztian; Lukacs, Miklos; Sz閘l Andr醩 *
* *
* DESCRIPTION: EZmac Internal function definitions *
* *
* REVISION: 01_2 March 04, 2005 deviation 75kHz *
* 01_3 March 23, 2005 Transmit and receive packet lenght *
* can be different in fixed leght mode*
* 01_4 April 20, 2005 EZradio initialization fime tuning, *
* Wake-up timer is in on state *
* between Wake_Up() and Sleep() *
* (not correct POR fix) *
* 01_5 April 28, 2005 Clock Recovery lock checking after *
* DQD check, *
* Received PL=0 corrected *
* 01_6 Aug 11, 2005 *
* 02_0 March 21, 2006 Finalize the HiTech porting *
* 02_1 April 03, 2006 Universal baud rate and freq band *
* EZMac Plus: *
* 01_0 Sept 28, 2006 Create EZMac Plus from EZMac *
* *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#pragma nolist
#ifndef EZmac_internal
#define EZmac_internal
/* ======================================= *
* I N T R O D U C T I O N *
* ======================================= */
/* */
/* ======================================= *
* P A R A M E T E R S *
* ======================================= */
//The timing is calculated for Timer1, prescaler = 8, clk = 4MHz -> one increment is 8us
#ifdef DATA_RATE_9600
#define WAKING_UP_PERIOD (TIMER_OVERFLOW-625) //crystal start up is 5ms
#elif defined DATA_RATE_19200
#define WAKING_UP_PERIOD (TIMER_OVERFLOW-1250) //crystal start up is 5ms
#elif defined DATA_RATE_38400
#define WAKING_UP_PERIOD (TIMER_OVERFLOW-2500) //crystal start up is 5ms
#elif defined DATA_RATE_57600
#define WAKING_UP_PERIOD (TIMER_OVERFLOW-3750) //crystal start up is 5ms
#elif defined DATA_RATE_115200
#define WAKING_UP_PERIOD (TIMER_OVERFLOW-7500) //crystal start up is 5ms
#endif
#define FIRST_DQD_TIMER_LIMIT (TIMER_OVERFLOW-20) //half byte time after the change of the freq will be the first DQD sample
#define DQD_TIMER_LIMIT (TIMER_OVERFLOW-8) //sample rate for DQD: 4 sample during half byte time (136us for 9600baud)
#define ONE_BYTE_TIMER_LIMIT 128 //bit longer, but easier to multiple with 2^x (for 9600 baud: 840us -> 1.024ms)
#define CRL_CHECK_TIMER_LIMIT 64 //it should be around haf byte time (512us for 9600bps)
#define TIMER_OVERFLOW (65535) //maximum value of the timer
#define MAX_RX_PACKET_TIMER (TIMER_OVERFLOW-(ONE_BYTE_TIMER_LIMIT * 23)) //max.: CID,SID,DID,PLEN,16*DATA,EDC1,EDC2; 22 bytes
#define MAX_TX_PACKET_TIMER (TIMER_OVERFLOW-(ONE_BYTE_TIMER_LIMIT * 37)) //max.: 11*Pre,2D,D4,CID,SID,DID,PLEN,16*DATA,EDC1,EDC2+1; 36 bytes
#define NMBR_OF_CHANNELS 8
#define EDC_SIZE 2
#define CRC_16_PATTERN 0x8005 //bit pattern (1)1000 0000 0000 0101
#define DQD_SAMPLE 5
#define SpiPufLen 22
#define FIFO_USED 0x0040 //
#define FIFO_NOT_USED 0x0FFBF //
#define TXREG_USED 0x0080 //
#define TXREG_NOT_USED 0x0FF7F //
//changed by mlu for rev1.4
#define RX_cmd_init_value RX_CMD // BW:defined in the IAI_EZMac.h; VDI:always on; LNA:max; DRSSI:-103; Pin8: VDIout
#define TX_cmd_init_value TX_CMD // f0+df; df and Pout defined in the IAI_EZMac.h
#define POW_cmd_init_value 0x8201 // switch everything off, also the clk output
#define FIFO_cmd_init_value 0xCA81 // Fill:synchron pattern; IT level:8; disable sensitive reset
#define DR_cmd_init_value DR_CMD // defined in the IAI_EZMac.h
#define DF_cmd_init_value 0xC2Ac // CR:AUTO; Digital LPF; DQD:4
#define AFC_cmd_init_value 0xC4F7 // enabled; fine mode; auto,keep offset; +3/-4; output enabled
#define WK_cmd_init_value 0xFFFF // very long...
#define LD_cmd_init_value 0xC80E // 10%, off
#define LB_cmd_init_value 0xC000 // uC clk:1MHz, threshold:2.2V
/* ======================================= *
* D E F I N I T I O N S *
* ======================================= */
#undef bool
#undef FALSE
#undef TRUE
#define IT_SOURCE_T1 0
#define IT_SOURCE_COMM 0X80 //FIFO or TX register IT
#define IT_SOURCE_OVUR 0X20 //FIFO or TX register overrun/underrun
#define IT_SOURCE_COMM_OVUR 0XA0 //FIFO or TX register IT and overrun/underrun
#ifdef EZMAC_BOARD_WITH_ADC
#define ARSSI_USED //comment out this line if the ARSSI is not connected
#define ARSSI_PIN AN0 //which pin is connected to the ARSSI?
#define ARSSI_CHANNEL 0
#endif
typedef enum
{
EZ_Idle = 0,
EZ_Sleep,
EZ_WakeUp,
EZ_RxDQDCheck,
EZ_RxCheckControl, // EzMacPlus
EZ_RxCheckCID,
EZ_RxCheckSID,
EZ_RxCheckDID,
EZ_RxCheckPL,
EZ_RxDataByte,
EZ_RxCheckEDC,
EZ_RxEnd,
EZ_TxCheckChannel,
EZ_TransmitError,
EZ_TxSendPreamble,
EZ_TxSendSyncPattern0,
EZ_TxSendSyncPattern1,
EZ_TxSendControl, // EzMacPlus
EZ_TxSendHeader1,
EZ_TxSendHeader2,
EZ_TxSendData,
EZ_TxCalcCrc,
EZ_TxCalcCrc1,
EZ_TxSendEdc,
EZ_TxEnd
} state;
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// This is a sample I/O setting, it should be
// changed according to the application Hardware!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//definitions for the PIC SW development board
#define CLK_PIN portb_reg.testreg.bit4 //
#define MOSI_PIN portb_reg.testreg.bit3 //
#define MISO_PIN portc_reg.testreg.bit4 //
#define SEL_PIN portb_reg.testreg.bit5 //
#define CLK_DIR trisb_reg.testreg.bit4 //
#define MOSI_DIR trisb_reg.testreg.bit3 //
#define SEL_DIR trisb_reg.testreg.bit5 //
#define IRQ_DIR trisb_reg.testreg.bit0 //
/*Test outputs*/
#define LED4 portc_reg.testreg.bit5 //
#define LED3 portc_reg.testreg.bit2 //
#define LED2 portc_reg.testreg.bit1 //
#define LED1 portc_reg.testreg.bit0 //
#define LED1_DIR trisc_reg.testreg.bit0 //
#define LED2_DIR trisc_reg.testreg.bit1 //
#define LED3_DIR trisc_reg.testreg.bit2 //
#define LED4_DIR trisc_reg.testreg.bit5 //
#define PIC_SW_DEV_BOARD
/*pushbuttons*/
#define PB1 porta_reg.testreg.bit2 //
#define PB2 porta_reg.testreg.bit3 //
#define PB3 porta_reg.testreg.bit4 //
#define PB4 porta_reg.testreg.bit5 //
#define PB1_DIR trisa_reg.testreg.bit2 //
#define PB2_DIR trisa_reg.testreg.bit3 //
#define PB3_DIR trisa_reg.testreg.bit4 //
#define PB4_DIR trisa_reg.testreg.bit5 //
/* ======================================= *
* T Y P E D E C L A R A T I O N *
* ======================================= */
typedef enum { FALSE = 0, TRUE } bool;
typedef union
{
reg_union bytes[2];
int16 adat;
}reg16_union;
//////////////////////////////////
// CONTROL REGISTER DEFINITIONS //
//////////////////////////////////
typedef struct { // MCR (Master Control Register) bits
unsigned int NRF : 3;
unsigned int ADEN : 1;
unsigned int DNPL : 1;
unsigned int CIDEN : 1;
unsigned int NWAD : 1;
unsigned int RAR : 1;
} T_MCR;
typedef struct { // TCR (Transmission Control Register) bits
unsigned int TF : 3;
unsigned int OP : 3;
unsigned int LBTEN : 1;
unsigned int AXOT : 1;
} T_TCR;
typedef struct { // RCR (Receiving Control Register) bits
unsigned int RF : 3;
unsigned int SCHEN : 1;
unsigned int RSSL : 3;
unsigned int AXOR : 1;
} T_RCR;
typedef struct { // PFCR (Packet Filter Control Register) bits
unsigned int ApnM : 1;
unsigned int PREN : 1;
unsigned int PLFEN : 1;
unsigned int BCEN : 1;
unsigned int MCFEN : 1;
unsigned int DFEN : 1;
unsigned int SFEN : 1;
unsigned int CFEN : 1;
} T_PFCR;
typedef struct {
unsigned int resvd : 1;
unsigned int BPLEN : 1;
unsigned int BCRC : 1;
unsigned int BADDR : 1;
unsigned int BCID : 1;
unsigned int SPM : 1;
unsigned int TRSY : 1;
unsigned int CB : 1;
} T_EDCR;
typedef struct { // PFWCR (Packet Forward Control Register) bits
unsigned int PFEN : 1; // Packet Forward Enable
unsigned int resvd : 6;
unsigned int ACKRQ : 1; // ACK request bit
} T_PFWCR;
//////////////////////////////////////
// DATA/STATUS REGISTER DEFINITIONS //
//////////////////////////////////////
typedef struct { // MSR/state bits
unsigned int resvd : 1;
unsigned int S0 : 1;
unsigned int S1 : 1;
unsigned int S2 : 1;
unsigned int TX : 1;
unsigned int RX : 1;
unsigned int IDLE : 1;
unsigned int WKUP : 1;
} T_MSR;
typedef struct {
unsigned int PRF : 3;
unsigned int DRSSI : 1;
unsigned int resvd : 1;
unsigned int BCA : 1;
unsigned int MCA : 1;
unsigned int SELFA : 1;
} T_RSR;
typedef struct { // registers bit-by-bit
/// CONTROL REGISTERS
T_MCR MCRB;
T_TCR TCRB;
T_RCR RCRB;
T_PFCR PFCRB;
byte FR[NMBR_OF_CHANNELS];
byte FMASKB;
byte EC[NMBR_OF_CHANNELS];
T_EDCR EDCRB;
byte CIDB;
byte SFLTNIDL;
byte SMSKNIDH;
byte SFIDB;
byte MCAMCM;
byte RPLMPL;
T_PFWCR PFWCRB; // EzMacPlus
/// DATA & STATUS REGISTERS
T_MSR MSRB;
T_RSR RSRB;
byte RX_CIDB;
byte SIDB;
byte DIDB;
byte PLENB;
byte DBuff[PLEN_MAX];
} T_EZRegfield;
typedef struct { // registers by byte
/// CONTROL REGISTERS
byte MCRB;
byte TCRB;
byte RCRB;
byte PFCRB;
byte FR[NMBR_OF_CHANNELS];
byte FMASKB;
byte EC[NMBR_OF_CHANNELS];
byte EDCRB;
byte CIDB;
byte SFLTNIDL;
byte SMSKNIDH;
byte SFIDB;
byte MCAMCM;
byte RPLMPL;
byte PFWCRB; // EzMacPlus
/// DATA & STATUS REGISTERS
byte MSRB;
byte RSRB;
byte RX_CIDB;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -