资源简介
维根协议驱动程序,linux平台下测试可用,采用中断方式读取数据,RFID学习必备,助你快速搞定RFID驱动
代码片段和文件信息
/*wiegand 协议驱动代码*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define WIEGAND_MAJOR 243
//delay 33ms to convert data
#define TIMER_DELAY HZ/30
#define DEVICE_NAME “wiegand“
bool TIMEER_FLAG = false;
bool RF_OPEN_FLAG = false;
struct wiegand_dev
{
char wiegand[26]; //Wiegand Data 26Bits
int hid;
int pid;
//unsigned char state;
int count; //Global Counter
struct cdev cdev;
struct semaphore sem;
struct completion receive_completion;
struct timer_list wiegand_timer;
};
static struct wiegand_dev *rf_card;
//应该除了初始化外,只能有这一个地方能够将rf_card->count置为0,其余地方置为0皆不合法
static char convert_data(void)
{
int ievenodd;
//奇校验
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<=12;i++)//hid转换
rf_card->hid = rf_card->hid << 1 |rf_card->wiegand[i];
rf_card->pid = 0;
for(i = 13 ;i<=25;i++)//pid转换
rf_card->pid = rf_card->pid << 1 |rf_card->wiegand[i];
rf_card->count = 0;
return 0;
error:
printk(“Parity Efficacy Error!\n“);
return -1;
}
static void wiegand_do_timer(unsigned long arg)
{
printk(“%s:wait wieg_data completed\n“__func__);
wait_for_completion(&(rf_card->receive_completion));//等待维根数据传送完毕才进行转换
disable_irq(IRQ_EINT(17));
disable_irq(IRQ_EINT(18));//防止wieg_data在转换期间发生变化
convert_data();
up(&rf_card->sem);
printk(“%s:complete convert wieg_datahid = %dpid = %d \n“__func__rf_card->hidrf_card->pid);
TIMEER_FLAG = false;
enable_irq(IRQ_EINT(17));
enable_irq(IRQ_EINT(18));
}
static void enable_irqs(void)
{
enable_irq(IRQ_EINT(17));
enable_irq(IRQ_EINT(18));
printk(“%s:the irq is setup!\n“__func__);
}
static irqreturn_t wiegand_irq0(int irq void *dev_id)
{
disable_irq_nosync(IRQ_EINT(17));
printk(“%s:IN\n“__func__);
udelay(5);
if(gpio_get_value(S3C64XX_GPL(9)) == 0)
{
rf_card->wiegand[rf_card->count] = 0;
printk(“%s:wiegand[%d] = %d\n“__func__rf_card->countrf_card->wiegand[rf_card->count]);
rf_card->count ++;
udelay(300);
}
else
goto end;
enable_irq(IRQ_EINT(17));
if(rf_card->count == 1)
init_completion(&(rf_card->receive_completion));
else i
相关资源
- 用Beckhoff(倍福)PLC读写巴鲁夫RFID
- uboot到linux logo显示不间断 补丁
- UNIX/LINUX编程实践教程的源码
- Linux任务管理器
- linux应用层的华容道游戏源代码
- ubuntu9.10 可加载内核模块和字符设备驱
- MP3文件ID3v2ID3v2APEv2标签读取
- 操作系统实验——虚存管理实验
- linux下的发包工具sendip
- 尚观培训linux许巍关于c 的笔记和讲义
- 尚观培训linux董亮老师关于数据结构的
- linux 线程池源码 c 版
- linux C 电梯程序练习
- linux下用多进程同步方法解决生产者
- Linux 操作系统实验(全)
- Linux From Scratch 中文手册
- linux 网络实验 ftp程序
- Linux命令大全离线版&在线版
- 操作系统共享内存实验
- dos 下运行Linux 命令--gnu_utils
- linux 0.12内核源代码
- linux简易shell C实现
- linux实验报告及心得体会
- 基于GTK的Linux环境下的简易任务管理器
- linux扫雷游戏代码
- CAN Linux驱动代码
- Linux系统教材
- intel 82579LM 网卡驱动Linux系统版 v1.9.
- SA1110处理器掌上电脑液晶显示器设计
- 基于Linux的串口服务器设计
评论
共有 条评论