From 836a726e2c63d8790330dd19795bcf89c2e71f20 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 2 May 2021 08:49:46 +0300 Subject: [PATCH 1/3] Added fast exp function for faster draw volt/watt units on graph --- plot.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/plot.c b/plot.c index 810c6a5..60b6a4d 100644 --- a/plot.c +++ b/plot.c @@ -376,6 +376,23 @@ dBm_to_Watt(const float v) return logf(v*1000.0)*(10.0/logf(10.0)); } +static float fast_expf(float x) +{ + union { float f; int32_t i; } v; + v.i = (int32_t)(12102203.0f*x) + 0x3F800000; + int32_t m = (v.i >> 7) & 0xFFFF; // copy mantissa +#if 1 + // cubic spline approximation + // empirical values for small maximum relative error (8.34e-5): + v.i += ((((((((1277*m) >> 14) + 14825)*m) >> 14) - 79749)*m) >> 11) - 626; +#else + // quartic spline approximation + // empirical values for small maximum relative error (1.21e-5): + v.i += (((((((((((3537*m) >> 16) + 13668)*m) >> 18) + 15817)*m) >> 14) - 80470)*m) >> 11); +#endif + return v.f; +} + static void trace_into_index_x_array(index_x_t *x, uint16_t points){ // Not need update if index calculated for this points count @@ -417,7 +434,7 @@ trace_into_index_y_array(index_y_t *y, float *array, int points) int max = NGRIDY * GRIDY, i; for (i=0;i Date: Sun, 2 May 2021 09:01:33 +0300 Subject: [PATCH 2/3] Revert some code ADF exchange update Fix bug --- si4468.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/si4468.c b/si4468.c index afb38a0..d90cca4 100644 --- a/si4468.c +++ b/si4468.c @@ -318,11 +318,12 @@ void ADF4351_WriteRegister32(int channel, const uint32_t value) // if (reg_dirty[value & 0x07] || (value & 0x07) == 0) { if (old_registers[value & 0x07] != registers[value & 0x07] || (value & 0x07) == 0 ) { registers[value & 0x07] = value; - for (int i = 3; i >= 0; i--) shiftOut((value >> (8 * i)) & 0xFF); - palSetLine(ADF4351_LE[channel]); - my_microsecond_delay(1); // Must palClearLine(ADF4351_LE[channel]); -// reg_dirty[value & 0x07] = false; + shiftOut((value >> 24) & 0xFF); + shiftOut((value >> 16) & 0xFF); + shiftOut((value >> 8) & 0xFF); + shiftOut((value >> 0) & 0xFF); + palSetLine(ADF4351_LE[channel]); old_registers[value & 0x07] = registers[value & 0x07]; } } @@ -332,11 +333,6 @@ void ADF4351_Set(int channel) set_SPI_mode(SPI_MODE_SI); if (SI4432_SPI_SPEED != ADF_SPI_SPEED) SPI_BR_SET(SI4432_SPI, ADF_SPI_SPEED); - -// my_microsecond_delay(1); - palClearLine(ADF4351_LE[channel]); -// my_microsecond_delay(1); - for (int i = 5; i >= 0; i--) { ADF4351_WriteRegister32(channel, registers[i]); } @@ -720,13 +716,13 @@ void SI4463_do_api(void* data, uint8_t len, void* out, uint8_t outLen) while (!SI4463_READ_CTS);// {SHORT_DELAY; } // Wait for CTS SI_CS_LOW; #if 1 // Inline transfer - while (len-- > 0) { + while (len--){ while (SPI_TX_IS_NOT_EMPTY(SI4432_SPI)); SPI_WRITE_8BIT(SI4432_SPI, *ptr++); } while (SPI_IS_BUSY(SI4432_SPI)); #else - while (len-- > 0) + while (len--) shiftOut(*ptr++); // (pgm_read_byte(&((uint8_t*)data)[i])); #endif SI_CS_HIGH; @@ -747,7 +743,7 @@ void SI4463_do_api(void* data, uint8_t len, void* out, uint8_t outLen) #endif // Get response data ptr = (uint8_t *)out; - while (outLen-- > 0) { + while (outLen--){ #if 1 // Inline transfer SPI_WRITE_8BIT(SI4432_SPI, 0x00); while (SPI_RX_IS_EMPTY(SI4432_SPI)); //wait rx data in buffer @@ -755,9 +751,8 @@ void SI4463_do_api(void* data, uint8_t len, void* out, uint8_t outLen) #else *ptr++ = shiftIn(); #endif - SI_CS_HIGH; } -// __enable_irq(); + SI_CS_HIGH; } #ifdef notused @@ -790,7 +785,7 @@ static void SI4463_set_properties(uint16_t prop, void* values, uint8_t len) #define GLOBAL_GPIO_PIN_CFG 0x13, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 #define GLOBAL_CLK_CFG 0x11, 0x00, 0x01, 0x01, 0x00 // ---------------------------------------------------------------------------------------------------- v ------------ RSSI control byte -#define GLOBAL_RF_MODEM_RAW_CONTROL 0x11, 0x20, 0x0A, 0x45, 0x03, 0x00, 0x00, 0x01, 0x00, 0x00, 0x06, 0x03, 0x10, 0x40 +#define GLOBAL_RF_MODEM_RAW_CONTROL 0x11, 0x20, 0x0A, 0x45, 0x03, 0x00, 0x00, 0x01, 0x00, 0x00, 0x06, 0x18, 0x10, 0x40 //0x11 SI446X_CMD_SET_PROPERTY //0x20 SI446X_PROP_GROUP_MODEM //0x0A 10 Count @@ -802,7 +797,7 @@ static void SI4463_set_properties(uint16_t prop, void* values, uint8_t len) //0x00 [0x49] MODEM_ANT_DIV_CONTROL //0xFF [0x4A] MODEM_RSSI_THRESH //0x06 [0x4B] MODEM_RSSI_JUMP_THRESH -//0x03 [0x4C] MODEM_RSSI_CONTROL +//0x18 [0x4C] MODEM_RSSI_CONTROL //0x10 [0x4D] MODEM_RSSI_CONTROL2 //0x40 [0x4E] MODEM_RSSI_COMP // -----------------------------------------------------------------------------------------------------^ -------------- @@ -1322,7 +1317,7 @@ void SI446x_Fill(int s, int start) my_microsecond_delay(t); #else #if 1 - SI_CS_LOW; + SI_CS_LOW; SPI_WRITE_8BIT(SI4432_SPI, SI446X_CMD_ID_START_RX); while (SPI_IS_BUSY(SI4432_SPI)) ; // wait tx SPI_READ_8BIT(SI4432_SPI); // Skip command byte response @@ -1668,9 +1663,10 @@ freq_t SI4463_set_freq(freq_t freq) #endif } else return 0; - - si_set_offset(0); - + if (SI4463_offset_active) { + si_set_offset(0); + SI4463_offset_active = false; + } uint32_t R = (freq * SI4463_outdiv) / (Npresc ? 2*config.setting_frequency_30mhz : 4*config.setting_frequency_30mhz) - 1; // R between 0x00 and 0x7f (127) uint64_t MOD = 524288; // = 2^19 uint32_t F = ((freq * SI4463_outdiv*MOD) / (Npresc ? 2*config.setting_frequency_30mhz : 4*config.setting_frequency_30mhz)) - R*MOD; From 8f60c125c9a7992557dc6609e247525020fd49f5 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 2 May 2021 14:01:42 +0300 Subject: [PATCH 3/3] Fix Zero span on 72M MCU Add macros for device CS delay (if need) Use 0xFF tx for SPI read --- si4468.c | 75 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 28 deletions(-) diff --git a/si4468.c b/si4468.c index 9df633f..c2a4db7 100644 --- a/si4468.c +++ b/si4468.c @@ -33,19 +33,30 @@ #define SI4432_10MHZ 10000000U // !!!! FROM ili9341.c for disable it !!!! //#define LCD_CS_HIGH palSetPad(GPIOB, GPIOB_LCD_CS) -#define SI_CS_LOW palClearLine(LINE_RX_SEL) -#define SI_CS_HIGH palSetLine(LINE_RX_SEL) -#define SI_SDN_LOW palClearLine(LINE_RX_SDN) -#define SI_SDN_HIGH palSetLine(LINE_RX_SDN) +// Not use delays for CS +#if 1 + #define SI_CS_DELAY + #define PE_CS_DELAY + #define ADF_CS_DELAY +#else + #define SI_CS_DELAY {__asm("NOP");__asm("NOP");__asm("NOP");__asm("NOP");} + #define PE_CS_DELAY {__asm("NOP");__asm("NOP");__asm("NOP");__asm("NOP");} + #define ADF_CS_DELAY {__asm("NOP");__asm("NOP");__asm("NOP");__asm("NOP");} +#endif +#define SI_CS_LOW {palClearLine(LINE_RX_SEL);SI_CS_DELAY;} +#define SI_CS_HIGH {SI_CS_DELAY;palSetLine(LINE_RX_SEL);} + +#define SI_SDN_LOW palClearLine(LINE_RX_SDN); +#define SI_SDN_HIGH palSetLine(LINE_RX_SDN); // Hardware or software SPI use #ifdef USE_HARDWARE_SPI_MODE #define SI4432_SPI SPI1 -//#define SI4432_SPI_SPEED SPI_BR_DIV64 -//#define SI4432_SPI_SPEED SPI_BR_DIV32 -#define SI4432_SPI_SPEED SPI_BR_DIV2 + +//#define SI4432_SPI_SPEED SPI_BR_DIV4 // for 72M MCU +#define SI4432_SPI_SPEED SPI_BR_DIV2 // for 48M MCU //#define ADF_SPI_SPEED SPI_BR_DIV64 //#define ADF_SPI_SPEED SPI_BR_DIV32 @@ -68,9 +79,10 @@ static uint32_t new_port_moder; #define SPI1_SDO ((palReadPort(GPIOB)>>GPIOB_SPI_MISO)&1) #define SPI1_portSDO (palReadPort(GPIOB)&(1<> 24) & 0xFF); shiftOut((value >> 16) & 0xFF); shiftOut((value >> 8) & 0xFF); shiftOut((value >> 0) & 0xFF); - palSetLine(ADF4351_LE[channel]); + // unselect + CS_ADF_HIGH(ADF4351_LE[channel]); old_registers[value & 0x07] = registers[value & 0x07]; } } @@ -653,7 +667,7 @@ void SI4463_do_api(void* data, uint8_t len, void* out, uint8_t outLen) SI_CS_LOW; #if 1 SPI_WRITE_8BIT(SI4432_SPI, SI446X_CMD_READ_CMD_BUFF); - SPI_WRITE_8BIT(SI4432_SPI, 0x00); + SPI_WRITE_8BIT(SI4432_SPI, 0xFF); while (SPI_IS_BUSY(SI4432_SPI)); SPI_READ_16BIT(SI4432_SPI); // drop SI446X_CMD_READ_CMD_BUFF and CTS 0xFF #else @@ -664,7 +678,7 @@ void SI4463_do_api(void* data, uint8_t len, void* out, uint8_t outLen) ptr = (uint8_t *)out; while (outLen--){ #if 1 // Inline transfer - SPI_WRITE_8BIT(SI4432_SPI, 0x00); + SPI_WRITE_8BIT(SI4432_SPI, 0xFF); while (SPI_RX_IS_EMPTY(SI4432_SPI)); //wait rx data in buffer *ptr++ = SPI_READ_8BIT(SI4432_SPI); #else @@ -1157,12 +1171,12 @@ static char Si446x_readRSSI(void){ SI_CS_LOW; SPI_WRITE_8BIT(SI4432_SPI, SI446X_CMD_READ_FRR_A); - SPI_WRITE_8BIT(SI4432_SPI, 0x00); // begin read 1 bytes + SPI_WRITE_8BIT(SI4432_SPI, 0xFF); // begin read 1 bytes while (SPI_IS_BUSY(SI4432_SPI)) ; // wait tx SPI_READ_8BIT(SI4432_SPI); // Skip command byte response rssi = SPI_READ_8BIT(SI4432_SPI); // Get FRR A SI_CS_HIGH; -#else +#elif 1 SI_CS_LOW; SPI_WRITE_8BIT(SI4432_SPI, SI446X_CMD_GET_MODEM_STATUS); while (SPI_IS_BUSY(SI4432_SPI)) ; // wait tx @@ -1173,17 +1187,22 @@ static char Si446x_readRSSI(void){ SPI_WRITE_8BIT(SI4432_SPI, SI446X_CMD_READ_CMD_BUFF); // read answer while (SPI_IS_BUSY(SI4432_SPI)) ; // wait tx SPI_READ_16BIT(SI4432_SPI); // Drop SI446X_CMD_GET_MODEM_STATUS read and SI446X_CMD_READ_CMD_BUFF read - SPI_WRITE_16BIT(SI4432_SPI, 0x00); // begin read 2 bytes - SPI_WRITE_16BIT(SI4432_SPI, 0x00); // next read 2 bytes + SPI_WRITE_16BIT(SI4432_SPI, 0xFFFF); // begin read 2 bytes + SPI_WRITE_16BIT(SI4432_SPI, 0xFFFF); // next read 2 bytes while (SPI_IS_BUSY(SI4432_SPI)); // wait tx SPI_READ_8BIT(SI4432_SPI); // read CMD_ COMPLETE SPI_READ_8BIT(SI4432_SPI); // MODEM_PEND SPI_READ_8BIT(SI4432_SPI); // MODEM_STATUS rssi = SPI_READ_8BIT(SI4432_SPI); // CURR_RSSI -// SPI_WRITE_8BIT(SI4432_SPI, 0x00); +// SPI_WRITE_8BIT(SI4432_SPI, 0xFF); // while (SPI_IS_BUSY(SI4432_SPI)) ; // wait tx // rssi = SPI_READ_8BIT(SI4432_SPI); // LATCH_RSSI SI_CS_HIGH; +#else + uint8_t data[4]; + data[0] = SI446X_CMD_GET_MODEM_STATUS; + SI4463_do_api(data, 1, data, 3); + rssi = data[2]; #endif return rssi; } @@ -1191,7 +1210,7 @@ static char Si446x_readRSSI(void){ void SI446x_Fill(int s, int start) { (void)s; - + set_SPI_mode(SPI_MODE_SI); #if 0 // Only for testing uint8_t data2[] = { 0x11, 0x20, 0x01, 0x4C, 0x03 // set RSSI control @@ -1238,7 +1257,7 @@ void SI446x_Fill(int s, int start) again: SI_CS_LOW; SPI_WRITE_8BIT(SI4432_SPI, SI446X_CMD_READ_FRR_A); - SPI_WRITE_8BIT(SI4432_SPI, 0x00); // begin read 1 bytes + SPI_WRITE_8BIT(SI4432_SPI, 0xFF); // begin read 1 bytes while (SPI_IS_BUSY(SI4432_SPI)) ; // wait tx SPI_READ_8BIT(SI4432_SPI); // Skip command byte response age[i] = SPI_READ_8BIT(SI4432_SPI); // Get FRR A