示例#1
0
static inline void
rfid_init_emulator (void)
{
	/* enable timer 32_0 */
	LPC_SYSCON->SYSAHBCLKCTRL |= EN_CT32B0;
	/* reset and stop counter */
	LPC_TMR32B0->TCR = 0x02;
	LPC_TMR32B0->TCR = 0x00;
	/* enable CT32B0_CAP0 timer clock */
	LPC_IOCON->PIO1_5 = 0x02;
	/* no capturing */
	LPC_TMR32B0->CCR = 0x00;
	/* no match */
	LPC_TMR32B0->MCR = 0;
	LPC_TMR32B0->EMR = 0;
	LPC_TMR32B0->PWMC = 0;
	/* incremented upon CAP0 input rising edge */
	LPC_TMR32B0->CTCR = 0x01;
	/* disable prescaling */
	LPC_TMR32B0->PR = 0;
	/* run counter */
	LPC_TMR32B0->TCR = 0x01;

	/* enable RxMultiple mode */
	rfid_write_register (0x6303, 0x0C);
	/* disable parity for TX/RX */
	rfid_write_register (0x630D, 0x10);

	/* enable SVDD switch */
	rfid_write_register (0x6306, 0x2F);
	rfid_write_register (0x6307, 0x03);
	rfid_write_register (0x6106, 0x10);
	/* enable secure clock */
	rfid_write_register (0x6330, 0x80);
	rfid_write_register (0x6104, 0x00);
	/* output envelope to AUX1 */
#if 1
	rfid_write_register (0x6321, 0x34);
	rfid_write_register (0x6322, 0x0E);
#else
	rfid_write_register (0x6321, 0x32);
	rfid_write_register (0x6322, 0x02);
#endif
	rfid_write_register (0x6328, 0xF9);

	/* WTF? FIXME !!! */
	LPC_SYSCON->SYSAHBCLKCTRL |= EN_CT32B0;
}
示例#2
0
static void
loop_rfid (void)
{
  int res;
  static unsigned char data[80];

  /* release reset line after 400ms */
  pmu_wait_ms (400);
  rfid_reset (1);
  /* wait for PN532 to boot */
  pmu_wait_ms (100);

  /* fully initialized */
  GPIOSetValue (LED_PORT, LED_BIT, LED_ON);

  /* read firmware revision */
  debug_printf ("\nreading firmware version...\n");
  data[0] = PN532_CMD_GetFirmwareVersion;
  while ((res = rfid_execute (&data, 1, sizeof (data))) < 0)
  {
    debug_printf ("Reading Firmware Version Error [%i]\n", res);
    pmu_wait_ms (450);
    GPIOSetValue (LED_PORT, LED_BIT, LED_ON);
    pmu_wait_ms (10);
    GPIOSetValue (LED_PORT, LED_BIT, LED_OFF);
  }

  debug_printf ("PN532 Firmware Version: ");
  if (data[1] != 0x32)
    rfid_hexdump (&data[1], data[0]);
  else
    debug_printf ("v%i.%i\n", data[2], data[3]);

  /* enable debug output */
  debug_printf ("\nenabling debug output...\n");
  rfid_write_register (0x6328, 0xFC);
  // select test bus signal
  rfid_write_register (0x6321, 6);
  // select test bus type
  rfid_write_register (0x6322, 0x07);

  /* enable debug output */
  GPIOSetValue (LED_PORT, LED_BIT, LED_ON);
  while (1)
    {
      /* wait 10ms */
      pmu_wait_ms (10);

      /* detect cards in field */
      data[0] = PN532_CMD_InListPassiveTarget;
      data[1] = 0x01;		/* MaxTg - maximum cards    */
      data[2] = 0x00;		/* BrTy - 106 kbps type A   */
      if (((res = rfid_execute (&data, 3, sizeof (data))) >= 11) && (data[1]
								     == 0x01)
	  && (data[2] == 0x01))
	{
	  GPIOSetValue (LED_PORT, LED_BIT, LED_ON);
	  pmu_wait_ms (50);
	  GPIOSetValue (LED_PORT, LED_BIT, LED_OFF);

	  debug_printf ("card id: ");
	  rfid_hexdump (&data[7], data[6]);
	}
      else
	{
	  GPIOSetValue (LED_PORT, LED_BIT, LED_ON);
	  if (res != -8)
	    debug_printf ("PN532 error res=%i\n", res);
	}

      /* turning field off */
      data[0] = PN532_CMD_RFConfiguration;
      data[1] = 0x01;		/* CfgItem = 0x01           */
      data[2] = 0x00;		/* RF Field = off           */
      rfid_execute (&data, 3, sizeof (data));
    }
}