📄 ics.c
字号:
/*************************************************************************** ics.c - ICS-5x4 driver ------------------- begin : 2003 authors : Linus Gasser emails : linus.gasser@epfl.ch***************************************************************************//*************************************************************************** Changes ------- date - name - description 03-09-16 - ineiti - 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. * * * ***************************************************************************/#define DBG_LVL 0#include "system.h"#include "debugging.h"#include "memory.h"#include "sdb.h"#include "ics_dev.h"#include "ics_564.h"#include "ics_554.h"#include "ics_564_test.h"#include "ics_554_test.h"#include "ics_test.h"#include "antenna.h"#include "rf_ics.h"int number_channels;// 0 -> no test// 1 -> 564// 2 -> 554// 3 -> both#define TEST 0/** * @short Initialises an antenna's channel */int swr_ant_ch_init( swr_ant_param_t *p ) { if ( number_channels < ADA_PER_BOARD ){#if TEST != 2 PR_DBG( 2, "Initialising tx-channel %i\n", number_channels ); board_tx.params[ number_channels ] = p; board_tx.number_channels = number_channels + 1;#endif#if TEST != 1 PR_DBG( 2, "Initialising rx-channel %i\n", number_channels ); board_rx.params[ number_channels ] = p; board_rx.number_channels = number_channels + 1;#endif p->addr_rx = 0; p->addr_tx = 0; p->rx_tx_delay = 256; p->gain_max_rx = 61; p->gain_max_tx = 46; return number_channels++; } else { return -1; }}/** * @short Deletes an antenna's channel */void swr_ant_ch_free( int nbr_ant ) { return;}/** * @short Starts the channel * HAS TO BE CHANGED: A call to channel start starts ALL initialised * channels, on both RX AND TX. * so far only TX - Selva */void swr_ant_ch_start( void ) { int nc; // if we don't test 554 only#if TEST != 2 if ( ( board_tx.params[0]->flags & ANTENNA_ONLY_RX ) != ANTENNA_ONLY_RX ){ if ( board_tx.params[0]->addr_tx ){ if ( !board_tx.blocks_per_frame ){ PR_DBG( 0, "Can't start with board_tx.blocks_per_frame == 0\n" ); return; } PR_DBG( 0*1, "Starting TX-part at %p\n", board_tx.params[0]->addr_tx ); // Start the TX-part ics564_set_buffer_size( &board_tx, board_tx.block_size * 2 ); // Transfer the DAC control information to AD9857 // Strange channel-mapping to avoid using CH2 of ICS564! nc = ( 1 << board_tx.number_channels ) - 1; // nc = ( ( nc & 0x3 ) << 2 ) + ( nc >> 2 ); PR_DBG( 2, "Loading %4.4x into the 564\n", nc ); ics564_load( &board_tx, nc ); // Set the block_count board_tx.block_count = 0; // Set the status flag to RUN - evaluated by the Interrupt Handler board_tx.flags |= ICS564_RUN; rtl_udelay( 100000 ); // First Data tranfer PR_DBG( 2, "Start next block\n" ); ics564_dma_next_block( &board_tx ); // if we test both or none#if TEST == 3 || TEST == 0 if ( !board_rx.params[0]->addr_rx || ( board_tx.flags & ICS564_TRIGGER_INT ) ){ PR_DBG( 1, "Triggering TX\n" ); ics564_trigger( &board_tx ); }#else ics564_trigger( &board_tx );#endif PR_DBG( 1, "Finished tx-part\n" ); } }#endif // if we don't test 564#if TEST != 1 if ( ( board_rx.params[0]->flags & ANTENNA_ONLY_TX ) != ANTENNA_ONLY_TX ){ if ( board_rx.params[0]->addr_rx ){ if ( !board_rx.blocks_per_frame ){ PR_DBG( 0, "Can't start with board_rx.blocks_per_frame == 0\n" ); return; } PR_DBG( 0*1, "Starting RX-part @ %p\n", board_rx.params[0]->addr_rx ); // Start the RX-part/* int cc; *//* // First update the channel-count *//* cc = ( 1 << ( 2 * number_channels ) ) - 1; *//* ics554_channel_count( &board_rx, cc & 0xf, cc >> 4 ); */ ics554_adc_reset( &board_rx ); ics554_enable( &board_rx, 3, 1 ); ics554_trigger( &board_rx ); } }#endif return;}/** * @short Stops the channel * @param nbr_ant The index of the antenna [0..MAX_ANTENNAS - 1] */void swr_ant_ch_stop( void ) { PR_DBG( 1, "Going to stop things..\n"); // Stop it#if TEST != 2 PR_DBG( 1, "Stopping 564\n" ); ics564_stop( &board_tx );#endif#if TEST != 1 PR_DBG( 1, "Stopping 554\n" ); ics554_stop( &board_rx );#endif PR_DBG( 3, "Everything is stopped now...\n"); return;}/** * @short IOs the antenna, returns time in us */int swr_ant_ch_io( int block ) {#if TEST == 0 u64 bc, b; // block is the 'target' block that is interesting to the // SRadio. Calculate the time needed for that block to pass // over the air. if ( ( board_tx.params[0]->flags & ANTENNA_ONLY_RX ) != ANTENNA_ONLY_RX ){ bc = board_tx.block_count * BOARD_BLOCK_SIZE / board_tx.number_channels; } else { bc = board_rx.block_count * BOARD_BLOCK_SIZE / board_rx.number_channels; } b = (u64)block; PR_DBG( 4, "Block(%lli) - target_block(%lli) = %lli\n", bc, b, b - bc ); if ( bc > b ){ PR_DBG( 1, "Oops, going too slow\n" ); return 0; } // The time of a block is 256 * Sample_period, where Sample_period // is around 1/2us return ( DAQ_DMA_BLOCK_SIZE_QI_SAMPLES * SAMPLE_PERIOD_NS ) / 1000 * ( b - bc );#else return 1000;#endif}/** * @short Set the RF attenutors */void swr_ant_ch_set_attn( int nbr_ant, int board_indx, double dB_rx, double dB_tx ){ PR_DBG( 4, "Reconfiguring attenuators[%i]: %i, %i\n", nbr_ant, (int)dB_rx, (int)dB_tx ); rf_set_attenuation( &board_tx,(u8)board_indx, dB_rx, dB_tx, (u8)nbr_ant );}/** * @short reconfigures all initialised channels */int swr_ant_ch_reconfig( int nbr_ant ){#if TEST == 0 swr_ant_param_t *p; if ( board_rx.params[0]->frame_blocks % BOARD_BLOCK_SIZE ){ PR_DBG( 0, "Oh-oh, frame_blocks(%i) is not a multiple of %i!\n", board_rx.params[0]->frame_blocks, BOARD_BLOCK_SIZE ); } board_tx.blocks_per_frame = board_rx.blocks_per_frame = board_rx.params[0]->frame_blocks / BOARD_BLOCK_SIZE; PR_DBG( 3, "Reconfiguring: blocks_per_frame = %i\n", board_tx.blocks_per_frame ); if ( nbr_ant < number_channels ){ p = board_tx.params[nbr_ant]; } else { return -1; } swr_ant_ch_set_attn( nbr_ant, 0, p->gain_max_rx - p->gain_rx, p->gain_max_tx - p->gain_tx );#endif return 0;}/** * @short Set the RF frequency synthetiser */void swr_ant_ch_set_synth( int nbr_ant, int board_indx, double RF, int side ){ rf_set_synth(&board_tx, (u8)board_indx, RF, side, (u8)nbr_ant);}/** * @short Switch the RF board to Rx or Tx modes */void swr_ant_ch_tx_enable( int nbr_ant, int tx){ PR_DBG( 4, "Reconfiguring enable tx\n" ); rf_tx_enable( &board_tx, (u8)tx, (u8)nbr_ant );}void swr_ant_ch_set_freq_diff( int nbr_ant, long int freq_diff ){ static int profile[4] = { 0, 0, 0, 0 }; profile[ nbr_ant ] ^= 1; ics564_freq_quad( &board_tx, nbr_ant, profile[ nbr_ant ], ICS564_CARRIER( CARRIER_MHZ ) + freq_diff ); PR_DBG( 4, "Wrote frequency %llx to profile %i of dac %i\n", ICS564_CARRIER( CARRIER_MHZ ) + freq_diff, profile[ nbr_ant ], nbr_ant );}/** * @short Initialises the module */int ics_init( void ) { number_channels = 0;#if TEST == 0 ics564_init(); ics554_init();#elif TEST == 1 ics564_init(); ics564_test_start( &board_tx );#elif TEST == 2 ics554_init(); ics554_test_start( &board_rx );#elif TEST == 3 ics564_init(); ics554_init(); ics_test_start();#endif return 0;}/** * @short Quits the module */void ics_exit( void ) {#if TEST == 0 ics554_free( &board_rx ); ics564_free( &board_tx );#elif TEST == 1 ics564_test_stop( &board_tx ); ics564_free( &board_tx );#elif TEST == 2 ics554_test_stop( &board_rx ); ics554_free( &board_rx );#elif TEST == 3 ics_test_stop(); ics554_free( &board_rx ); ics564_free( &board_tx );#endif /* pthread_mutex_destroy( &ics_tx.mutex ); */ /* pthread_mutex_destroy( &ics_rx.mutex ); */}module_init( ics_init );module_exit( ics_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_ch_set_synth);EXPORT_SYMBOL(swr_ant_ch_tx_enable);EXPORT_SYMBOL(swr_ant_ch_set_freq_diff);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -