Merge branch 'DiSlord_test_branch'

pull/4/head
erikkaashoek 6 years ago
commit eaf7020a95

@ -854,27 +854,6 @@ int plot_printf(char *str, int, const char *fmt, ...);
//extern int setting_step_delay; //extern int setting_step_delay;
//extern int actualStepDelay; //extern int actualStepDelay;
//extern int setting_mode; //extern int setting_mode;
void update_rbw(void);
int get_actual_RBW(void);
#define byte uint8_t
extern volatile int SI4432_Sel; // currently selected SI4432
void SI4432_Write_Byte(byte ADR, byte DATA );
byte SI4432_Read_Byte( byte ADR );
void SI4432_Init(void);
void SI4432_Drive(int);
int16_t SI4432_RSSI(uint32_t i, int s);
#ifdef __FAST_SWEEP__
void SI4432_Fill(int s, int start);
#if 0
int SI4432_is_fast_mode(void);
#endif
#endif
void SI4432_Set_Frequency ( uint32_t Freq );
uint16_t SI4432_SET_RBW(uint16_t WISH);
void SI4432_SetReference(int freq);
extern uint16_t SI4432_force_RBW(int i);
// Speed profile definition // Speed profile definition
#define START_PROFILE systime_t time = chVTGetSystemTimeX(); #define START_PROFILE systime_t time = chVTGetSystemTimeX();
@ -886,6 +865,15 @@ extern uint16_t SI4432_force_RBW(int i);
#define define_to_STR(x) STR1(x) #define define_to_STR(x) STR1(x)
// sa_core.c // sa_core.c
typedef uint8_t deviceRSSI_t;
typedef int16_t pureRSSI_t;
// RSSI values conversion macrp
#define DEVICE_TO_PURE_RSSI(rssi) ((rssi)<<4)
#define float_TO_PURE_RSSI(rssi) ((rssi)*32.0)
#define PURE_TO_float(rssi) ((rssi)/32.0)
int get_waterfall(void); int get_waterfall(void);
void toggle_tracking(void); void toggle_tracking(void);
void calibrate(void); void calibrate(void);
@ -896,6 +884,7 @@ void set_unit(int);
void set_switches(int); void set_switches(int);
void set_trigger_level(float); void set_trigger_level(float);
void set_trigger(int); void set_trigger(int);
void update_rbw(void);
//extern int setting_measurement; //extern int setting_measurement;
void self_test(int); void self_test(int);
//extern int setting_test; //extern int setting_test;

