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

📄 iai_ezmac_lite_int.c

📁 Integration的EZMac Lite
💻 C
📖 第 1 页 / 共 3 页
字号:
   {
      #ifdef SM_PRINT_STATE
      _PrintState();
      #endif
      if( It_Source == IT_SOURCE_T1 )
      {//SW Watchdog timer overrun -> Trixie HW error
         _TrixieHWError();
         return;
      }
      //write byte (0xD4) to the Trixie
      #ifdef SM_REAL_FUNCTION
      _WriteByte_Trixie (0xd4);
      #endif

      //save the previosly calculated data byte
      Data1 = Data;
      //next state
      EZInternalState = EZ_TxSendHeader1;
      //the second header byte (H2)
      Data = EZ_reg.bytes.SIDB;
      //calc CRC for this byte
      Crc_On_Fly(Data);
      //the CRC was calculated for all of the databytes
      #ifdef SM_PRINTF_TX
      printf("TxSy1: D4 %x\n\r",Data);
      #endif
      break;
   }

 /*Send the 1. header byte...*/
   case EZ_TxSendHeader1:
   {
      #ifdef SM_PRINT_STATE
      _PrintState();
      #endif
      if( It_Source == IT_SOURCE_T1 )
      {//SW Watchdog timer overrun -> Trixie HW error
         _TrixieHWError();
         return;
      }
      //write byte (Data1) to the trixie
      #ifdef SM_REAL_FUNCTION
      _WriteByte_Trixie (Data1);
      #endif

      #ifdef SM_PRINTF_TX
      printf("TxH1: %x",Data1);
      #endif
      //save the previosly calculated data byte
      Data1 = Data;
      //next state
      EZInternalState = EZ_TxSendHeader2;
      //the 3d header byte (H3)
      Data = EZ_reg.bytes.DIDB;

      //calc CRC for this byte
      Crc_On_Fly(Data);
      //the CRC was calculated for all of the databytes
      #ifdef SM_PRINTF_TX
      printf(" %x\n\r",Data);
      #endif
      break;
   }

 /*Send the 2. header byte*/
   case EZ_TxSendHeader2:
   {
      #ifdef SM_PRINT_STATE
      _PrintState();
      #endif
      if( It_Source == IT_SOURCE_T1 )
      {//SW Watchdog timer overrun -> Trixie HW error
         _TrixieHWError();
         return;
      }
      //write byte (Data1) to the trixie
      #ifdef SM_REAL_FUNCTION
      _WriteByte_Trixie (Data1);
      #endif
      #ifdef SM_PRINTF_TX
      printf("TxH2: %x",Data1);
      #endif
      //save the previosly calculated data byte
      Data1 = Data;
      //next state
      EZInternalState = EZ_TxSendData;
      //fix packet length
      Data = EZ_reg.bytes.DBuff[DataByteCounter];
      DataByteCounter++;
      EZInternalState = EZ_TxSendData;
      //calc CRC for this byte
      Crc_On_Fly(Data);
      //the CRC was calculated for all of the databytes
      if( DataByteCounter == EZ_reg.bytes.PLENB )
         EZInternalState = EZ_TxCalcCrc;
      #ifdef SM_PRINTF_TX
      printf(" %x\n\r",Data);
      #endif
      break;
   }
 /*Send the data bytes*/
   case EZ_TxSendData:
   {
      #ifdef SM_PRINT_STATE
      _PrintState();
      #endif
      if( It_Source == IT_SOURCE_T1 )
      {//SW Watchdog timer overrun -> Trixie HW error
         _TrixieHWError();
         return;
      }
      //write byte (Data1) to the trixie
      #ifdef SM_REAL_FUNCTION
      _WriteByte_Trixie (Data1);
      #endif

      #ifdef SM_PRINTF_TX
      printf("TxD: %x",Data1);
      #endif
      //save the previosly calculated data byte
      Data1 = Data;
      //the new data byte
      Data = EZ_reg.bytes.DBuff[DataByteCounter];
      DataByteCounter++;
      //Calc CRC
      Crc_On_Fly(Data);
      if( DataByteCounter == EZ_reg.bytes.PLENB )
         EZInternalState = EZ_TxCalcCrc;
      #ifdef SM_PRINTF_TX
      printf(" %x\n\r",Data);
      #endif
      break;
   }
 /*Send the data bytes, calc the CRC for the CRC bytes (0x00)*/
   case EZ_TxCalcCrc:
   {
      #ifdef SM_PRINT_STATE
      _PrintState();
      #endif
      if( It_Source == IT_SOURCE_T1 )
      {//SW Watchdog timer overrun -> Trixie HW error
         _TrixieHWError();
         return;
      }
      //write byte (Data1) to the Trixie
      #ifdef SM_REAL_FUNCTION
      _WriteByte_Trixie (Data1);
      #endif

      #ifdef SM_PRINTF_TX
      printf("TxCCrc: %x\n\r",Data1);
      #endif
      //calc CRC
      Crc_On_Fly(0x00);
      //save the previosly calculated data byte
      Data1 = Data;
      EZInternalState = EZ_TxCalcCrc1;
      break;
   }
 /*Send the last data byte, calc the CRC*/
   case EZ_TxCalcCrc1:
   {
      #ifdef SM_PRINT_STATE
      _PrintState();
      #endif
      if( It_Source == IT_SOURCE_T1 )
      {//SW Watchdog timer overrun -> Trixie HW error
         _TrixieHWError();
         return;
      }
      //write byte (Data1) to the Trixie
      #ifdef SM_REAL_FUNCTION
      _WriteByte_Trixie (Data1);
      #endif

      #ifdef SM_PRINTF_TX
      printf("TxCCrc1: %x\n\r",Data1);
      #endif
      //calc CRC
      Crc_On_Fly(0x00);
      //set the last 2 bytes
      Data = EZ_crc.bytes[0].adat;
      Data1 = EZ_crc.bytes[1].adat;
      EZInternalState = EZ_TxSendEdc;
      //One byte more should be copied to the FIFO to send the last byte correctly
      DataByteCounter = 2;
      break;
   }
 /*Send the CRC bytes*/
   case EZ_TxSendEdc:
      #ifdef SM_PRINT_STATE
         _PrintState();
      #endif
      if( It_Source == IT_SOURCE_T1 )
         {//SW Watchdog timer overrun -> Trixie HW error
         _TrixieHWError();
         return;
         }
      //write byte (Data1) to the trixie
      #ifdef SM_REAL_FUNCTION
       _WriteByte_Trixie (Data1);
      #endif

      #ifdef SM_PRINTF_TX
       printf("TxEdc: %x\n\r",Data1);
      #endif
      Data1 = Data;
      if( DataByteCounter == 0 )
         //it was the last byte, end of Tx
         EZInternalState = EZ_TxEnd;
      else
         DataByteCounter--;
   break;

 /*End of the transmit*/
   case EZ_TxEnd:
      #ifdef SM_PRINT_STATE
         _PrintState();
      #endif
      #ifdef SM_DEBUG
       TRIGGER = 0;
      #endif
      #ifdef SM_PRINTF_TX
       printf("TxEnd\n\r");
      #endif
      if( It_Source == IT_SOURCE_T1 )
         {//SW Watchdog timer overrun -> Trixie HW error
         _TrixieHWError();
         return;
         }
      //turn off Trixie and go to Idle or Sleep state (depend on AXOT bit)
      EZMac_Idle();
   break;

   }
}

