diff options
author | henryk <henryk@6dc7ffe9-61d6-0310-9af1-9938baff3ed1> | 2007-12-09 06:06:04 +0000 |
---|---|---|
committer | henryk <henryk@6dc7ffe9-61d6-0310-9af1-9938baff3ed1> | 2007-12-09 06:06:04 +0000 |
commit | bdc39aadd1a26d7709ff15722be90c016be2057a (patch) | |
tree | 6fcc1c756a4edf588818aaf3e973a3dfe64fa395 | |
parent | be5251b669e1812fe13668bafe2832d3a574210e (diff) |
Make it possible to send long frames for debugging
git-svn-id: https://svn.openpcd.org:2342/trunk@380 6dc7ffe9-61d6-0310-9af1-9938baff3ed1
-rw-r--r-- | openpicc/application/iso14443_layer3a.c | 98 | ||||
-rw-r--r-- | openpicc/application/ssc_picc.c | 2 | ||||
-rw-r--r-- | openpicc/application/tc_fdt.c | 17 | ||||
-rw-r--r-- | openpicc/application/tc_fdt.h | 1 |
4 files changed, 82 insertions, 36 deletions
diff --git a/openpicc/application/iso14443_layer3a.c b/openpicc/application/iso14443_layer3a.c index 381097f..a5db2cd 100644 --- a/openpicc/application/iso14443_layer3a.c +++ b/openpicc/application/iso14443_layer3a.c @@ -54,7 +54,9 @@ const iso14443_frame NULL_FRAME = { {{STANDARD_FRAME, PARITY}}, 4, 0, 0, - {0, 0, 0, 0}, + //{0xF3, 0xFB, 0xAE, 0xED}, + {0xFF, 0xFF, 0xFF, 0xFF}, + //{0, 0, 0, 0}, {} }; @@ -66,6 +68,12 @@ const iso14443_frame NULL_FRAME = { #define INITIAL_STATE IDLE //#define INITIAL_STATE ACTIVE +#if INITIAL_STATE == IDLE +#define INITIAL_FRAME ATQA_FRAME +#else +#define INITIAL_FRAME NULL_FRAME +#endif + static int atqa_sent = 0; /* Running in ISR mode */ void __ramfunc iso14443_layer3a_irq_ext(u_int32_t ssc_sr, enum ssc_mode ssc_mode, u_int8_t* samples) @@ -131,6 +139,19 @@ static int prefill_buffer(ssc_dma_tx_buffer_t *dest, const iso14443_frame *src) } +static u_int8_t received_buffer[256]; + +static void enable_reception(enum ssc_mode mode) { + tc_fdt_set(ISO14443A_FDT_SHORT_0); + ssc_rx_mode_set(mode); +#ifdef FOUR_TIMES_OVERSAMPLING + tc_cdiv_set_divider(32); +#else + tc_cdiv_set_divider(64); +#endif + ssc_rx_start(); +} + extern void main_help_print_buffer(ssc_dma_rx_buffer_t *buffer, int *pktcount); void iso14443_layer3a_state_machine (void *pvParameters) { @@ -199,13 +220,13 @@ void iso14443_layer3a_state_machine (void *pvParameters) break; case POWERED_OFF: if(switch_on == 1) { - if(prefill_buffer(&ssc_tx_buffer, &ATQA_FRAME)) { + if(prefill_buffer(&ssc_tx_buffer, &INITIAL_FRAME)) { LAYER3_DEBUG("Buffer prefilled\n\r"); DumpUIntToUSB(ssc_tx_buffer.state); DumpStringToUSB(" "); DumpUIntToUSB((unsigned int)ssc_tx_buffer.source); DumpStringToUSB(" "); - DumpUIntToUSB((unsigned int)&ATQA_FRAME); + DumpUIntToUSB((unsigned int)&INITIAL_FRAME); DumpStringToUSB(" "); DumpUIntToUSB(ssc_tx_buffer.len); DumpStringToUSB(" "); @@ -213,16 +234,10 @@ void iso14443_layer3a_state_machine (void *pvParameters) DumpStringToUSB("\n\r"); state=INITIAL_STATE; if(INITIAL_STATE == IDLE) - ssc_rx_mode_set(SSC_MODE_14443A_SHORT); + enable_reception(SSC_MODE_14443A_SHORT); else if(INITIAL_STATE == ACTIVE) - ssc_rx_mode_set(SSC_MODE_14443A_STANDARD); - else ssc_rx_mode_set(SSC_MODE_NONE); -#ifdef FOUR_TIMES_OVERSAMPLING - tc_cdiv_set_divider(32); -#else - tc_cdiv_set_divider(64); -#endif - ssc_rx_start(); + enable_reception(SSC_MODE_14443A_STANDARD); + else enable_reception(SSC_MODE_NONE); } else { LAYER3_DEBUG("SSC TX overflow error, please debug"); state=ERROR; @@ -250,10 +265,13 @@ void iso14443_layer3a_state_machine (void *pvParameters) portEXIT_CRITICAL(); u_int32_t first_sample = *(u_int32_t*)buffer->data; - DumpStringToUSB("Frame: "); - DumpUIntToUSB(first_sample); - DumpStringToUSB(" "); - main_help_print_buffer(buffer, &pktcount); + if(0) { + DumpStringToUSB("Frame: "); + DumpUIntToUSB(first_sample); + DumpStringToUSB(" "); + main_help_print_buffer(buffer, &pktcount); + } + vLedBlinkGreen(); switch(state) { case IDLE: @@ -266,33 +284,47 @@ void iso14443_layer3a_state_machine (void *pvParameters) LAYER3_DEBUG(", woke up to send ATQA\n\r"); atqa_sent = 0; } - /* For debugging, wait 1ms, then wait for another frame */ + /* For debugging, wait 1ms, then wait for another frame + * Normally we'd go to anticol from here*/ vTaskDelay(portTICK_RATE_MS); if(prefill_buffer(&ssc_tx_buffer, &ATQA_FRAME)) { - ssc_rx_mode_set(SSC_MODE_14443A_SHORT); -#ifdef FOUR_TIMES_OVERSAMPLING - tc_cdiv_set_divider(32); -#else - tc_cdiv_set_divider(64); -#endif - ssc_rx_start(); + enable_reception(SSC_MODE_14443A_SHORT); } } else { /* Wait for another frame */ - ssc_rx_mode_set(SSC_MODE_14443A_SHORT); -#ifdef FOUR_TIMES_OVERSAMPLING - tc_cdiv_set_divider(32); -#else - tc_cdiv_set_divider(64); -#endif - ssc_rx_start(); + enable_reception(SSC_MODE_14443A_SHORT); } break; case ACTIVE: case ACTIVE_STAR: + if(0) { + DumpStringToUSB("Decoded: "); + decoder_decode(DECODER_MILLER, (const char*)buffer->data, buffer->len, received_buffer); + DumpBufferToUSB((char*)received_buffer, 100); + DumpStringToUSB("\n\r"); + } /* Wait for another frame */ - ssc_rx_mode_set(SSC_MODE_14443A_STANDARD); - ssc_rx_start(); + if(0) { + ssc_rx_mode_set(SSC_MODE_14443A_STANDARD); + ssc_rx_start(); + } else { + //vTaskDelay(portTICK_RATE_MS); + if(ssc_tx_buffer.source == &ATQA_FRAME) ssc_tx_buffer.state = FREE; + if(prefill_buffer(&ssc_tx_buffer, &NULL_FRAME)) { + usb_print_string_f("Sending response ...",0); + ssc_tx_buffer.state = PROCESSING; + tc_cdiv_set_divider(8); + tc_fdt_set_to_next_slot(1); + ssc_tx_start(&ssc_tx_buffer); + while( ssc_tx_buffer.state != FREE ) { + vTaskDelay(portTICK_RATE_MS); + } + usb_print_string("done\n\r"); + usb_print_flush(); + } + /* Wait for another frame */ + enable_reception(SSC_MODE_14443A_STANDARD); + } default: break; } diff --git a/openpicc/application/ssc_picc.c b/openpicc/application/ssc_picc.c index 8faa681..98f9e46 100644 --- a/openpicc/application/ssc_picc.c +++ b/openpicc/application/ssc_picc.c @@ -76,7 +76,7 @@ static const struct {u_int16_t transfersize; u_int16_t transfers;} ssc_sizes[] = /* 14443A Short Frame: 1 transfer of ISO14443A_SHORT_LEN bits */ [SSC_MODE_14443A_SHORT] = {ISO14443A_SHORT_TRANSFER_SIZE, 1}, /* 14443A Standard Frame: FIXME 16 transfers of 32 bits (maximum number), resulting in 512 samples */ - [SSC_MODE_14443A_STANDARD] = {32, 16}, + [SSC_MODE_14443A_STANDARD] = {32, 4}, [SSC_MODE_14443B] = {32, 16}, /* 64 bytes */ [SSC_MODE_EDGE_ONE_SHOT] = {32, 16}, /* 64 bytes */ [SSC_MODE_CONTINUOUS] = {32, 511}, /* 2044 bytes */ diff --git a/openpicc/application/tc_fdt.c b/openpicc/application/tc_fdt.c index 03ef5a4..6005125 100644 --- a/openpicc/application/tc_fdt.c +++ b/openpicc/application/tc_fdt.c @@ -41,6 +41,7 @@ #include "tc_fdt.h" #include "usb_print.h" #include "ssc_picc.h" +#include "cmd.h" static AT91PS_TC tcfdt = AT91C_BASE_TC2; @@ -49,6 +50,18 @@ void tc_fdt_set(u_int16_t count) tcfdt->TC_RA = count; } +void __ramfunc tc_fdt_set_to_next_slot(int last_bit) +{ + int reference_time; + if(last_bit == 0) reference_time = ISO14443A_FDT_OFFSET_0-FALLING_EDGE_DETECTION_DELAY; + else reference_time = ISO14443A_FDT_OFFSET_1-FALLING_EDGE_DETECTION_DELAY; + + if(tcfdt->TC_SR & AT91C_TC_CLKSTA) + while(tcfdt->TC_CV != 0xFFFF && (tcfdt->TC_CV - reference_time) % 128 != 0); + tcfdt->TC_CCR = AT91C_TC_SWTRG; + tc_fdt_set(2*128); +} + /* 'count' number of carrier cycles after the last modulation pause, * we deem the frame to have ended */ @@ -109,12 +122,12 @@ void tc_fdt_init(void) /* Clock XC1, Wave Mode, No automatic reset on RC comp * TIOA2 in RA comp = set, TIOA2 on RC comp = clear, - * TIOA2 on EEVT = clear + * TIOA2 on EEVT = clear, TIOA2 on SWTRG = clear, * TIOB2 as input, EEVT = TIOB2, Reset/Trigger on EEVT */ tcfdt->TC_CMR = AT91C_TC_CLKS_XC1 | AT91C_TC_WAVE | AT91C_TC_WAVESEL_UP | AT91C_TC_ACPA_SET | AT91C_TC_ACPC_CLEAR | - AT91C_TC_AEEVT_CLEAR | + AT91C_TC_AEEVT_CLEAR | AT91C_TC_ASWTRG_CLEAR | AT91C_TC_BEEVT_NONE | AT91C_TC_BCPB_NONE | AT91C_TC_EEVT_TIOB | AT91C_TC_ETRGEDG_FALLING | AT91C_TC_ENETRG | AT91C_TC_CPCSTOP ; diff --git a/openpicc/application/tc_fdt.h b/openpicc/application/tc_fdt.h index b39b935..28e7e7e 100644 --- a/openpicc/application/tc_fdt.h +++ b/openpicc/application/tc_fdt.h @@ -5,5 +5,6 @@ extern void tc_fdt_init(void); extern void tc_fdt_set(u_int16_t count); +extern void __ramfunc tc_fdt_set_to_next_slot(int last_bit); #endif |