📄 rf.c
字号:
/*************************************************************************** * rf.c - A simple interface for the RF-cards * ------------------- * begin : 02/10/30 * authors : Linus Gasser * emails : linus.gasser@epfl.ch ***************************************************************************//*************************************************************************** * Changes * ------- * date - name - description * 04/01/01 - proud - begin * 04/03/06 - ineiti - cleanup: killed RF_send, as there is only one module, * and renamed the caps to lower-case letters. * 04/03/06 - ineiti - adjusted description * **************************************************************************//*************************************************************************** * * * 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. * * * ***************************************************************************//** * This is a simple interface for the RF-ICS cards. It mainly serves as * a placeholder for the different configuration-variables available * in Base/Antenna/ICS/ */#include "spc.h"#include "rf.h"#include "antenna.h"#define DBG_LVL 0typedef struct { // The tx_attenuation int rx_attn; // 0 // The rx_attenuation int tx_attn; // 0 // if tx = 0, we're receiving, if tx = 1, we're sending int tx; // 0 // The frequency of the RF-board. It's in kHz, and between // 2300 and 2500 double freq; // 2420 // We can have low-side or high-side injection of the signal. If // this is 0, we're automatically trying to keep the LO out of the // ISM-band. If it is 1, it's low-side injection, 2 is high-side // injection. int side; // 0}config_t;typedef struct {}stats_t;typedef struct { double rx_attn ; double tx_attn; int tx; double freq; int side;}private_t;/* * The initialisation function, or constructor, * is called the first time this module is instantiated. */int rf_init( swr_sdb_t *context ) { // Begin system-definitions { config_t *config; stats_t *stats; MOD_INC_USE_COUNT; if ( sizeof( private_t ) > 0 ) context->private_data = swr_malloc( sizeof( private_t ) ); swr_sdb_get_config_struct( context->id, (void**)&config ); swr_sdb_get_stats_struct( context->id, (void**)&stats ); // } End of system-definitions config->rx_attn = 0; config->tx_attn = 0; config->side = 0; config->freq = 2420; config->tx=0; // Begin system-definitions swr_sdb_free_stats_struct( context->id, (void**)&stats ); swr_sdb_free_config_struct( context->id, (void**)&config ); return 0; // End system-definitions}/* * Every time modules from the outside change the value of a configuration parameter, * this function is called. */int rf_reconfig( swr_sdb_t *context ) { // Definition of variables - don't touch config_t *config; int nbr_ant=0; int board_indx=0; PR_DBG(4,"RF_board goes reconfig\n"); swr_sdb_get_config_struct( context->id, (void**)&config ); if(config->freq != private->freq || config->side != private->side){ swr_ant_ch_set_synth( nbr_ant, board_indx, config->freq, config->side); private->freq=config->freq; private->side=config->side; } if(config->rx_attn != private->rx_attn || config->tx_attn != private->tx_attn){ swr_ant_set_attn( nbr_ant, config->rx_attn, config->tx_attn); private->rx_attn=config->rx_attn; private->tx_attn=config->tx_attn; } if(config->tx != private->tx ){ swr_ant_ch_tx_enable( nbr_ant, config->tx); private->tx=config->tx; } // Definition - don't touch swr_sdb_free_config_struct( context->id, (void**)&config ); return 0;}/** * * User messages * */int rf_custom_msg( swr_sdb_t *context, swr_usr_msg_t *data, swr_msgq ret ) { return 0;}/* * This is the `destructor'. */int rf_finalize( swr_sdb_t *context ) { if ( sizeof( private_t ) > 0 ) swr_free( private ); MOD_DEC_USE_COUNT; return 0;}/* * This function is called upon "insmod" and is used to register the * different parts of the module to the SPM. */swr_spc_id_t mod_id;int rf_module_init(void) { swr_spc_desc_t *desc; /** * Get a description-part from SPM * Give the following parameters: * Input-ports, output-ports, config-params, stat-params */ desc = swr_spc_get_new_desc( 0, 0, 5, 0 ); if ( !desc ) { PR_DBG( 0, "Can't initialise the module. This is BAD!\n" ); return -1; } /** * Define the different parts of config and stats. You have to define * them in the same order as they appear in the structures. The names * can be freely chosen. * * UM_CONFIG_{INT,DOUBLE,STRING128}( "name" ); * UM_STATS_{INT,DOUBLE,STRING128}( "name" ); */ UM_CONFIG_INT( "gain_rx" ); UM_CONFIG_INT( "gain_tx" ); UM_CONFIG_INT( "tx_enable" ); UM_CONFIG_DOUBLE( "freq"); UM_CONFIG_INT( "side" ); /** * The in- and outputs have also to be defined in the right order. First * port first. The additional flag is not used yet, but it will... * * UM_INPUT( SIG_{U8,SYMBOL_{S16,COMPLEX,MMX},SAMPLE_S12,S32}, 0 ); * UM_OUTPUT( SIG_{U8,SYMBOL_{S16,COMPLEX,MMX},SAMPLE_S12,S32}, 0 ); */ // Initialise the callback-functions. Delete the ones you don't use desc->fn_init = rf_init; desc->fn_reconfigure = rf_reconfig; desc->fn_custom_msg = rf_custom_msg; desc->fn_finalize = rf_finalize; // And register the module in the SPM. Change the name! mod_id = swr_cdb_register_spc( &desc, "rf_board" ); if ( mod_id == SWR_SPM_INVALID_ID ) { swr_spc_free_desc( desc ); PR_DBG( 0, "Couldn't register the module!\n" ); return 1; } PR_DBG( 4, "Ready\n" ); return 0;}/* * This is called upon rmmod */void rf_module_exit( void ) { PR_DBG( 4, "Freeing id: %i\n", mod_id ); if ( swr_cdb_unregister_spc( mod_id ) < 0 ) { PR_DBG( 0, "Still in use somewhere\n" ); }}module_init( rf_module_init );module_exit( rf_module_exit );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -