예제 #1
0
파일: zigbee.c 프로젝트: uriahjb/symphotron
int ZigBee_Init()
{

  if ( ZigBee_CheckPartAndVers() == 0 )
  {
#if defined(DEBUG)
    printf("zigbee found!\r\n");
#endif
  }
  else
  {
#if defined(DEBUG)
    printf("zigbee NOT found!!\r\n");
#endif
    return -1;
  }

  ZigBee_ConfigClock();

  _delay_us(10);

  if (ZigBee_ForceTrxOff() != 0)
    return -1;

  //enable Auto CRC, disable RX buffer empty IRQ
  ZigBee_WriteReg(REG_TRX_CTRL_1, 0x20);

  _delay_us(2);

  ZigBee_WriteReg(REG_TRX_CTRL_2, 0x2C); //modulation: OQPSK-SIN-250

  _delay_us(2);

  ZigBee_WriteReg(REG_PHY_TX_PWR, 0xE1);   //output power setting to 10dBm

  if (ZigBee_SetModeRx() == 0)
  {
#if defined(DEBUG)
    printf("zigbee initialization complete.\r\n");
#endif
  }
  else
  {
#if defined(DEBUG)
    printf("zigbee initialization FAILED.\r\n");
#endif
/*     while(1)
    {
      uint8_t zigbee_ret = ZigBee_ReadState();
      switch(zigbee_ret)
      {
      case STATUS_P_ON:
        mRedTOGGLE; break;
      case STATUS_BUSY_RX:
        mWhiteTOGGLE; break;
      case STATUS_BUSY_TX:
        mGreenTOGGLE; break;
      //case STATUS_RX_ON:
        //mAmberTOGGLE; break;
      case STATUS_TRX_OFF:
        mRedTOGGLE; mWhiteTOGGLE; break;
      case STATUS_PLL_ON:
        mRedTOGGLE; mGreenTOGGLE; break;
      case 0xF:
        mRedTOGGLE; mAmberTOGGLE; break;
      case 0x11:
        mRedTOGGLE; mWhiteTOGGLE; mGreenTOGGLE; break;
      case 0x12:
        mRedTOGGLE; mWhiteTOGGLE; mAmberTOGGLE; break;
      case 0x16:
        mRedTOGGLE; mWhiteTOGGLE; mAmberTOGGLE; mGreenTOGGLE; break;
      case 0x19:
        mWhiteTOGGLE; mGreenTOGGLE; break;
      case 0x1C:
        mWhiteTOGGLE; mAmberTOGGLE; break;
      case 0x1D:
        mWhiteTOGGLE; mGreenTOGGLE; mAmberTOGGLE; break;
      case 0x1E:
        mGreenTOGGLE; mAmberTOGGLE; break;
      case 0x1F:
        mAmberTOGGLE; break;
        int irq_ret = ZigBee_ReadIrq();
        if((irq_ret & 0x40) != 0)
        {
          // Frame Buffer access violation
          mRedON;
          mWhiteON;
        }
        else if((irq_ret & 0x02) != 0)
        {
          // PLL unlock
          mRedON;
          mGreenON;
        }
        else if((irq_ret & 0x01) != 0)
        {
          // PLL lock
          mGreenON;
          mWhiteON;
        }
      }
      _delay_ms(500);
    } */
    return -1;
  }

  return 0;
}
예제 #2
0
int ZigBee_Init()
{

  if ( ZigBee_CheckPartAndVers() == 0 )
  {
#if defined(DEBUG)
    printf("zigbee found!\r\n");
#endif
  }
  else
  {
#if defined(DEBUG)
    printf("zigbee NOT found!!\r\n");
#endif
    return -1;
  }

  ZigBee_ConfigClock();

  DelayMicroseconds(10);

  if (ZigBee_ForceTrxOff() != 0)
    return -1;

  //enable Auto CRC, disable RX buffer empty IRQ
  // ZigBee_WriteReg(REG_TRX_CTRL_1, 0x20);
  // _delay_us(2);

  //enable Auto CRC, disable RX buffer empty IRQ, Enable Amplifier+LEDs
  ZigBee_WriteReg(REG_TRX_CTRL_1, 0xE0);
  DelayMicroseconds(2);

  // see TRX_CTRL_2 register descriptions in datasheet
  ZigBee_WriteReg(REG_TRX_CTRL_2, 0b00001100); // modulation: OQPSK-SIN-250, fairly reliable within Modlab
  // ZigBee_WriteReg(REG_TRX_CTRL_2, 0b00001101); // modulation: OQPSK-SIN-500, fairly reliable within Modlab
  // ZigBee_WriteReg(REG_TRX_CTRL_2, 0b00101110); // modulation: OQPSK-SIN-1000-SCR-ON, high data loss at any range

  DelayMicroseconds(2);

#ifndef AMPLIFIED_OUTPUT
  ZigBee_WriteReg(REG_PHY_TX_PWR, 0xE1);   //output power setting to 10dBm
#else
  ZigBee_WriteReg(REG_PHY_TX_PWR, 0x84);   //output power setting to 5dBm (Amplified)
  mOrangeOFF;
#endif

  if (ZigBee_SetModeRx() == 0)
  {
#if defined(DEBUG)
    printf("zigbee initialization complete.\r\n");
#endif
  }
  else
  {
#if defined(DEBUG)
    printf("zigbee initialization FAILED.\r\n");
#endif
/*     while(1)
    {
      uint8_t zigbee_ret = ZigBee_ReadState();
      switch(zigbee_ret)
      {
      case STATUS_P_ON:
        mRedTOGGLE; break;
      case STATUS_BUSY_RX:
        mWhiteTOGGLE; break;
      case STATUS_BUSY_TX:
        mGreenTOGGLE; break;
      //case STATUS_RX_ON:
        //mAmberTOGGLE; break;
      case STATUS_TRX_OFF:
        mRedTOGGLE; mWhiteTOGGLE; break;
      case STATUS_PLL_ON:
        mRedTOGGLE; mGreenTOGGLE; break;
      case 0xF:
        mRedTOGGLE; mAmberTOGGLE; break;
      case 0x11:
        mRedTOGGLE; mWhiteTOGGLE; mGreenTOGGLE; break;
      case 0x12:
        mRedTOGGLE; mWhiteTOGGLE; mAmberTOGGLE; break;
      case 0x16:
        mRedTOGGLE; mWhiteTOGGLE; mAmberTOGGLE; mGreenTOGGLE; break;
      case 0x19:
        mWhiteTOGGLE; mGreenTOGGLE; break;
      case 0x1C:
        mWhiteTOGGLE; mAmberTOGGLE; break;
      case 0x1D:
        mWhiteTOGGLE; mGreenTOGGLE; mAmberTOGGLE; break;
      case 0x1E:
        mGreenTOGGLE; mAmberTOGGLE; break;
      case 0x1F:
        mAmberTOGGLE; break;
        int irq_ret = ZigBee_ReadIrq();
        if((irq_ret & 0x40) != 0)
        {
          // Frame Buffer access violation
          mRedON;
          mWhiteON;
        }
        else if((irq_ret & 0x02) != 0)
        {
          // PLL unlock
          mRedON;
          mGreenON;
        }
        else if((irq_ret & 0x01) != 0)
        {
          // PLL lock
          mGreenON;
          mWhiteON;
        }
      }
      DelayMilliseconds(500);
    } */
      return -1;
    }

    return 0;
  }