add wait_dsp function, add trace all off command, fix hang on ploting polar with trace 0

This commit is contained in:
TT 2016-11-28 23:44:21 +09:00
parent 25dd4bf182
commit 69c41aa57e
4 changed files with 44 additions and 42 deletions

9
dsp.c
View file

@ -75,7 +75,7 @@ hilbert_transform(void)
} }
} }
void calclate_gamma(float *gamma) void calculate_gamma(float *gamma)
#if 0 #if 0
{ {
__SIMD32_TYPE *r = __SIMD32_CONST(refiq_buf); __SIMD32_TYPE *r = __SIMD32_CONST(refiq_buf);
@ -110,10 +110,12 @@ void calclate_gamma(float *gamma)
float acc_ref = 0; float acc_ref = 0;
int i; int i;
float rn; float rn;
int32_t offset_s0 = 0; int32_t offset_s0 = 0;
int32_t offset_r0 = 0; int32_t offset_r0 = 0;
int32_t offset_i0 = 0; int32_t offset_i0 = 0;
__disable_irq();
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
offset_s0 += *s++; offset_s0 += *s++;
offset_i0 += *r++; offset_i0 += *r++;
@ -133,6 +135,9 @@ void calclate_gamma(float *gamma)
acc_i += (float)(s0 * ri); acc_i += (float)(s0 * ri);
acc_ref += (float)rr*rr + (float)ri*ri; acc_ref += (float)rr*rr + (float)ri*ri;
} }
__enable_irq();
//rn = sqrtf(acc_ref / len) * 2e3 * len; //rn = sqrtf(acc_ref / len) * 2e3 * len;
rn = acc_ref / 10; rn = acc_ref / 10;
gamma[0] = -acc_r / rn; gamma[0] = -acc_r / rn;

67
main.c
View file

@ -211,13 +211,18 @@ static struct {
int16_t rx_buffer[AUDIO_BUFFER_LEN * 2]; int16_t rx_buffer[AUDIO_BUFFER_LEN * 2];
int16_t dump_buffer[AUDIO_BUFFER_LEN]; int16_t dump_buffer[AUDIO_BUFFER_LEN];
volatile int16_t wait_count = 0;
int16_t dump_selection = 0; int16_t dump_selection = 0;
volatile int16_t wait_count = 0;
int16_t dsp_disabled = FALSE;
float measured[2][101][2]; float measured[2][101][2];
static void
wait_dsp(int count)
{
wait_count = count;
while (wait_count)
;
}
void i2s_end_callback(I2SDriver *i2sp, size_t offset, size_t n) void i2s_end_callback(I2SDriver *i2sp, size_t offset, size_t n)
{ {
@ -230,8 +235,7 @@ void i2s_end_callback(I2SDriver *i2sp, size_t offset, size_t n)
(void)n; (void)n;
//palClearPad(GPIOC, GPIOC_LED); //palClearPad(GPIOC, GPIOC_LED);
if (!dsp_disabled) dsp_process(p, n);
dsp_process(p, n);
if (wait_count > 0) { if (wait_count > 0) {
if (dump_selection == 1) if (dump_selection == 1)
@ -297,10 +301,9 @@ static void cmd_dump(BaseSequentialStream *chp, int argc, char *argv[])
if (argc == 1) if (argc == 1)
dump_selection = atoi(argv[0]); dump_selection = atoi(argv[0]);
wait_count = 3;
//palClearPad(GPIOC, GPIOC_LED); //palClearPad(GPIOC, GPIOC_LED);
while (wait_count) wait_dsp(3);
;
len = AUDIO_BUFFER_LEN; len = AUDIO_BUFFER_LEN;
if (dump_selection == 1 || dump_selection == 2) if (dump_selection == 1 || dump_selection == 2)
len /= 2; len /= 2;
@ -320,12 +323,8 @@ static void cmd_gamma(BaseSequentialStream *chp, int argc, char *argv[])
(void)argv; (void)argv;
pause_sweep(); pause_sweep();
wait_count = 4; wait_dsp(4);
while (wait_count) calculate_gamma(gamma);
;
dsp_disabled = TRUE;
calclate_gamma(gamma);
dsp_disabled = FALSE;
chprintf(chp, "%d %d\r\n", gamma[0], gamma[1]); chprintf(chp, "%d %d\r\n", gamma[0], gamma[1]);
} }
@ -390,17 +389,11 @@ static void cmd_scan(BaseSequentialStream *chp, int argc, char *argv[])
delay += 2; delay += 2;
for (i = 0; i < sweep_points; i++) { for (i = 0; i < sweep_points; i++) {
freq = freq + step; freq = freq + step;
wait_count = delay + 1; wait_dsp(delay+1);
while (wait_count)
;
//dsp_disabled = TRUE;
__disable_irq();
delay = set_frequency(freq); delay = set_frequency(freq);
palClearPad(GPIOC, GPIOC_LED); palClearPad(GPIOC, GPIOC_LED);
calclate_gamma(gamma); calculate_gamma(gamma);
palSetPad(GPIOC, GPIOC_LED); palSetPad(GPIOC, GPIOC_LED);
//dsp_disabled = FALSE;
__enable_irq();
chprintf(chp, "%d %d\r\n", gamma[0], gamma[1]); chprintf(chp, "%d %d\r\n", gamma[0], gamma[1]);
} }
} }
@ -414,24 +407,18 @@ void scan_lcd(void)
delay = set_frequency(frequencies[0]); delay = set_frequency(frequencies[0]);
delay += 2; delay += 2;
for (i = 0; i < sweep_points; i++) { for (i = 0; i < sweep_points; i++) {
wait_count = delay + 2;
tlv320aic3204_select_in3(); tlv320aic3204_select_in3();
while (wait_count) wait_dsp(delay+2);
;
palClearPad(GPIOC, GPIOC_LED); palClearPad(GPIOC, GPIOC_LED);
__disable_irq();
/* calculate reflection coeficient */ /* calculate reflection coeficient */
calclate_gamma(measured[0][i]); calculate_gamma(measured[0][i]);
__enable_irq();
tlv320aic3204_select_in1(); tlv320aic3204_select_in1();
wait_count = 2 + 2; wait_dsp(2+2);
while (wait_count)
;
__disable_irq();
/* calculate transmission coeficient */ /* calculate transmission coeficient */
calclate_gamma(measured[1][i]); calculate_gamma(measured[1][i]);
__enable_irq();
delay = set_frequency(frequencies[(i+1)%sweep_points]); delay = set_frequency(frequencies[(i+1)%sweep_points]);
palSetPad(GPIOC, GPIOC_LED); palSetPad(GPIOC, GPIOC_LED);
@ -879,6 +866,16 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
} }
return; return;
} }
if (strcmp(argv[0], "all") == 0 &&
argc > 1 && strcmp(argv[1], "off") == 0) {
set_trace_type(0, TRC_OFF);
set_trace_type(1, TRC_OFF);
set_trace_type(2, TRC_OFF);
set_trace_type(3, TRC_OFF);
goto exit;
}
t = atoi(argv[0]); t = atoi(argv[0]);
if (t < 0 || t >= 4) if (t < 0 || t >= 4)
goto usage; goto usage;
@ -919,7 +916,7 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
exit: exit:
return; return;
usage: usage:
chprintf(chp, "trace [n] [logmag|phase|smith|swr] [src]\r\n"); chprintf(chp, "trace {0|1|2|3|all} [logmag|phase|smith|linear|delay|swr|off] [src]\r\n");
} }
static void cmd_marker(BaseSequentialStream *chp, int argc, char *argv[]) static void cmd_marker(BaseSequentialStream *chp, int argc, char *argv[])

View file

@ -49,7 +49,7 @@ extern int16_t samp_buf[];
extern int16_t refiq_buf[]; extern int16_t refiq_buf[];
void dsp_process(int16_t *src, size_t len); void dsp_process(int16_t *src, size_t len);
void calclate_gamma(float *gamma); void calculate_gamma(float *gamma);
int si5351_set_frequency_with_offset(int freq, int offset, uint8_t drive_strength); int si5351_set_frequency_with_offset(int freq, int offset, uint8_t drive_strength);

8
plot.c
View file

@ -1066,10 +1066,10 @@ draw_cell(int m, int n)
#if 1 #if 1
/* draw rectanglar plot */ /* draw rectanglar plot */
if (search_index_x(x0, trace_index[0], &i0, &i1)) { for (t = 0; t < TRACES_MAX; t++) {
for (t = 0; t < TRACES_MAX; t++) { if (!trace[t].enabled || trace[t].polar)
if (!trace[t].enabled || trace[t].polar) continue;
continue; if (search_index_x(x0, trace_index[t], &i0, &i1)) {
if (i0 > 0) if (i0 > 0)
i0--; i0--;
for (i = i0; i < i1; i++) { for (i = i0; i < i1; i++) {