53 #define AS3980WAITTIME 510
57 #define WaitForAS3980() {\
58 delay_ms(AS3980WAITTIME); \
61 #define WaitForAS3980() {}
78 static void as3993PrintRfpLine(
void)
86 ch_val_i = ((s8)(val&0xff));
87 ch_val_q = ((s8)((val>>8)&0xff));
88 rf = sqrt(ch_val_i * ch_val_i + ch_val_q * ch_val_q);
93 for (val = -32; val <= 32 ; val ++)
100 if ( val == ch_val_i && val == ch_val_q)
105 if ( val == ch_val_i )
110 if ( val == ch_val_q )
135 myBuf[0] = AS3993_REG_DEVICEVERSION;
136 LOG(
"version reg %hhx->",myBuf[0]);
138 LOG(
"%hhx\n",myBuf[0]);
140 #if AS3993_DO_SELFTEST
147 memset(myBuf, 0x33,
sizeof(myBuf));
149 if ((myBuf[0]!=0x55) ||
154 LOG(
"%hhx %hhx %hhx %hhx\n", myBuf[0], myBuf[1], myBuf[2], myBuf[3]);
161 if ((myBuf[0]==0x55) ||
166 LOG(
"EN pin failed\n");
185 if ( !(as3993GetResponse() & RESP_FIFO) )
220 #if FEMTO2 || FETMO2_1
263 LOG(
"BALANCED INP\n");
345 #if FEMTO2 || FEMTO2_1 || RADON
372 as3993SetSensitivity(-AS3993_NOM_SENSITIVITY);
374 #if AS3993_DO_SELFTEST
379 if (!(myBuf[0] & 0x03))
383 if (!(myBuf[0] & 0x02))
393 as3993PrintRfpLine();
395 for( i = 860000UL; i< 960000UL ;i+=1000UL)
397 LOG(
"%hx%hx ",(u16)(i>>16),(u16)(i&0xffff));
399 as3993PrintRfpLine();
415 #if RUN_ON_AS3993 || RUN_ON_AS3980
419 static u8 addr =
READ | AS3993_REG_IRQSTATUS1;
426 #ifdef RFDATARECEIVELED
428 else RFDATARECEIVELED(LEDOFF);
431 }
while(AS3993_PORT_INT);
467 static u8 address = AS3993_REG_FIFO |
READ ;
480 if (address >= 0x23 && address <= 0x26)
506 if (address >= 0x23 && address <= 0x26)
517 u8 address, u8 *buf, u8 buf_len)
535 #if !USE_UART_STREAM_DRIVER
554 #if !USE_UART_STREAM_DRIVER
597 static void as3993LockPLL(
void)
619 if ( vco_voltage <= 1 || vco_voltage >= 6 )
628 }
while ( (var & 0x02)==0 && (i<3));
637 u16 ref=0, i, j, x, reg_A,reg_B;
642 if (regs == AS3993_REG_PLLMAIN1)
645 switch (buf[0]& 0x70)
671 divisor=frequency/ref;
673 i = 0x3FFF & (divisor >> 6);
703 if (regs==AS3993_REG_PLLMAIN1)
705 buf[0] = (buf[0] & 0xF0) | ((u8)((reg_B >> 6) & 0x0F));
706 buf[1] = (u8)((reg_B << 2) & 0xFC) | (u8)((reg_A >> 8) & 0x03);
727 for (i=1; i<AS3993_REG_ICD; i++)
760 for (i=1; i<AS3993_REG_ICD; i++)
776 if (!(buf[0] & 0x03))
778 LOG(
"/******** Crystal not stable */\n");
780 if (!(buf[0] & 0x02))
782 LOG(
"/********* PLL not locked */\n");
868 while (!(((version == 0x60) && (osc_ok & 0x01)) || (count > 250)));
878 unsigned count = 200;
883 if ((val & 0x03) == 0x03)
892 while (count-- && ( (
as3993SingleRead(AS3993_REG_AGCANDSTATUS) & 0x04) != 0x04 ) )
900 if ((val & 0x03) != 0x03)
913 #ifdef RFDATARECEIVELED
914 RFDATARECEIVELED(LEDOFF);
924 u8 reg0a, reg0d, gain;
931 sensitivity -= AS3993_NOM_SENSITIVITY;
932 if ( (reg0a & 0x03) == 0x03 )
936 else if ( (reg0a & 0x03) == 0x00 )
943 sensitivity -= AS3993_NOM_SENSITIVITY;
953 gain = (reg0a >> 6) * 3;
965 s8 as3993SetSensitivity( s8 minimumSignal )
967 u8 reg0d, reg0a, gain;
975 minimumSignal += AS3993_NOM_SENSITIVITY;
976 if ( minimumSignal >= 6 )
981 else if ( minimumSignal <= -6 )
991 minimumSignal += AS3993_NOM_SENSITIVITY;
992 if ( minimumSignal >= 8 )
997 if ( minimumSignal <= -10 )
1003 if ( minimumSignal > 0)
1006 gain = minimumSignal / 3;
1007 if ( gain>3 ) gain = 3;
1008 minimumSignal -= gain*3;
1014 gain = (-minimumSignal+2) / 3;
1015 if ( gain>3 ) gain = 3;
1016 minimumSignal += gain*3;
1020 return minimumSignal;
1024 void as3993GetRSSIMaxSensitive( u16 num_of_ms_to_scan, u8 *rawIQ)
1026 u8 regValRXFilter, regValRXMixerGain = 0;
1033 as3993SetSensitivity(-90);
1038 as3993GetRSSI(num_of_ms_to_scan, rawIQ);
1046 void as3993GetRSSI( u16 num_of_ms_to_scan, u8 *rawIQ)
1048 u8 rawVal,valI, valQ = 0;
1049 u8 regValStatusCtrl, regValProtoCtrl = 0;
1050 u8 regValIRQ1Mask, regValStatusPage, regValStatus = 0;
1052 u8 singelMeasVal = 0;
1053 u16 num_of_reads = num_of_ms_to_scan * 2 + 1;
1054 unsigned count = 200;
1059 while (count-- && ( (
as3993SingleRead(AS3993_REG_AGCANDSTATUS) & 0x02) != 0x02 ) )
1061 LOG(
"PLL not locked!\n");
1080 while (count-- && ( (
as3993SingleRead(AS3993_REG_AGCANDSTATUS) & 0x04) != 0x04 ) )
1082 LOG(
"RF field not stable !\n");
1089 while (num_of_reads--)
1094 valQ = ((rawVal >> 4) & 0xf);
1096 singelMeasVal = (rawVal&0x0f) + (rawVal>>4);
1097 if (singelMeasVal >= sumRSSI)
1099 sumRSSI = singelMeasVal;
1115 #define CONVERT_ADC_TO_NAT(A) (((A)&0x80)?((A)&0x7f):(0 - ((A)&0x7f)))
1122 val = CONVERT_ADC_TO_NAT(val);
1130 u8 regMeas, regStatus;
1147 value = (value & 0xff) | (adcVal << 8);
1157 u8 regMeas, regStatus;
1173 value = (i_0 & 0xff) | (q_0 << 8);
1181 u8 *rxbuf, u16 *rxbits,
1182 u8 norestime, u8 followCmd,
1188 u8 checkRxLength = 0;
1193 rxbytes = (*rxbits + 7) / 8;
1201 if ((cmd != AS3993_CMD_QUERYREP) && (cmd != AS3993_CMD_QUERYADJUSTUP)&& (cmd != AS3993_CMD_QUERYADJUSTNIC)&& (cmd != AS3993_CMD_QUERYADJUSTDOWN))
1211 buf[1] = rxs & 0xff;
1212 buf[0] = ((rxs>>8) & 0x0F) | 0x10;
1214 if ((cmd != AS3993_CMD_QUERY)&&(cmd != AS3993_CMD_QUERYREP) && (cmd != AS3993_CMD_QUERYADJUSTUP)&& (cmd != AS3993_CMD_QUERYADJUSTNIC)&& (cmd != AS3993_CMD_QUERYADJUSTDOWN))
1224 u8 txbytes = (txbits + 7)/8;
1226 if (totx > 24) totx = 24;
1229 buf[1] = (txbits % 8) << 1;
1230 buf[1] |= (txbits / 8) << 4;
1231 buf[0] = txbits / 128;
1232 if (cmd != AS3993_CMD_QUERY)
1242 if (totx > 16) totx = 18;
1245 as3993ClrResponseMask(RESP_FIFO);
1257 if (currCmd && waitTxIrq)
1260 as3993ClrResponseMask(RESP_TXIRQ | RESP_FIFO);
1262 if (rxbits && !rxs && !rxbuf)
1273 if (0xff == norestime)
1275 u16 responseTimout = 30;
1278 case GEN2_LF_40 : responseTimout = 120;
break;
1295 while (as3993GetResponse() & RESP_FIFO &&
1296 !(as3993GetResponse() & RESP_RXIRQ))
1299 if (checkRxLength && count > rxbytes)
1302 LOG(
"limiting1 %hhx %hhx resp %hx\n",count,rxbytes,as3993GetResponse());
1310 as3993ClrResponseMask(RESP_FIFO);
1311 if (checkRxLength && rxbytes == 0)
1312 return AS3993_ERR_RXCOUNT;
1316 resp = as3993GetResponse();
1317 as3993ClrResponse();
1318 if (followCmd && !(resp & (RESP_NORESINTERRUPT | RESP_RXERR)))
1328 currCmd = followCmd;
1331 if (checkRxLength && count > rxbytes)
1334 LOG(
"limiting %hhx %hhx\n",count,rxbytes);
1337 resp |= RESP_RXCOUNTERROR;
1352 if (currCmd != AS3993_CMD_TRANSMCRCEHEAD)
1353 resp &= ~RESP_HEADERBIT;
1355 if(resp & (RESP_NORESINTERRUPT | RESP_RXERR | RESP_HEADERBIT | RESP_RXCOUNTERROR))
1358 if(resp & RESP_RXERR)
1364 if (resp & RESP_NORESINTERRUPT)
1365 return AS3993_ERR_NORES;
1366 if (resp & RESP_HEADERBIT && currCmd == AS3993_CMD_TRANSMCRCEHEAD)
1367 return AS3993_ERR_HEADER;
1369 if (resp & RESP_RXCOUNTERROR)
1371 if (!(resp & RESP_RXERR))
1375 return AS3993_ERR_RXCOUNT;
1377 if (resp & RESP_PREAMBLEERROR)
return AS3993_ERR_PREAMBLE;
1378 if (resp & RESP_CRCERROR)
return AS3993_ERR_CRC;
s8 as3993TxRxGen2Bytes(u8 cmd, u8 *txbuf, u16 txbits, u8 *rxbuf, u16 *rxbits, u8 norestime, u8 followCmd, u8 waitTxIrq)
void as3993ExitDirectMode()
Leave the direct mode.
void as3993EnterPowerStandbyMode()
Enter the standby power down mode: EN is high, stby is high and rf_on bit is low. ...
u16 as3993GetReflectedPowerNoiseLevel(void)
#define WAITFORRESPONSECOUNT
Declaration of low level functions provided by the as3993 series chips.
#define WAITFORRESPONSEDELAY
void as3993EnterPowerNormalMode()
Enter the normal power mode: EN is high, stby and rf_on bits are low.
void as3993WaitForResponse(u16 waitMask)
static u8 gChipRevisionZero
u16 as3993Initialize(u32 baseFreq)
This file provides declarations for global helper functions.
This file is the include file for the timer.c file.
void as3993ContinuousWrite(u8 address, u8 *buf, s8 len)
static u8 as3993PowerDownRegs[AS3993_REG_ICD+6]
void as3993WaitForResponseTimed(u16 waitMask, u16 counter)
s8 as3993GetSensitivity()
void as3993SingleWrite(u8 address, u8 value)
struct gen2Config * getGen2IntConfig()
Returns the Gen2 Configuration.
void as3993FifoRead(s8 len, u8 *readbuf)
void as3993SetBaseFrequency(u8 regs, u32 frequency)
void INTERRUPT as3993Isr(void)
u8 as3993ReadChipVersion(void)
void as3993EnterPowerNormalRfMode()
Enter the normal power mode with rf on. EN is high, stby bit is low and rf_on bit is high...
void as3993ResetDoNotPreserveRegisters(void)
void as3993AntennaPower(u8 on)
Configuration file for all AS99x firmware.
#define AS3993_IRQ1_RXERR
void as3993WaitForResponseFAST(u16 waitMask)
void as3993SingleCommand(u8 command)
void as3993CommandContinuousAddress(u8 *command, u8 com_len, u8 address, u8 *buf, u8 buf_len)
u8 as3993SingleRead(u8 address)
u16 as3993GetReflectedPower(void)
serial output log declaration file
void as3993EnterDirectMode()
Enter the direct mode.
Declaration of public functions provided by the AS3993 series chips.
void as3993WaitForStartup(void)
after EN goes high the IRQ register has to be read after osc_ok goes high.
void as3993ExitPowerStandbyMode()
Exit the standby power down mode.
void as3993ExitPowerNormalMode()
Exit the normal power mode.
void as3993EnterPowerDownMode()
Enter the power down mode by setting EN pin to low, saving registers beforehand.
This file provides declarations for functions for the GEN2 aka ISO6c protocol.
void as3993ContinuousRead(u8 address, s8 len, u8 *readbuf)
volatile u16 as3993Response
void as3993ExitPowerDownMode()
Exit the power down mode by setting EN pin to high, restoring registers afterwards.
void as3993ExitPowerNormalRfMode()
Exit the normal power mode with rf on.