diff --git a/main.c b/main.c index 67fe4a0..eaaf20c 100644 --- a/main.c +++ b/main.c @@ -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 diff --git a/sa_cmd.c b/sa_cmd.c index 6c2d0d2..2130e29 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -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>8) & 0xFF)); - // enable led + df+=error;if (df >=step) {f++;df -= step;} } streamPut(shell_stream, '}'); setting.frequency_step = old_step; diff --git a/si4432.c b/si4432.c index 7e17dd6..bab4a4d 100644 --- a/si4432.c +++ b/si4432.c @@ -24,6 +24,9 @@ #include #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_SDO)&1) - +#define SPI2_SDO ((palReadPort(GPIOB)>>GPIO_SPI2_SDO)&1) +#define SPI2_portSDO (palReadPort(GPIOB)&(1<>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) 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