Skip to content

Commit ccdd91d

Browse files
committed
Merge branch 'cw-tone-command'
2 parents dec460d + 6f41a8d commit ccdd91d

File tree

5 files changed

+85
-79
lines changed

5 files changed

+85
-79
lines changed

display.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ static int mag_shift = 0;
863863
static inline int
864864
v2ypos(q31_t v)
865865
{
866-
v >>= 22 - mag_shift;
866+
v >>= 24 - mag_shift;
867867
v += HEIGHT/2;
868868
if (v < 0) v = 0;
869869
if (v >= HEIGHT) v = HEIGHT-1;
@@ -897,7 +897,9 @@ draw_waveform(void)
897897
if (uistat.wfdispmode == WATERFALL)
898898
return;
899899

900-
if (uistat.wfdispmode == WAVEFORM_MAG)
900+
if (uistat.wfdispmode == WAVEFORM_MAG2)
901+
mag_shift = 6;
902+
else if (uistat.wfdispmode == WAVEFORM_MAG)
901903
mag_shift = 3;
902904
else
903905
mag_shift = 0;

dsp.c

Lines changed: 45 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ cos_sin(uint16_t phase)
283283

284284
uint16_t nco1_phase = 0;
285285
uint16_t nco2_phase = 0;
286-
#define SSB_NCO_PHASESTEP (65536L*SSB_FREQ_OFFSET/48000)
286+
#define SSB_NCO_PHASESTEP PHASESTEP(SSB_FREQ_OFFSET)
287287

288288

289289
// Bi-Quad IIR Filter state
@@ -329,8 +329,22 @@ q15_t bq_coeffs_150hz[] = {
329329
arm_biquad_casd_df1_inst_q15 bq_cw_i = { 3, bq_i_state, bq_coeffs_150hz, 1};
330330
arm_biquad_casd_df1_inst_q15 bq_cw_q = { 3, bq_q_state, bq_coeffs_150hz, 1};
331331

332+
typedef struct {
333+
int16_t phasestep1;
334+
int16_t phasestep2;
335+
arm_biquad_casd_df1_inst_q15 *bq_i;
336+
arm_biquad_casd_df1_inst_q15 *bq_q;
337+
} weaver_demod_conf_t;
338+
339+
const weaver_demod_conf_t usb_demod_conf = {
340+
SSB_NCO_PHASESTEP, SSB_NCO_PHASESTEP, &bq_i, &bq_q
341+
};
342+
const weaver_demod_conf_t lsb_demod_conf = {
343+
-SSB_NCO_PHASESTEP, -SSB_NCO_PHASESTEP, &bq_i, &bq_q
344+
};
345+
332346
void
333-
ssb_demod(int16_t *src, int16_t *dst, size_t len, int phasestep)
347+
demod_weaver(int16_t *src, int16_t *dst, size_t len, const weaver_demod_conf_t *dc)
334348
{
335349
q15_t *bufi = buffer[0];
336350
q15_t *bufq = buffer[1];
@@ -343,16 +357,16 @@ ssb_demod(int16_t *src, int16_t *dst, size_t len, int phasestep)
343357
// shift frequency
344358
for (i = 0; i < len/2; i++) {
345359
uint32_t cossin = cos_sin(nco1_phase);
346-
nco1_phase -= phasestep;
360+
nco1_phase -= dc->phasestep1;
347361
uint32_t iq = *s++;
348362
*bufi++ = __SMLSDX(iq, cossin, 0) >> (15-0);
349363
*bufq++ = __SMLAD(iq, cossin, 0) >> (15-0);
350364
}
351365
disp_fetch_samples(B_IF1, BT_IQ, buffer[0], buffer[1], len/2);
352366

353367
// apply low pass filter
354-
arm_biquad_cascade_df1_q15(&bq_i, buffer[0], buffer2[0], len/2);
355-
arm_biquad_cascade_df1_q15(&bq_q, buffer[1], buffer2[1], len/2);
368+
arm_biquad_cascade_df1_q15(dc->bq_i, buffer[0], buffer2[0], len/2);
369+
arm_biquad_cascade_df1_q15(dc->bq_q, buffer[1], buffer2[1], len/2);
356370

357371
disp_fetch_samples(B_IF2, BT_IQ, buffer2[0], buffer2[1], len/2);
358372

@@ -361,7 +375,7 @@ ssb_demod(int16_t *src, int16_t *dst, size_t len, int phasestep)
361375
bufq = buffer2[1];
362376
for (i = 0; i < len/2; i++) {
363377
uint32_t cossin = cos_sin(nco2_phase);
364-
nco2_phase += phasestep;
378+
nco2_phase += dc->phasestep2;
365379
uint32_t iq = __PKHBT(*bufi++, *bufq++, 16);
366380
uint32_t r = __SMLAD(iq, cossin, 0) >> (15-0);
367381
*d++ = __PKHBT(r, r, 16);
@@ -370,6 +384,30 @@ ssb_demod(int16_t *src, int16_t *dst, size_t len, int phasestep)
370384
disp_fetch_samples(B_PLAYBACK, BT_R_INTERLEAVE, dst, NULL, len);
371385
}
372386

387+
void
388+
lsb_demod(int16_t *src, int16_t *dst, size_t len)
389+
{
390+
demod_weaver(src, dst, len, &lsb_demod_conf);
391+
}
392+
393+
void
394+
usb_demod(int16_t *src, int16_t *dst, size_t len)
395+
{
396+
demod_weaver(src, dst, len, &usb_demod_conf);
397+
}
398+
399+
void
400+
cw_demod(int16_t *src, int16_t *dst, size_t len)
401+
{
402+
weaver_demod_conf_t dc = {
403+
mode_freqoffset_phasestep, cw_tone_phasestep, &bq_cw_i, &bq_cw_q
404+
};
405+
406+
demod_weaver(src, dst, len, &dc);
407+
}
408+
409+
410+
373411
__attribute__ ( ( always_inline ) ) __STATIC_INLINE
374412
float _VSQRTF(float op1) {
375413
float result;
@@ -383,8 +421,6 @@ void
383421
am_demod(int16_t *src, int16_t *dst, size_t len)
384422
#if defined(AM_FREQ_OFFSET) && AM_FREQ_OFFSET
385423
{
386-
#define PHASESTEP 65536L*AM_FREQ_OFFSET/48000
387-
388424
q15_t *bufi = buffer[0];
389425
q15_t *bufq = buffer[1];
390426
int32_t *s = __SIMD32(src);
@@ -395,7 +431,7 @@ am_demod(int16_t *src, int16_t *dst, size_t len)
395431

396432
for (i = 0; i < len/2; i++) {
397433
uint32_t cossin = cos_sin(nco1_phase);
398-
nco1_phase -= PHASESTEP;
434+
nco1_phase -= mode_freqoffset_phasestep;
399435
uint32_t iq = *s++;
400436
*bufi++ = __SMLSDX(iq, cossin, 0) >> (15-0);
401437
*bufq++ = __SMLAD(iq, cossin, 0) >> (15-0);
@@ -446,66 +482,6 @@ am_demod(int16_t *src, int16_t *dst, size_t len)
446482
}
447483
#endif
448484

449-
void
450-
lsb_demod(int16_t *src, int16_t *dst, size_t len)
451-
{
452-
ssb_demod(src, dst, len, -SSB_NCO_PHASESTEP);
453-
}
454-
455-
void
456-
usb_demod(int16_t *src, int16_t *dst, size_t len)
457-
{
458-
ssb_demod(src, dst, len, SSB_NCO_PHASESTEP);
459-
}
460-
461-
462-
int16_t cw_phasestep1 = 65536L*10000/48000;;
463-
int16_t cw_phasestep2 = 65536L*400/48000;
464-
465-
void
466-
cw_demod(int16_t *src, int16_t *dst, size_t len)
467-
{
468-
q15_t *bufi = buffer[0];
469-
q15_t *bufq = buffer[1];
470-
int32_t *s = __SIMD32(src);
471-
int32_t *d = __SIMD32(dst);
472-
uint32_t i;
473-
474-
disp_fetch_samples(B_CAPTURE, BT_C_INTERLEAVE, src, NULL, len);
475-
476-
// shift frequency
477-
for (i = 0; i < len/2; i++) {
478-
uint32_t cossin = cos_sin(nco1_phase);
479-
nco1_phase -= cw_phasestep1;
480-
uint32_t iq = *s++;
481-
*bufi++ = __SMLSDX(iq, cossin, 0) >> (15-0);
482-
*bufq++ = __SMLAD(iq, cossin, 0) >> (15-0);
483-
}
484-
disp_fetch_samples(B_IF1, BT_IQ, buffer[0], buffer[1], len/2);
485-
486-
// apply low pass filter
487-
arm_biquad_cascade_df1_q15(&bq_cw_i, buffer[0], buffer2[0], len/2);
488-
arm_biquad_cascade_df1_q15(&bq_cw_q, buffer[1], buffer2[1], len/2);
489-
490-
disp_fetch_samples(B_IF2, BT_IQ, buffer2[0], buffer2[1], len/2);
491-
492-
// shift frequency inverse
493-
bufi = buffer2[0];
494-
bufq = buffer2[1];
495-
for (i = 0; i < len/2; i++) {
496-
uint32_t cossin = cos_sin(nco2_phase);
497-
nco2_phase -= cw_phasestep2;
498-
uint32_t iq = __PKHBT(*bufi++, *bufq++, 16);
499-
uint32_t r = __SMLAD(iq, cossin, 0) >> (15-0);
500-
*d++ = __PKHBT(r, r, 16);
501-
}
502-
503-
disp_fetch_samples(B_PLAYBACK, BT_R_INTERLEAVE, dst, NULL, len);
504-
}
505-
506-
507-
508-
509485

510486

511487
struct {

flash.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ checksum(const void *start, size_t len)
8181

8282
// last page of flash memory. assume STM32F303CBT6 flash 128k Device
8383
const uint32_t save_config_area = 0x0801f800;
84+
const uint32_t save_config_prop_area_size = 0x800;
8485

8586
int
8687
config_save(void)
@@ -123,8 +124,6 @@ config_recall(void)
123124
return 0;
124125
}
125126

126-
const uint32_t save_config_prop_area_size = 0x800;
127-
128127
void
129128
clear_all_config_prop_data(void)
130129
{

main.c

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ const char *agcmode_table[] = {
125125

126126
signal_process_func_t signal_process = am_demod;
127127
int16_t mode_freq_offset = AM_FREQ_OFFSET;
128+
int16_t mode_freqoffset_phasestep;
129+
int16_t cw_tone_phasestep = PHASESTEP(800);
128130
int32_t center_frequency;
129131

130132
// restored from/into flash memory
@@ -144,7 +146,8 @@ config_t config = {
144146
.volume = 0,
145147
.rfgain = 40, // 0 ~ 95
146148
//.agcmode = AGC_MANUAL,
147-
.agcmode = AGC_MID
149+
.agcmode = AGC_MID,
150+
.cw_tone_freq = 800
148151
},
149152
.channels = {
150153
/* freq, modulation */
@@ -187,9 +190,14 @@ void set_modulation(modulation_t mod)
187190
{
188191
if (mod >= MOD_MAX)
189192
return;
193+
190194
set_fs(mod_table[mod].fs);
191195
signal_process = mod_table[mod].demod_func;
196+
192197
mode_freq_offset = mod_table[mod].freq_offset;
198+
mode_freqoffset_phasestep = PHASESTEP(mode_freq_offset);
199+
cw_tone_phasestep = PHASESTEP(uistat.cw_tone_freq);
200+
193201
uistat.modulation = mod;
194202
disp_update();
195203
}
@@ -267,10 +275,6 @@ static const I2SConfig i2sconfig = {
267275
2 // i2spr
268276
};
269277

270-
271-
272-
#define FS 48000
273-
274278
static void tone_generate(int freq)
275279
{
276280
int i;
@@ -630,6 +634,25 @@ static void cmd_mode(BaseSequentialStream *chp, int argc, char *argv[])
630634
}
631635
}
632636

637+
static void cmd_cwtone(BaseSequentialStream *chp, int argc, char *argv[])
638+
{
639+
int freq = 0;
640+
if (argc == 0) {
641+
chprintf(chp, "%d\r\n", uistat.cw_tone_freq);
642+
return;
643+
}
644+
645+
if (argc == 1)
646+
freq = atoi(argv[0]);
647+
648+
if (freq == 0) {
649+
chprintf(chp, "usage: cwtone {audio frequency(Hz)}\r\n");
650+
return;
651+
}
652+
uistat.cw_tone_freq = freq;
653+
cw_tone_phasestep = PHASESTEP(freq);
654+
}
655+
633656
static void cmd_fs(BaseSequentialStream *chp, int argc, char *argv[])
634657
{
635658
int fs = 0;
@@ -778,6 +801,7 @@ static const ShellCommand commands[] =
778801
{ "dac", cmd_dac },
779802
{ "uitest", cmd_uitest },
780803
{ "tone", cmd_tone },
804+
{ "cwtone", cmd_cwtone },
781805
{ "data", cmd_data },
782806
{ "stat", cmd_stat },
783807
{ "gain", cmd_gain },

nanosdr.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,15 @@ void fm_demod_stereo(int16_t *src, int16_t *dst, size_t len);
9797

9898
void dsp_init(void);
9999

100+
#define FS 48000
100101
#define AM_FREQ_OFFSET 10000
101102
#define SSB_FREQ_OFFSET 1300
103+
#define PHASESTEP(freq) (65536L * freq / FS)
102104

103105
extern int32_t center_frequency;
104106
extern int16_t mode_freq_offset;
107+
extern int16_t mode_freqoffset_phasestep;
108+
extern int16_t cw_tone_phasestep;
105109

106110
typedef struct {
107111
int16_t *buffer;
@@ -236,7 +240,8 @@ typedef struct {
236240
int8_t digit; /* 0~5 */
237241
int freq_offset;
238242
enum { SPDISP_CAP, SPDISP_CAP2, SPDISP_IF, SPDISP_AUD, SPDISP_MODE_MAX } spdispmode;
239-
enum { WATERFALL, WAVEFORM, WAVEFORM_MAG, WFDISP_MODE_MAX } wfdispmode;
243+
enum { WATERFALL, WAVEFORM, WAVEFORM_MAG, WAVEFORM_MAG2, WFDISP_MODE_MAX } wfdispmode;
244+
int16_t cw_tone_freq;
240245
} uistat_t;
241246

242247
extern uistat_t uistat;

0 commit comments

Comments
 (0)