📄 rf.c
字号:
/*************************************************************************** rf.c - An implementation of antenna ------------------- begin : 2002 authors : Linus Gasser emails : linus.gasser@epfl.ch ***************************************************************************//*************************************************************************** Changes ------- date - name - description 02-10-01 - ineiti - create 02-12-12 - ineiti - it's now a child of antenna **************************************************************************//*************************************************************************** * * * 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. * * * ***************************************************************************/#define DBG_LVL 0#define EXPORT_SYMTAB#include <linux/kernel.h>#include <linux/init.h>#include <linux/module.h>#include <pthread.h>#include <semaphore.h>#include <linux/config.h>#include <math.h>#include "debugging.h"#include "memory.h"#include "channel_rf.h"#include "rf_io.h"#include "rf_dev.h"#include "sdb.h"// is either 0 or 1. This is used for the non-good initialised gains...#include "/var/local/sradio/rf-card.h"#ifndef CARD_TYPE#define CARD_TYPE 0#endifint init_cards;/** * @short Initialises an antenna's channel */int swr_ant_ch_init( swr_ant_param_t *p ) { device_t *dev_rf; if ( init_cards >= num_cards ) { PR_DBG( 0, "Asked for rf-card %i, but only %i are available\n", init_cards, num_cards ); return -1; } dev_rf = &rf_cards[ init_cards ]; pthread_mutex_lock( &dev_rf->mutex ); dev_rf->param = p; p->rx_tx_delay = 4 * DAQ_DMA_BLOCK_SIZE_BYTES + 80; p->slot_length = 20; p->gain_rx = 0.; p->gain_tx = 0.; p->is_complex = 0; dev_rf->mboxes[0] = 0; dev_rf->mboxes[1] = 0; dev_rf->running = 0; dev_rf->rx_buffer = NULL; dev_rf->tx_buffer = NULL; dev_rf->blocks_in_frame = 0; setmode( dev_rf, NORMAL_RX ); rf_writel( 0, dev_rf->data_base+PCI_START_STOP_DMA );#if CARD_TYPE == 1 swr_rf_set_gains( dev_rf, 670, 800, 690, 500 );#else swr_rf_set_gains( dev_rf, 750, 519, 650, 600 );#endif pthread_mutex_unlock( &dev_rf->mutex ); init_cards++; return 0;}/** * @short Deletes an antenna's channel */void swr_ant_ch_free( int nbr_ant ) { unsigned int baseptr; device_t *dev_rf; if ( nbr_ant >= init_cards ) { PR_DBG( 0, "Asked for rf-card %i, but only %i are initialised\n", nbr_ant, init_cards ); return; } dev_rf = &rf_cards[ nbr_ant ]; baseptr = dev_rf->data_base; // Stop the DMA-transfer pthread_mutex_lock( &dev_rf->mutex ); rf_writel( 0, baseptr+PCI_START_STOP_DMA ); PR_DBG( 3, "Stopped DMA\n" ); pthread_mutex_unlock( &dev_rf->mutex ); init_cards--; return;}/** * @short Starts the channel */void swr_ant_ch_start( void ) { unsigned int baseptr; device_t *dev_rf; int nbr_ant; swr_ant_param_t *p; for ( nbr_ant=0; nbr_ant<init_cards; nbr_ant++ ){ dev_rf = &rf_cards[ nbr_ant ]; p = dev_rf->param; dev_rf->rx_buffer = p->addr_rx; dev_rf->tx_buffer = p->addr_tx; if ( !dev_rf->tx_buffer || !dev_rf->rx_buffer ) { // Either of the buffers is not allocated PR_DBG( 0, "Buffers not allocated! Not starting DMA\n" ); return; } pthread_mutex_lock( &dev_rf->mutex ); baseptr = dev_rf->data_base; dev_rf->running = 1; dev_rf->blocks_in_frame = dev_rf->param->frame_blocks; dev_rf->rx_buffer = p->addr_rx; dev_rf->tx_buffer = p->addr_tx; if ( dev_rf->rx_buffer && dev_rf->tx_buffer && dev_rf->blocks_in_frame ) { setup_regs( dev_rf ); rf_writel( DMA_ADC_ON + CNT_ADC_ON + DMA_DAC_ON + CNT_DAC_ON, baseptr+PCI_START_STOP_DMA); } else { PR_DBG( 0, "Somethings missing: tx/rx buffer %p/%p, bpf: %i\n", p->addr_tx, p->addr_rx, p->frame_blocks ); } pthread_mutex_unlock( &dev_rf->mutex ); } return;}/** * @short Stops the channel */void swr_ant_ch_stop( void ) { unsigned int baseptr; device_t *dev_rf; int nbr_ant; for ( nbr_ant=0; nbr_ant<init_cards; nbr_ant++ ){ dev_rf = &rf_cards[ nbr_ant ]; pthread_mutex_lock( &dev_rf->mutex ); dev_rf->running = 0; baseptr = dev_rf->data_base; rf_writel( 0, baseptr+PCI_START_STOP_DMA ); pthread_mutex_unlock( &dev_rf->mutex ); } return;}/** * @short IOs the antenna */int swr_ant_ch_io( int nbr_ant, int block ) { int diff, wait; device_t *dev_rf; if ( nbr_ant >= num_cards ) { PR_DBG( 0, "Asked for rf-card %i, but only %i available\n", nbr_ant, num_cards ); return -1; } dev_rf = &rf_cards[ nbr_ant ]; diff = block - dev_rf->mboxes[0]; wait = diff * DURATION_DMA_BLOCK * 2;// wait = 60000; return wait;}/** * @short Update transciever proprieties */void set_rx_gain( int nbr_ant, double rx_gain ) { device_t *dev_rf; int gain; if ( nbr_ant >= num_cards ) { PR_DBG( 0, "Asked for rf-card %i, but only %i are available\n", nbr_ant, num_cards ); return; } dev_rf = &rf_cards[ nbr_ant ]; PR_DBG( 3, "New rx-gain=%s%i.%i\n", swr_ftosii( rx_gain ) ); // The .x_.._gain's are used for the 'basic' setup of the gains, // while .x_gain's are used for the 'relative' amplitude. // The former shouldn't change, while the latter may change during a // session. pthread_mutex_lock( &dev_rf->mutex ); gain = dev_rf->rx_if_gain + rx_gain; dev_rf->rx_gain = rx_gain; writegain( dev_rf, RX_IF_GAIN, gain ); pthread_mutex_unlock( &dev_rf->mutex );}void set_tx_gain( int nbr_ant, double tx_gain ) { device_t *dev_rf; int gain; if ( nbr_ant >= num_cards ) { PR_DBG( 0, "Asked for rf-card %i, but only %i are available\n", nbr_ant, num_cards ); return; } dev_rf = &rf_cards[ nbr_ant ]; PR_DBG( 3, "New tx-gain=%s%i.%i\n", swr_ftosii( tx_gain ) ); // The .x_.._gain's are used for the 'basic' setup of the gains, // while .x_gain's are used for the 'relative' amplitude. // The former shouldn't change, while the latter may change during a // session. pthread_mutex_lock( &dev_rf->mutex ); tx_gain = min( tx_gain, (double)500. ); dev_rf->tx_gain = tx_gain; gain = max( (int)(dev_rf->tx_if_gain + tx_gain), 0 ); gain = min( gain, 1023 ); writegain( dev_rf, TX_IF_GAIN, gain ); pthread_mutex_unlock( &dev_rf->mutex );}/** * @short Gets the gains from the RF-card */int swr_ant_rf_get_gains( int nbr_ant, int *tx_pa, int *tx_med, int *tx_if, int *rx_if ) { device_t *dev_rf; if ( nbr_ant >= num_cards ) { PR_DBG( 0, "Asked for rf-card %i, but only %i are available\n", nbr_ant, num_cards ); return -1; } dev_rf = &rf_cards[ nbr_ant ]; pthread_mutex_lock( &dev_rf->mutex ); swr_rf_get_gains( dev_rf, tx_pa, tx_med, tx_if, rx_if ); pthread_mutex_unlock( &dev_rf->mutex ); return 0;}/** * @short Sets the gains of the RF-card */int swr_ant_rf_set_gains( int nbr_ant, int tx_pa, int tx_med, int tx_if, int rx_if ) { device_t *dev_rf; if ( nbr_ant >= num_cards ) { PR_DBG( 0, "Asked for rf-card %i, but only %i are available\n", nbr_ant, num_cards ); return -1; } dev_rf = &rf_cards[ nbr_ant ]; pthread_mutex_lock( &dev_rf->mutex ); swr_rf_set_gains( dev_rf, tx_pa, tx_med, tx_if, rx_if ); pthread_mutex_unlock( &dev_rf->mutex ); return 0;}int swr_ant_ch_reconfig( int nbr_ant ){ device_t *dev_rf; if ( nbr_ant >= num_cards ) { PR_DBG( 0, "Asked for rf-card %i, but only %i are available\n", nbr_ant, num_cards ); return -1; } dev_rf = &rf_cards[ nbr_ant ]; set_rx_gain( nbr_ant, dev_rf->param->gain_rx ); set_tx_gain( nbr_ant, dev_rf->param->gain_tx ); return 0;}/** * @short Initialises the module */int rf_init( void ) { int ret; PR_DBG( 1, "RF is initialising\n" ); init_cards = 0; ret = init_dev(); return ret;}/** * @short Quits the module */void rf_exit( void ) { cleanup_dev(); if ( init_cards > 0 ){ PR_DBG( 0, "Still some cards hold by the software-radio\n" ); } PR_DBG( 1, "RF quits\n" );}module_init( rf_init );module_exit( rf_exit );EXPORT_SYMBOL(swr_ant_ch_init);EXPORT_SYMBOL(swr_ant_ch_free);EXPORT_SYMBOL(swr_ant_ch_start);EXPORT_SYMBOL(swr_ant_ch_stop);EXPORT_SYMBOL(swr_ant_ch_io);EXPORT_SYMBOL(swr_ant_ch_reconfig);EXPORT_SYMBOL(swr_ant_rf_set_gains);EXPORT_SYMBOL(swr_ant_rf_get_gains);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -