//-----------------------------------------------------------------------------
bool FpgaSetupSscDma(uint8_t *buf, int len)
{
- if (buf == NULL) {
+ if (buf == NULL)
return false;
- }
AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS; // Disable DMA Transfer
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) buf; // transfer to this memory address
compressed_fpga_stream->avail_out = OUTPUT_BUFFER_LEN;
fpga_image_ptr = output_buffer;
int res = inflate(compressed_fpga_stream, Z_SYNC_FLUSH);
- if (res != Z_OK) {
+
+ if (res != Z_OK)
Dbprintf("inflate returned: %d, %s", res, compressed_fpga_stream->msg);
- }
- if (res < 0) {
+
+ if (res < 0)
return res;
- }
}
- uncompressed_bytes_cnt++;
+ ++uncompressed_bytes_cnt;
return *fpga_image_ptr++;
}
get_from_fpga_combined_stream(compressed_fpga_stream, output_buffer);
}
- return get_from_fpga_combined_stream(compressed_fpga_stream, output_buffer);
-
+ return get_from_fpga_combined_stream(compressed_fpga_stream, output_buffer);
}
fpga_image_ptr = output_buffer;
- for (uint16_t i = 0; i < FPGA_BITSTREAM_FIXED_HEADER_SIZE; i++) {
+ for (uint16_t i = 0; i < FPGA_BITSTREAM_FIXED_HEADER_SIZE; i++)
header[i] = get_from_fpga_stream(bitstream_version, compressed_fpga_stream, output_buffer);
- }
// Check for a valid .bit file (starts with _bitparse_fixed_header)
- if(memcmp(_bitparse_fixed_header, header, FPGA_BITSTREAM_FIXED_HEADER_SIZE) == 0) {
+ if(memcmp(_bitparse_fixed_header, header, FPGA_BITSTREAM_FIXED_HEADER_SIZE) == 0)
return true;
- } else {
- return false;
- }
+
+ return false;
}
void FpgaDownloadAndGo(int bitstream_version)
{
z_stream compressed_fpga_stream;
- uint8_t output_buffer[OUTPUT_BUFFER_LEN];
+ uint8_t output_buffer[OUTPUT_BUFFER_LEN] = {0x00};
// check whether or not the bitstream is already loaded
if (downloaded_bitstream == bitstream_version)
void FpgaGatherVersion(int bitstream_version, char *dst, int len)
{
unsigned int fpga_info_len;
- char tempstr[40];
+ char tempstr[40] = {0x00};
z_stream compressed_fpga_stream;
- uint8_t output_buffer[OUTPUT_BUFFER_LEN];
+ uint8_t output_buffer[OUTPUT_BUFFER_LEN] = {0x00};
dst[0] = '\0';
// ensure that we can allocate enough memory for decompression:
BigBuf_free();
- if (!reset_fpga_stream(bitstream_version, &compressed_fpga_stream, output_buffer)) {
+ if (!reset_fpga_stream(bitstream_version, &compressed_fpga_stream, output_buffer))
return;
- }
if(bitparse_find_section(bitstream_version, 'a', &fpga_info_len, &compressed_fpga_stream, output_buffer)) {
for (uint16_t i = 0; i < fpga_info_len; i++) {
//-----------------------------------------------------------------------------
void RAMFUNC SnoopIClass(void)
{
-
-
// We won't start recording the frames that we acquire until we trigger;
// a good trigger condition to get started is probably when we see a
// response from the tag.
for(;;) {
LED_A_ON();
WDT_HIT();
- int behindBy = (lastRxCounter - AT91C_BASE_PDC_SSC->PDC_RCR) &
- (DMA_BUFFER_SIZE-1);
- if(behindBy > maxBehindBy) {
+ int behindBy = (lastRxCounter - AT91C_BASE_PDC_SSC->PDC_RCR) & (DMA_BUFFER_SIZE-1);
+
+ if ( behindBy > maxBehindBy) {
maxBehindBy = behindBy;
- if(behindBy > (9 * DMA_BUFFER_SIZE / 10)) {
+ if ( behindBy > (9 * DMA_BUFFER_SIZE / 10)) {
Dbprintf("blew circular buffer! behindBy=0x%x", behindBy);
goto done;
}
}
- if(behindBy < 1) continue;
+ if( behindBy < 1) continue;
- LED_A_OFF();
+ LED_A_OFF();
smpl = upTo[0];
upTo++;
lastRxCounter -= 1;
- if(upTo - dmaBuf > DMA_BUFFER_SIZE) {
+ if (upTo - dmaBuf > DMA_BUFFER_SIZE) {
upTo -= DMA_BUFFER_SIZE;
lastRxCounter += DMA_BUFFER_SIZE;
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) upTo;
}
//samples += 4;
- samples += 1;
+ samples += 1;
- if(smpl & 0xF) {
- decbyte ^= (1 << (3 - div));
- }
+ if(smpl & 0xF)
+ decbyte ^= (1 << (3 - div));
+
- // FOR READER SIDE COMMUMICATION...
+ // FOR READER SIDE COMMUMICATION...
- decbyter <<= 2;
- decbyter ^= (smpl & 0x30);
+ decbyter <<= 2;
+ decbyter ^= (smpl & 0x30);
- div++;
+ ++div;
- if((div + 1) % 2 == 0) {
- smpl = decbyter;
- if(OutOfNDecoding((smpl & 0xF0) >> 4)) {
- rsamples = samples - Uart.samples;
- time_stop = (GetCountSspClk()-time_0) << 4;
- LED_C_ON();
-
- //if(!LogTrace(Uart.output,Uart.byteCnt, rsamples, Uart.parityBits,TRUE)) break;
- //if(!LogTrace(NULL, 0, Uart.endTime*16 - DELAY_READER_AIR2ARM_AS_SNIFFER, 0, TRUE)) break;
- if(tracing) {
- uint8_t parity[MAX_PARITY_SIZE];
- GetParity(Uart.output, Uart.byteCnt, parity);
- LogTrace(Uart.output,Uart.byteCnt, time_start, time_stop, parity, TRUE);
- }
-
+ if (( div + 1) % 2 == 0) {
+ smpl = decbyter;
+ if ( OutOfNDecoding((smpl & 0xF0) >> 4)) {
+ rsamples = samples - Uart.samples;
+ time_stop = (GetCountSspClk()-time_0) << 4;
+ LED_C_ON();
+
+ //if(!LogTrace(Uart.output,Uart.byteCnt, rsamples, Uart.parityBits,TRUE)) break;
+ //if(!LogTrace(NULL, 0, Uart.endTime*16 - DELAY_READER_AIR2ARM_AS_SNIFFER, 0, TRUE)) break;
+ if(tracing) {
+ uint8_t parity[MAX_PARITY_SIZE];
+ GetParity(Uart.output, Uart.byteCnt, parity);
+ LogTrace(Uart.output,Uart.byteCnt, time_start, time_stop, parity, TRUE);
+ }
- /* And ready to receive another command. */
- Uart.state = STATE_UNSYNCD;
- /* And also reset the demod code, which might have been */
- /* false-triggered by the commands from the reader. */
- Demod.state = DEMOD_UNSYNCD;
- LED_B_OFF();
- Uart.byteCnt = 0;
- }else{
- time_start = (GetCountSspClk()-time_0) << 4;
+ /* And ready to receive another command. */
+ Uart.state = STATE_UNSYNCD;
+ /* And also reset the demod code, which might have been */
+ /* false-triggered by the commands from the reader. */
+ Demod.state = DEMOD_UNSYNCD;
+ LED_B_OFF();
+ Uart.byteCnt = 0;
+ } else {
+ time_start = (GetCountSspClk()-time_0) << 4;
+ }
+ decbyter = 0;
}
- decbyter = 0;
- }
- if(div > 3) {
- smpl = decbyte;
- if(ManchesterDecoding(smpl & 0x0F)) {
- time_stop = (GetCountSspClk()-time_0) << 4;
+ if(div > 3) {
+ smpl = decbyte;
+ if(ManchesterDecoding(smpl & 0x0F)) {
+ time_stop = (GetCountSspClk()-time_0) << 4;
- rsamples = samples - Demod.samples;
- LED_B_ON();
+ rsamples = samples - Demod.samples;
+ LED_B_ON();
- if(tracing) {
- uint8_t parity[MAX_PARITY_SIZE];
- GetParity(Demod.output, Demod.len, parity);
- LogTrace(Demod.output, Demod.len, time_start, time_stop, parity, FALSE);
- }
+ if(tracing) {
+ uint8_t parity[MAX_PARITY_SIZE];
+ GetParity(Demod.output, Demod.len, parity);
+ LogTrace(Demod.output, Demod.len, time_start, time_stop, parity, FALSE);
+ }
- // And ready to receive another response.
- memset(&Demod, 0, sizeof(Demod));
- Demod.output = tagToReaderResponse;
- Demod.state = DEMOD_UNSYNCD;
- LED_C_OFF();
- }else{
- time_start = (GetCountSspClk()-time_0) << 4;
+ // And ready to receive another response.
+ memset(&Demod, 0, sizeof(Demod));
+ Demod.output = tagToReaderResponse;
+ Demod.state = DEMOD_UNSYNCD;
+ LED_C_OFF();
+ } else {
+ time_start = (GetCountSspClk()-time_0) << 4;
+ }
+
+ div = 0;
+ decbyte = 0x00;
}
-
- div = 0;
- decbyte = 0x00;
- }
- //}
- if(BUTTON_PRESS()) {
+ if (BUTTON_PRESS()) {
DbpString("cancelled_a");
goto done;
}
AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS;
Dbprintf("%x %x %x", maxBehindBy, Uart.state, Uart.byteCnt);
Dbprintf("%x %x %x", Uart.byteCntMax, BigBuf_get_traceLen(), (int)Uart.output[0]);
- LED_A_OFF();
- LED_B_OFF();
- LED_C_OFF();
- LED_D_OFF();
+ LEDsoff();
set_tracing(FALSE);
}
void rotateCSN(uint8_t* originalCSN, uint8_t* rotatedCSN) {
int i;
- for(i = 0; i < 8; i++) {
+ for(i = 0; i < 8; i++)
rotatedCSN[i] = (originalCSN[i] >> 3) | (originalCSN[(i+1)%8] << 5);
- }
}
//-----------------------------------------------------------------------------
}
}
- //Dbprintf("%x", cmdsRecvd);
- LED_A_OFF();
- LED_B_OFF();
- LED_C_OFF();
-
+ LEDsoff();
+
if(buttonPressed)
- {
DbpString("Button pressed");
- }
+
return buttonPressed;
}