Monitor now works on UART
pull/13/head
ArjanteMarvelde 2021-05-15 22:12:44 +02:00
rodzic 00eba10ebc
commit 2a73cef9f0
5 zmienionych plików z 126 dodań i 76 usunięć

Wyświetl plik

@ -28,8 +28,8 @@ pico_set_program_version(uSDR "0.1")
target_link_libraries(uSDR pico_stdlib)
# Disable uart output, enable usb output
pico_enable_stdio_uart(uSDR 0)
pico_enable_stdio_usb(uSDR 1)
pico_enable_stdio_uart(uSDR 1)
pico_enable_stdio_usb(uSDR 0)
# Add any user requested libraries

14
dsp.c
Wyświetl plik

@ -78,13 +78,7 @@ volatile uint16_t dac_iq, dac_audio;
volatile uint32_t fifo_overrun, fifo_rx, fifo_tx, fifo_xx, fifo_incnt;
volatile bool tx_enabled;
/*
* Interface method to (de-)assert PTT
*/
void dsp_ptt(bool active)
{
tx_enabled = active;
}
/*
@ -262,14 +256,14 @@ bool tx(void)
* Classic Hilbert transform 15 taps, 12 bits (see Iowa Hills):
*/
a_accu = (a_s[0]-a_s[14])*315L + (a_s[2]-a_s[12])*440L + (a_s[4]-a_s[10])*734L + (a_s[6]-a_s[ 8])*2202L;
qh = a_accu / 4096;
qh = (int16_t)(a_accu >> 12);
/*
* Write I and Q to QSE DACs, phase is 7 back.
* Need to multiply AC with DAC_RANGE/ADC_RANGE (appr 1/16, but compensate for losses)
*/
pwm_set_chan_level(dac_iq, PWM_CHAN_A, DAC_BIAS + (a_s[7]/8));
pwm_set_chan_level(dac_iq, PWM_CHAN_B, DAC_BIAS + (qh/8));
pwm_set_chan_level(dac_iq, PWM_CHAN_A, DAC_BIAS + (a_s[7]/4));
pwm_set_chan_level(dac_iq, PWM_CHAN_B, DAC_BIAS + (qh/4));
return true;
}

4
dsp.h
Wyświetl plik

@ -13,9 +13,9 @@
#include "hardware/adc.h"
#include "hardware/pwm.h"
extern volatile bool tx_enabled;
void dsp_init();
void dsp_ptt(bool active);
#endif

13
hmi.c
Wyświetl plik

