|
void dwt_readdiagnostics(dwt_rxdiag_t *diagnostics)
{
// Read the HW FP index
diagnostics->firstPath = dwt_read16bitoffsetreg(RX_TIME_ID, RX_TIME_FP_INDEX_OFFSET);
// LDE diagnostic data
diagnostics->maxNoise = dwt_read16bitoffsetreg(LDE_IF_ID, LDE_THRESH_OFFSET);
// Read all 8 bytes in one SPI transaction
dwt_readfromdevice(RX_FQUAL_ID, 0x0, 8, (uint8*)&diagnostics->stdNoise);
diagnostics->firstPathAmp1 = dwt_read16bitoffsetreg(RX_TIME_ID, RX_TIME_FP_AMPL1_OFFSET);
diagnostics->rxPreamCount = (dwt_read32bitreg(RX_FINFO_ID) & RX_FINFO_RXPACC_MASK) >> RX_FINFO_RXPACC_SHIFT ;
}
dwt_rxdiag_t Diagnostics;
void ReadRssiFirstPath(u8 Count)
{
u16 Rssi[10] = {0};
dwt_readdiagnostics(&Diagnostics);//Diagnostics
M = dwt_read16bitoffsetreg(0x12, 6);
Rssi[0] = Diagnostics.maxNoise;
Rssi[1] = Diagnostics.firstPathAmp1;
Rssi[2] = Diagnostics.firstPathAmp2;
Rssi[3] = Diagnostics.firstPathAmp3;
Rssi[4] = Diagnostics.maxGrowthCIR;
Rssi[5] = Diagnostics.rxPreamCount;
Rssi[6] = Diagnostics.firstPath;
Rssi[7] = Diagnostics.stdNoise;
RxLevel = 10*log10( (M*131072.0)/(Rssi[5]*Rssi[5]) ) - 121.74; //RSSI值
FirstPath[Count] = 10*log10( (Rssi[1]*Rssi[1]+Rssi[2]*Rssi[2]+Rssi[3]*Rssi[3])/(Rssi[5]*Rssi[5]) ) - 121.74; //首经功率
}
int dwt_sedtxpowermode(int8_t coarsePower, int8_t finePower) //设置发送功率增益
{
uint32_t pow = 0;
float total_power = 0.0;
switch(coarsePower)
{
case 0:
pow |= (0x06 << 5); total_power = 0;
break;//0dB
case 1:
pow |= (0x05 << 5); total_power = 3;
break;//3dB
case 2:
pow |= (0x04 << 5); total_power = 6;
break;//6dB
case 3:
pow |= (0x03 << 5); total_power = 9;
break;//9dB
case 4:
pow |= (0x02 << 5); total_power = 12;
break;//12dB
case 5:
pow |= (0x01 << 5); total_power = 15;
break;//15dB
case 6:
pow |= (0x00 << 5); total_power = 18;
break;//18dB
default:
printf("Coarse power error\r\n");
return DWT_ERROR;
}
switch(finePower)
{
case 0:
pow |= 0x00; total_power += 0;
break;//0dB
case 1:
pow |= 0x01; total_power += 0.5;
break;//0.5dB
case 2:
pow |= 0x02; total_power += 1;
break;//1.0dB
case 3:
pow |= 0x03; total_power += 1.5;
break;//1.5dB
case 4:
pow |= 0x04; total_power += 2;
break;//2dB
case 5:
pow |= 0x05; total_power += 2.5;
break;//2.5dB
case 6:
pow |= 0x06; total_power += 3;
break;//3dB
case 7:
pow |= 0x07; total_power += 3.5;
break;//3.5dB
case 8:
pow |= 0x08; total_power += 4;
break;//4dB
case 9:
pow |= 0x09; total_power += 4.5;
break;//4.5dB
case 10:
pow |= 0x0a; total_power += 5;
break;//5.0dB
case 11:
pow |= 0x0b; total_power += 5.5;
break;//5.5dB
case 12:
pow |= 0x0c; total_power += 6;
break;//6dB
case 13:
pow |= 0x0d; total_power += 6.5;
break;//6.5dB
case 14:
pow |= 0x0e; total_power += 7;
break;//7dB
case 15:
pow |= 0x0f; total_power += 7.5;
break;//7.5dB
case 16:
pow |= 0x10; total_power += 8;
break;//8dB
case 17:
pow |= 0x11; total_power += 8.5;
break;//8.5dB
case 18:
pow |= 0x12; total_power += 9;
break;//9dB
case 19:
pow |= 0x13; total_power += 9.5;
break;//9.5dB
case 20:
pow |= 0x14; total_power += 10;
break;//10dB
case 21:
pow |= 0x15; total_power += 10.5;
break;//10.5dB
case 22:
pow |= 0x16; total_power += 11;
break;//11dB
case 23:
pow |= 0x17; total_power += 11.5;
break;//11.5dB
case 24:
pow |= 0x18; total_power += 12;
break;//12dB
case 25:
pow |= 0x19; total_power += 12.5;
break;//12.5dB
case 26:
pow |= 0x1a; total_power += 13;
break;//13dB
case 27:
pow |= 0x1b; total_power += 13.5;
break;//13.5dB
case 28:
pow |= 0x1c; total_power += 14;
break;//14dB
case 29:
pow |= 0x1d; total_power += 14.5;
break;//14.5dB
case 30:
pow |= 0x1e; total_power += 15;
break;//15dB
case 31:
pow |= 0x1f; total_power += 15.5;
break;//15.5dB
default:
printf("Fine power error\r\n");
return DWT_ERROR;
}
pow = (pow << 24) + (pow << 16) + (pow << 8) + pow;
dwt_write32bitoffsetreg(TX_POWER_ID, 0,pow);
printf("the power is %f dB \r\n", total_power);
return DWT_SUCCESS;
}
|
|