Ejemplo n.º 1
0
uint32_t samr21RadioRandomGet(void)
{
    uint32_t result;

    radioWakeup();

    result = PHY_RandomReq() << 16 | PHY_RandomReq();

    radioRestore();

    return result;
}
Ejemplo n.º 2
0
/*************************************************************************//**
*****************************************************************************/
void PHY_Init(void)
{
	sysclk_enable_peripheral_clock(&TRX_CTRL_0);

	TRXPR_REG_s.trxrst = 1;

	phyRxState = false;
	phyState = PHY_STATE_IDLE;

	phyTrxSetState(TRX_CMD_TRX_OFF);

	TRX_CTRL_2_REG_s.rxSafeMode = 1;

#ifdef PHY_ENABLE_RANDOM_NUMBER_GENERATOR
	CSMA_SEED_0_REG = (uint8_t)PHY_RandomReq();
#endif

#if defined(PLATFORM_WM100) || defined(PLATFORM_WM100_DUINO)
	#if (ANTENNA_DIVERSITY == 1)
		ANT_DIV_REG_s.antCtrl = 2;
		RX_CTRL_REG_s.pdtThres = 0x03;
		ANT_DIV_REG_s.antDivEn = 1;
		ANT_DIV_REG_s.antExtSwEn = 1;
	#endif // ANTENNA_DIVERSITY
	#ifdef EXT_RF_FRONT_END_CTRL
		TRX_CTRL_1_REG_s.paExtEn = 1;
	#endif // EXT_RF_FRONT_END_CTRL
#endif // PLATFORM_WM100
}
Ejemplo n.º 3
0
/*************************************************************************//**
*****************************************************************************/
static void appInit(void)
{
  appMsg.messageType          = 1;
  appMsg.nodeType             = APP_NODE_TYPE;
  appMsg.extAddr              = APP_ADDR;
  appMsg.shortAddr            = APP_ADDR;
  appMsg.softVersion          = 0x01010100;
  appMsg.channelMask          = (1L << APP_CHANNEL);
  appMsg.panId                = APP_PANID;
  appMsg.workingChannel       = APP_CHANNEL;
  appMsg.parentShortAddr      = 0;
  appMsg.lqi                  = 0;
  appMsg.rssi                 = 0;

  appMsg.sensors.type        = 1;
  appMsg.sensors.size        = sizeof(int32_t) * 3;
  appMsg.sensors.battery     = 0;
  appMsg.sensors.temperature = 0;
  appMsg.sensors.light       = 0;

  appMsg.caption.type         = 32;
  appMsg.caption.size         = APP_CAPTION_SIZE;
  memcpy(appMsg.caption.text, APP_CAPTION, APP_CAPTION_SIZE);

  NWK_SetAddr(APP_ADDR);
  NWK_SetPanId(APP_PANID);
  PHY_SetChannel(APP_CHANNEL);
#if (defined(PHY_AT86RF212B) || defined(PHY_AT86RF212))
  PHY_SetBand(APP_BAND);
  PHY_SetModulation(APP_MODULATION);
#endif
  PHY_SetRxState(true);

#ifdef NWK_ENABLE_SECURITY
  NWK_SetSecurityKey((uint8_t *)APP_SECURITY_KEY);
#endif

  NWK_OpenEndpoint(APP_ENDPOINT, appDataInd);

  appDataSendingTimer.interval = APP_SENDING_INTERVAL;
  appDataSendingTimer.mode = SYS_TIMER_INTERVAL_MODE;
  appDataSendingTimer.handler = appDataSendingTimerHandler;

#if APP_ROUTER || APP_ENDDEVICE
  appNetworkStatus = false;
  appNetworkStatusTimer.interval = 500;
  appNetworkStatusTimer.mode = SYS_TIMER_PERIODIC_MODE;
  appNetworkStatusTimer.handler = appNetworkStatusTimerHandler;
  SYS_TimerStart(&appNetworkStatusTimer);
#else
  LED_On(LED_NETWORK);
#endif

#ifdef PHY_ENABLE_RANDOM_NUMBER_GENERATOR
  srand(PHY_RandomReq());
#endif

  appState = APP_STATE_SEND;
}
Ejemplo n.º 4
0
void samr21RadioRandomGetTrue(uint8_t *aOutput, uint16_t aOutputLength)
{
    radioWakeup();

    for (uint16_t i = 0; i < aOutputLength / sizeof(uint16_t); i++)
    {
        *((uint16_t *)aOutput) = PHY_RandomReq();
        aOutput += sizeof(uint16_t);
    }

    for (uint16_t i = 0; i < aOutputLength % sizeof(uint16_t); i++)
    {
        aOutput[i] = PHY_RandomReq();
    }

    radioRestore();
}
Ejemplo n.º 5
0
/*************************************************************************//**
*****************************************************************************/
void PHY_Init(void)
{
  TRXPR_REG_s.trxrst = 1;

  phyRxState = false;
  phyState = PHY_STATE_IDLE;

  phyTrxSetState(TRX_CMD_TRX_OFF);

  TRX_CTRL_2_REG_s.rxSafeMode = 1;

#ifdef PHY_ENABLE_RANDOM_NUMBER_GENERATOR
  CSMA_SEED_0_REG = (uint8_t)PHY_RandomReq();
#endif
}
Ejemplo n.º 6
0
static void appInit(void)
{
  msg.messageType          = 1;
  msg.nodeType             = APP_NODE_TYPE;
  msg.extAddr              = APP_ADDR;
  msg.shortAddr            = APP_ADDR;
  msg.softVersion          = 0x01010100;
  msg.channelMask          = (1L << APP_CHANNEL);
  msg.panId                = APP_PANID;
  msg.workingChannel       = APP_CHANNEL;
  msg.parentShortAddr      = 0;
  msg.lqi                  = 0;
  msg.rssi                 = 0;

  msg.sensors.type        = 1;
  msg.sensors.size        = sizeof(int32_t) * 3;
  msg.sensors.battery     = 0;
  msg.sensors.temperature = 0;
  msg.sensors.light       = 0;

  msg.caption.type         = 32;
  msg.caption.size         = APP_CAPTION_SIZE;
  memcpy(msg.caption.text, APP_CAPTION, APP_CAPTION_SIZE);

#if APP_COORDINATOR
  // Enable RCB_BB RS232 level converter
  #if defined(PLATFORM_RCB128RFA1)
    DDRD = (1 << 4) | (1 << 6) | (1 << 7);
    PORTD = (0 << 4) | (1 << 6) | (1 << 7);
  #endif

  #if defined(PLATFORM_RCB231)
    DDRC = (1 << 4) | (1 << 6) | (1 << 7);
    PORTC = (0 << 4) | (1 << 6) | (1 << 7);
  #endif
#endif

  ledsInit();

  NWK_SetAddr(APP_ADDR);
  NWK_SetPanId(APP_PANID);
  PHY_SetChannel(APP_CHANNEL);
  PHY_SetRxState(true);

#ifdef NWK_ENABLE_SECURITY
  NWK_SetSecurityKey((uint8_t *)APP_SECURITY_KEY);
#endif

  NWK_OpenEndpoint(APP_ENDPOINT, appDataInd);

  appDataSendingTimer.interval = APP_SENDING_INTERVAL;
  appDataSendingTimer.mode = SYS_TIMER_INTERVAL_MODE;
  appDataSendingTimer.handler = appDataSendingTimerHandler;

#if APP_ROUTER || APP_ENDDEVICE
  appNetworkStatus = false;
  appNetworkStatusTimer.interval = 500;
  appNetworkStatusTimer.mode = SYS_TIMER_PERIODIC_MODE;
  appNetworkStatusTimer.handler = appNetworkStatusTimerHandler;
  SYS_TimerStart(&appNetworkStatusTimer);
#else
  ledOn(LED_NETWORK);
#endif

#ifdef PHY_ENABLE_RANDOM_NUMBER_GENERATOR
  PHY_RandomReq();
#endif

  appState = APP_STATE_SEND;
}