diff options
author | laforge <laforge@6dc7ffe9-61d6-0310-9af1-9938baff3ed1> | 2006-12-18 12:32:48 +0000 |
---|---|---|
committer | laforge <laforge@6dc7ffe9-61d6-0310-9af1-9938baff3ed1> | 2006-12-18 12:32:48 +0000 |
commit | 6c6b1878f4e3b9b848f6329e98d27db7b99c212b (patch) | |
tree | 43386acccc982edd82cae447a6c495e6fb154ec8 | |
parent | 5200cf56dd9f0c698011c59b96abdb447a76ac1f (diff) |
- add new DAC driver (instead of poti) for PICC
- DFU: put all DEBUG_ defines in "#ifdef DEBUG" enclosure
- alter GPIO defines for new OpenPICC v0.4 prototype
- add new AT91F_DBGU_Fini() function
- take care of new inverted USB pullip in OpenPICC v0.4 prototype
- fix typo in 'opicc_reg_write' macro
- add some more PICC related SSC code
NOTE: this firmware is the first version that will _NOT_ run on a OpenPICC v0.3 anymore!
(All changes by Henryk Ploetz)
git-svn-id: https://svn.openpcd.org:2342/trunk@283 6dc7ffe9-61d6-0310-9af1-9938baff3ed1
-rw-r--r-- | firmware/Makefile | 2 | ||||
-rw-r--r-- | firmware/src/dfu/dfu.c | 6 | ||||
-rw-r--r-- | firmware/src/openpcd.h | 6 | ||||
-rw-r--r-- | firmware/src/os/dbgu.c | 11 | ||||
-rw-r--r-- | firmware/src/os/pcd_enumerate.c | 8 | ||||
-rw-r--r-- | firmware/src/picc/main_openpicc.c | 24 | ||||
-rw-r--r-- | firmware/src/picc/openpicc.c | 2 | ||||
-rw-r--r-- | firmware/src/picc/opicc_reg.h | 2 | ||||
-rw-r--r-- | firmware/src/picc/ssc_picc.c | 80 |
9 files changed, 111 insertions, 30 deletions
diff --git a/firmware/Makefile b/firmware/Makefile index dcc0ffe..b7bb60f 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -105,7 +105,7 @@ ifeq ($(BOARD), PICC) SRCARM += src/picc/tc_fdt.c src/picc/ssc_picc.c src/picc/adc.c \ src/picc/decoder.c src/picc/decoder_miller.c \ src/picc/load_modulation.c src/picc/tc_cdiv_sync.c \ - src/picc/decoder_nrzl.c src/picc/poti.c src/picc/pll.c \ + src/picc/decoder_nrzl.c src/picc/da.c src/picc/pll.c \ src/picc/openpicc.c # finally, the actual main application SRCARM += src/picc/$(TARGET).c diff --git a/firmware/src/dfu/dfu.c b/firmware/src/dfu/dfu.c index f5abe46..20778bd 100644 --- a/firmware/src/dfu/dfu.c +++ b/firmware/src/dfu/dfu.c @@ -42,8 +42,10 @@ * and therefore have to omit flashing */ //#define DEBUG_DFU_NOFLASH +#ifdef DEBUG #define DEBUG_DFU_EP0 //#define DEBUG_DFU_RECV +#endif #ifdef DEBUG_DFU_EP0 #define DEBUGE DEBUGP @@ -78,7 +80,9 @@ static void __dfufunc udp_init(void) /* Enable UDP PullUp (USB_DP_PUP) : enable & Clear of the * corresponding PIO Set in PIO mode and Configure in Output */ +#if defined(PCD) AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, OPENPCD_PIO_UDP_PUP); +#endif AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, OPENPCD_PIO_UDP_PUPv4); } @@ -899,7 +903,9 @@ void __dfufunc dfu_main(void) /* End-of-Bus-Reset is always enabled */ /* Clear for set the Pull up resistor */ +#if defined(PCD) AT91F_PIO_SetOutput(AT91C_BASE_PIOA, OPENPCD_PIO_UDP_PUP); +#endif AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, OPENPCD_PIO_UDP_PUPv4); flash_init(); diff --git a/firmware/src/openpcd.h b/firmware/src/openpcd.h index f84f121..a65cd0e 100644 --- a/firmware/src/openpcd.h +++ b/firmware/src/openpcd.h @@ -26,7 +26,7 @@ #define USB_PRODUCT_ID OPENPCD_PRODUCT_ID #elif defined(PICC) #define OPENPCD_PIO_UDP_CNX NO_UDP_CNX -#define OPENPCD_PIO_UDP_PUP AT91C_PIO_PA22 +#define OPENPCD_PIO_UDP_PUPv4 AT91C_PIO_PA16 #define OPENPCD_PIO_LED1 AT91C_PIO_PA25 #define OPENPCD_PIO_LED2 AT91C_PIO_PA12 #define PIO_BOOTLDR AT91C_PIO_PA6 @@ -153,7 +153,9 @@ #define OPENPICC_PIO_SS1_GAIN AT91C_PIO_PA11 #define OPENPICC_PIO_PLL_LOCK AT91C_PIO_PA4 -#define OPENPICC_PIO_AB_DETECT AT91C_PIO_PA20 +#define OPENPICC_PIO_FRAME AT91C_PIO_PA20 +#define OPENPICC_PIO_SSC_DATA_CONTROL AT91C_PIO_PA21 +#define OPENPICC_PIO_AB_DETECT AT91C_PIO_PA22 #define OPENPICC_PIO_PLL_INHIBIT AT91C_PIO_PA24 #define OPENPICC_ADC_FIELD_STRENGTH AT91C_ADC_CH4 diff --git a/firmware/src/os/dbgu.c b/firmware/src/os/dbgu.c index 32432a3..026b56b 100644 --- a/firmware/src/os/dbgu.c +++ b/firmware/src/os/dbgu.c @@ -157,6 +157,17 @@ void AT91F_DBGU_Init(void) "Toggle LED2\r\n9) Reset\n\r"); } +/* + * Disable the PIO assignments for the DBGU + */ +void AT91F_DBGU_Fini(void) +{ + ((AT91PS_USART) AT91C_BASE_DBGU)->US_CR = AT91C_US_RXDIS | AT91C_US_TXDIS; + AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, AT91C_PA10_DTXD); + AT91F_PIO_CfgInput(AT91C_BASE_PIOA, AT91C_PA9_DRXD); + // Maybe FIXME, do more? -- Henryk Plötz <henryk@ploetzli.ch> +} + //*---------------------------------------------------------------------------- //* \fn AT91F_DBGU_Printk //* \brief This function is used to send a string through the DBGU channel (Very low level debugging) diff --git a/firmware/src/os/pcd_enumerate.c b/firmware/src/os/pcd_enumerate.c index 6c45af6..5fc47a3 100644 --- a/firmware/src/os/pcd_enumerate.c +++ b/firmware/src/os/pcd_enumerate.c @@ -557,18 +557,18 @@ out: void udp_pullup_on(void) { - AT91F_PIO_SetOutput(AT91C_BASE_PIOA, OPENPCD_PIO_UDP_PUP); #ifdef PCD - AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, OPENPCD_PIO_UDP_PUPv4); + AT91F_PIO_SetOutput(AT91C_BASE_PIOA, OPENPCD_PIO_UDP_PUP); #endif + AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, OPENPCD_PIO_UDP_PUPv4); } void udp_pullup_off(void) { - AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, OPENPCD_PIO_UDP_PUP); #ifdef PCD - AT91F_PIO_SetOutput(AT91C_BASE_PIOA, OPENPCD_PIO_UDP_PUPv4); + AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, OPENPCD_PIO_UDP_PUP); #endif + AT91F_PIO_SetOutput(AT91C_BASE_PIOA, OPENPCD_PIO_UDP_PUPv4); } /* Open USB Device Port */ diff --git a/firmware/src/picc/main_openpicc.c b/firmware/src/picc/main_openpicc.c index ff89dc2..3e615a4 100644 --- a/firmware/src/picc/main_openpicc.c +++ b/firmware/src/picc/main_openpicc.c @@ -30,7 +30,7 @@ #include <os/pwm.h> #include <os/tc_cdiv.h> #include <os/pio_irq.h> -#include <picc/poti.h> +#include <picc/da.h> #include <picc/pll.h> #include <picc/ssc_picc.h> #include <picc/load_modulation.h> @@ -50,7 +50,7 @@ void _init_func(void) /* low-level hardware initialization */ pio_irq_init(); pll_init(); - poti_init(); + da_init(); load_mod_init(); tc_cdiv_init(); tc_fdt_init(); @@ -64,12 +64,13 @@ void _init_func(void) opicc_usbapi_init(); AT91F_PIO_CfgInput(AT91C_BASE_PIOA, OPENPICC_PIO_BOOTLDR); + da_comp_carr(64); } static void help(void) { - DEBUGPCR("q: poti decrease q: poti increase\r\n" - "e: poti retransmit P: PLL inhibit toggle"); + DEBUGPCR("q: da decrease w: da increase\r\n" + "e: da retransmit P: PLL inhibit toggle"); DEBUGPCR("o: decrease duty p: increase duty\r\n" "k: stop pwm l: start pwn\r\n" "n: decrease freq m: incresae freq"); @@ -96,18 +97,18 @@ int _main_dbgu(char key) case 'q': if (poti > 0) poti--; - poti_comp_carr(poti); - DEBUGPCRF("Poti: %u", poti); + da_comp_carr(poti); + DEBUGPCRF("DA: %u", poti); break; case 'w': - if (poti < 127) + if (poti < 255) poti++; - poti_comp_carr(poti); - DEBUGPCRF("Poti: %u", poti); + da_comp_carr(poti); + DEBUGPCRF("DA: %u", poti); break; case 'e': - poti_comp_carr(poti); - DEBUGPCRF("Poti: %u", poti); + da_comp_carr(poti); + DEBUGPCRF("DA: %u", poti); break; case 'P': pll_inh++; @@ -238,6 +239,7 @@ int _main_dbgu(char key) tc_cdiv_print(); //tc_fdt_print(); + ssc_print(); return -EINVAL; } diff --git a/firmware/src/picc/openpicc.c b/firmware/src/picc/openpicc.c index fa1f840..54139a9 100644 --- a/firmware/src/picc/openpicc.c +++ b/firmware/src/picc/openpicc.c @@ -14,6 +14,7 @@ * OpenPICC Register set ********************************************************************/ +#ifdef DEBUG /* Our registers, including their power-up default values */ static u_int16_t opicc_regs[_OPICC_NUM_REGS] = { [OPICC_REG_14443A_UIDLEN] = 4, @@ -42,6 +43,7 @@ void opicc_reg_write(enum opicc_reg reg, u_int16_t val) opicc_regs[reg] = val; return; } +#endif /******************************************************************** * OpenPICC USB Commandset (access to register set, ...) diff --git a/firmware/src/picc/opicc_reg.h b/firmware/src/picc/opicc_reg.h index e77d157..adc9305 100644 --- a/firmware/src/picc/opicc_reg.h +++ b/firmware/src/picc/opicc_reg.h @@ -10,7 +10,7 @@ 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) +#define opicc_reg_write(x, y) (opicc_regs[x] = y) #endif void opicc_usbapi_init(void); diff --git a/firmware/src/picc/ssc_picc.c b/firmware/src/picc/ssc_picc.c index 50dce06..b7c4219 100644 --- a/firmware/src/picc/ssc_picc.c +++ b/firmware/src/picc/ssc_picc.c @@ -36,8 +36,6 @@ #include <os/led.h> #include "../openpcd.h" -#include <picc/tc_cdiv_sync.h> - //#define DEBUG_SSC_REFILL /* definitions for four-times oversampling */ @@ -123,6 +121,7 @@ void ssc_rx_mode_set(enum ssc_mode ssc_mode) * (at least not yet in the current hardware) */ //start_cond = AT91C_SSC_START_EDGE_RF; start_cond = AT91C_SSC_START_CONTINOUS; + //AT91C_SSC_START_RISE_RF; sync_len = 0; data_len = 32; num_data = 16; @@ -136,7 +135,7 @@ void ssc_rx_mode_set(enum ssc_mode ssc_mode) (((num_data-1) & 0x0f) << 8) | (((sync_len-1) & 0x0f) << 16); ssc->SSC_RCMR = AT91C_SSC_CKS_RK | AT91C_SSC_CKO_NONE | - AT91C_SSC_CKI | start_cond; + (0x2 << 6) | AT91C_SSC_CKI | start_cond; /* Enable Rx DMA */ AT91F_PDC_EnableRx(rx_pdc); @@ -204,6 +203,7 @@ static inline void init_opcdhdr(struct req_ctx *rctx) rctx->tot_len = sizeof(opcd_ssc_hdr); } +#define DEBUG_SSC_REFILL 1 #ifdef DEBUG_SSC_REFILL #define DEBUGR(x, args ...) DEBUGPCRF(x, ## args) #else @@ -307,6 +307,7 @@ static int8_t ssc_rx_refill(void) static void __ramfunc ssc_irq(void) { u_int32_t ssc_sr = ssc->SSC_SR; + int i, *tmp, emptyframe = 0; DEBUGP("ssc_sr=0x%08x, mode=%u: ", ssc_sr, ssc_state.mode); if (ssc_sr & AT91C_SSC_ENDRX) { @@ -316,15 +317,56 @@ static void __ramfunc ssc_irq(void) * packet. */ if (ssc_state.mode == SSC_MODE_EDGE_ONE_SHOT) { DEBUGP("DISABLE_RX "); - AT91F_SSC_DisableRx(AT91C_BASE_SSC); + ssc_rx_stop(); } //AT91F_SSC_DisableIt(AT91C_BASE_SSC, SSC_RX_IRQ_MASK); #endif +#if 0 +/* Experimental start SSC on frame, stop on FFFFFFFF */ + if (ssc_state.mode == SSC_MODE_CONTINUOUS) { + //ssc->SSC_RCMR = (ssc->SSC_RCMR & ~AT91C_SSC_START) | AT91C_SSC_START_CONTINOUS; + tmp = (u_int32_t*)ssc_state.rx_ctx[0]->data; + for(i = ssc_state.rx_ctx[0]->size / 4; i >= 0 ; i--) { + if( *tmp++ == 0xFFFFFFFF ) { + *(tmp-1) = 0xAAAAAAAA; // debug marker + /* No modulation for a long time, stop sampling + * and prepare for next frame */ + DEBUGP("RESTART RX "); + ssc_rx_stop(); + ssc_rx_mode_set(ssc_state.mode); + ssc_rx_start(); + led_toggle(1); + break; + } + } + } +#endif + /* Ignore empty frames */ + if (ssc_state.mode == SSC_MODE_CONTINUOUS) { + tmp = (u_int32_t*)ssc_state.rx_ctx[0]->data + MAX_HDRSIZE; + emptyframe = 1; + for(i = (ssc_state.rx_ctx[0]->size-MAX_HDRSIZE) / 4 - 8/*WTF?*/; i > 0; i--) { + if( *tmp++ != 0xFFFFFFFF ) { + DEBUGPCR("NONEMPTY(%08x, %i): %08x", tmp, i, *(tmp-1)); + emptyframe = 0; + break; + } else { + //DEBUGPCR("DUNNO(%08x, %i): %08x", tmp, i, tmp[i]); + } + } + } //DEBUGP("Sending primary RCTX(%u, len=%u) ", req_ctx_num(ssc_state.rx_ctx[0]), ssc_state.rx_ctx[0]->tot_len); /* Mark primary RCTX as ready to send for usb */ - req_ctx_set_state(ssc_state.rx_ctx[0], - RCTX_STATE_UDP_EP2_PENDING); - //RCTX_STATE_FREE); + if(!emptyframe) { + DEBUGP("NONEMPTY"); + req_ctx_set_state(ssc_state.rx_ctx[0], + RCTX_STATE_UDP_EP2_PENDING); + //RCTX_STATE_FREE); + } else { + DEBUGP("EMPTY"); + req_ctx_put(ssc_state.rx_ctx[0]); + } + /* second buffer gets propagated to primary */ ssc_state.rx_ctx[0] = ssc_state.rx_ctx[1]; ssc_state.rx_ctx[1] = NULL; @@ -356,7 +398,7 @@ static void __ramfunc ssc_irq(void) AT91C_SSC_OVRUN); #endif } - + if (ssc_sr & AT91C_SSC_OVRUN) DEBUGP("RX_OVERRUN "); @@ -401,6 +443,14 @@ static void __ramfunc ssc_irq(void) AT91F_AIC_ClearIt(AT91C_BASE_AIC, AT91C_ID_SSC); } +void ssc_print(void) +{ + DEBUGP("PDC_RPR=0x%08x ", rx_pdc->PDC_RPR); + DEBUGP("PDC_RCR=0x%08x ", rx_pdc->PDC_RCR); + DEBUGP("PDC_RNPR=0x%08x ", rx_pdc->PDC_RNPR); + DEBUGP("PDC_RNCR=0x%08x ", rx_pdc->PDC_RNCR); +} + void ssc_rx_unthrottle(void) { @@ -410,12 +460,18 @@ void ssc_rx_unthrottle(void) void ssc_rx_start(void) { + volatile int i; //DEBUGPCRF("starting SSC RX\n"); /* Enable Reception */ AT91F_SSC_EnableIt(ssc, AT91C_SSC_ENDRX | AT91C_SSC_CP0 | AT91C_SSC_RXBUFF | AT91C_SSC_OVRUN); AT91F_SSC_EnableRx(AT91C_BASE_SSC); + + // Clear the flipflop + AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, OPENPICC_PIO_SSC_DATA_CONTROL); + for(int i = 0; i<0xff; i++) { } + AT91F_PIO_SetOutput(AT91C_BASE_PIOA, OPENPICC_PIO_SSC_DATA_CONTROL); } void ssc_rx_stop(void) @@ -462,15 +518,17 @@ static int ssc_usb_in(struct req_ctx *rctx) void ssc_rx_init(void) { - tc_cdiv_sync_init(); - rx_pdc = (AT91PS_PDC) &(ssc->SSC_RPR); AT91F_SSC_CfgPMC(); AT91F_PIO_CfgPeriph(AT91C_BASE_PIOA, - OPENPCD_PIO_MFOUT_SSC_RX | OPENPCD_PIO_SSP_CKIN, + OPENPCD_PIO_MFOUT_SSC_RX | OPENPCD_PIO_SSP_CKIN | + OPENPICC_PIO_FRAME, 0); + + AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, OPENPICC_PIO_SSC_DATA_CONTROL); + AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, OPENPICC_PIO_SSC_DATA_CONTROL); AT91F_AIC_ConfigureIt(AT91C_BASE_AIC, AT91C_ID_SSC, OPENPCD_IRQ_PRIO_SSC, |