Esempio n. 1
0
static void
PtInternalTransmit (BRFPacket * pkg)
{
  /* update the sequence */
  if (sequence_seed == 0)
    return;

  /* turn on redLED for TX indication */
  vLedSetRed (1);

  /* disable receive mode */
  nRFCMD_CE (0);

  /* wait in case a packet is currently received */
  vTaskDelay (3 / portTICK_RATE_MS);

  /* set TX mode */
  nRFAPI_SetRxMode (0);

  if (pkg->mac == 0xffff)
    rf_sent_broadcast++;
  else
    rf_sent_unicast++;

  pkg->sequence = sequence_seed + (xTaskGetTickCount () / portTICK_RATE_MS);

  /* update crc */
  pkg->crc =
    PtSwapLong (crc32
		((unsigned char *) pkg, sizeof (*pkg) - sizeof (pkg->crc)));

  /* encrypt the data */
  shuffle_tx_byteorder ((unsigned long *) pkg, sizeof (*pkg) / sizeof (long));
  xxtea_encode ((long *) pkg, sizeof (*pkg) / sizeof (long));
  shuffle_tx_byteorder ((unsigned long *) pkg, sizeof (*pkg) / sizeof (long));

  /* upload data to nRF24L01 */
  //hex_dump((unsigned char *) pkg, 0, sizeof(*pkg));
  nRFAPI_TX ((unsigned char *) pkg, sizeof (*pkg));

  /* transmit data */
  nRFCMD_CE (1);

  /* wait till packet is transmitted */
  vTaskDelay (3 / portTICK_RATE_MS);

  /* switch to RX mode again */
  nRFAPI_SetRxMode (1);

  /* turn off red TX indication LED */
  vLedSetRed (0);
}
Esempio n. 2
0
void
nrf_off (void)
{
  /* disable RX mode */
  nRFCMD_CE (0);

  /* wait till RX is done */
  pmu_sleep_ms (5);

  /* switch to TX mode */
  nRFAPI_SetRxMode (0);
}
Esempio n. 3
0
static void
nRF_tx (uint8_t power)
{

  /* encrypt data */
  xxtea_encode (g_Beacon.block, XXTEA_BLOCK_COUNT, xxtea_key);

  /* set TX power */
  nRFAPI_SetTxPower (power & 0x3);

  /* upload data to nRF24L01 */
  nRFAPI_TX (g_Beacon.byte, sizeof (g_Beacon));

  /* transmit data */
  nRFCMD_CE (1);

  /* wait for packet to be transmitted */
  pmu_sleep_ms (2);

  /* transmit data */
  nRFCMD_CE (0);
}
Esempio n. 4
0
void
init_authentication (void)
{
	if (!nRFAPI_Init(DEFAULT_CHANNEL, broadcast_mac, sizeof (broadcast_mac), ENABLED_NRF_FEATURES))
		return;

	nRFAPI_SetPipeSizeRX (0, 16);
	nRFAPI_SetTxPower (3);
	nRFAPI_SetRxMode (1);
	nRFCMD_CE (1);
	
	xTaskCreate (authentication_task, (signed portCHAR *) "AUTHENTICATION",
	       TASK_NRF_STACK, NULL, TASK_NRF_PRIORITY, NULL);
}
Esempio n. 5
0
void
nRFCMD_Shutdown (void)
{
  /* disable RX mode */
  nRFCMD_CE (0);

  /* wait 5ms */
  pmu_sleep_ms (5);

  /* switch to TX mode */
  nRFAPI_SetRxMode (0);

  /* powering down */
  nRFAPI_PowerDown ();

  /* set pins to lowest power */
  GPIOSetDir (RF_IRQ_CPU_PORT, RF_IRQ_CPU_PIN, 1);
  GPIOSetValue (RF_IRQ_CPU_PORT, RF_IRQ_CPU_PIN, 0);
  GPIOSetValue (CPU_CE_RF_PORT, CPU_CE_RF_PIN, 0);
  GPIOSetValue (CPU_SWITCH_RF_PORT, CPU_SWITCH_RF_PIN, 0);
}
Esempio n. 6
0
static inline s_int8_t
PtInitNRF (void)
{
    if (!nRFAPI_Init (DEFAULT_CHANNEL, broadcast_mac,
                      sizeof (broadcast_mac), ENABLED_NRF_FEATURES))
        return 0;

    jam_density_ms = DEFAULT_JAM_DENSITY;

    nrf_powerlevel_last = nrf_powerlevel_current = -1;
    PtSetRfPowerLevel (NRF_POWERLEVEL_MAX);

    nRFAPI_SetSizeMac (sizeof (wmcu_mac));
    nRFAPI_SetPipeSizeRX (0, sizeof (rfpkg));
    nRFAPI_SetPipeSizeRX (1, sizeof (rfpkg));
    nRFAPI_PipesEnable (ERX_P0 | ERX_P1);
    PtUpdateWmcuId (env.e.mcu_id == 0);

    nRFAPI_SetRxMode (0);
    nRFCMD_CE (0);

    return 1;
}