Small improvements

tinySA
erikkaashoek 6 years ago
parent a7ae6d4197
commit 2d430a4f58

@ -294,9 +294,11 @@ static const uint8_t ili9341_init_seq[] = {
// POWER_CONTROL_2 // POWER_CONTROL_2
ILI9341_POWER_CONTROL_2, 1, 0x11, ILI9341_POWER_CONTROL_2, 1, 0x11,
// VCOM_CONTROL_1 // VCOM_CONTROL_1
ILI9341_VCOM_CONTROL_1, 2, 0x35, 0x3E, // ILI9341_VCOM_CONTROL_1, 2, 0x35, 0x3E,
ILI9341_VCOM_CONTROL_1, 2, 0x3e, 0x28,
// VCOM_CONTROL_2 // VCOM_CONTROL_2
ILI9341_VCOM_CONTROL_2, 1, 0xBE, ILI9341_VCOM_CONTROL_2, 1, 0xBE,
// ILI9341_VCOM_CONTROL_2, 1, 0x86,
// MEMORY_ACCESS_CONTROL // MEMORY_ACCESS_CONTROL
//ILI9341_MEMORY_ACCESS_CONTROL, 1, 0x48, // portlait //ILI9341_MEMORY_ACCESS_CONTROL, 1, 0x48, // portlait
ILI9341_MEMORY_ACCESS_CONTROL, 1, DISPLAY_ROTATION_0, // landscape ILI9341_MEMORY_ACCESS_CONTROL, 1, DISPLAY_ROTATION_0, // landscape

@ -2613,7 +2613,7 @@ static UARTConfig uart_cfg_1 = {
}; };
#endif #endif
#if 1 #if 0
static const SerialConfig default_config = static const SerialConfig default_config =
{ {
9600, 9600,
@ -2621,14 +2621,34 @@ static const SerialConfig default_config =
USART_CR2_STOP2_BITS, USART_CR2_STOP2_BITS,
0 0
}; };
#endif
myWrite(char *buf)
void myWrite(char *buf)
{ {
int len = strlen(buf); int len = strlen(buf);
while(len-- > 0) while(len-- > 0) {
sdPut(&SD1,*buf++); sdPut(&SD1,*buf++);
osalThreadSleepMicroseconds(1000);
}
}
static int serial_count = 0;
int mySerialReadline(unsigned char *buf, int len)
{
int i;
do {
i = sdReadTimeout(&SD1,&buf[serial_count], 20-serial_count,TIME_IMMEDIATE);
serial_count += i;
if (i > 0)
osalThreadSleepMicroseconds(1000);
} while (serial_count < len && i > 0);
if (buf[serial_count-1] == '\n') {
serial_count = 0;
return(i);
} else
return 0;
} }
#endif
// Main thread stack size defined in makefile USE_PROCESS_STACKSIZE = 0x200 // Main thread stack size defined in makefile USE_PROCESS_STACKSIZE = 0x200
// Profile stack usage (enable threads command by def ENABLE_THREADS_COMMAND) show: // Profile stack usage (enable threads command by def ENABLE_THREADS_COMMAND) show:
@ -2673,22 +2693,27 @@ int main(void)
uartStartReceive(&UARTD1, 1, buf); uartStartReceive(&UARTD1, 1, buf);
#endif #endif
#if 1 #if 0
palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(1)); // USART1 TX. palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(1)); // USART1 TX.
palSetPadMode(GPIOA,10, PAL_MODE_ALTERNATE(1)); // USART1 RX. palSetPadMode(GPIOA,10, PAL_MODE_ALTERNATE(1)); // USART1 RX.
uint8_t buf[10]; uint8_t buf[10];
sdStart(&SD1,&default_config); sdStart(&SD1,&default_config);
osalThreadSleepMilliseconds(10); osalThreadSleepMilliseconds(10);
myWrite("Hallo!?"); mySerialWrite("Hallo!?\n");
osalThreadSleepMilliseconds(10); osalThreadSleepMilliseconds(10);
mySerialReadline(buf, 10);
sdReadTimeout(&SD1,buf,10, 10); sdReadTimeout(&SD1,buf,10, 10);
sdWrite(&SD1,(const uint8_t *)"Test123",7); sdWrite(&SD1,(const uint8_t *)"Test123",7);
osalThreadSleepMilliseconds(10); osalThreadSleepMicroseconds(10);
sdReadTimeout(&SD1,buf,10,TIME_IMMEDIATE);
sdReadTimeout(&SD1,buf,10, 10); sdReadTimeout(&SD1,buf,10, 10);
int i = sdReadTimeout(&SD1,buf,10,TIME_IMMEDIATE);
#endif #endif
/* /*

@ -29,6 +29,7 @@
#define __ICONS__ #define __ICONS__
#define __MEASURE__ #define __MEASURE__
#define __SELFTEST__ #define __SELFTEST__
#define __CALIBRATE__
/* /*
* main.c * main.c

@ -1534,7 +1534,28 @@ draw_all_cells(bool flush_markmap)
g = 255 - b - r g = 255 - b - r
return r, g, b return r, g, b
*/ */
int r,g,b; int r,g,b;
#if 0
int ratio = (int)(1024 * (actual_t[i] - w_min) / (w_max - w_min));
r = ratio - 512;
if (r<0) r=0;
b = (1024 - ratio*4) - 512;
if (b<0) b=0;
g = 512-r-b;
if (r>255) r=255;
if (g>255) g=255;
if (b>255) b=255;
#define gamma_correct(X,L) X = (L + X * (255 - L)/255 )
gamma_correct(r,160);
gamma_correct(g,160);
gamma_correct(b,160);
#endif
#if 1
float ratio = (int)(510.0 * (actual_t[i] - w_min) / (w_max - w_min)); float ratio = (int)(510.0 * (actual_t[i] - w_min) / (w_max - w_min));
// float ratio = (i*2); // Uncomment for testing the waterfall colors // float ratio = (i*2); // Uncomment for testing the waterfall colors
b = 255 - ratio; b = 255 - ratio;
@ -1549,6 +1570,7 @@ draw_all_cells(bool flush_markmap)
gamma_correct(r,128); gamma_correct(r,128);
gamma_correct(g,128); gamma_correct(g,128);
gamma_correct(b,128); gamma_correct(b,128);
#endif
#if 0 #if 0
int k = (actual_t[i]+120)* 2 * 8; int k = (actual_t[i]+120)* 2 * 8;
k &= 255; k &= 255;

@ -513,7 +513,11 @@ switch(m) {
case M_LOW: // Mixed into 0 case M_LOW: // Mixed into 0
SI4432_Sel = 0; SI4432_Sel = 0;
SI4432_Receive(); SI4432_Receive();
SetSwitchReceive(); if (setting_step_atten) {
SetSwitchTransmit();
} else {
SetSwitchReceive();
}
SetAGCLNA(); SetAGCLNA();
SI4432_Sel = 1; SI4432_Sel = 1;
@ -1424,17 +1428,16 @@ void draw_cal_status(void)
} }
// -------------------- Self testing ------------------------------------------------- // -------------------- Self testing -------------------------------------------------
#ifdef __SELFTEST__
enum { enum {
TC_SIGNAL, TC_BELOW, TC_ABOVE, TC_FLAT, TC_MEASURE, TC_SET, TC_END, TC_SIGNAL, TC_BELOW, TC_ABOVE, TC_FLAT, TC_MEASURE, TC_SET, TC_END,
}; };
enum { enum {
TP_SILENT, TPH_SILENT, TP_10MHZ, TP_10MHZEXTRA, TP_30MHZ, TPH_30MHZ TP_SILENT, TPH_SILENT, TP_10MHZ, TP_10MHZEXTRA, TP_10MHZ_SWITCH, TP_30MHZ, TPH_30MHZ
}; };
#define TEST_COUNT 16 #define TEST_COUNT 17
static const struct { static const struct {
int kind; int kind;
@ -1455,12 +1458,13 @@ static const struct {
{TC_SIGNAL, TP_10MHZEXTRA, 10, 8, -13, 55, -60 }, // 7 BPF loss and stop band {TC_SIGNAL, TP_10MHZEXTRA, 10, 8, -13, 55, -60 }, // 7 BPF loss and stop band
{TC_FLAT, TP_10MHZEXTRA, 10, 4, -18, 20, -60}, // 8 BPF pass band flatness {TC_FLAT, TP_10MHZEXTRA, 10, 4, -18, 20, -60}, // 8 BPF pass band flatness
{TC_BELOW, TP_30MHZ, 430, 60, -65, 0, -75}, // 9 LPF cutoff {TC_BELOW, TP_30MHZ, 430, 60, -65, 0, -75}, // 9 LPF cutoff
{TC_SIGNAL, TP_10MHZ_SWITCH,20, 7, -58, 30, -90 }, // 10 Switch isolation
{TC_END, 0, 0, 0, 0, 0, 0}, {TC_END, 0, 0, 0, 0, 0, 0},
{TC_MEASURE, TP_30MHZ, 30, 7, -22.5, 30, -70 }, // 11 Measure power level and noise {TC_MEASURE, TP_30MHZ, 30, 7, -22.5, 30, -70 }, // 12 Measure power level and noise
{TC_MEASURE, TP_30MHZ, 270, 4, -45, 30, -75 }, // 12 Measure powerlevel and noise {TC_MEASURE, TP_30MHZ, 270, 4, -45, 30, -75 }, // 13 Measure powerlevel and noise
{TC_MEASURE, TPH_30MHZ, 270, 4, -45, 30, -75 }, // 13 Calibrate power high mode {TC_MEASURE, TPH_30MHZ, 270, 4, -45, 30, -65 }, // 14 Calibrate power high mode
{TC_END, 0, 0, 0, 0, 0, 0}, {TC_END, 0, 0, 0, 0, 0, 0},
{TC_MEASURE, TP_30MHZ, 30, 1, -20, 30, -70 }, // 15 Measure RBW step time {TC_MEASURE, TP_30MHZ, 30, 1, -20, 30, -70 }, // 16 Measure RBW step time
{TC_END, 0, 0, 0, 0, 0, 0}, {TC_END, 0, 0, 0, 0, 0, 0},
}; };
@ -1539,20 +1543,29 @@ void cell_draw_test_info(int x0, int y0)
#define fabs(X) ((X)<0?-(X):(X)) #define fabs(X) ((X)<0?-(X):(X))
int validate_peak_within(int i, float margin) int validate_signal_within(int i, float margin)
{ {
if (fabs(peakLevel-test_case[i].pass) > margin) test_fail_cause[i] = "Signal level ";
return false; if (fabs(peakLevel-test_case[i].pass) > 2*margin) {
return(test_case[i].center * 1000000 - 100000 < peakFreq && peakFreq < test_case[i].center * 1000000 + 100000 ); return TS_FAIL;
}
if (fabs(peakLevel-test_case[i].pass) > margin) {
return TS_CRITICAL;
}
test_fail_cause[i] = "Frequency ";
if (peakFreq < test_case[i].center * 1000000 - 100000 || test_case[i].center * 1000000 + 100000 < peakFreq )
return TS_FAIL;
test_fail_cause[i] = "";
return TS_PASS;
} }
int validate_peak_below(int i, float margin) { int validate_peak_below(int i, float margin) {
return(test_case[i].pass - peakLevel > margin); return(test_case[i].pass - peakLevel > margin);
} }
int validate_below(void) { int validate_below(int tc, int from, int to) {
int status = TS_PASS; int status = TS_PASS;
for (int j = 0; j < POINTS_COUNT; j++) { for (int j = from; j < to; j++) {
if (actual_t[j] > stored_t[j] - 5) if (actual_t[j] > stored_t[j] - 5)
status = TS_CRITICAL; status = TS_CRITICAL;
else if (actual_t[j] > stored_t[j]) { else if (actual_t[j] > stored_t[j]) {
@ -1560,11 +1573,14 @@ int validate_below(void) {
break; break;
} }
} }
if (status != TS_PASS)
test_fail_cause[tc] = "Above ";
return(status); return(status);
} }
int validate_flatness(int i) { int validate_flatness(int i) {
volatile int j; volatile int j;
test_fail_cause[i] = "Passband ";
for (j = peakIndex; j < POINTS_COUNT; j++) { for (j = peakIndex; j < POINTS_COUNT; j++) {
if (actual_t[j] < peakLevel - 3) // Search right -3dB if (actual_t[j] < peakLevel - 3) // Search right -3dB
break; break;
@ -1577,10 +1593,11 @@ int validate_flatness(int i) {
} }
if (peakIndex - j < test_case[i].width) if (peakIndex - j < test_case[i].width)
return(TS_FAIL); return(TS_FAIL);
test_fail_cause[i] = "";
return(TS_PASS); return(TS_PASS);
} }
int validate_above(void) { int validate_above(int tc) {
int status = TS_PASS; int status = TS_PASS;
for (int j = 0; j < POINTS_COUNT; j++) { for (int j = 0; j < POINTS_COUNT; j++) {
if (actual_t[j] < stored_t[j] + 5) if (actual_t[j] < stored_t[j] + 5)
@ -1590,6 +1607,8 @@ int validate_above(void) {
break; break;
} }
} }
if (status != TS_PASS)
test_fail_cause[tc] = "Below ";
return(status); return(status);
} }
@ -1607,32 +1626,12 @@ int test_validate(int i)
SetPowerLevel(test_case[i].pass); SetPowerLevel(test_case[i].pass);
goto common; goto common;
case TC_MEASURE: case TC_MEASURE:
case TC_SIGNAL: // Validate signal case TC_SIGNAL: // Validate signal
common: common: current_test_status = validate_signal_within(i, 5.0);
if (validate_peak_within(i, 5.0)) // Validate Peak
current_test_status = TS_PASS;
else if (validate_peak_within(i, 10.0))
current_test_status = TS_CRITICAL;
else
current_test_status = TS_FAIL;
if (current_test_status != TS_PASS)
test_fail_cause[i] = "Peak ";
if (current_test_status == TS_PASS) { // Validate noise floor if (current_test_status == TS_PASS) { // Validate noise floor
for (int j = 0; j < POINTS_COUNT/2 - test_case[i].width; j++) { current_test_status = validate_below(i, 0, POINTS_COUNT/2 - test_case[i].width);
if (actual_t[j] > test_case[i].stop - 5) if (current_test_status == TS_PASS) {
current_test_status = TS_CRITICAL; current_test_status = validate_below(i, POINTS_COUNT/2 + test_case[i].width, POINTS_COUNT);
else if (actual_t[j] > test_case[i].stop) {
current_test_status = TS_FAIL;
break;
}
}
for (int j = POINTS_COUNT/2 + test_case[i].width; j < POINTS_COUNT; j++) {
if (actual_t[j] > test_case[i].stop - 5)
current_test_status = TS_CRITICAL;
else if (actual_t[j] > test_case[i].stop) {
current_test_status = TS_FAIL;
break;
}
} }
if (current_test_status != TS_PASS) if (current_test_status != TS_PASS)
test_fail_cause[i] = "Stopband "; test_fail_cause[i] = "Stopband ";
@ -1641,28 +1640,15 @@ int test_validate(int i)
test_value = peakLevel; test_value = peakLevel;
else else
test_value = 0; // Not valid test_value = 0; // Not valid
break; break;
case TC_ABOVE: // Validate signal above curve case TC_ABOVE: // Validate signal above curve
for (int j = 0; j < POINTS_COUNT; j++) { current_test_status = validate_above(i);
if (actual_t[j] < test_case[i].pass + 5)
current_test_status = TS_CRITICAL;
else if (actual_t[j] < test_case[i].pass) {
current_test_status = TS_FAIL;
break;
}
}
if (current_test_status != TS_PASS)
test_fail_cause[i] = "Above ";
break; break;
case TC_BELOW: // Validate signal below curve case TC_BELOW: // Validate signal below curve
current_test_status = validate_below(); current_test_status = validate_below(i, 0, POINTS_COUNT);
if (current_test_status != TS_PASS) break;
test_fail_cause[i] = "Above ";
break;
case TC_FLAT: // Validate passband flatness case TC_FLAT: // Validate passband flatness
current_test_status = validate_flatness(i); current_test_status = validate_flatness(i);
if (current_test_status != TS_PASS)
test_fail_cause[i] = "Passband ";
break; break;
} }
@ -1682,6 +1668,8 @@ int test_validate(int i)
void test_prepare(int i) void test_prepare(int i)
{ {
setting_tracking = false; //Default test setup setting_tracking = false; //Default test setup
setting_step_atten = false;
SetAttenuation(0);
switch(test_case[i].setup) { // Prepare test conditions switch(test_case[i].setup) { // Prepare test conditions
case TPH_SILENT: // No input signal case TPH_SILENT: // No input signal
SetMode(M_HIGH); SetMode(M_HIGH);
@ -1693,9 +1681,15 @@ common_silent:
for (int j = 0; j < POINTS_COUNT; j++) for (int j = 0; j < POINTS_COUNT; j++)
stored_t[j] = test_case[i].pass; stored_t[j] = test_case[i].pass;
break; break;
case TP_10MHZ_SWITCH:
SetMode(M_LOW);
set_refer_output(2);
setting_step_atten = true;
goto common;
case TP_10MHZEXTRA: // Swept receiver case TP_10MHZEXTRA: // Swept receiver
SetMode(M_LOW); SetMode(M_LOW);
setting_tracking = true; //Sweep BPF setting_tracking = true; //Sweep BPF
frequency_IF = 434000000; // Center on SAW filters
set_refer_output(2); set_refer_output(2);
goto common; goto common;
case TP_10MHZ: // 10MHz input case TP_10MHZ: // 10MHz input
@ -1719,11 +1713,12 @@ common_silent:
set_refer_output(0); set_refer_output(0);
goto common; goto common;
} }
setting_auto_attenuation = false;
setting_attenuate = 0;
trace[TRACE_STORED].enabled = true; trace[TRACE_STORED].enabled = true;
SetReflevel(test_case[i].pass+10); SetReflevel(test_case[i].pass+10);
set_sweep_frequency(ST_CENTER, (int32_t)(test_case[i].center * 1000000)); set_sweep_frequency(ST_CENTER, (int32_t)(test_case[i].center * 1000000));
set_sweep_frequency(ST_SPAN, (int32_t)(test_case[i].span * 1000000)); set_sweep_frequency(ST_SPAN, (int32_t)(test_case[i].span * 1000000));
SetAttenuation(0);
draw_cal_status(); draw_cal_status();
} }
@ -1745,11 +1740,10 @@ int add_spur(int f)
} }
return 1; return 1;
} }
#endif
void self_test(void) void self_test(void)
{ {
#ifdef __SELFTEST__
#if 0 #if 0
in_selftest = true; in_selftest = true;
@ -1800,7 +1794,7 @@ void self_test(void)
int local_test_status; int local_test_status;
in_selftest = true; in_selftest = true;
reset_settings(M_LOW); reset_settings(M_LOW);
int i = 14; // calibrate low mode power on 30 MHz; int i = 15; // calibrate low mode power on 30 MHz;
test_prepare(i); test_prepare(i);
for (int j= 0; j < 32; j++ ) { for (int j= 0; j < 32; j++ ) {
test_prepare(i); test_prepare(i);
@ -1815,7 +1809,7 @@ void self_test(void)
int local_test_status; int local_test_status;
in_selftest = true; in_selftest = true;
reset_settings(M_LOW); reset_settings(M_LOW);
int i = 14; // calibrate low mode power on 30 MHz; int i = 15; // calibrate low mode power on 30 MHz;
test_prepare(i); test_prepare(i);
setting_step_delay = 6000; setting_step_delay = 6000;
for (int j= 0; j < 57; j++ ) { for (int j= 0; j < 57; j++ ) {
@ -1845,7 +1839,7 @@ void self_test(void)
} }
return; return;
#else #else
int old_IF = frequency_IF;
in_selftest = true; in_selftest = true;
menu_autosettings_cb(0); menu_autosettings_cb(0);
for (int i=0; i < TEST_COUNT; i++) { // All test cases waiting for (int i=0; i < TEST_COUNT; i++) { // All test cases waiting
@ -1857,6 +1851,7 @@ void self_test(void)
show_test_info = TRUE; show_test_info = TRUE;
int i=0; int i=0;
while (test_case[i].kind != TC_END) { while (test_case[i].kind != TC_END) {
frequency_IF = old_IF;
test_prepare(i); test_prepare(i);
test_acquire(i); // Acquire test test_acquire(i); // Acquire test
test_status[i] = test_validate(i); // Validate test test_status[i] = test_validate(i); // Validate test
@ -1877,8 +1872,6 @@ void self_test(void)
reset_settings(M_LOW); reset_settings(M_LOW);
in_selftest = false; in_selftest = false;
#endif #endif
#endif
} }
void reset_calibration(void) void reset_calibration(void)
@ -1897,7 +1890,7 @@ void calibrate(void)
in_selftest = true; in_selftest = true;
SetPowerLevel(100); SetPowerLevel(100);
reset_settings(M_LOW); reset_settings(M_LOW);
int i = 10; // calibrate low mode power on 30 MHz; int i = 11; // calibrate low mode power on 30 MHz;
for (int j= 0; j < CALIBRATE_RBWS; j++ ) { for (int j= 0; j < CALIBRATE_RBWS; j++ ) {
SetRBW(power_rbw[j]); SetRBW(power_rbw[j]);
test_prepare(i); test_prepare(i);
@ -1913,7 +1906,7 @@ void calibrate(void)
chThdSleepMilliseconds(1000); chThdSleepMilliseconds(1000);
} }
} }
i = 11; // Measure 270MHz in low mode i = 12; // Measure 270MHz in low mode
SetRBW(100); SetRBW(100);
test_prepare(i); test_prepare(i);
test_acquire(i); // Acquire test test_acquire(i); // Acquire test
@ -1923,7 +1916,7 @@ void calibrate(void)
config.high_level_offset = 0; /// Preliminary setting config.high_level_offset = 0; /// Preliminary setting
i = 12; // Calibrate 270MHz in high mode i = 13; // Calibrate 270MHz in high mode
for (int j = 0; j < CALIBRATE_RBWS; j++) { for (int j = 0; j < CALIBRATE_RBWS; j++) {
SetRBW(power_rbw[j]); SetRBW(power_rbw[j]);
test_prepare(i); test_prepare(i);

@ -1384,7 +1384,7 @@ static void menu_item_modify_attribute(
mark = true; mark = true;
} }
} else if (MT_MASK(menu[item].type) != MT_CALLBACK && (menu == menu_drive || menu == menu_drive_wide || menu == menu_drive_wide2|| menu == menu_drive_wide3)) { } else if (MT_MASK(menu[item].type) == MT_CALLBACK && (menu == menu_drive || menu == menu_drive_wide || menu == menu_drive_wide2|| menu == menu_drive_wide3)) {
if (data == setting_drive){ if (data == setting_drive){
mark = true; mark = true;
} }

Loading…
Cancel
Save

Powered by TurnKey Linux.