//===============================================================================================

// start new CRC calculation
void Crc_Init()
{
   // EZ_crc have to be initialized before the first CRC calculation
   EZ_crccnt = 0;
}

//===============================================================================================
#pragma separate
// Changed by Laszlo Kadar on 26.11.05
void Crc_On_Fly(int8 Data)
{
// Changed by Laszlo Kadar on 29.11.05
#ifdef HITECH_COMPILER
   static _NEAR__ int8 BANK_2 bit_counter;
#endif
#ifdef CCS_C_COMPILER
   int8 bit_counter;
#endif

   #ifdef FIX_MEM_ADDRESS
    #pragma byte Data = 0x63
    #pragma byte bit_counter = 0x65;
   #endif

   if (EZ_crccnt<2)                        // first two bytes
   {
      if (EZ_crccnt==0)
      {
// Changed by Laszlo Kadar on 26.11.05
         EZ_crc.bytes[1].adat = Data; // first byte: CrcH
         EZ_crccnt++;
      }
      else
      { // crccnt ==1
// Changed by Laszlo Kadar on 26.11.05
         EZ_crc.bytes[0].adat = Data;   // second byte: CrcL
         EZ_crccnt++;
      }
   }
   else // bytes 3, 4...
   {
      for(bit_counter=8; bit_counter > 0; bit_counter--)
      {
         if(!EZ_crc.bytes[1].testreg.bit7)
            {
            EZ_crc.adat <<= 1;
// Changed by Laszlo Kadar on 26.11.05
            if(Data&0x80)
               EZ_crc.adat |= 0x0001;
// Changed by Laszlo Kadar on 26.11.05
            Data <<= 1;
            }
         else
            {
            EZ_crc.adat <<= 1;
// Changed by Laszlo Kadar on 26.11.05
            if(Data&0x80)
               EZ_crc.adat |= 0x0001;
// Changed by Laszlo Kadar on 26.11.05
            Data <<= 1;

            EZ_crc.adat ^= CRC_16_PATTERN;
            }
      }
   }
}