@ -16,11 +16,8 @@
*/ */
extern volatile int SI4432_Sel; // currently selected SI4432 static int VFO = 0;
void SI4432_Write_Byte(byte ADR, byte DATA ); static int points = 101; // For 's' and 'm' commands
byte SI4432_Read_Byte( byte ADR );
int VFO = 0;
int points = 101; // For 's' and 'm' commands
VNA_SHELL_FUNCTION(cmd_mode) VNA_SHELL_FUNCTION(cmd_mode)
{ {

@ -1288,9 +1288,10 @@ static const int am_modulation[5] = { 4,0,1,5,7 }; // 5 step AM modulat
static const int nfm_modulation[5] = { 0, 2, 1, -1, -2}; // 5 step narrow FM modulation static const int nfm_modulation[5] = { 0, 2, 1, -1, -2}; // 5 step narrow FM modulation
static const int wfm_modulation[5] = { 0, 190, 118, -118, -190 }; // 5 step wide FM modulation static const int wfm_modulation[5] = { 0, 190, 118, -118, -190 }; // 5 step wide FM modulation
char age[POINTS_COUNT]; deviceRSSI_t age[POINTS_COUNT];
static float old_a = -150; static float old_a = -150;
static float correct_RSSI;
systime_t start_of_sweep_timestamp; systime_t start_of_sweep_timestamp;
float perform(bool break_on_operation, int i, uint32_t f, int tracking) // Measure the RSSI for one frequency, used from sweep and other measurement routines. Must do all HW setup float perform(bool break_on_operation, int i, uint32_t f, int tracking) // Measure the RSSI for one frequency, used from sweep and other measurement routines. Must do all HW setup
@ -1299,8 +1300,6 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M
apply_settings(); // Initialize HW apply_settings(); // Initialize HW
scandirty = true; // This is the first pass with new settings scandirty = true; // This is the first pass with new settings
dirty = false; dirty = false;
if (setting.spur) // if in spur avoidance mode
setting.spur = 1; // resync spur in case of previous abort
// Set for actual time pre calculated value (update after sweep) // Set for actual time pre calculated value (update after sweep)
setting.actual_sweep_time_us = calc_min_sweep_time_us(); setting.actual_sweep_time_us = calc_min_sweep_time_us();
// Change actual sweep time as user input if it greater minimum // Change actual sweep time as user input if it greater minimum
@ -1414,7 +1413,7 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M
} }
// -------------------------------- Acquisition loop for one requested frequency covering spur avoidance and vbwsteps ------------------------ // -------------------------------- Acquisition loop for one requested frequency covering spur avoidance and vbwsteps ------------------------
float RSSI = -150.0; pureRSSI_t RSSI = float_TO_PURE_RSSI(-150.0);
int t = 0; int t = 0;
do { do {
int offs = 0,sm; int offs = 0,sm;
@ -1432,13 +1431,18 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M
offs = (int)(offs * actual_rbw_x10/10.0); offs = (int)(offs * actual_rbw_x10/10.0);
lf = (uint32_t)(f + offs); lf = (uint32_t)(f + offs);
} }
// Calculate the RSSI correction for later use
if (i == 0){ // only cases where the value can change on 0 point of sweep
correct_RSSI = getSI4432_RSSI_correction();
if (setting.frequency_step != 0 )
correct_RSSI+= get_level_offset()
+ get_attenuation()
- get_signal_path_loss()
- setting.offset
+ get_frequency_correction(f);
}
// --------------- Set all the LO's ------------------------ // --------------- Set all the LO's ------------------------
#ifdef __SPUR__
float spur_RSSI = 0;
#endif
if (/* MODE_INPUT(setting.mode) && */ i > 0 && FREQ_IS_CW()) // In input mode in zero span mode after first setting of the LO's if (/* MODE_INPUT(setting.mode) && */ i > 0 && FREQ_IS_CW()) // In input mode in zero span mode after first setting of the LO's
goto skip_LO_setting; // No more LO changes required, save some time and jump over the code goto skip_LO_setting; // No more LO changes required, save some time and jump over the code
@ -1556,16 +1560,7 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M
SI4432_Fill(MODE_SELECT(setting.mode), 0); SI4432_Fill(MODE_SELECT(setting.mode), 0);
} }
#endif #endif
static float correct_RSSI; // This is re-used between calls pureRSSI_t pureRSSI;
if (i == 0 || setting.frequency_step != 0 ){ // only cases where the value can change
correct_RSSI = get_level_offset()
+ get_attenuation()
- get_signal_path_loss()
- setting.offset
+ get_frequency_correction(f)
+ getSI4432_RSSI_correction(); // calcuate the RSSI correction for later use
}
int16_t pureRSSI;
// if ( i < 3) // if ( i < 3)
// shell_printf("%d %.3f %.3f %.1f\r\n", i, local_IF/1000000.0, lf/1000000.0, subRSSI); // shell_printf("%d %.3f %.3f %.1f\r\n", i, local_IF/1000000.0, lf/1000000.0, subRSSI);
@ -1582,20 +1577,20 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M
if (i == 0 && setting.frequency_step == 0 && setting.trigger != T_AUTO) { // if in zero span mode and wait for trigger to happen and NOT in trigger mode if (i == 0 && setting.frequency_step == 0 && setting.trigger != T_AUTO) { // if in zero span mode and wait for trigger to happen and NOT in trigger mode
register uint16_t t_mode; register uint16_t t_mode;
uint16_t trigger_lvl; pureRSSI_t trigger_lvl;
uint16_t data_level = T_LEVEL_UNDEF; uint16_t data_level = T_LEVEL_UNDEF;
// Calculate trigger level // Calculate trigger level
trigger_lvl = (setting.trigger_level - correct_RSSI) * 32; trigger_lvl = float_TO_PURE_RSSI(setting.trigger_level - correct_RSSI);
if (setting.trigger_direction == T_UP) if (setting.trigger_direction == T_UP)
t_mode = T_UP_MASK; t_mode = T_UP_MASK;
else else
t_mode = T_DOWN_MASK; t_mode = T_DOWN_MASK;
uint32_t count = 32;
uint32_t additional_delay = 0;// reduce noise uint32_t additional_delay = 0;// reduce noise
if (setting.sweep_time_us >= 100*ONE_MS_TIME) additional_delay = 20; if (setting.sweep_time_us >= 100*ONE_MS_TIME) additional_delay = 20;
SI4432_Sel = MODE_SELECT(setting.mode);
do{ // wait for trigger to happen do{ // wait for trigger to happen
pureRSSI = SI4432_Read_Byte(SI4432_REG_RSSI)<<4; pureRSSI = DEVICE_TO_PURE_RSSI((deviceRSSI_t)SI4432_Read_Byte(SI4432_REG_RSSI));
if (break_on_operation && operation_requested) // allow aborting a wait for trigger if (break_on_operation && operation_requested) // allow aborting a wait for trigger
return 0; // abort return 0; // abort
@ -1604,11 +1599,6 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M
data_level = ((data_level<<1) | (pureRSSI < trigger_lvl ? T_LEVEL_BELOW : T_LEVEL_ABOVE))&(T_LEVEL_CLEAN); data_level = ((data_level<<1) | (pureRSSI < trigger_lvl ? T_LEVEL_BELOW : T_LEVEL_ABOVE))&(T_LEVEL_CLEAN);
if (data_level == t_mode) // wait trigger if (data_level == t_mode) // wait trigger
break; break;
// DIRTY HACK!!! FIX ME HERE
// not get data after dirty = true apply in code at first run!!!!
if (pureRSSI == 0 && --count == 0)
break;
if (additional_delay) if (additional_delay)
my_microsecond_delay(additional_delay); my_microsecond_delay(additional_delay);
}while(1); }while(1);
@ -1624,27 +1614,26 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M
else else
pureRSSI = SI4432_RSSI(lf, MODE_SELECT(setting.mode)); // Get RSSI, either from pre-filled buffer pureRSSI = SI4432_RSSI(lf, MODE_SELECT(setting.mode)); // Get RSSI, either from pre-filled buffer
float subRSSI = pureRSSI / 32.0;
// add correction
subRSSI+=correct_RSSI;
#ifdef __SPUR__ #ifdef __SPUR__
if (setting.spur == 1) { // If first spur pass static pureRSSI_t spur_RSSI = -1;
spur_RSSI = subRSSI; // remember measure RSSI if (setting.spur == 1) {
setting.spur = -1; // and prepare for second pass if(spur_RSSI == -1) { // If first spur pass
goto again; // Skip all other processing spur_RSSI = pureRSSI; // remember measure RSSI
} else if (setting.spur == -1) { // If second spur pass goto again; // Skip all other processing
subRSSI = ( subRSSI < spur_RSSI ? subRSSI : spur_RSSI); // Take minimum of two } else { // If second spur pass
setting.spur = 1; // and prepare for next call of perform. pureRSSI = ( pureRSSI < spur_RSSI ? pureRSSI : spur_RSSI); // Take minimum of two
spur_RSSI =-1; // and prepare for next call of perform.
}
} }
#endif #endif
if (RSSI < subRSSI) // Take max during subscanning if (RSSI < pureRSSI) // Take max during subscanning
RSSI = subRSSI; RSSI = pureRSSI;
t++; // one subscan done t++; // one subscan done
if (break_on_operation && operation_requested) // break subscanning if requested if (break_on_operation && operation_requested) // break subscanning if requested
break; // abort break; // abort
} while (t < vbwSteps); // till all sub steps done } while (t < vbwSteps); // till all sub steps done
return(RSSI); return PURE_TO_float(RSSI) + correct_RSSI; // add correction
} }
#define MAX_MAX 4 #define MAX_MAX 4

