⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rf.c

📁 软件无线电的平台
💻 C
字号:
/***************************************************************************                      rf.c - Control of the RF board                            -------------------    begin                :  2004    authors              :  Philippe Roud    emails               :  philippe.roud@epfl.ch ***************************************************************************//***************************************************************************                                 Changes                                 ------- date - name - description 04-01-19 - philippe - create **************************************************************************//*************************************************************************** *                                                                         * *    This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * ***************************************************************************/#include "ics_564.h"#include "rf_ics.h"#include "debugging.h"#include "std.h"#define DBG_LVL 0double ATT_VALUE[5]={1, 2, 4, 8, 16};u8 tx_state;// 11 bits: 1/2,1,2,4,8,1/2,1,2,4,8,15u16  rf_set_rx_att( double dB ){  int att=0x7ff;  int i;  double pad_value = 15;  if (dB >= 61 ){    att=0x0; //full rx att 11bits 0;    return att;  }  if ( dB > 46 ){    att-=1;  //activate 15dB rx PAD    dB-=pad_value;  }   if ( dB > 15.5 ){    att-=0x1f<<6; //activate rx second bank (HMC306, 15.5dB total)    dB-=15.5;  }  // Calculate first bank  for( i = 5; i > 0; i--) {    if ( ATT_VALUE[i-1] <= dB ) {      PR_DBG( 4, "i=%i, ATTVALUE=%i, db=%s%i.%i \n",i,ATT_VALUE[i-1],swr_ftosii(dB));      dB -= ATT_VALUE[i-1];      PR_DBG( 4, "new db=%i\n",dB);      att -= (1 << (6-i));      if ( dB <= 0 ){	break;      }      PR_DBG(4,"new att=%x\n",att);    }  }    PR_DBG( 4, "rx is %x\n", att );  return att;}// 10 bits: .5(MSB),1,2,4,8,1,2,4,8,16(LSB)u16  rf_set_tx_att( double dB ){  u16 att=0x3ff;  int i;  if ( dB>=46 ){    att=0x0; // full tx att    return att;  }   if ( dB > 15.5 ){    att=0x1f;//activate HMC306 (15.5dB total)    dB-=15.5;  }  // Calculate for HMC273 ( 31dB total )  for(  i = 5; i > 0; i--) {    if (ATT_VALUE[i-1]<=dB) {      dB = dB-ATT_VALUE[i-1];      att = att-(1 << (5-i));      if(dB<=0){break;}    }  }  return att;}u32 rf_set_synth_freq(double RF, u8 side){  double LO = 0;  u32 N = 0; //Reference freq multiplier    if(side == 0){    if(RF <= 2434){      side = 1;    }    else {      side = 2;    }  }  if (side == 1) {    LO = RF - 70;  }  else {    LO = RF + 70;  }  // for R=2500 and fRef=50 MHz :N = 50*LO;  // for R=5040 and fRef=50 MHz :N = 5040*LO / 50  // for R=10 and fRef=25MHz: N = 10 * LO / 25  //N = 5040*LO / 50;  //N = 50*LO;  //N = 15 * LO / 25;  N = RF_SYNCH_N( LO );  PR_DBG( 2, "RF freq multiplier N set to %i for LO %i and RF %i\n", 	  N, (int)LO, (int)RF );  return N;}void rf_set_synth( struct ics_dev *board,  u8 board_indx, double RF,  		   u8 side, u8 adr){  u32 RF_bits = 0;  u8 reg_address=0x3;  // Si4136 third register  PR_DBG(2,"Reconfiguring synth in rf.c, tx_state=%i\n",tx_state );  RF_bits = rf_set_synth_freq( RF, side );  RF_bits = (RF_bits << 4)+reg_address;  ics564_send_serial( board, ICS_564_SYNTH_W_SIZE, RF_bits, 		      ICS_564_SYNTH_CHIP, tx_state, adr);}// 24 bits 11+10+3(void)void rf_set_attenuation( struct ics_dev *board,u8 board_indx, double dB_rx, 			 double dB_tx, u8 adr) {  u32 att,rx_att, tx_att;   rx_att=tx_att = 0;  PR_DBG(2,"Reconfiguring attenuators in rf.c, tx_state=%i\n",tx_state);  rx_att=rf_set_rx_att( dB_rx );  tx_att=rf_set_tx_att( dB_tx );  att = ( rx_att << 13  ) + ( tx_att << 3 );  PR_DBG( 4, "Attenuation is: %x\n", att );/*     //  Swap left-right the dB_rx *//*     int i, a; *//*     a = dB_rx; *//*     for ( i=0, att=0; i<11; i++ ){ *//*       if ( a & ( 1 << i ) ){ *//* 	att += 1 << ( 10 - i ); *//*       } *//*     } *//*     att <<= 13; *//*   } */  ics564_send_serial( board, ICS_564_ATT_W_SIZE, att, ICS_564_ATT_CHIP, 		      tx_state, adr);}void rf_tx_enable(struct ics_dev *board, u8 tx, u8 adr){  PR_DBG(2,"Enabling tx in rf.c\n");  tx_state=tx;  if(tx){    WRITE_ICS564_U16( board, USER_IO,  0x124 + (adr<<6) );    usleep(10);  }  else{    WRITE_ICS564_U16( board, USER_IO,  0x24 + (adr<<6) );    usleep(10);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -