#include "lfsampling.h"
+/*
+Default LF config is set to:
+ decimation = 1 (we keep 1 out of 1 samples)
+ bits_per_sample = 8
+ averaging = YES
+ divisor = 95 (125khz)
+ trigger_threshold = 0
+ */
sample_config config = { 1, 8, 1, 95, 0 } ;
void printConfig() {
Dbprintf(" [q] divisor: %d ", config.divisor);
Dbprintf(" [b] bps: %d ", config.bits_per_sample);
Dbprintf(" [d] decimation: %d ", config.decimation);
- Dbprintf(" [a] averaging: %d ", config.averaging);
+ Dbprintf(" [a] averaging: %s ", (config.averaging) ? "Yes" : "No");
Dbprintf(" [t] trigger threshold: %d ", config.trigger_threshold);
}
-
/**
* Called from the USB-handler to set the sampling configuration
* The sampling config is used for std reading and snooping.
void setSamplingConfig(sample_config *sc) {
if(sc->divisor != 0) config.divisor = sc->divisor;
if(sc->bits_per_sample != 0) config.bits_per_sample = sc->bits_per_sample;
- if(sc->decimation != 0) config.decimation = sc->decimation;
if(sc->trigger_threshold != -1) config.trigger_threshold = sc->trigger_threshold;
-
+
+ config.decimation = (sc->decimation != 0) ? sc->decimation : 1;
config.averaging = sc->averaging;
if(config.bits_per_sample > 8) config.bits_per_sample = 8;
- if(config.decimation < 1) config.decimation = 1;
printConfig();
}
return &config;
}
-typedef struct {
+struct BitstreamOut {
uint8_t * buffer;
uint32_t numbits;
uint32_t position;
-} BitstreamOut;
+};
/**
* @brief Pushes bit onto the stream
// Connect the A/D to the peak-detected low-frequency path.
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
- // Give it a bit of time for the resonant antenna to settle.
+ // 50ms for the resonant antenna to settle.
SpinDelay(50);
// Now set up the SSC to get the ADC samples that are now streaming at us.
FpgaSetupSsc();
-
// start a 1.5ticks is 1us
StartTicks();
}
* @param silent - is true, now outputs are made. If false, dbprints the status
* @return the number of bits occupied by the samples.
*/
-uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averaging, int trigger_threshold,bool silent) {
+uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averaging, int trigger_threshold, bool silent) {
//bigbuf, to hold the aquired raw data signal
uint8_t *dest = BigBuf_get_addr();
uint16_t bufsize = BigBuf_max_traceLen();
while(!BUTTON_PRESS() && !usb_poll_validate_length() ) {
WDT_HIT();
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) {
- AT91C_BASE_SSC->SSC_THR = 0x43;
+ AT91C_BASE_SSC->SSC_THR = 0x00; //0x43;
LED_D_ON();
}
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
* @return number of bits sampled
**/
uint32_t SampleLF(bool printCfg) {
- return ReadLF(true, printCfg);
+ BigBuf_Clear_ext(false);
+ uint32_t ret = ReadLF(true, printCfg);
+ FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
+ return ret;
}
/**
* Initializes the FPGA for snoop-mode (field off), and acquires the samples.
* @return number of bits sampled
**/
uint32_t SnoopLF() {
- return ReadLF(false, true);
+ BigBuf_Clear_ext(false);
+ uint32_t ret = ReadLF(false, true);
+ FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
+ return ret;
}
/**
while(!BUTTON_PRESS() && !usb_poll_validate_length() && skipCnt < 1000 && (i < bufsize) ) {
WDT_HIT();
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) {
- AT91C_BASE_SSC->SSC_THR = 0x43;
+ AT91C_BASE_SSC->SSC_THR = 0x43; //43
LED_D_ON();
}
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
skipCnt++;
continue;
}
- // skip until the first Low sample below threshold
+ // skip until the first low sample below threshold
if (!startFound && curSample < T55xx_READ_LOWER_THRESHOLD) {
//if (curSample > lastSample)
lastSample = curSample;
continue;
}
-
// skip until first high samples begin to change
if (startFound || curSample > T55xx_READ_LOWER_THRESHOLD + T55xx_READ_TOL){
// if just found start - recover last sample