Example #1
0
	void Rfid::init_rfid(void)
	{
		if(geteuid()!=0 || getenv("FAKEROOTKEY"))
		{
			(*_pLinkToConsole)->printOut("You need to be root to properly run this program");
			throw "You need to be root to properly run this program";
		}
		if(!bcm2835_init())
		{
			(*_pLinkToConsole)->printOut("Not able to initialize BCM2835");
			throw "Not able to initialize BCM2835";
		}

		bcm2835_spi_begin();
		bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);	// default
		bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);					// default
		bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_32);	// default
		bcm2835_spi_chipSelect(BCM2835_SPI_CS0);					// default
		bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW);	// default

		/*
		uid_t uid=500;
		setuid(uid);
		*/

		InitRc522();
	}
Example #2
0
void init_RFID()
{
	uint8_t gpio=255;
	uint32_t spi_speed=10000000L;
	if (HW_init(spi_speed,gpio)) fprintf(stderr, "HW init failure\n"); // Если не удалось инициализировать RC522 выходим.
	InitRc522();
}
Example #3
0
/****************************************************************************************
 rfid处理程序
****************************************************************************************/
void rfid_proc_task(void *pdata)
{
	u8  err;
    
	pdata = pdata;
	rfid_gpio_init();
	for( port_id = 0 ; port_id < MAX_RFID_CNT ; port_id++ )
		InitRc522();
	while(1)
    {
    	RC522();
        OSTimeDly(5);
		OSFlagPost(TaskCheckOSFlag,OSFLAG_RFID_PROC_TASK,OS_FLAG_SET,&err);
    }
}
Example #4
0
int main(void)
{		
//	u8 x=0;
	unsigned char status;
	u8 Data[16];
	u8 i;
	u8 k=0;//读写错误重试次数
	u8 j;
	
  
	USART1_Config();
	//printf("USART1_Config success\n");
	SysTick_Init();
	
	//printf("SysTick_Init success\n");
	SPI_FLASH_Init();
	//printf("SPI_FLASH_Init success\n");
	InitRc522();				
	//printf("InitRc522 success\n");
	TIM3_PWM_Init();
	//printf("TIM3_PWM_Init success\n");
	GPIO_OUT_Init();
	//NVIC_Configuration();
	EXTI_PB1_Config();
	EXTI_PB2_Config();
	BEEP_Init();
	beep_ok();
	
  	while(1) 
{	
		
			status = PcdRequest(PICC_REQIDL,CT);/*扫描卡*/
			status = PcdAnticoll(SN);/*防冲撞*/
			//printf("%d",status);
			if (status==MI_OK)
			{
				k=0;
				sn=((SN[0]<<24)|(SN[1]<<16)|(SN[2]<<8)|(SN[3]));
				//printf("MI_OK\n");
				//printf("%x\n",sn);
				
				if((sn==YANGCHENGUANG)||(sn==LIUZHIYU)||(sn==CHENDUYU)||(sn==WUPENG)||(sn==BLUECARD))
				{
					//printf("OPEN DOOR\n");
					beep_ok();
					opendoor();
				}
				
			}
			else
			{
				k++;
				if((k++)>20)
				{
					SPI_FLASH_Init();
					//printf("SPI_FLASH_Init success\n");
					Reset_RC522();
					//printf("InitRc522 success\n");
					k=0;
				}
			}
			delay_ms(100);
	}
}