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