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 minFreq;
extern uint32_t maxFreq; extern uint32_t maxFreq;
float frequencyStart; uint32_t frequencyStart;
float frequencyStop; uint32_t frequencyStop;
int32_t frequencyExtra; int32_t frequencyExtra;
#define START_MIN minFreq #define START_MIN minFreq
#define STOP_MAX maxFreq #define STOP_MAX maxFreq
@ -133,6 +133,7 @@ static THD_FUNCTION(Thread1, arg)
ui_process(); ui_process();
while (1) { while (1) {
// START_PROFILE
if (sweep_mode&(SWEEP_ENABLE|SWEEP_ONCE)) { if (sweep_mode&(SWEEP_ENABLE|SWEEP_ONCE)) {
// if (dirty) // if (dirty)
completed = sweep(true); completed = sweep(true);
@ -151,6 +152,7 @@ static THD_FUNCTION(Thread1, arg)
// if (setting.mode != -1) // if (setting.mode != -1)
__WFI(); __WFI();
} }
// STOP_PROFILE
// Run Shell command in sweep thread // Run Shell command in sweep thread
if (shell_function) { if (shell_function) {
operation_requested = OP_NONE; // otherwise commands will be aborted 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); 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) VNA_SHELL_FUNCTION(cmd_y)
{ {
int rvalue; int rvalue;
int lvalue = 0; int lvalue = 0;
if (argc != 1 && argc != 2) { 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; return;
} }
rvalue = xtoi(argv[0]); rvalue = my_atoui(argv[0]);
SI4432_Sel = VFO; SI4432_Sel = VFO;
if (argc == 2){ if (argc == 2){
lvalue = xtoi(argv[1]); lvalue = my_atoui(argv[1]);
SI4432_Write_Byte(rvalue, lvalue); SI4432_Write_Byte(rvalue, lvalue);
} else { } else {
lvalue = SI4432_Read_Byte(rvalue); lvalue = SI4432_Read_Byte(rvalue);
@ -359,7 +341,7 @@ return; // Don't use!!!!
SI4432_Init(); SI4432_Init();
shell_printf("SI4432 init done\r\n"); shell_printf("SI4432 init done\r\n");
if (argc == 1) { if (argc == 1) {
rvalue = xtoi(argv[0]); rvalue = my_atoui(argv[0]);
set_switches(rvalue); set_switches(rvalue);
set_mode(rvalue); set_mode(rvalue);
shell_printf("SI4432 mode %d set\r\n", rvalue); shell_printf("SI4432 mode %d set\r\n", rvalue);
@ -389,10 +371,10 @@ VNA_SHELL_FUNCTION(cmd_a)
{ {
(void)argc; (void)argc;
if (argc != 1) { if (argc != 1) {
shell_printf("a=%d\r\n", frequencyStart); shell_printf("a=%u\r\n", frequencyStart);
return; return;
} }
int32_t value = my_atoi(argv[0]); uint32_t value = my_atoui(argv[0]);
frequencyStart = value; frequencyStart = value;
} }
@ -401,10 +383,10 @@ VNA_SHELL_FUNCTION(cmd_b)
{ {
(void)argc; (void)argc;
if (argc != 1) { if (argc != 1) {
shell_printf("b=%d\r\n", frequencyStop); shell_printf("b=%u\r\n", frequencyStop);
return; return;
} }
int32_t value = my_atoi(argv[0]); uint32_t value = my_atoui(argv[0]);
frequencyStop = value; frequencyStop = value;
} }
@ -443,20 +425,25 @@ VNA_SHELL_FUNCTION(cmd_s)
void sweep_remote(void) void sweep_remote(void)
{ {
int old_step = setting.frequency_step; uint32_t i;
uint32_t f_step = (frequencyStop-frequencyStart)/ points; uint32_t step = (points - 1);
setting.frequency_step = f_step; 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, '{'); streamPut(shell_stream, '{');
dirty = true; dirty = true;
for (int i = 0; i<points; i++) { for (i = 0; i <= step; i++, f+=delta) {
if (operation_requested) if (operation_requested)
break; 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'); streamPut(shell_stream, 'x');
int v = val*2 + 256; int v = val*2 + 256;
streamPut(shell_stream, (uint8_t)(v & 0xFF)); streamPut(shell_stream, (uint8_t)(v & 0xFF));
streamPut(shell_stream, (uint8_t)((v>>8) & 0xFF)); streamPut(shell_stream, (uint8_t)((v>>8) & 0xFF));
// enable led df+=error;if (df >=step) {f++;df -= step;}
} }
streamPut(shell_stream, '}'); streamPut(shell_stream, '}');
setting.frequency_step = old_step; setting.frequency_step = old_step;

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

Loading…
Cancel
Save

Powered by TurnKey Linux.