//===============================================================================================
#pragma separate
// Changed by Laszlo Kadar on 26.11.05
#ifdef HITECH_COMPILER
 #pragma interrupt_level 1
#endif
void _Set_Timer1(int16 Limit)
{
   #ifdef FIX_MEM_ADDRESS
    #pragma locate Limit = 0x68
   #endif
   /*changed by krk for rev1.6 -> clear the timer and flags before restart it*/
   _Turn_Off_Timer1();
   //set up Timer1 to wake up the state machine for various events
   setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);      //internal oscillator (Fosc/4), prescaler = 8
   set_timer1(Limit);                             //setup the timer interval
   #ifdef SM_DEBUG                                //only for debug: show the start of the new timer interval
    TRIGGER2 = 0;                                 //help to measure the timer interval
    #asm
    nop
    #endasm
    TRIGGER2 = 1;
   #endif
   //enable the interrupt
   clear_interrupt(INT_TIMER1);
   enable_interrupts(INT_TIMER1);
}

//===============================================================================================
#ifdef CCS_C_COMPILER
 #pragma inline
#endif
void _Turn_Off_Timer1(void)
{  //turn of the Timer1
   setup_timer_1(T1_DISABLED);
   disable_interrupts(INT_TIMER1);
}

//===============================================================================================
#pragma separate
// Changed by Laszlo Kadar on 26.11.05
#ifdef HITECH_COMPILER
 #pragma interrupt_level 1
#endif
char EZRadio_CMD_Write (int8 CMD_index)
{
// Changed by Laszlo Kadar on 29.11.05
#ifdef HITECH_COMPILER
   static _NEAR__ int16 BANK_2 EZcmd;
#endif
#ifdef CCS_C_COMPILER
   int16 EZcmd;
#endif

   EZcmd=EZ_commands.arr[CMD_index];
   //send a command for Trixie
   SEL_PIN = 0;                     //SPI sel pin = 0
   EZ_Spi_Write(EZcmd>>8);      //write high byte
   EZ_Spi_Write(EZcmd);         //write low byte
   SEL_PIN = 1;                     //set SPI sel pin
}

//===============================================================================================

