1 /* AT91SAM7 "presence reader" firmware for OpenPCD
3 * (C) 2006 by Milosch Meriac <meriac@openpcd.de>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <lib_AT91SAM7.h>
24 #include <librfid/rfid_layer2_iso14443a.h>
28 #include <os/pcd_enumerate.h>
29 #include <os/usb_handler.h>
30 #include <pcd/rc632_highlevel.h>
32 #include <librfid/rfid_reader.h>
33 #include <librfid/rfid_layer2.h>
35 #include "../openpcd.h"
40 u_int32_t delay_scan,delay_blink,last_uid,last_polled_uid;
41 static struct rfid_reader_handle *rh;
42 static struct rfid_layer2_handle *l2h;
44 static int usb_presence_rx(struct req_ctx *rctx)
46 struct openpcd_hdr *poh = (struct openpcd_hdr *) rctx->data;
50 case OPENPCD_CMD_PRESENCE_UID_GET:
51 DEBUGPCRF("get presence UID");
53 poh->flags |= OPENPCD_FLAG_RESPOND;
57 poh->data[0]=(u_int8_t)(last_polled_uid>>24);
58 poh->data[1]=(u_int8_t)(last_polled_uid>>16);
59 poh->data[2]=(u_int8_t)(last_polled_uid>> 8);
60 poh->data[3]=(u_int8_t)(last_polled_uid );
66 return USB_ERR(USB_ERR_CMD_UNKNOWN);
70 if (poh->flags & OPENPCD_FLAG_RESPOND)
71 return USB_RET_RESPOND;
78 DEBUGPCRF("enabling RC632");
81 DEBUGPCRF("turning on RF");
82 rc632_turn_on_rf(RAH);
84 DEBUGPCRF("initializing 14443A operation");
85 rh = rfid_reader_open(NULL, RFID_READER_OPENPCD);
86 l2h = rfid_layer2_init(rh, RFID_LAYER2_ISO14443A);
88 DEBUGPCRF("registering USB handler");
89 usb_hdlr_register(&usb_presence_rx, OPENPCD_CMD_CLS_PRESENCE);
91 delay_scan=delay_blink=0;
95 int _main_dbgu(char key)
101 AT91F_DBGU_Printk("Testing RC632 : ");
102 if (rc632_test(RAH) == 0)
103 AT91F_DBGU_Printk("SUCCESS!\n\r");
105 AT91F_DBGU_Printk("ERROR!\n\r");
109 opcd_rc632_reg_read(RAH, RC632_REG_RX_WAIT, &value);
110 DEBUGPCR("Reading RC632 Reg RxWait: 0x%02xr", value);
114 DEBUGPCR("Writing RC632 Reg RxWait: 0x55");
115 opcd_rc632_reg_write(RAH, RC632_REG_RX_WAIT, 0x55);
125 void _main_func(void)
130 status = rfid_layer2_open(l2h);
131 if (status >= 0 && l2h->uid_len==4)
133 uid=((u_int32_t)l2h->uid[0]) |
134 ((u_int32_t)l2h->uid[1])<< 8|
135 ((u_int32_t)l2h->uid[2])<<16|
136 ((u_int32_t)l2h->uid[3])<<24;
142 last_uid=last_polled_uid=uid;
145 DEBUGPCR("UID:0x%08X", uid);
154 led_switch(1,(delay_blink==0)?1:0);
158 /* first we try to get rid of pending to-be-sent stuff */
160 /* next we deal with incoming reqyests from USB EP1 (OUT) */