From 5712116f1b4c47d0a7c3cf5e2c06318e4a763211 Mon Sep 17 00:00:00 2001 From: laforge Date: Sat, 24 May 2008 13:01:25 +0000 Subject: Follow-up fixes for IRQ/ERR bitmaks mess (Bjoern Riemer) Patch 011 git-svn-id: https://svn.gnumonks.org/trunk/librfid@2101 e0336214-984f-0b4b-a45f-81c69e1f0ede --- include/librfid/rfid_asic_rc632.h | 6 +++--- src/rfid_asic_rc632.c | 43 ++++++++++++++++++++++++++++++++------- src/rfid_layer2_iso14443a.c | 3 +++ 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/include/librfid/rfid_asic_rc632.h b/include/librfid/rfid_asic_rc632.h index d8adac7..3ca8469 100644 --- a/include/librfid/rfid_asic_rc632.h +++ b/include/librfid/rfid_asic_rc632.h @@ -60,7 +60,7 @@ struct rfid_asic_rc632 { const struct iso15693_anticol_cmd *acf, unsigned int acf_len, struct iso15693_anticol_resp *resp, - unsigned int *rx_len, char *bit_of_col); + unsigned int *rx_len, unsigned char *bit_of_col); } iso15693; struct { int (*setkey)(struct rfid_asic_handle *h, @@ -143,8 +143,8 @@ extern int rc632_register_dump(struct rfid_asic_handle *handle, u_int8_t *buf); DEBUGPC(", mTXsof"); \ DEBUGPC("\n"); } while (0); -#define DEBUGP_INTERRUPT_FLAG(foo) do {\ - DEBUGP("interrupt_flag: 0x%0.2x",foo); \ +#define DEBUGP_INTERRUPT_FLAG(txt,foo) do {\ + DEBUGP("%s: 0x%0.2x",txt,foo); \ if (foo & RC632_INT_HIALERT) \ DEBUGPC(", HiA"); \ if (foo & RC632_INT_LOALERT) \ diff --git a/src/rfid_asic_rc632.c b/src/rfid_asic_rc632.c index effe813..5a0f12f 100644 --- a/src/rfid_asic_rc632.c +++ b/src/rfid_asic_rc632.c @@ -240,7 +240,7 @@ rc632_timer_set(struct rfid_asic_handle *handle, u_int64_t timeout) { int ret; - u_int8_t prescaler, divisor; + u_int8_t prescaler, divisor, irq; timeout *= TIMER_RELAX_FACTOR; @@ -255,7 +255,10 @@ rc632_timer_set(struct rfid_asic_handle *handle, RC632_TMR_START_TX_END|RC632_TMR_STOP_RX_BEGIN); /* clear timer irq bit */ - ret = rc632_set_bits(handle, RC632_REG_INTERRUPT_RQ, RC632_IRQ_TIMER); + ret = rc632_clear_irqs(handle, RC632_IRQ_TIMER); + + /* enable timer IRQ */ + ret |= rc632_reg_write(handle, RC632_REG_INTERRUPT_EN, RC632_IRQ_SET | RC632_IRQ_TIMER); ret |= rc632_reg_write(handle, RC632_REG_TIMER_RELOAD, divisor); @@ -268,6 +271,18 @@ static int rc632_wait_idle_timer(struct rfid_asic_handle *handle) int ret; u_int8_t stat, irq, cmd; + ret = rc632_reg_read(handle, RC632_REG_INTERRUPT_EN, &irq); + if (ret < 0) + return ret; + DEBUGP_INTERRUPT_FLAG("irq_en",irq); + + ret = rc632_reg_write(handle, RC632_REG_INTERRUPT_EN, RC632_IRQ_SET + | RC632_IRQ_TIMER + | RC632_IRQ_IDLE + | RC632_IRQ_RX ); + if (ret < 0) + return ret; + while (1) { rc632_reg_read(handle, RC632_REG_PRIMARY_STATUS, &stat); DEBUGP_STATUS_FLAG(stat); @@ -278,17 +293,20 @@ static int rc632_wait_idle_timer(struct rfid_asic_handle *handle) if (err & (RC632_ERR_FLAG_COL_ERR | RC632_ERR_FLAG_PARITY_ERR | RC632_ERR_FLAG_FRAMING_ERR | - RC632_ERR_FLAG_CRC_ERR)) + /* FIXME: why get we CRC errors in CL2 anticol at iso14443a operation with mifare UL? */ + /* RC632_ERR_FLAG_CRC_ERR | */ + 0)) return -EIO; } if (stat & RC632_STAT_IRQ) { ret = rc632_reg_read(handle, RC632_REG_INTERRUPT_RQ, &irq); if (ret < 0) return ret; - DEBUGP_INTERRUPT_FLAG(irq); + DEBUGP_INTERRUPT_FLAG("irq_rq",irq); if (irq & RC632_IRQ_TIMER && !(irq & RC632_IRQ_RX)) { DEBUGP("timer expired before RX!!\n"); + rc632_clear_irqs(handle, RC632_IRQ_TIMER); return -ETIMEDOUT; } } @@ -297,8 +315,10 @@ static int rc632_wait_idle_timer(struct rfid_asic_handle *handle) if (ret < 0) return ret; - if (cmd == 0) + if (cmd == 0) { + rc632_clear_irqs(handle, RC632_IRQ_RX); return 0; + } /* poll every millisecond */ usleep(1000); @@ -333,7 +353,7 @@ rc632_wait_idle(struct rfid_asic_handle *handle, u_int64_t timeout) /* check if IRQ has occurred (IRQ flag set)*/ if (foo & RC632_STAT_IRQ) { ret = rc632_reg_read(handle, RC632_REG_INTERRUPT_RQ, &foo); - DEBUGP_INTERRUPT_FLAG(foo); + DEBUGP_INTERRUPT_FLAG("irq_rq",foo); /* clear all interrupts */ rc632_clear_irqs(handle, 0xff); } @@ -1578,6 +1598,12 @@ static struct register_file icode1_std_script[] = { }, { .reg = RC632_REG_CRC_PRESET_MSB, .val = 0xff, + /* }, { + .reg = RC632_REG_INTERRUPT_EN, + .val = RC632_INT_IDLE | + RC632_INT_TIMER | + RC632_INT_RX | + RC632_INT_TX, */ } }; @@ -1732,7 +1758,7 @@ rc632_iso15693_transceive_ac(struct rfid_asic_handle *handle, const struct iso15693_anticol_cmd *acf, unsigned int acf_len, struct iso15693_anticol_resp *resp, - unsigned int *rx_len, char *bit_of_col) + unsigned int *rx_len, unsigned char *bit_of_col) { u_int8_t error_flag, boc; //u_int8_t rx_len; @@ -1757,12 +1783,15 @@ rc632_iso15693_transceive_ac(struct rfid_asic_handle *handle, return ret; DEBUGP_ERROR_FLAG(error_flag); + //FIXME: check for framing and crc errors... if (error_flag & RC632_ERR_FLAG_COL_ERR) { /* retrieve bit of collission */ ret = rc632_reg_read(handle, RC632_REG_COLL_POS, &boc); if (ret < 0) return ret; *bit_of_col = boc; + } else { + *bit_of_col = 0; } return 0; diff --git a/src/rfid_layer2_iso14443a.c b/src/rfid_layer2_iso14443a.c index f2b3d26..98722f5 100644 --- a/src/rfid_layer2_iso14443a.c +++ b/src/rfid_layer2_iso14443a.c @@ -170,6 +170,7 @@ cascade: iso14443a_code_nvb_bits(&acf.nvb, 16); ret = iso14443a_transceive_acf(handle, &acf, &bit_of_col); + DEBUGP("tran_acf->%d boc: %d\n",ret,bit_of_col); if (ret < 0) return ret; @@ -198,6 +199,7 @@ cascade: switch (acf.sel_code) { case ISO14443A_AC_SEL_CODE_CL1: /* cascading from CL1 to CL2 */ + DEBUGP("cascading from CL1 to CL2\n"); if (acf.uid_bits[0] != 0x88) { DEBUGP("Cascade bit set, but UID0 != 0x88\n"); return -1; @@ -208,6 +210,7 @@ cascade: break; case ISO14443A_AC_SEL_CODE_CL2: /* cascading from CL2 to CL3 */ + DEBUGP("cascading from CL2 to CL3\n"); memcpy(&handle->uid[3], &acf.uid_bits[1], 3); acf.sel_code = ISO14443A_AC_SEL_CODE_CL3; h->level = ISO14443A_LEVEL_CL3; -- cgit v1.2.3