diff options
Diffstat (limited to 'firmware/src/picc')
-rw-r--r-- | firmware/src/picc/adc.c | 10 | ||||
-rw-r--r-- | firmware/src/picc/decoder.c | 2 | ||||
-rw-r--r-- | firmware/src/picc/main_openpicc.c | 5 | ||||
-rw-r--r-- | firmware/src/picc/openpicc.c | 82 | ||||
-rw-r--r-- | firmware/src/picc/opicc_reg.h | 18 | ||||
-rw-r--r-- | firmware/src/picc/pll.c | 1 | ||||
-rw-r--r-- | firmware/src/picc/ssc_picc.c | 21 |
7 files changed, 120 insertions, 19 deletions
diff --git a/firmware/src/picc/adc.c b/firmware/src/picc/adc.c index c78f89d..f350a49 100644 --- a/firmware/src/picc/adc.c +++ b/firmware/src/picc/adc.c @@ -74,7 +74,7 @@ static void adc_irq(void) if (sr & AT91C_ADC_ENDRX) { /* rctx full, get rid of it */ DEBUGADC("sending rctx (val=%s) ", - hexdump(rctx->tx.data[4], 2)); + hexdump(rctx->data[4], 2)); req_ctx_set_state(rctx, RCTX_STATE_UDP_EP2_PENDING); adc_state.state = ADC_NONE; @@ -115,8 +115,7 @@ u_int16_T adc_read_pll_dem(void) static int adc_usb_in(struct req_ctx *rctx) { - struct openpcd_hdr *poh = (struct openpcd_hdr *) &rctx->rx.data[0]; - struct openpcd_hdr *pih = (struct openpcd_hdr *) &rctx->tx.data[0]; + struct openpcd_hdr *poh = (struct openpcd_hdr *) &rctx->data[0]; switch (poh->cmd) { case OPENPCD_CMD_ADC_READ: @@ -129,9 +128,8 @@ static int adc_usb_in(struct req_ctx *rctx) adc_state.state = ADC_READ_CONTINUOUS_USB; adc_state.rctx = rctx; - memcpy(pih, poh, sizeof(*pih)); - rctx->tx.tot_len = sizeof(*pih) + poh->val * 2; - AT91F_PDC_SetRx(AT91C_BASE_PDC_ADC, rctx->rx.data, poh->val); + rctx->tot_len = sizeof(*poh) + poh->val * 2; + AT91F_PDC_SetRx(AT91C_BASE_PDC_ADC, rctx->data, poh->val); AT91F_PDC_EnableRx(AT91C_BASE_PDC_ADC); AT91F_ADC_EnableChannel(AT91C_BASE_ADC, OPENPICC_ADC_CH_FIELDSTR); AT91F_ADC_EnableIt(AT91C_BASE_ADC, AT91C_ADC_ENDRX | diff --git a/firmware/src/picc/decoder.c b/firmware/src/picc/decoder.c index ab77250..bdd910e 100644 --- a/firmware/src/picc/decoder.c +++ b/firmware/src/picc/decoder.c @@ -17,8 +17,6 @@ * */ - - #include <errno.h> #include <sys/types.h> #include <picc/decoder.h> diff --git a/firmware/src/picc/main_openpicc.c b/firmware/src/picc/main_openpicc.c index c8d2fd0..df754de 100644 --- a/firmware/src/picc/main_openpicc.c +++ b/firmware/src/picc/main_openpicc.c @@ -47,6 +47,7 @@ static u_int8_t load_mod = 0; void _init_func(void) { + /* low-level hardware initialization */ pio_irq_init(); pll_init(); poti_init(); @@ -57,6 +58,10 @@ void _init_func(void) adc_init(); ssc_rx_init(); // ssc_tx_init(); + + /* high-level protocol */ + decoder_init(); + opicc_usbapi_init(); AT91F_PIO_CfgInput(AT91C_BASE_PIOA, OPENPICC_PIO_BOOTLDR); } 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 <hwelte@hmw-consulting.de> */ + +#include <sys/types.h> +#include <openpcd.h> +#include <openpicc_regs.h> +#include <openpicc.h> +#include <os/req_ctx.h> +#include <os/usb_handler.h> + +#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); +} diff --git a/firmware/src/picc/opicc_reg.h b/firmware/src/picc/opicc_reg.h new file mode 100644 index 0000000..e77d157 --- /dev/null +++ b/firmware/src/picc/opicc_reg.h @@ -0,0 +1,18 @@ +#ifndef _OPCD_REG_H +#define _OPCD_REG_H + +#include <openpicc.h> +#include <sys/types.h> + +#ifdef DEBUG +u_int16_t opicc_reg_read(enum opicc_reg reg); +void opicc_reg_write(enum opicc_reg reg, u_int16_t val); +#else +u_int16_t opicc_regs[_OPICC_NUM_REGS]; +#define opicc_reg_read(x) (opicc_regs[x]) +#define opicc_reg_Write(x, y) (opicc_regs[x] = y) +#endif + +void opicc_usbapi_init(void); + +#endif diff --git a/firmware/src/picc/pll.c b/firmware/src/picc/pll.c index f98d171..7eb49a4 100644 --- a/firmware/src/picc/pll.c +++ b/firmware/src/picc/pll.c @@ -22,6 +22,7 @@ #include <lib_AT91SAM7.h> #include <os/pio_irq.h> #include <os/dbgu.h> +#include <os/led.h> #include "../openpcd.h" void pll_inhibit(int inhibit) diff --git a/firmware/src/picc/ssc_picc.c b/firmware/src/picc/ssc_picc.c index ea48de5..d4db71a 100644 --- a/firmware/src/picc/ssc_picc.c +++ b/firmware/src/picc/ssc_picc.c @@ -166,8 +166,8 @@ static struct openpcd_hdr opcd_ssc_hdr = { static inline void init_opcdhdr(struct req_ctx *rctx) { - memcpy(&rctx->tx.data[0], &opcd_ssc_hdr, sizeof(opcd_ssc_hdr)); - rctx->tx.tot_len = MAX_HDRSIZE + MAX_REQSIZE -1; + memcpy(rctx->data, &opcd_ssc_hdr, sizeof(opcd_ssc_hdr)); + rctx->tot_len = MAX_HDRSIZE + MAX_REQSIZE -1; } #ifdef DEBUG_SSC_REFILL @@ -191,7 +191,7 @@ static int8_t ssc_rx_refill(void) #if 1 struct req_ctx *rctx; - rctx = req_ctx_find_get(RCTX_STATE_FREE, RCTX_STATE_SSC_RX_BUSY); + rctx = req_ctx_find_get(1, RCTX_STATE_FREE, RCTX_STATE_SSC_RX_BUSY); if (!rctx) { DEBUGPCRF("no rctx for refill!"); return -1; @@ -200,12 +200,12 @@ static int8_t ssc_rx_refill(void) if (AT91F_PDC_IsRxEmpty(rx_pdc)) { DEBUGR("filling primary SSC RX dma ctx"); - AT91F_PDC_SetRx(rx_pdc, &rctx->rx.data[MAX_HDRSIZE], - (sizeof(rctx->rx.data)-MAX_HDRSIZE)>>2); + AT91F_PDC_SetRx(rx_pdc, &rctx->data[MAX_HDRSIZE], + (rctx->size-MAX_HDRSIZE)>>2); ssc_state.rx_ctx[0] = rctx; /* If primary is empty, secondary must be empty, too */ - rctx = req_ctx_find_get(RCTX_STATE_FREE, + rctx = req_ctx_find_get(1, RCTX_STATE_FREE, RCTX_STATE_SSC_RX_BUSY); if (!rctx) { DEBUGPCRF("no rctx for secondary refill!"); @@ -216,8 +216,8 @@ static int8_t ssc_rx_refill(void) if (AT91F_PDC_IsNextRxEmpty(rx_pdc)) { DEBUGR("filling secondary SSC RX dma ctx"); - AT91F_PDC_SetNextRx(rx_pdc, &rctx->rx.data[MAX_HDRSIZE], - (sizeof(rctx->rx.data)-MAX_HDRSIZE)>2); + AT91F_PDC_SetNextRx(rx_pdc, &rctx->data[MAX_HDRSIZE], + (rctx->size-MAX_HDRSIZE)>2); ssc_state.rx_ctx[1] = rctx; return 2; } else { @@ -331,8 +331,7 @@ void ssc_tx_init(void) static int ssc_usb_in(struct req_ctx *rctx) { - struct openpcd_hdr *poh = (struct openpcd_hdr *) &rctx->rx.data[0]; - struct openpcd_hdr *pih = (struct openpcd_hdr *) &rctx->tx.data[0]; + struct openpcd_hdr *poh = (struct openpcd_hdr *) rctx->data; switch (poh->cmd) { case OPENPCD_CMD_SSC_READ: @@ -366,7 +365,7 @@ void ssc_rx_init(void) /* Reset */ //ssc->SSC_CR = AT91C_SSC_SWRST; - /* don't divide clock */ + /* don't divide clock inside SSC, we do that in tc_cdiv */ ssc->SSC_CMR = 0; ssc->SSC_RCMR = AT91C_SSC_CKS_RK | AT91C_SSC_CKO_NONE | |