From 6a189e6160b55368f9fcbf1982aa870e7399da6e Mon Sep 17 00:00:00 2001 From: laforge Date: Wed, 4 Oct 2006 17:49:08 +0000 Subject: add feature to write full register set git-svn-id: https://svn.openpcd.org:2342/trunk@259 6dc7ffe9-61d6-0310-9af1-9938baff3ed1 --- firmware/src/pcd/rc632.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'firmware/src/pcd') diff --git a/firmware/src/pcd/rc632.c b/firmware/src/pcd/rc632.c index 8513d2a..5287300 100644 --- a/firmware/src/pcd/rc632.c +++ b/firmware/src/pcd/rc632.c @@ -185,6 +185,8 @@ struct rc632 { #define RC632_F_FIFO_TX 0x0001 static struct rc632 rc632; +#define RC632_WRITE_ADDR(x) ((x << 1) & 0x7e) + /* RC632 access primitives */ int rc632_reg_write(struct rfid_asic_handle *hdl, @@ -194,7 +196,7 @@ int rc632_reg_write(struct rfid_asic_handle *hdl, DEBUG632("[0x%02x] <= 0x%02x", addr, data); - addr = (addr << 1) & 0x7e; + addr = RC632_WRITE_ADDR(addr); spi_outbuf[0] = addr; spi_outbuf[1] = data; @@ -203,6 +205,32 @@ int rc632_reg_write(struct rfid_asic_handle *hdl, return spi_transceive(spi_outbuf, 2, spi_inbuf, &rx_len); } +#define RC632_REGSET_START 0x10 +#define RC632_REGSET_END 0x3f +#define RC632_REGSET_MAXSIZE (RC632_REGSET_END-RC632_REGSET_START) +static char regset_buf[RC632_REGSET_MAXSIZE * 2]; + +int rc632_reg_write_set(struct rfid_asic_handle *hdl, + u_int8_t *regs, int len) +{ + u_int8_t i, j = 0; + u_int16_t rx_len; + + if (len > RC632_REGSET_MAXSIZE) + return -E2BIG; + + for (i = RC632_REGSET_START; i <= RC632_REGSET_END; i++) { + /* skip bank registers */ + if (i % 8 == 0) + continue; + regset_buf[j++] = RC632_WRITE_ADDR(i); + regset_buf[j++] = regs[i - RC632_REGSET_START]; + } + + rx_len = j; + return spi_transceive(regset_buf, j, spi_inbuf, &rx_len); +} + int rc632_fifo_write(struct rfid_asic_handle *hdl, u_int8_t len, u_int8_t *data, u_int8_t flags) { @@ -457,6 +485,10 @@ static int rc632_usb_in(struct req_ctx *rctx) DEBUGP("WRITE_REG(0x%02x, 0x%02x) ", poh->reg, poh->val); rc632_reg_write(RAH, poh->reg, poh->val); break; + case OPENPCD_CMD_WRITE_REG_SET: + DEBUGP("WRITE_REG_SET(%s) ", hexdump(poh->data, len)); + rc632_reg_write_set(RAH, poh->data, len); + break; case OPENPCD_CMD_WRITE_FIFO: DEBUGP("WRITE FIFO(len=%u): %s ", len, hexdump(poh->data, len)); -- cgit v1.2.3