More compact shiftIn and shiftOut

Add buffer shiftInBuf and shiftOutBuf in/out
Replace int freq on uint32_t
Fix in SI4432_Set_Frequency Freq_Band overflow
pull/4/head
DiSlord 6 years ago
parent 95fda046ef
commit 744a8db67d

@ -226,7 +226,7 @@ void set_decay(int);
void set_noise(int); void set_noise(int);
void toggle_tracking_output(void); void toggle_tracking_output(void);
extern int32_t frequencyExtra; extern int32_t frequencyExtra;
void set_10mhz(int); void set_10mhz(uint32_t);
void set_modulation(int); void set_modulation(int);
//extern int setting.modulation; //extern int setting.modulation;
void set_measurement(int); void set_measurement(int);
@ -847,7 +847,7 @@ float SI4432_RSSI(uint32_t i, int s);
#ifdef __FAST_SWEEP__ #ifdef __FAST_SWEEP__
void SI4432_Fill(int s, int start); void SI4432_Fill(int s, int start);
#endif #endif
void SI4432_Set_Frequency ( long Freq ); void SI4432_Set_Frequency ( uint32_t Freq );
float SI4432_SET_RBW(float WISH); float SI4432_SET_RBW(float WISH);
void SI4432_SetReference(int freq); void SI4432_SetReference(int freq);

@ -41,7 +41,7 @@
#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_SDO ((palReadPort(GPIOB) & (1<<GPIO_SPI2_SDO))?1:0) #define SPI2_SDO ((palReadPort(GPIOB)>>GPIO_SPI2_SDO)&1)
//#define MAXLOG 1024 //#define MAXLOG 1024
@ -53,32 +53,60 @@
void shiftOut(uint8_t val) void shiftOut(uint8_t val)
{ {
uint8_t i;
SI4432_log(SI4432_Sel); SI4432_log(SI4432_Sel);
SI4432_log(val); SI4432_log(val);
for (i = 0; i < 8; i++) { uint8_t i = 0;
if (val & (1 << (7 - i))) do {
if (val & 0x80)
SPI2_SDI_HIGH; SPI2_SDI_HIGH;
else else
SPI2_SDI_LOW; SPI2_SDI_LOW;
val<<=1;
SPI2_CLK_HIGH; SPI2_CLK_HIGH;
SPI2_CLK_LOW; SPI2_CLK_LOW;
} }while((++i) & 0x07);
} }
uint8_t shiftIn(void) { uint8_t shiftIn(void) {
uint8_t value = 0; uint8_t value = 0;
uint8_t i; uint8_t i = 0;
for (i = 0; i < 8; ++i) { do {
SPI2_CLK_HIGH; SPI2_CLK_HIGH;
value |= SPI2_SDO << (7 - i); value = (value<<1)|SPI2_SDO;
SPI2_CLK_LOW; SPI2_CLK_LOW;
} }while((++i) & 0x07);
return value; return value;
} }
void shiftInBuf(uint8_t *buf, uint16_t size) {
uint8_t i = 0;
do{
uint8_t value = 0;
do {
SPI2_CLK_HIGH;
value = (value<<1)|SPI2_SDO;
SPI2_CLK_LOW;
}while((++i) & 0x07);
*buf++=value;
}while(--size);
}
void shiftOutBuf(uint8_t *buf, uint16_t size) {
uint8_t i = 0;
do{
uint8_t val = *buf++;
do{
if (val & 0x80)
SPI2_SDI_HIGH;
else
SPI2_SDI_LOW;
val<<=1;
SPI2_CLK_HIGH;
SPI2_CLK_LOW;
}while((++i) & 0x07);
}while(--size);
}
const int SI_nSEL[3] = { GPIO_RX_SEL, GPIO_LO_SEL, 0}; // #3 is dummy!!!!!! const int SI_nSEL[3] = { GPIO_RX_SEL, GPIO_LO_SEL, 0}; // #3 is dummy!!!!!!
volatile int SI4432_Sel = 0; // currently selected SI4432 volatile int SI4432_Sel = 0; // currently selected SI4432
@ -276,7 +304,7 @@ float SI4432_SET_RBW(float w) {
int setting_frequency_10mhz = 10000000; int setting_frequency_10mhz = 10000000;
void set_10mhz(int f) void set_10mhz(uint32_t f)
{ {
setting_frequency_10mhz = f; setting_frequency_10mhz = f;
} }
@ -285,19 +313,19 @@ int SI4432_frequency_changed = false;
//static int old_freq_band[2] = {-1,-1}; //static int old_freq_band[2] = {-1,-1};
//static int written[2]= {0,0}; //static int written[2]= {0,0};
void SI4432_Set_Frequency ( long Freq ) { void SI4432_Set_Frequency ( uint32_t Freq ) {
int hbsel; uint8_t hbsel;
long Carrier; if (Freq >= 480000000U) {
if (Freq >= 480000000) { hbsel = 1<<5;
hbsel = 1; Freq>>=1;
Freq = Freq / 2;
} else { } else {
hbsel = 0; hbsel = 0;
} }
int sbsel = 1; uint8_t sbsel = 1 << 6;
long N = Freq / setting_frequency_10mhz; uint32_t N = (Freq / setting_frequency_10mhz - 24)&0x1F;
Carrier = ( 4 * ( Freq - N * setting_frequency_10mhz )) / 625; uint32_t K = Freq % setting_frequency_10mhz;
int Freq_Band = ( N - 24 ) | ( hbsel << 5 ) | ( sbsel << 6 ); uint32_t Carrier = (K<<2) / 625;
uint8_t Freq_Band = N | hbsel | sbsel;
// if (old_freq_band[SI4432_Sel] == Freq_Band) { // if (old_freq_band[SI4432_Sel] == Freq_Band) {
// if (written[SI4432_Sel]++ < 6) // if (written[SI4432_Sel]++ < 6)
// SI4432_Write_Byte ( 0x75, Freq_Band ); // SI4432_Write_Byte ( 0x75, Freq_Band );
@ -323,6 +351,7 @@ 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 float t = setting.sweep_time - calc_min_sweep_time(); // Time to delay in mS
if (t < 0) if (t < 0)
t = 0; t = 0;
@ -336,6 +365,11 @@ void SI4432_Fill(int s, int start)
if (ti) if (ti)
my_microsecond_delay(ti); my_microsecond_delay(ti);
} }
#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;
} }

@ -32,7 +32,7 @@ float 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 ( long Freq ); void SI4432_Set_Frequency ( uint32_t Freq );
void SI4432_Transmit(int d); void SI4432_Transmit(int d);
void SI4432_Receive(void); void SI4432_Receive(void);
float SI4432_SET_RBW(float WISH); float SI4432_SET_RBW(float WISH);

Loading…
Cancel
Save

Powered by TurnKey Linux.