#pragma separate
void EZ_Reg_Default(void)
{
// Changed by Laszlo Kadar on 29.11.05
#ifdef HITECH_COMPILER
   static _NEAR__ int8 BANK_2 i;
#endif
#ifdef CCS_C_COMPILER
   int8 i;
#endif

   EZ_state = EZMac_S_Sleep;                    //first state: Sleep
   EZInternalState = EZ_Sleep;

   for(i=MCR;i<PLEN;i++)
    EZMacReg_Write(i,0);                        //delete all registers, except the read only registers

   /*set the default values of the registers*/
   //AXOT = 1, LBTEN = 1, OutPow = min
   EZ_reg.bytes.TCRB = 0xF8;
   //AXOR = 1
   EZ_reg.bytes.RCRB = 0x80;
   //promiscuous mode
   EZ_reg.bytes.PFCRB = 0x02;
   //different freq in the freq register
   for(i=1;i<9;i++)
      EZ_reg.bytes.FR[i-1] = i;
   EZ_reg.bytes.CIDB = DEFAULT_CID;             //customers can set the default value of this registers
   EZ_reg.bytes.SFIDB = DEFAULT_SFID;           //see IAI_EZMac.h
   EZ_reg.bytes.SFLTB = DEFAULT_SFLT;
   EZ_reg.bytes.SMSKB = DEFAULT_SMSK;
   EZ_reg.bytes.RPLB = 0x01;
   SetSpiEn = TRUE;                             //External Interrupt routine should set the SPI select pin
}

//===============================================================================================

#pragma separate
void EZ_Radio_Config(void)
{
//changed by mlu for rev1.4

   EZ_commands.arr[Config_command]=0x8000 | FREQ_Band | XTAL_COMP;
   EZ_commands.arr[Power_command]=POW_cmd_init_value;             // switch everything off, also the clk output
   EZ_commands.arr[Fifo_command]=FIFO_cmd_init_value;             // Fill:synchron pattern; IT level:8; disable sensitive reset
   EZ_commands.arr[Data_Rate_command]=DR_cmd_init_value;          // 8842bps
   EZ_commands.arr[RX_Ctrl_command]=RX_cmd_init_value;            // BW:135kHz; VDI:always on; LNA:max; DRSSI:-103; Pin8: VDIout
   EZ_commands.arr[TX_Ctrl_command]=TX_cmd_init_value;            // f0+df; df:75kHz; Pout:min
   EZ_commands.arr[Data_Filter_command]=DF_cmd_init_value;        // CR:slow; Digital LPF; DQD:7
   EZ_commands.arr[AFC_command]=AFC_cmd_init_value;               // enabled; fine mode; auto,keep offset; +7/-8; output enabled
   EZ_commands.arr[Freq_command]=0xA000 + ((int16)(FREQ_maxid/2)*FREQ_step + FREQ_start);
   EZ_commands.arr[Wake_command]=WK_cmd_init_value;               // very long...
   EZ_commands.arr[Low_Duty_command]=LD_cmd_init_value;           // 10%, off
   EZ_commands.arr[LBD_command]=LB_cmd_init_value;                // uC clk:1MHz, threshold:2.2V

   EZRadio_CMD_Write(Power_command);
   EZRadio_CMD_Write(Config_command);
   EZRadio_CMD_Write(Fifo_command);
   EZRadio_CMD_Write(Data_Rate_command);
   EZRadio_CMD_Write(TX_Ctrl_command);
   EZRadio_CMD_Write(RX_Ctrl_command);
   EZRadio_CMD_Write(Data_Filter_command);
   EZRadio_CMD_Write(AFC_command);
   EZRadio_CMD_Write(Freq_command);
   EZRadio_CMD_Write(Wake_command);
   EZRadio_CMD_Write(Low_Duty_command);
   EZRadio_CMD_Write(LBD_command);
/*   Power_command |= 0x0010;                not needed, because it is automatic when switching on the TX or RX       //switch on the synthesizer for calibrating
   EZRadio_Write(Power_command);
   Power_command &= 0xff07;
   EZRadio_Write(Power_command);
*/
   EZRadio_Statusread ();
}


⌨️ 快捷键说明

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