@ -82,7 +82,7 @@ static uint8_t shiftIn(void)
return value>>GPIO_SPI2_SDO; return value>>GPIO_SPI2_SDO;
} }
static inline void shiftInBuf(uint16_t sel, uint8_t addr, uint8_t *buf, uint16_t size, uint16_t delay) { static inline void shiftInBuf(uint16_t sel, uint8_t addr, deviceRSSI_t *buf, uint16_t size, uint16_t delay) {
uint8_t i = 0; uint8_t i = 0;
do{ do{
uint32_t value = addr; uint32_t value = addr;
@ -392,7 +392,7 @@ int SI4432_step_delay = 1500;
//extern int setting.repeat; //extern int setting.repeat;
#ifdef __FAST_SWEEP__ #ifdef __FAST_SWEEP__
extern char age[POINTS_COUNT]; extern deviceRSSI_t age[POINTS_COUNT];
static int buf_index = 0; static int buf_index = 0;
static bool buf_read = false; static bool buf_read = false;
@ -432,7 +432,7 @@ void SI4432_Fill(int s, int start)
my_microsecond_delay(t); my_microsecond_delay(t);
} while(1); } while(1);
#else #else
shiftInBuf(sel, SI4432_REG_RSSI, (uint8_t *)&age[start], sweep_points - start, t); shiftInBuf(sel, SI4432_REG_RSSI, &age[start], sweep_points - start, t);
#endif #endif
// __enable_irq(); // __enable_irq();
setting.measure_sweep_time_us = (chVTGetSystemTimeX() - measure)*100; setting.measure_sweep_time_us = (chVTGetSystemTimeX() - measure)*100;
@ -448,10 +448,10 @@ float getSI4432_RSSI_correction(void){
return SI4432_RSSI_correction; return SI4432_RSSI_correction;
}; };
int16_t SI4432_RSSI(uint32_t i, int s) pureRSSI_t SI4432_RSSI(uint32_t i, int s)
{ {
(void) i; (void) i;
int32_t RSSI_RAW; pureRSSI_t RSSI_RAW;
(void) i; (void) i;
// SEE DATASHEET PAGE 61 // SEE DATASHEET PAGE 61
#ifdef USE_SI4463 // Not used!!!!!!! #ifdef USE_SI4463 // Not used!!!!!!!
@ -464,7 +464,7 @@ int16_t SI4432_RSSI(uint32_t i, int s)
if (buf_read) { if (buf_read) {
if (buf_index == sweep_points-1) if (buf_index == sweep_points-1)
buf_read = false; buf_read = false;
return (unsigned char)age[buf_index++]<<4; return DEVICE_TO_PURE_RSSI(age[buf_index++]);
} }
#endif #endif
SI4432_Sel = s; SI4432_Sel = s;
@ -485,7 +485,7 @@ int16_t SI4432_RSSI(uint32_t i, int s)
i = setting.repeat; i = setting.repeat;
RSSI_RAW = 0; RSSI_RAW = 0;
do{ do{
RSSI_RAW += ((unsigned int)SI4432_Read_Byte(SI4432_REG_RSSI))<<4; RSSI_RAW += DEVICE_TO_PURE_RSSI((deviceRSSI_t)SI4432_Read_Byte(SI4432_REG_RSSI));
if (--i == 0) break; if (--i == 0) break;
my_microsecond_delay(100); my_microsecond_delay(100);
}while(1); }while(1);
@ -495,7 +495,8 @@ int16_t SI4432_RSSI(uint32_t i, int s)
// if (MODE_INPUT(setting.mode) && RSSI_RAW == 0) // if (MODE_INPUT(setting.mode) && RSSI_RAW == 0)
// SI4432_Init(); // SI4432_Init();
#ifdef __SIMULATION__ #ifdef __SIMULATION__
RSSI_RAW = Simulated_SI4432_RSSI(i,s)<<4; #error "Fixme!!! add correct simulation in pureRSSI_t type"
RSSI_RAW = Simulated_SI4432_RSSI(i,s);
#endif #endif
//STOP_PROFILE //STOP_PROFILE
// Serial.println(dBm,2); // Serial.println(dBm,2);

@ -104,24 +104,37 @@
#define SI4432_FIFO 0x7F #define SI4432_FIFO 0x7F
typedef byte uint8_t; typedef uint8_t byte;
extern volatile int SI4432_Sel; // currently selected SI4432 extern volatile int SI4432_Sel; // currently selected SI4432
void SI4432_Write_Byte(byte ADR, byte DATA ); void SI4432_Write_Byte(byte ADR, byte DATA );
byte SI4432_Read_Byte( byte ADR ); byte SI4432_Read_Byte( byte ADR );
void SI4432_Transmit(int d);
void SI4432_Receive(void);
void SI4432_Init(void); void SI4432_Init(void);
void SI4432_Drive(int);
float getSI4432_RSSI_correction(void); float getSI4432_RSSI_correction(void);
int16_t SI4432_RSSI(uint32_t i, int s); pureRSSI_t SI4432_RSSI(uint32_t i, int s);
#ifdef __SIMULATION__ #ifdef __SIMULATION__
float Simulated_SI4432_RSSI(uint32_t i, int s); float Simulated_SI4432_RSSI(uint32_t i, int s);
#endif #endif
void SI4432_Set_Frequency ( uint32_t Freq ); void SI4432_Set_Frequency ( uint32_t Freq );
void SI4432_Transmit(int d);
void SI4432_Receive(void); uint16_t SI4432_force_RBW(int i);
uint16_t SI4432_SET_RBW(uint16_t WISH); uint16_t SI4432_SET_RBW(uint16_t WISH);
void SI4432_SetReference(int freq);
bool PE4302_Write_Byte(unsigned char DATA ); bool PE4302_Write_Byte(unsigned char DATA );
void PE4302_init(void); void PE4302_init(void);
#ifdef __FAST_SWEEP__
void SI4432_Fill(int s, int start);
#if 0
int SI4432_is_fast_mode(void);
#endif
#endif
#ifdef __ULTRA_SA__ #ifdef __ULTRA_SA__
extern int ADF4351_LE[]; extern int ADF4351_LE[];
extern int debug; extern int debug;

Loading…
Cancel
Save

Powered by TurnKey Linux.