more debugstatements

This commit is contained in:
iceman1001 2020-06-23 11:21:17 +02:00
parent 1c7de4a8c3
commit d9f606d70b
2 changed files with 72 additions and 37 deletions

View file

@ -16,6 +16,7 @@
#include "util.h"
#include "lfdemod.h"
#include "string.h" // memset
#include "appmain.h" // print stack
/*
Default LF config is set to:
@ -29,6 +30,12 @@ Default LF config is set to:
*/
static sample_config config = { 1, 8, 1, LF_DIVISOR_125, 0, 0, 1} ;
// Holds bit packed struct of samples.
static BitstreamOut data = {0, 0, 0};
// internal struct to keep track of samples gathered
static sampling_t samples = {0, 0, 0, 0};
void printConfig(void) {
uint32_t d = config.divisor;
DbpString(_CYAN_("LF Sampling config"));
@ -38,6 +45,18 @@ void printConfig(void) {
Dbprintf(" [a] averaging...........%s", (config.averaging) ? "Yes" : "No");
Dbprintf(" [t] trigger threshold...%d", config.trigger_threshold);
Dbprintf(" [s] samples to skip.....%d ", config.samples_to_skip);
DbpString(_CYAN_("LF Sampling Stack"));
print_stack_usage();
}
void printSamples(void) {
DbpString(_CYAN_("LF Sampling memory"));
Dbprintf(" decimation counter.....%d ", samples.dec_counter);
Dbprintf(" sum.....%u ", samples.sum);
Dbprintf(" counter.....%u ", samples.counter);
Dbprintf(" total saved.....%u ", samples.total_saved);
print_stack_usage();
}
/**
@ -99,12 +118,6 @@ static void pushBit(BitstreamOut *stream, uint8_t bit) {
stream->numbits++;
}
// Holds bit packed struct of samples.
static BitstreamOut data = {0, 0, 0};
// internal struct to keep track of samples gathered
static sampling_t samples = {0, 0, 0, 0};
void initSampleBuffer(uint32_t *sample_size) {
initSampleBufferEx(sample_size, false);
}
@ -116,9 +129,7 @@ void initSampleBufferEx(uint32_t *sample_size, bool use_malloc) {
}
BigBuf_free();
// We can't erase the buffer now, it would drastically delay the acquisition
if (use_malloc) {
if (*sample_size == 0) {
@ -141,7 +152,7 @@ void initSampleBufferEx(uint32_t *sample_size, bool use_malloc) {
//
samples.dec_counter = 0;
samples.sum = 0;
samples.counter = 0;
samples.counter = *sample_size;
samples.total_saved = 0;
}
@ -157,13 +168,13 @@ void logSample(uint8_t sample, uint8_t decimation, uint8_t bits_per_sample, bool
if (!data.buffer) return;
if (bits_per_sample == 0) bits_per_sample = 1;
// keep track of total gather samples regardless how many was discarded.
if (samples.counter-- == 0) return;
if (bits_per_sample == 0) bits_per_sample = 1;
if (bits_per_sample > 8) bits_per_sample = 8;
if (decimation == 0) decimation = 1;
// keep track of total gather samples regardless how many was discarded.
samples.counter++;
if (avg) {
samples.sum += sample;
}
@ -224,6 +235,7 @@ void LFSetupFPGAForADC(int divisor, bool reader_field) {
// Connect the A/D to the peak-detected low-frequency path.
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
// 50ms for the resonant antenna to settle.
if (reader_field)
SpinDelay(50);
@ -255,6 +267,11 @@ uint32_t DoAcquisition(uint8_t decimation, uint8_t bits_per_sample, bool avg, in
initSampleBuffer(&sample_size);
if (DBGLEVEL >= DBG_DEBUG) {
Dbprintf("lf sampling - after init");
printSamples();
}
uint32_t cancel_counter = 0;
int16_t checked = 0;
@ -262,7 +279,7 @@ uint32_t DoAcquisition(uint8_t decimation, uint8_t bits_per_sample, bool avg, in
// only every 1000th times, in order to save time when collecting samples.
// interruptible only when logging not yet triggered
if ((checked == 2000) && (trigger_threshold > 0)) {
if ((checked == 4000) && (trigger_threshold > 0)) {
if (data_available()) {
checked = -1;
break;
@ -306,7 +323,7 @@ uint32_t DoAcquisition(uint8_t decimation, uint8_t bits_per_sample, bool avg, in
if (samples.total_saved >= sample_size) break;
}
}
if (checked == -1 && verbose) {
Dbprintf("lf sampling aborted");
}
@ -397,10 +414,19 @@ void doT55x7Acquisition(size_t sample_size) {
bool lowFound = false;
uint16_t checker = 0;
if (DBGLEVEL >= DBG_DEBUG) {
Dbprintf("doT55x7Acquisition - after init");
print_stack_usage();
}
while (skipCnt < 1000 && (i < bufsize)) {
if (checker == 1000) {
if (BUTTON_PRESS() || data_available())
if (BUTTON_PRESS())
break;
if (checker == 4000) {
if (data_available())
break;
else
checker = 0;
@ -462,21 +488,24 @@ void doT55x7Acquisition(size_t sample_size) {
void doCotagAcquisition(size_t sample_size) {
uint8_t *dest = BigBuf_get_addr();
uint16_t bufsize = BigBuf_max_traceLen();
if (bufsize > sample_size)
bufsize = sample_size;
uint16_t bufsize = MIN(sample_size, BigBuf_max_traceLen());
dest[0] = 0;
uint8_t firsthigh = 0, firstlow = 0;
uint16_t i = 0;
uint16_t noise_counter = 0;
uint16_t checker = 0;
uint16_t i = 0, noise_counter = 0, checker = 0;
if (DBGLEVEL >= DBG_DEBUG) {
Dbprintf("doCotagAcquisition - after init");
print_stack_usage();
}
while ((i < bufsize) && (noise_counter < (COTAG_T1 << 1))) {
if (checker == 1000) {
if (BUTTON_PRESS() || data_available())
if (BUTTON_PRESS())
break;
if (checker == 4000) {
if (data_available())
break;
else
checker = 0;
@ -530,21 +559,26 @@ void doCotagAcquisition(size_t sample_size) {
uint32_t doCotagAcquisitionManchester(void) {
uint8_t *dest = BigBuf_get_addr();
uint16_t bufsize = BigBuf_max_traceLen();
if (bufsize > COTAG_BITS)
bufsize = COTAG_BITS;
uint16_t bufsize = MIN(COTAG_BITS, BigBuf_max_traceLen());
dest[0] = 0;
uint8_t firsthigh = 0, firstlow = 0;
uint16_t sample_counter = 0, period = 0;
uint8_t curr = 0, prev = 0;
uint16_t noise_counter = 0;
uint16_t checker = 0;
uint16_t sample_counter = 0, period = 0;
uint16_t noise_counter = 0, checker = 0;
if (DBGLEVEL >= DBG_DEBUG) {
Dbprintf("doCotagAcquisitionManchester - after init");
print_stack_usage();
}
while ((sample_counter < bufsize) && (noise_counter < (COTAG_T1 << 1))) {
if (checker == 1000) {
if (BUTTON_PRESS() || data_available())
if (BUTTON_PRESS())
break;
if (checker == 4000) {
if ( data_available())
break;
else
checker = 0;

View file

@ -100,5 +100,6 @@ void setSamplingConfig(sample_config *sc);
sample_config *getSamplingConfig(void);
void printConfig(void);
void printSamples(void);
#endif // __LFSAMPLING_H