From 514b0f72f50b50b75ef855f008c888f29989d68e Mon Sep 17 00:00:00 2001 From: laforge Date: Wed, 20 Sep 2006 11:44:10 +0000 Subject: - Add OpenPICC register definition (and USB command handling) - Add automatic generation of include/compile.h with svn revision and compiletime - Add openpcd_compile_version structure to obtain version via USB - Move LED commands into new CMD_CLS_GENERIC family - Update TODO - Add support for large (2048 byte) request contexts in addition to 64byte - Shrink req_ctx size by collapsing rx and tx buffer into one - move definition of DFU_API_LOCATION to header file - Implement large req_ctx aware USB transmit / refill routines - Implement TX refilling for IRQ Endpoint - Print version information at startup time - move some generic req_ctx processing into usb_handler.c - Some further work on DFU (still not finished) - Only use '-Os' for DFU, use '-O2' for application code git-svn-id: https://svn.openpcd.org:2342/trunk@208 6dc7ffe9-61d6-0310-9af1-9938baff3ed1 --- firmware/src/picc/openpicc.c | 82 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 firmware/src/picc/openpicc.c (limited to 'firmware/src/picc/openpicc.c') diff --git a/firmware/src/picc/openpicc.c b/firmware/src/picc/openpicc.c new file mode 100644 index 0000000..7b2b5f2 --- /dev/null +++ b/firmware/src/picc/openpicc.c @@ -0,0 +1,82 @@ +/* Main state machine and register implementation for OpenPICC + * (C) 2006 by Harald Welte */ + +#include +#include +#include +#include +#include +#include + +#include "opicc_reg.h" + +/******************************************************************** + * OpenPICC Register set + ********************************************************************/ + +/* Our registers, including their power-up default values */ +static u_int16_t opicc_regs[_OPICC_NUM_REGS] = { + [OPICC_REG_14443A_UIDLEN] = 4, + [OPICC_REG_14443A_FDT0] = 1236, + [OPICC_REG_14443A_FDT1] = 1172, + [OPICC_REG_14443A_STATE] = ISO14443A_ST_POWEROFF, + [OPICC_REG_RX_CLK_DIV] = 32, + [OPICC_REG_RX_CLK_PHASE] = 0, + [OPICC_REG_RX_CONTROL] = 0, + [OPICC_REG_TX_CLK_DIV] = 16, + [OPICC_REG_TX_CONTROL] = 0, + [OPICC_REG_RX_COMP_LEVEL] = 0, +}; + +u_int16_t opicc_reg_read(enum opicc_reg reg) +{ + if (reg < _OPICC_NUM_REGS) + return opicc_regs[reg]; + return 0; +} + +void opicc_reg_write(enum opicc_reg reg, u_int16_t val) +{ + if (reg < _OPICC_NUM_REGS) + opicc_regs[reg] = val; + return; +} + +/******************************************************************** + * OpenPICC USB Commandset (access to register set, ...) + ********************************************************************/ + +static int opicc_reg_usb_in(struct req_ctx *rctx) +{ + struct openpcd_hdr *poh = (struct openpcd_hdr *) &rctx->data[0]; + u_int16_t *val16 = (u_int16_t *) poh->data; + + poh->val = 0; + rctx->tot_len = sizeof(*poh); + + switch (poh->cmd) { + case OPENPCD_CMD_PICC_REG_READ: + *val16 = opicc_reg_read(poh->reg); + rctx->tot_len += sizeof(u_int16_t); + poh->flags |= OPENPCD_FLAG_RESPOND; + break; + case OPENPCD_CMD_PICC_REG_WRITE: + if (rctx->tot_len < sizeof(*poh) + sizeof(u_int16_t)) { + poh->flags = OPENPCD_FLAG_ERROR; + } + opicc_reg_write(poh->reg, *val16); + break; + default: + return USB_ERR(USB_ERR_CMD_UNKNOWN); + } + + if (poh->flags & OPENPCD_FLAG_RESPOND) + return USB_RET_RESPOND; + + return 0; +} + +void opicc_usbapi_init(void) +{ + usb_hdlr_register(&opicc_reg_usb_in, OPENPCD_CMD_CLS_PICC); +} -- cgit v1.2.3