Merge branch 'DiSlord_test_branch'

pull/4/head
erikkaashoek 6 years ago
commit dd289f8ecd

@ -38,8 +38,8 @@
extern uint32_t minFreq;
extern uint32_t maxFreq;
float frequencyStart;
float frequencyStop;
uint32_t frequencyStart;
uint32_t frequencyStop;
int32_t frequencyExtra;
#define START_MIN minFreq
#define STOP_MAX maxFreq
@ -133,6 +133,7 @@ static THD_FUNCTION(Thread1, arg)
ui_process();
while (1) {
// START_PROFILE
if (sweep_mode&(SWEEP_ENABLE|SWEEP_ONCE)) {
// if (dirty)
completed = sweep(true);
@ -151,6 +152,7 @@ static THD_FUNCTION(Thread1, arg)
// if (setting.mode != -1)
__WFI();
}
// STOP_PROFILE
// Run Shell command in sweep thread
if (shell_function) {
operation_requested = OP_NONE; // otherwise commands will be aborted

@ -274,36 +274,18 @@ VNA_SHELL_FUNCTION(cmd_v)
shell_printf("VFO %d\r\n", VFO);
}
int xtoi(char *t)
{
int v=0;
while (*t) {
if ('0' <= *t && *t <= '9')
v = v*16 + *t - '0';
else if ('a' <= *t && *t <= 'f')
v = v*16 + *t - 'a' + 10;
else if ('A' <= *t && *t <= 'F')
v = v*16 + *t - 'A' + 10;
else
return v;
t++;
}
return v;
}
VNA_SHELL_FUNCTION(cmd_y)
{
int rvalue;
int lvalue = 0;
if (argc != 1 && argc != 2) {
shell_printf("usage: y {addr(0-95)} [value(0-FF)]\r\n");
shell_printf("usage: y {addr(0-95)} [value(0-0xFF)]\r\n");
return;
}
rvalue = xtoi(argv[0]);
rvalue = my_atoui(argv[0]);
SI4432_Sel = VFO;
if (argc == 2){
lvalue = xtoi(argv[1]);
lvalue = my_atoui(argv[1]);
SI4432_Write_Byte(rvalue, lvalue);
} else {
lvalue = SI4432_Read_Byte(rvalue);
@ -359,7 +341,7 @@ return; // Don't use!!!!
SI4432_Init();
shell_printf("SI4432 init done\r\n");
if (argc == 1) {
rvalue = xtoi(argv[0]);
rvalue = my_atoui(argv[0]);
set_switches(rvalue);
set_mode(rvalue);
shell_printf("SI4432 mode %d set\r\n", rvalue);
@ -389,10 +371,10 @@ VNA_SHELL_FUNCTION(cmd_a)
{
(void)argc;
if (argc != 1) {
shell_printf("a=%d\r\n", frequencyStart);
shell_printf("a=%u\r\n", frequencyStart);
return;
}
int32_t value = my_atoi(argv[0]);
uint32_t value = my_atoui(argv[0]);
frequencyStart = value;
}
@ -401,10 +383,10 @@ VNA_SHELL_FUNCTION(cmd_b)
{
(void)argc;
if (argc != 1) {
shell_printf("b=%d\r\n", frequencyStop);
shell_printf("b=%u\r\n", frequencyStop);
return;
}
int32_t value = my_atoi(argv[0]);
uint32_t value = my_atoui(argv[0]);
frequencyStop = value;
}
@ -443,20 +425,25 @@ VNA_SHELL_FUNCTION(cmd_s)
void sweep_remote(void)
{
int old_step = setting.frequency_step;
uint32_t f_step = (frequencyStop-frequencyStart)/ points;
setting.frequency_step = f_step;
uint32_t i;
uint32_t step = (points - 1);
uint32_t span = frequencyStop - frequencyStart;
uint32_t delta = span / step;
uint32_t error = span % step;
uint32_t f = frequencyStart - setting.frequency_IF, df = step>>1;
uint32_t old_step = setting.frequency_step;
setting.frequency_step = delta;
streamPut(shell_stream, '{');
dirty = true;
for (int i = 0; i<points; i++) {
for (i = 0; i <= step; i++, f+=delta) {
if (operation_requested)
break;
float val = perform(false, i, frequencyStart - setting.frequency_IF + f_step * i, false);
float val = perform(false, i, f, false);
streamPut(shell_stream, 'x');
int v = val*2 + 256;
streamPut(shell_stream, (uint8_t)(v & 0xFF));
streamPut(shell_stream, (uint8_t)((v>>8) & 0xFF));
// enable led
df+=error;if (df >=step) {f++;df -= step;}
}
streamPut(shell_stream, '}');
setting.frequency_step = old_step;

@ -24,6 +24,9 @@
#include <math.h>
#include "si4432.h"
#pragma GCC push_options
#pragma GCC optimize ("O2")
#define CS_SI0_HIGH palSetPad(GPIOC, GPIO_RX_SEL)
#define CS_SI1_HIGH palSetPad(GPIOC, GPIO_LO_SEL)
#define CS_PE_HIGH palSetPad(GPIOC, GPIO_PE_SEL)
@ -40,9 +43,10 @@
#define SPI2_SDI_HIGH palSetPad(GPIOB, GPIO_SPI2_SDI)
#define SPI2_SDI_LOW palClearPad(GPIOB, GPIO_SPI2_SDI)
#define SPI2_RESET palClearPort(GPIOB, (1<<GPIO_SPI2_CLK)|(1<<GPIO_SPI2_SDI))
#define SPI2_SDO ((palReadPort(GPIOB)>>GPIO_SPI2_SDO)&1)
#define SPI2_SDO ((palReadPort(GPIOB)>>GPIO_SPI2_SDO)&1)
#define SPI2_portSDO (palReadPort(GPIOB)&(1<<GPIO_SPI2_SDO))
//#define MAXLOG 1024
//unsigned char SI4432_logging[MAXLOG];
@ -51,10 +55,11 @@
//#define SI4432_log(X) { if (log_index < MAXLOG) SI4432_logging[log_index++] = X; }
#define SI4432_log(X)
void shiftOut(uint8_t val)
static void shiftOut(uint8_t val)
{
SI4432_log(SI4432_Sel);
SI4432_log(val);
#if 0
uint8_t i = 0;
do {
if (val & 0x80)
@ -65,20 +70,32 @@ void shiftOut(uint8_t val)
SPI2_CLK_HIGH;
SPI2_CLK_LOW;
}while((++i) & 0x07);
#else
uint8_t i = 0;
do {
if (val & 0x80)
SPI2_SDI_HIGH;
SPI2_CLK_HIGH;
SPI2_RESET;
val<<=1;
}while((++i) & 0x07);
#endif
}
uint8_t shiftIn(void) {
uint8_t value = 0;
static uint8_t shiftIn(void)
{
uint32_t value = 0;
uint8_t i = 0;
do {
value<<=1;
SPI2_CLK_HIGH;
value = (value<<1)|SPI2_SDO;
value|=SPI2_portSDO;
SPI2_CLK_LOW;
}while((++i) & 0x07);
return value;
return value>>GPIO_SPI2_SDO;
}
void shiftInBuf(uint8_t *buf, uint16_t size) {
static void shiftInBuf(uint8_t *buf, uint16_t size, uint16_t delay) {
uint8_t i = 0;
do{
uint8_t value = 0;
@ -88,10 +105,12 @@ void shiftInBuf(uint8_t *buf, uint16_t size) {
SPI2_CLK_LOW;
}while((++i) & 0x07);
*buf++=value;
if (delay)
my_microsecond_delay(delay);
}while(--size);
}
void shiftOutBuf(uint8_t *buf, uint16_t size) {
static void shiftOutBuf(uint8_t *buf, uint16_t size) {
uint8_t i = 0;
do{
uint8_t val = *buf++;
@ -376,25 +395,19 @@ void SI4432_Fill(int s, int start)
{
SI4432_Sel = s;
int sel = SI_nSEL[SI4432_Sel];
#if 1
float t = setting.sweep_time - calc_min_sweep_time(); // Time to delay in mS
if (t < 0)
t = 0;
int ti = t * 1000 / 290.0; // Now in uS per point if (t < 30000)
for (int i=start; i<sweep_points; ) {
SPI2_CLK_LOW;
float t = setting.sweep_time - calc_min_sweep_time(); // Time to delay in mS for all sweep
uint32_t ti = t < 0 ? 0 : t * 1000 / (sweep_points - 1); // Now in uS per point if (t < 30000)
SPI2_CLK_LOW;
int i = 0;
do {
palClearPad(GPIOC, sel);
shiftOut( 0x26 );
age[i++]=(char)shiftIn();
age[i]=(char)shiftIn();
palSetPad(GPIOC, sel);
if (++i >= sweep_points) break;
if (ti)
my_microsecond_delay(ti);
}
#else
palClearPad(GPIOC, sel);
shiftInBuf((uint8_t*)age, sweep_points);
palSetPad(GPIOC, sel);
#endif
} while(1);
buf_index = start;
buf_read = true;
}
@ -1055,3 +1068,5 @@ void ADF4351_prep_frequency(int channel, unsigned long freq, int drive) // freq
#endif
#pragma GCC pop_options

Loading…
Cancel
Save

Powered by TurnKey Linux.