Skip to content

Commit

Permalink
KiwiSDR 2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
jks-prv committed Sep 3, 2023
1 parent 11bb5a2 commit d03590c
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 94 deletions.
3 changes: 0 additions & 3 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ Boston, MA 02110-1301, USA.
// LOGGING_HOST, KIWI_UI_LIST, REPO
// {EDATA_DEVEL, EDATA_EMBED}

typedef enum { PLATFORM_BBG_BBB, PLATFORM_BB_AI, PLATFORM_BB_AI64, PLATFORM_RPI } platform_e;
extern platform_e platform;

typedef enum { ESPEED_AUTO = 0, ESPEED_10M = 1, ESPEED_100M = 2 } espeed_e;

#define FW_SEL_SDR_RX4_WF4 0
Expand Down
19 changes: 18 additions & 1 deletion init/cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,34 @@ void cfg_reload()
cfg_test();
#endif

model_e model;
int serno = eeprom_check(&model);
if ((serial_number = cfg_int("serial_number", NULL, CFG_OPTIONAL)) > 0) {
lprintf("serial number override from configuration: %d\n", serial_number);
} else {
if ((serial_number = eeprom_check()) <= 0) {
if ((serial_number = serno) <= 0) {
lprintf("can't read serial number from EEPROM and no configuration override\n");
serial_number = 0;
} else {
lprintf("serial number from EEPROM: %d\n", serial_number);
}
}

bool err;
kiwi.model = (model_e) admcfg_int("kiwi_model", &err, CFG_OPTIONAL);
if (!err) {
lprintf("Kiwi model override from configuration: KiwiSDR %d\n", kiwi.model);
} else {
if (serno <= 0 || model <= 0) {
lprintf("can't read Kiwi model from EEPROM and no configuration override\n");
lprintf("assuming model: KiwiSDR 1\n");
kiwi.model = KiwiSDR_1;
} else {
kiwi.model = model;
lprintf("model: KiwiSDR %d\n", model);
}
}

#ifdef USE_SDR
dx_label_init();
#endif
Expand Down
11 changes: 11 additions & 0 deletions kiwi.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ Boston, MA 02110-1301, USA.
#define CUTESDR_MAX_VAL ((float) ((1 << CUTESDR_SCALE) - 1))
#define CUTESDR_MAX_PWR (CUTESDR_MAX_VAL * CUTESDR_MAX_VAL)

typedef enum { KiwiSDR_1 = 1, KiwiSDR_2 = 2 } model_e;

typedef enum { PLATFORM_BBG_BBB, PLATFORM_BB_AI, PLATFORM_BB_AI64, PLATFORM_RPI } platform_e;

typedef enum { DAILY_RESTART_NO = 0, DAILY_RESTART = 1, DAILY_REBOOT = 2} daily_restart_e;

typedef struct {
model_e model;
platform_e platform;

bool allow_admin_conns;
bool spectral_inversion, spectral_inversion_lockout;

Expand All @@ -56,6 +65,8 @@ typedef struct {
// low-res lat/lon from timezone process
int lowres_lat, lowres_lon;

daily_restart_e daily_restart;

int ant_switch_nch;
} kiwi_t;

Expand Down
28 changes: 6 additions & 22 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Boston, MA 02110-1301, USA.
#include "sanitizer.h"
#include "shmem.h" // shmem_init()
#include "debug.h"
#include "fpga.h"

#include "other.gen.h"

Expand Down Expand Up @@ -80,7 +81,6 @@ int main_argc;
char **main_argv;
char *fpga_file;
static bool _kiwi_restart;
platform_e platform;

void kiwi_restart()
{
Expand Down Expand Up @@ -140,19 +140,19 @@ int main(int argc, char *argv[])
#endif

#ifdef PLATFORM_beaglebone_black
platform = PLATFORM_BBG_BBB;
kiwi.platform = PLATFORM_BBG_BBB;
#endif

#ifdef PLATFORM_beaglebone_ai
platform = PLATFORM_BB_AI;
kiwi.platform = PLATFORM_BB_AI;
#endif

#ifdef PLATFORM_beaglebone_ai64
platform = PLATFORM_BB_AI64;
kiwi.platform = PLATFORM_BB_AI64;
#endif

#ifdef PLATFORM_raspberrypi
platform = PLATFORM_RPI;
kiwi.platform = PLATFORM_RPI;
#endif

kstr_init();
Expand Down Expand Up @@ -444,23 +444,7 @@ int main(int argc, char *argv[])
if (!(ext_clk || ext_ADC_clk)) ctrl |= CTRL_OSC_EN;
ctrl_clr_set(0, ctrl);

// read device DNA
#define CTRL_DNA_CLK CTRL_SER_CLK
#define CTRL_DNA_READ CTRL_SER_LE_CSN
#define CTRL_DNA_SHIFT CTRL_SER_DATA

ctrl_set_ser_dev(CTRL_SER_DNA);
ctrl_clr_set(CTRL_DNA_CLK | CTRL_DNA_SHIFT, CTRL_DNA_READ);
ctrl_positive_pulse(CTRL_DNA_CLK);
ctrl_clr_set(CTRL_DNA_CLK | CTRL_DNA_READ, CTRL_DNA_SHIFT);
net.dna = 0;
for (int i=0; i < 64; i++) {
stat_reg_t stat = stat_get();
net.dna = (net.dna << 1) | ((stat.word & STAT_DNA_DATA)? 1ULL : 0ULL);
ctrl_positive_pulse(CTRL_DNA_CLK);
}
ctrl_clr_set(CTRL_DNA_CLK | CTRL_DNA_READ | CTRL_DNA_SHIFT, 0);
ctrl_clr_ser_dev();
net.dna = fpga_dna();
printf("device DNA %08x|%08x\n", PRINTF_U64_ARG(net.dna));
}

Expand Down
4 changes: 2 additions & 2 deletions rx/rx_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,8 @@ bool rx_common_cmd(int stream_type, conn_t *conn, char *cmd)
conn->isPassword = is_password;

if (stream_snd_or_wf || stream_admin_or_mfg) {
send_msg(conn, SM_NO_DEBUG, "MSG version_maj=%d version_min=%d debian_ver=%d platform=%d",
version_maj, version_min, debian_ver, platform);
send_msg(conn, SM_NO_DEBUG, "MSG version_maj=%d version_min=%d debian_ver=%d model=%d platform=%d",
version_maj, version_min, debian_ver, kiwi.model, kiwi.platform);
}

// send cfg once to javascript
Expand Down
36 changes: 18 additions & 18 deletions ui/mfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,20 @@ Boston, MA 02110-1301, USA.

bool sd_copy_in_progress;

static void mfg_send_info(conn_t *conn)
{
int next_serno = eeprom_next_serno(SERNO_READ, 0);
model_e model;
int serno = eeprom_check(&model);
send_msg(conn, SM_NO_DEBUG, "MFG next_serno=%d serno=%d model=%d", next_serno, serno, model);
}

void c2s_mfg_setup(void *param)
{
conn_t *conn = (conn_t *) param;

send_msg(conn, SM_NO_DEBUG, "MFG ver_maj=%d ver_min=%d", version_maj, version_min);

int next_serno = eeprom_next_serno(SERNO_READ, 0);
int serno = eeprom_check();
send_msg(conn, SM_NO_DEBUG, "MFG next_serno=%d serno=%d", next_serno, serno);
mfg_send_info(conn);
}

void c2s_mfg(void *param)
Expand All @@ -79,16 +84,14 @@ void c2s_mfg(void *param)
if (rx_common_cmd(STREAM_MFG, conn, cmd))
continue;

printf("MFG: <%s>\n", cmd);

i = strcmp(cmd, "SET write");
if (i == 0) {
printf("MFG: received write\n");
eeprom_write(SERNO_ALLOC, 0);

serno = eeprom_check();
next_serno = eeprom_next_serno(SERNO_READ, 0);
send_msg(conn, SM_NO_DEBUG, "MFG next_serno=%d serno=%d", next_serno, serno);
//printf("MFG: <%s>\n", cmd);

int _model = 0;
i = sscanf(cmd, "SET write model=%d", &_model);
if (i == 1 && _model > 0) {
printf("MFG: received write, model=%d\n", _model);
eeprom_write(SERNO_ALLOC, 0, _model);
mfg_send_info(conn);
continue;
}

Expand All @@ -97,10 +100,7 @@ void c2s_mfg(void *param)
if (i == 1) {
printf("MFG: received set_serno=%d\n", next_serno);
eeprom_next_serno(SERNO_WRITE, next_serno);

serno = eeprom_check();
next_serno = eeprom_next_serno(SERNO_READ, 0);
send_msg(conn, SM_NO_DEBUG, "MFG next_serno=%d serno=%d", next_serno, serno);
mfg_send_info(conn);
continue;
}

Expand Down
18 changes: 14 additions & 4 deletions web/kiwi/kiwi.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
var kiwi = {
d: {}, // debug

KiwiSDR_1: 1,
KiwiSDR_2: 2,
model: 1,

PLATFORM_BBG_BBB: 0,
PLATFORM_BB_AI: 1,
PLATFORM_BB_AI64: 2,
Expand Down Expand Up @@ -117,6 +121,8 @@ var kiwi = {
bands: null,
bands_community: null,

rf_attn: 0,

_ver_: 1.578,
_last_: null
};
Expand Down Expand Up @@ -2446,11 +2452,11 @@ function cpu_stats_cb(o, uptime_secs, ecpu, waterfall_fps)
var hr = Math.trunc(t % 24); t = Math.trunc(t/24);
var days = t;

var s = ' ';
var s = ' up ';
if (days) s += days +'d:';
s += hr +':'+ min.leadingZeros(2) +':'+ sec.leadingZeros(2);
w3_innerHTML('id-status-config',
w3_text('w3-text-css-orange', 'Up'),
w3_text('w3-text-css-orange', 'KiwiSDR '+ kiwi.model),
w3_text('', s +', '+ kiwi_config_str)
);

Expand All @@ -2471,9 +2477,9 @@ function cpu_stats_cb(o, uptime_secs, ecpu, waterfall_fps)

function config_str_update(rx_chans, gps_chans, vmaj, vmin)
{
kiwi_config_str = 'v'+ vmaj +'.'+ vmin +', '+ rx_chans +' SDR ch, '+ gps_chans +' GPS ch';
kiwi_config_str = 'v'+ vmaj +'.'+ vmin +', ch: '+ rx_chans +' SDR '+ gps_chans +' GPS';
w3_innerHTML('id-status-config', kiwi_config_str);
kiwi_config_str_long = 'Config: v'+ vmaj +'.'+ vmin +', '+ rx_chans +' SDR channels, '+ gps_chans +' GPS channels';
kiwi_config_str_long = 'KiwiSDR '+ kiwi.model +', v'+ vmaj +'.'+ vmin +', '+ rx_chans +' SDR channels, '+ gps_chans +' GPS channels';
w3_innerHTML('id-msg-config', kiwi_config_str);
}

Expand Down Expand Up @@ -2898,6 +2904,10 @@ function kiwi_msg(param, ws)
debian_ver = parseInt(param[1]);
break;

case "model":
kiwi.model = parseInt(param[1]);
break;

case "platform":
kiwi.platform = parseInt(param[1]);
break;
Expand Down
4 changes: 2 additions & 2 deletions web/kiwi/kiwi.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d03590c

Please sign in to comment.