bool pn532_bus_i2c_WaitForReady(uint32_t timeout)
{
  uint8_t busy = 1;
  uint8_t busyTimeout = 0;

  if (timeout)
  {
    /* Wait up to the specified number of ms for the IRQ */
    while (busy)
    {
      busy = GPIOGetPinValue(CFG_PN532_I2C_IRQPORT, CFG_PN532_I2C_IRQPIN);
      systickDelay(1);
      busyTimeout++;
      if (busyTimeout == PN532_I2C_READYTIMEOUT)
      {
         return false;
       }
    }
  }
  else
  {
    /* Wait forever for the IRQ */
    while (busy)
    {
      busy = GPIOGetPinValue(CFG_PN532_I2C_IRQPORT, CFG_PN532_I2C_IRQPIN);
      systickDelay(1);
    }
  }

  return true;
}
示例#2
0
文件: main.c 项目: ipTronix/SmartTool
int main(void) {

	if (GPIOGetPinValue( PIN_ISP ) == 0)
	{
		ReinvokeISP();
	}
	/* Prepare the hardware to run this demo. */
	prvSetupHardware();

	xTaskCreate(ui_task,                                /* The function that implements the task. */
				( signed char * ) "UI",                 /* The text name assigned to the task - for debug only as it is not used by the kernel. */
				200,                                    /* The size of the stack to allocate to the task. */
				NULL,                                   /* The parameter passed to the task - just to check the functionality. */
				tskIDLE_PRIORITY,                       /* The priority assigned to the task. */
				NULL );

	xTaskCreate(nfc_task,                                /* The function that implements the task. */
				( signed char * ) "NFC",                /* The text name assigned to the task - for debug only as it is not used by the kernel. */
				500,                                    /* The size of the stack to allocate to the task. */
				NULL,                                   /* The parameter passed to the task - just to check the functionality. */
				tskIDLE_PRIORITY,                       /* The priority assigned to the task. */
				NULL );

	xUIQueue = xQueueCreate(1,sizeof(secure_payload_sample_t));

	/* Start the tasks and timer running. */
	vTaskStartScheduler();

	/* If all is well, the scheduler will now be running, and the following
	line will never be reached.  If the following line does execute, then
	there was insufficient FreeRTOS heap memory available for the idle and/or
	timer tasks	to be created.  See the memory management section on the
	FreeRTOS web site for more details. */
	for( ;; );
}
示例#3
0
文件: gpio.cpp 项目: Penta-/eXodusino
int digitalRead(int pin)
{
	volatile int readValue;
	if(pin < 100) return 0;	//(20~99:reserved)

	if(pin < 200)			//maryPinAssign(100~199?)
	{
		pin = pin - 100;
		readValue = GPIOGetPinValue(xpresso_pinAssign[pin * 2], xpresso_pinAssign[pin * 2 + 1]);
		return readValue;
	}
	return 0;
}
示例#4
0
文件: main.c 项目: ipTronix/SmartTool
static void prvSetupHardware( void )
{

	SystemCoreClockUpdate();

    // enable clock to RAM1
	LPC_SYSCON->SYSAHBCLKCTRL |= (1<<26);

	// init GPIO
	GPIOInit();

	// init I2C
	I2CInit(I2CMASTER);

	//init ADC
	ADCInit(ADC_CLK);

	// init SPI ports
	SSP_IOConfig( 0 );
	SSP_Init( 0 );
	SSP_IOConfig( 1 );
	SSP_Init( 1 );

	if (GPIOGetPinValue( PIN_CAL_DET ))
	{
		m_eAppCFGStatus = appANTENNA_CAL;

		// init CLKOUT pin
		LPC_IOCON->PIO0_1=1;        // enable CLKOUT
		LPC_SYSCON->CLKOUTSEL=3;    // select main clock
		LPC_SYSCON->CLKOUTUEN=1;      // update clock source
		LPC_SYSCON->CLKOUTDIV=2;      // divide by 2
	}
	else
	{
		m_eAppCFGStatus = appNFC_KEYB_TEMP_SWITCH;

		// init keyboard
		CAP_KEY_Init();

		// init MOSFET pin
		LPC_IOCON->PIO1_25=0x90;
		GPIOSetDir(PIN_MOSFET,1);
	}

}
U8 chb_set_state(U8 state)
{
    U8 curr_state, delay;

    // if we're sleeping then don't allow transition
    if (GPIOGetPinValue(CFG_CHIBI_SLPTRPORT, CFG_CHIBI_SLPTRPIN))
    {
        return RADIO_WRONG_STATE;
    }

    // if we're in a transition state, wait for the state to become stable
    curr_state = chb_get_state();
    if ((curr_state == BUSY_TX_ARET) || (curr_state == BUSY_RX_AACK) || (curr_state == BUSY_RX) || (curr_state == BUSY_TX))
    {
        while (chb_get_state() == curr_state);
    }

    // At this point it is clear that the requested new_state is:
    // TRX_OFF, RX_ON, PLL_ON, RX_AACK_ON or TX_ARET_ON.
    // we need to handle some special cases before we transition to the new state
    switch (state)
    {
    case TRX_OFF:
        /* Go to TRX_OFF from any state. */
        CHB_SLPTR_DISABLE();
        chb_reg_read_mod_write(TRX_STATE, CMD_FORCE_TRX_OFF, 0x1f);
        chb_delay_us(TIME_ALL_STATES_TRX_OFF);
        break;

    case TX_ARET_ON:
        if (curr_state == RX_AACK_ON)
        {
            /* First do intermediate state transition to PLL_ON, then to TX_ARET_ON. */
            chb_reg_read_mod_write(TRX_STATE, CMD_PLL_ON, 0x1f);
            chb_delay_us(TIME_RX_ON_PLL_ON);
        }
        break;

    case RX_AACK_ON:
        if (curr_state == TX_ARET_ON)
        {
            /* First do intermediate state transition to RX_ON, then to RX_AACK_ON. */
            chb_reg_read_mod_write(TRX_STATE, CMD_PLL_ON, 0x1f);
            chb_delay_us(TIME_RX_ON_PLL_ON);
        }
        break;
    }

    /* Now we're okay to transition to any new state. */
    chb_reg_read_mod_write(TRX_STATE, state, 0x1f);

    /* When the PLL is active most states can be reached in 1us. However, from */
    /* TRX_OFF the PLL needs time to activate. */
    delay = (curr_state == TRX_OFF) ? TIME_TRX_OFF_PLL_ON : TIME_RX_ON_PLL_ON;
    chb_delay_us(delay);

    if (chb_get_state() == state)
    {
        return RADIO_SUCCESS;
    }
    return RADIO_TIMED_OUT;
}
示例#6
0
uint8_t swspiTransferByte(swspi_config_t *config, uint8_t byte)
{
  int8_t i, b;
  uint8_t output = 0x00;

  // ToDo: This can be significantly optimised by only checking the
  // mode once and writing optimised code for each of the four modes
  // Current code yields <1MHz @ 72MHz!
  for (i=8; i>0; i--)
  {
    // Drive SCK early for CPHA = 1
    if (config->cpha)
    {
      // Drive SCK low if CPOL == 1, high if CPOL == 0
      if (config->cpol)
      {
        LPC_GPIO->CLR[config->sck_port] = (1 << config->sck_pin);
      }
      else
      {
        LPC_GPIO->SET[config->sck_port] = (1 << config->sck_pin);
      }
      if (config->sck_delay)
      {
        swspiDelay(config->sck_delay);
      }
    }

    // Write current bit
    if (byte & (1 << (i-1)))
    {
      LPC_GPIO->SET[config->mosi_port] = (1 << config->mosi_pin);
    }
    else
    {
      LPC_GPIO->CLR[config->mosi_port] = (1 << config->mosi_pin);
    }

    // Mid SCK
    if (config->cpha)
    {
      // Drive SCK high if CPOL == 1, low if CPOL == 0
      if (config->cpol)
      {
        LPC_GPIO->SET[config->sck_port] = (1 << config->sck_pin);
      }
      else
      {
        LPC_GPIO->CLR[config->sck_port] = (1 << config->sck_pin);
      }
    }
    else
    {
      // Drive SCK low if CPOL == 1, high if CPOL = 0
      if (config->cpol)
      {
        LPC_GPIO->CLR[config->sck_port] = (1 << config->sck_pin);
      }
      else
      {
        LPC_GPIO->SET[config->sck_port] = (1 << config->sck_pin);
      }
    }
    if (config->sck_delay)
    {
      swspiDelay(config->sck_delay);
    }

    // Read current bit and shift it into output at the appropriate location
    b = GPIOGetPinValue(config->miso_port, config->miso_pin);
    output |= ((b & 0x01) << (i-1));

    // Drive SCK later for CPHA = 0
    if (!(config->cpha))
    {
      // Drive SCK high if CPOL == 1, low if CPOL == 0
      if (config->cpol)
      {
        LPC_GPIO->SET[config->sck_port] = (1 << config->sck_pin);
      }
      else
      {
        LPC_GPIO->CLR[config->sck_port] = (1 << config->sck_pin);
      }
      if (config->sck_delay)
      {
        swspiDelay(config->sck_delay);
      }
    }
  }

  return output;
}
示例#7
0
文件: main.c 项目: ipTronix/SmartTool
void cal_task( void * data)
{
	// initialize LCD
	lcd_clear_all();
	lcd_init();
	lcd_led_power(1);

	// draw splash screen
	lcd_text(32,10,3,"NFC",0);
	lcd_text(12,40,1,"ipTronix   Arrow   NXP",0);
	lcd_update(0,63);

	// initialize pll
	Si5351_Initialize();

	// prepare new screen during splash wait
	lcd_clear_all();
	lcd_vert_line(10,63,64);
	vTaskDelay(500);

	// application main loop
	for (;;)
	{
		int i;
		int max = 0;
		int maxval = 0;
		for (i=0;i<128;i++)
		{
			Si5351_OutputFrequency((9560000+i*8000000/128)*25/24);
			lcd_update(0,63);
			vTaskDelay(1);
			samples[i] = ADCRead(3);
			if (i!=64)
				lcd_clear_area(i,10,i,63);
			lcd_vert_line(63-samples[i]*51/1023,63,i);
			if (maxval<samples[i])
			{
				maxval = samples[i];
				max = i;
			}

			if (GPIOGetPinValue( PIN_ISP ) == 0)
			{
				lcd_clear_all();
				lcd_text(52,26,2,"ISP",0);
				lcd_update(0,63);
				NVIC_SystemReset();
			}
			if (GPIOGetPinValue( PIN_CAL_DET ) == 0)
			{
				NVIC_SystemReset();
			}
		}
		char str[20];
		float freq= 9.56+(float)max*8/128;
		sprintf(str,"fmax = %2d.%03d MHz",(int)freq,((int)(freq*1000))%1000);
		lcd_text(0, 0 , 0, str, 0);
		lcd_update(0,63);
		vTaskDelay(1500);
		lcd_clear_all();
		lcd_vert_line(10,63,64);
	}

}
示例#8
0
文件: main.c 项目: ipTronix/SmartTool
void ui_task( void * data)
{
	int i;
	portBASE_TYPE res;
	int count = 10;
	char acTempStr[20];
	uint8_t acTemp[2];
	uint8_t bMosfetEnabled = 0;

	// init LCD;
	lcd_clear_all();
	lcd_init();
	lcd_led_power(1);
	//lcd_test(0);
	lcd_text(32,10,3,"NFC",0);
	lcd_text(12,40,1,"ipTronix   Arrow   NXP",0);
	lcd_update(0,63);

	lcd_clear_all();
	vTaskDelay(1500);

	lcd_clear_all();

	for (;;)
	{
		KEY_EVENT_t key;
		char str[30];
		lcd_text(12,10,1,"Please approach card",0);

		lcd_update(0,63);

		do
		{
			res = xQueueReceive(xUIQueue,&taginfo,/*portMAX_DELAY*/20);
			key=CAP_KEY_GetEvent();
			count++;
			if ((count >= 3) && (res!= pdPASS))
			{
				count = 0;
				I2CRead(0x90,0,&acTemp[0],2);
				sprintf(acTempStr,"Temperature %d",acTemp[0]);
				lcd_text(12,27,1,acTempStr,0);
				sprintf(acTempStr,"Keys %d",keystate);
				lcd_text(28,46,2,acTempStr,0);
				lcd_update(0,63);
			}
			if (bMosfetEnabled)
			{
				bMosfetEnabled = 0;
				GPIOSetBitValue(PIN_MOSFET,0);
			}
			else
			{
				bMosfetEnabled = 1;
				GPIOSetBitValue(PIN_MOSFET,1);
			}

			if (GPIOGetPinValue( PIN_ISP ) == 0)
			{
				lcd_clear_all();
				lcd_text(52,26,2,"ISP",0);
				lcd_update(0,63);
				NVIC_SystemReset();
			}

			if (GPIOGetPinValue( PIN_CAL_DET ))
			{
				NVIC_SystemReset();
			}

		} while (res!= pdPASS) ;

		if (res == pdPASS)
		{
			lcd_clear_all();
			sprintf(str, "UID ");
			for (i=0;i<taginfo.szUidLen;i++)
			{
				sprintf(&str[4+i*2],"%02X",taginfo.abtUid[i]);
			}
			lcd_text(0,0,1,str,0);
			sprintf(str,"NDEF Len %d",taginfo.msgLen);
			lcd_text(0,12,1,str,0);
			snprintf(str,30,"MSG %s",taginfo.msg);
			lcd_text(0,24,1,str,0);
			lcd_update(0,63);
			vTaskDelay(1500);
			lcd_clear_all();
			count = 10;
		}
		lcd_update(0,63);

	}
}
示例#9
0
文件: main.c 项目: ipTronix/SmartTool
void ui_task( void * data)
{
	portBASE_TYPE res;
	m_eMode = mdAUTHENTICATE;
	// init LCD;
	lcd_clear_all();
	lcd_init();
	lcd_led_power(1);
	//lcd_test(0);
	lcd_text(32,10,3,"NFC",0);
	lcd_text(12,40,1,"ipTronix   Arrow   NXP",0);
	lcd_update(0,63);

	lcd_clear_all();
	vTaskDelay(1500);

	for (;;)
	{
		char str[30];
		lcd_clear_all();
		lcd_text(32,0,1,"Authentication",0);
		lcd_text(32,20,2,"Scan card",0);
		switch (m_eMode)
		{
			case mdAUTHENTICATE:
				lcd_text(10,40,2,"AUTHENTICATE",1);
				break;
			case mdAUTHORIZE:
				lcd_text(22,40,2,"AUTHORIZE",1);
				break;
			case mdDENY:
				lcd_text(42,40,2,"DENY",1);
				break;
		}
		lcd_update(0,63);


		do
		{
			key=CAP_KEY_GetEvent();
			res = xQueueReceive(xUIQueue,&payload,100);

			if (GPIOGetPinValue( PIN_ISP ) == 0)
			{
				lcd_clear_all();
				lcd_text(52,26,2,"ISP",0);
				lcd_update(0,63);
				NVIC_SystemReset();
			}
		} while ((key==keNONE) && (res!= pdPASS));
		if (key==keK3_PRESS || key==keK3_REPEAT)
		{
			if (m_eMode<mdDENY)
				m_eMode++;
			else
				m_eMode=mdAUTHENTICATE;
		}
		else if (key==keK1_PRESS || key==keK1_REPEAT)
		{
			if (m_eMode>mdAUTHENTICATE)
				m_eMode--;
			else
				m_eMode = mdDENY;
		}
		key=keNONE;

		if (res==pdPASS)
		{
			lcd_clear_all();
			snprintf(str, sizeof(payload.name),"Name %s", payload.name);
			lcd_text(0,20,2,str,0);
			sprintf(str,"Access %08X",payload.access_rights);
			lcd_text(0,40,2,str,0);
			lcd_update(0,63);
			if (payload.access_rights==0xffffffff)
				GPIOSetBitValue(PIN_MOSFET,1);
			vTaskDelay(1500);
			GPIOSetBitValue(PIN_MOSFET,0);
		}
	}

}