]> cvs.zerfleddert.de Git - proxmark3-svn/blob - armsrc/hfsnoop.c
Merge pull request #337 from Proxmark/iceman1001-patch-4
[proxmark3-svn] / armsrc / hfsnoop.c
1 #include "proxmark3.h"
2 #include "apps.h"
3 #include "BigBuf.h"
4 #include "util.h"
5
6 static void RAMFUNC optimizedSnoop(void);
7
8 static void RAMFUNC optimizedSnoop(void)
9 {
10 int n = BigBuf_max_traceLen() / sizeof(uint16_t); // take all memory
11
12 uint16_t *dest = (uint16_t *)BigBuf_get_addr();
13 uint16_t *destend = dest + n;
14
15 AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(16); // Setting Frame mode, 16 bits per word
16 // Reading data loop
17 while(dest <= destend)
18 {
19 if(AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY)
20 {
21 *dest = (uint16_t)(AT91C_BASE_SSC->SSC_RHR);
22 dest++;
23 }
24 }
25 //Resetting Frame mode (First set in fpgaloader.c)
26 AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(8) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0);
27 }
28
29 void HfSnoop(int samplesToSkip, int triggersToSkip)
30 {
31 BigBuf_free(); BigBuf_Clear();
32
33 Dbprintf("Skipping first %d sample pairs, Skipping %d triggers.\n", samplesToSkip, triggersToSkip);
34 int trigger_cnt;
35 LED_D_ON();
36 // Select correct configs
37 FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
38 // Set up the synchronous serial port
39 FpgaSetupSsc();
40 // connect Demodulated Signal to ADC:
41 SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
42 FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_SNOOP);
43 SpinDelay(100);
44
45 AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(16); // Setting Frame Mode For better performance on high speed data transfer.
46
47 trigger_cnt = 0;
48 uint16_t r = 0;
49 while(!BUTTON_PRESS() && !usb_poll_validate_length()) {
50 WDT_HIT();
51 if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
52 r = (uint16_t)AT91C_BASE_SSC->SSC_RHR;
53 r = MAX(r & 0xff, r >> 8);
54 if (r >= 240) {
55 if (++trigger_cnt > triggersToSkip)
56 break;
57 }
58 }
59 }
60
61 if(!BUTTON_PRESS()) {
62 int waitcount = samplesToSkip; // lets wait 40000 ticks of pck0
63 while(waitcount != 0) {
64 if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY))
65 waitcount--;
66 }
67 optimizedSnoop();
68 Dbprintf("Trigger kicked! Value: %d, Dumping Samples Hispeed now.", r);
69 }
70
71 DbpString("HF Snoop end");
72 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
73 LED_D_OFF();
74 }
75
Impressum, Datenschutz