コード例 #1
0
ファイル: proto.c プロジェクト: bomma/openbeacon
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);
}
コード例 #2
0
void ob_switchTXMode() {
	if(ob_int_mgmt.Mode!=2) {
		nRFLL_CE(0);
		nRFAPI_SetRxMode(0);
		ob_int_mgmt.Mode = 2;
	}
}
コード例 #3
0
void ob_switchRXMode() {
	if(ob_int_mgmt.Mode!=1) {
		nRFLL_CE(1);
		nRFAPI_SetRxMode(1);
		ob_int_mgmt.Mode = 1;
	}
}
コード例 #4
0
ファイル: main_tx.c プロジェクト: KhMassri/DTNWorkspace
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);
}
コード例 #5
0
ファイル: nRF_API.c プロジェクト: CMon/dld
unsigned char nRFAPI_Init(
    unsigned char channel,
    const unsigned char *mac,
    unsigned char mac_size,
    unsigned char features
)
{
    unsigned char i;

    // init lower layer
    nRFCMD_Init();

    // check validity
    if(	mac_size<3 ||
            mac_size>5 ||
            !nRFAPI_DetectChip()
      )
        return 0;

    // update mac
    nRFAPI_SetSizeMac(mac_size);
    nRFAPI_SetTxMAC(mac,mac_size);

    // enables pipe
    nRFAPI_SetRxMAC(mac,mac_size,0);
    nRFAPI_PipesEnable(ERX_P0);
    nRFAPI_PipesAck(0);

    // set payload sizes
    for(i=0; i<=5; i++)
        nRFAPI_SetPipeSizeRX(i,2);

    // set TX retry count
    nRFAPI_TxRetries(0);

    // set selected channel
    nRFAPI_SetChannel(channel);

    // set Tx power
    nRFAPI_SetTxPower(3);

    // flush FIFOs
    nRFAPI_FlushRX();
    nRFAPI_FlushTX();

    nRFAPI_SetRxMode(0);

    if(features != 0)
        nRFAPI_SetFeatures(features);

    return 1;
}
コード例 #6
0
ファイル: authentication.c プロジェクト: bomma/openbeacon
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);
}
コード例 #7
0
ファイル: nRF_CMD.c プロジェクト: KhMassri/DTNWorkspace
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);
}
コード例 #8
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;
}
コード例 #9
0
ファイル: main_tx.c プロジェクト: KhMassri/DTNWorkspace
int
main (void)
{
/* accelerometer readings fifo */
		TFifoEntry acc_lowpass;
		TFifoEntry fifo_buf[FIFO_DEPTH];
		int fifo_pos;
		TFifoEntry *fifo;

		uint32_t SSPdiv;
		uint16_t oid_last_seen;
		uint8_t cmd_buffer[64], cmd_pos, c;
		uint8_t volatile *uart;
		int x, y, z, moving;
		volatile int t;
		int i;

		/* wait on boot - debounce */
		for (t = 0; t < 2000000; t++);

		/* Initialize GPIO (sets up clock) */
		GPIOInit ();

		/* initialize pins */
		pin_init ();

		/* fire up LED 1 */
		GPIOSetValue (1, 1, 1);

		/* initialize SPI */
		spi_init ();

		/* read device UUID */
		bzero (&device_uuid, sizeof (device_uuid));
		iap_read_uid (&device_uuid);
		tag_id = crc16 ((uint8_t *) & device_uuid, sizeof (device_uuid));
		random_seed =
				device_uuid[0] ^ device_uuid[1] ^ device_uuid[2] ^ device_uuid[3];

		/************ IF Plugged to computer upon reset ? ******************/
		if (GPIOGetValue (0, 3))
		{
			/* wait some time till Bluetooth is off */
			for (t = 0; t < 2000000; t++);

			/* Init 3D acceleration sensor */
			acc_init (1);
			/* Init Flash Storage with USB */
			storage_init (TRUE, tag_id);
			g_storage_items = storage_items ();

			/* Init Bluetooth */
			bt_init (TRUE, tag_id);

			/* switch to LED 2 */
			GPIOSetValue (1, 1, 0);
			GPIOSetValue (1, 2, 1);

			/* set command buffer to empty */
			cmd_pos = 0;

			/* spin in loop */
			while (1)
			{
				/* reset after USB unplug */
				if (!GPIOGetValue (0, 3))
					NVIC_SystemReset ();

				/* if UART rx send to menue */
				if (UARTCount)
				{
					/* blink LED1 upon Bluetooth command */
					GPIOSetValue (1, 1, 1);
					/* execute menue command with last character received */

					/* scan through whole UART buffer */
					uart = UARTBuffer;
					for (i = UARTCount; i > 0; i--)
					{
						UARTCount--;
						c = *uart++;
						if ((c < ' ') && cmd_pos)
						{
							/* if one-character command - execute */
							if (cmd_pos == 1)
								main_menue (cmd_buffer[0]);
							else
							{
								cmd_buffer[cmd_pos] = 0;
								debug_printf
								("Unknown command '%s' - please press H+[Enter] for help\n# ",
										cmd_buffer);
							}

							/* set command buffer to empty */
							cmd_pos = 0;
						}
						else if (cmd_pos < (sizeof (cmd_buffer) - 2))
							cmd_buffer[cmd_pos++] = c;
					}

					/* reset UART buffer */
					UARTCount = 0;
					/* un-blink LED1 */
					GPIOSetValue (1, 1, 0);
				}
			}
		} /* End of if plugged to computer*/


		/***************** IF UNPLUGGED TO PC ........********/

		/* Init Bluetooth */
		bt_init (FALSE, tag_id);

		/* shut down up LED 1 */
		GPIOSetValue (1, 1, 0);

		/* Init Flash Storage without USB */
		storage_init (FALSE, tag_id);

		/* get current FLASH storage write postition */
		g_storage_items = storage_items ();

		/* initialize power management */
		pmu_init ();

		/* blink once to show initialized flash */
		blink (1);

		/* Init 3D acceleration sensor */
		acc_init (0);
		blink (2);

		/* Initialize OpenBeacon nRF24L01 interface */
		if (!nRFAPI_Init(CONFIG_TRACKER_CHANNEL, broadcast_mac, sizeof (broadcast_mac), 0))
			for (;;)
			{
				GPIOSetValue (1, 2, 1);
				pmu_sleep_ms (500);
				GPIOSetValue (1, 2, 0);
				pmu_sleep_ms (500);
			}
		/* set tx power power to high */
		nRFCMD_Power (1);

		/* blink three times to show flash initialized RF interface */
		blink (3);

		/* blink LED for 1s to show readyness */
		GPIOSetValue (1, 1, 0);
		GPIOSetValue (1, 2, 1);
		pmu_sleep_ms (1000);
		GPIOSetValue (1, 2, 0);

		/* disable unused jobs */
		SSPdiv = LPC_SYSCON->SSPCLKDIV;
		i = 0;
		oid_last_seen = 0;

		/* reset proximity buffer */
		prox_head = prox_tail = 0;
		bzero (&prox, sizeof (prox));

		/*initialize FIFO */
		fifo_pos = 0;
		bzero (&acc_lowpass, sizeof (acc_lowpass));
		bzero (&fifo_buf, sizeof (fifo_buf));

		moving = 0;
		g_sequence = 0;

		while (1)
		{
			
			pmu_sleep_ms (500);

			LPC_SYSCON->SSPCLKDIV = SSPdiv;
			acc_power (1);
			pmu_sleep_ms (20);
			acc_xyz_read (&x, &y, &z);
			acc_power (0);

			fifo = &fifo_buf[fifo_pos];
			if (fifo_pos >= (FIFO_DEPTH - 1))
				fifo_pos = 0;
			else
				fifo_pos++;

			acc_lowpass.x += x - fifo->x;
			fifo->x = x;
			acc_lowpass.y += y - fifo->y;
			fifo->y = y;
			acc_lowpass.z += z - fifo->z;
			fifo->z = z;


			nRFAPI_SetRxMode (0);

			bzero (&g_Beacon, sizeof (g_Beacon));
			g_Beacon.pkt.proto = RFBPROTO_BEACONTRACKER_EXT;
			g_Beacon.pkt.flags = moving ? RFBFLAGS_MOVING : 0;
			g_Beacon.pkt.oid = htons (tag_id);
			g_Beacon.pkt.p.tracker.strength = (i & 1) + TX_STRENGTH_OFFSET;
			g_Beacon.pkt.p.tracker.seq = htonl (LPC_TMR32B0->TC);
			g_Beacon.pkt.p.tracker.oid_last_seen = oid_last_seen;
			g_Beacon.pkt.p.tracker.time = htons ((uint16_t)g_sequence++);
			g_Beacon.pkt.p.tracker.battery = 0;
			g_Beacon.pkt.crc = htons (
					crc16(g_Beacon.byte, sizeof (g_Beacon) - sizeof (g_Beacon.pkt.crc))
					);

			nRFCMD_Power (0);
			nRF_tx (g_Beacon.pkt.p.tracker.strength);
			nRFCMD_Power (1);
			nRFAPI_PowerDown ();
			LPC_SYSCON->SSPCLKDIV = 0x00;
			blink (10);
		}
		

	
	return 0;
}