RK3288平台韦根接收

/*wiegand 协议接收驱动代码*/
#include <linux/module.h>
#include <linux/types.h>
#include <linux/fs.h>
#include <linux/errno.h>
#include <linux/mm.h>
#include <linux/sched.h>
#include <linux/init.h>
#include <linux/cdev.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/time.h>
#include <linux/device.h>
#include <linux/semaphore.h>
#include <linux/kernel.h>
#include <linux/uaccess.h>
#include <linux/gpio.h>
#include <linux/slab.h>
#define WIEGAND_MAJOR 243        
//delay 33ms to convert data
#define TIMER_DELAY HZ/8
#define DEVICE_NAME "wiegand" 
 
bool TIMEER_FLAG = false;   
bool RF_OPEN_FLAG = false;
static struct class *cdev_class; 
//dev_t dev = 0;

#define  D0_GPIO_NO  32*8+7-8  //gpio2_a7
#define  D1_GPIO_NO  32*8+1-8  //gpio2_b0

struct wiegand_dev
{
    char wiegand[26];    //Wiegand-26
    int hid;
    int pid;
    int count;    //Global Counter
    struct cdev cdev;
    struct semaphore sem;
    struct completion receive_completion;
    struct timer_list wiegand_timer;
    struct work_struct     pen_event_work;
    struct workqueue_struct *ts_workqueue;

    int gpio_d0;
    int gpio_d1;
    int d0_irq;
    int d1_irq;
    
};

static struct wiegand_dev *rf_card;


//应该除了初始化外,只能有这一个地方能够将rf_card->count置为0,其余地方置为0皆不合法
static char convert_data(void)
{
    int i,even,odd;
        int cardno ; 

    //偶校验
        even = 0;
        for(i = 1; i < 13;i++)
        {
         if(rf_card->wiegand[i] == 1)    
          even = (~even) & 0x01; 
        }
         if(even != rf_card->wiegand[0])
          {
        rf_card->count = 0;
        goto error;
          }    
    //奇校验  
        odd = 1;
        for(i = 13; i< 25;i++)
        {
        if(rf_card->wiegand[i] == 1)             
            odd = (~odd)& 0x01;          
         }
         if(odd != rf_card->wiegand[25])
          {
        rf_card->count = 0;
           goto error;
          }

    //奇偶校验通过
    rf_card->hid = 0;
    for(i = 1 ;i<=8;i++)//hid转换
        rf_card->hid =  rf_card->hid << 1 |rf_card->wiegand[i];    

    rf_card->pid = 0;
  

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值