@ -248,9 +248,9 @@ void hmi_callback(uint gpio, uint32_t events)
break;
case GP_PTT: // PTT
if (events&GPIO_IRQ_EDGE_FALL)
dsp_ptt(true);
tx_enabled = true;
else
dsp_ptt(false);
tx_enabled = false;
return;
default:
return;
@ -298,8 +298,8 @@ void hmi_init(void)
hmi_option = 4; // Active kHz digit
hmi_freq = 7074000UL; // Initial frequency
SI_SETFREQ(0, 2*hmi_freq); // Set freq to 2*7074 kHz
SI_SETPHASE(0, 2); // Set phase to 180deg
SI_SETFREQ(0, hmi_freq); // Set freq to 7074 kHz
SI_SETPHASE(0, 1); // Set phase to 90deg
}
/*
@ -309,7 +309,7 @@ void hmi_evaluate(void)
{
char s[20];
sprintf(s, "%s %7.1f %3d", hmi_o_mode[hmi_sub[HMI_S_MODE]], (double)hmi_freq/1000.0, 920);
sprintf(s, "%s %7.1f %c%3d", hmi_o_mode[hmi_sub[HMI_S_MODE]], (double)hmi_freq/1000.0, (tx_enabled?126:127),920);
lcd_writexy(0,0,s);
switch (hmi_state)
{
@ -341,6 +341,7 @@ void hmi_evaluate(void)
default:
break;
}
SI_SETFREQ(0, 2*hmi_freq); // Set freq to latest
SI_SETFREQ(0, hmi_freq); // Set freq to latest
}

167
monitor.c
Wyświetl plik

@ -6,6 +6,7 @@
*
* Command shell on stdin/stdout.
* Collects characters and parses commandstring.
* Additional commands can easily be added.
*/
#include <stdio.h>
@ -18,70 +19,118 @@
#include "monitor.h"
/* Monitor definitions */
#define ENDSTDIN 255
#define CR 13
#define LF 10
#define CMD_LEN 32
char mon_cmd[CMD_LEN+1];
uint8_t si5351_reg[200];
bool ptt = false;
extern volatile uint32_t fifo_overrun, fifo_rx, fifo_tx, fifo_xx, fifo_incnt;
extern uint32_t adc_count;
/* Commandstring parser */
typedef struct
{
char *cmdstr; // Command string
int cmdlen; // Command string length
void (*cmd)(char* par); // Command executive
char *cmdsyn; // Command syntax
char *help; // Command help text
} shell_t;
/* ------------------------------------------------------------- */
/* Below the definitions of the shell commands, add where needed */
/* ------------------------------------------------------------- */
/*
* Dumps a defined range of Si5351 registers
*/
uint8_t si5351_reg[200];
void mon_si(char *par)
{
int base=0, nreg=200, i;
// Next: p = strtok(NULL, delim); (returns NULL if none left)
for (i=0; i<nreg; i++) si5351_reg[i] = 0xaa;
si_getreg(si5351_reg, (uint8_t)base, (uint8_t)nreg);
for (i=0; i<nreg; i++) printf("%02x ",(int)(si5351_reg[i]));
printf("\n");
}
/*
* Dumps the complete built-in and programmed characterset on the LCD
*/
void mon_lt(char *par)
{
printf("Check LCD...");
lcd_test();
printf("\n");
}
/*
* Checks for inter-core fifo overruns
*/
extern volatile uint32_t fifo_overrun, fifo_rx, fifo_tx, fifo_xx, fifo_incnt;
void mon_fo(char *par)
{
printf("Fifo input: %lu\n", fifo_incnt);
printf("Fifo rx: %lu\n", fifo_rx);
printf("Fifo tx: %lu\n", fifo_tx);
printf("Fifo unknown: %lu\n", fifo_xx);
printf("Fifo overruns: %lu\n", fifo_overrun);
}
/*
* Toggles the PTT status, overriding the HW signal
*/
bool ptt = false;
void mon_pt(char *par)
{
if (ptt)
{
ptt = false;
printf("PTT released\n");
}
else
{
ptt = true;
printf("PTT active\n");
}
tx_enabled = ptt;
}
#define NCMD 4
shell_t shell[NCMD]=
{
{"si", 2, &mon_si, "si <start> <nr of reg>", "Dumps Si5351 registers"},
{"lt", 2, &mon_lt, "lt (no parameters)", "LCD test, dumps characterset on LCD"},
{"fo", 2, &mon_fo, "fo (no parameters)", "Returns inter core fifo overruns"},
{"pt", 2, &mon_pt, "pt (no parameters)", "Toggles PTT status"}
};
/* Commandstring parser, checks commandstring and invokes shellcommand */
char delim[] = " ";
#define NCMD 5
char shell[NCMD][3] = {"si", "lt", "fo", "pt", "ad"};
void mon_parse(char* s)
{
char *p;
int base, nreg, i;
int i;
p = s; //strtok(s, delim); // Get command part of string
p = s; // Get command part of string
for (i=0; i<NCMD; i++)
if (strncmp(p, shell[i], 2) == 0) break;
switch(i)
if (strncmp(p, shell[i].cmdstr, shell[i].cmdlen) == 0) break;
if (i<NCMD)
(*shell[i].cmd)(p);
else
{
case 0:
// Next: p = strtok(NULL, delim); (returns NULL if none left)
for (i=0; i<nreg; i++) si5351_reg[i] = 0xaa;
si_getreg(si5351_reg, (uint8_t)base, (uint8_t)nreg);
for (i=0; i<nreg; i++) printf("%02x ",(int)(si5351_reg[i]));
printf("\n");
break;
case 1:
printf("%s\n", p);
lcd_test();
break;
case 2:
printf("Fifo input: %lu\n", fifo_incnt);
printf("Fifo rx: %lu\n", fifo_rx);
printf("Fifo tx: %lu\n", fifo_tx);
printf("Fifo unknown: %lu\n", fifo_xx);
printf("Fifo overruns: %lu\n", fifo_overrun);
break;
case 3:
if (ptt)
{
ptt = false;
printf("PTT released\n");
}
else
{
ptt = true;
printf("PTT active\n");
}
dsp_ptt(ptt);
break;
case 4:
printf("ADC IRQ count: %lu\n", adc_count);
break;
default:
printf("??\n");
break;
for (i=0; i<NCMD; i++)
printf("%s\n %s\n", shell[i].cmdsyn, shell[i].help);
}
}
@ -89,31 +138,37 @@ void mon_init()
{
stdio_init_all(); // Initialize Standard IO
mon_cmd[CMD_LEN] = '\0'; // Termination to be sure
printf("\n");
printf("=============\n");
printf(" uSDR-Pico \n");
printf(" PE1ATM \n");
printf(" 2021, Udjat \n");
printf("=============\n");
printf("Pico> "); // prompt
}
/*
* This function collects characters from stdin until CR or LF
* This function collects characters from stdin until CR
* Then the command is send to a parser and executed.
*/
void mon_evaluate(uint32_t timeout)
{
static int i = 0;
int c = getchar_timeout_us(timeout); // This is the only SDK way to read from stdin
int c = getchar_timeout_us(timeout); // NOTE: this is the only SDK way to read from stdin
if (c==PICO_ERROR_TIMEOUT) return; // Early bail out
switch (c)
{
case CR: // CR : need to parse command string
putchar((char)c); // Echo character
putchar('\n'); // Echo character, assume terminal appends CR
mon_cmd[i] = '\0'; // Terminate command string
if (i>0) // something to parse?
mon_parse(mon_cmd); // process command
mon_parse(mon_cmd); // --> process command
i=0; // reset index
printf("Pico> "); // prompt
break;
case LF:
putchar((char)c); // Echo character
break; // Further ignore, assume CR as terminator
break; // Ignore, assume CR as terminator
default:
if ((c<32)||(c>=128)) break; // Only allow alfanumeric
putchar((char)c); // Echo character