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

📄 gps.c

📁 This a framework to test new ideas in transmission technology. Actual development is a LDPC-coder in
💻 C
字号:
/*************************************************************************** *    storage.c  -  Framework for storage of received symbols *                           ------------------- *   begin                :  2004 *   authors              :  ineiti *   emails               :  linus.gasser@epfl.ch ***************************************************************************//*************************************************************************** *                                Changes *                                ------- * date - name - description * 2004 - ineiti - start * **************************************************************************//*************************************************************************** *                                                                         * *   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.                                   * *                                                                         * ***************************************************************************//** * It just retrieves one big hunck of memory */#include "spc.h"#include "antenna.h"#define DBG_LVL 2// If set to one, storage will use directly bigphys-allocations// Memory_sys: 0 - swr_malloc, 1 - bigphys, 2 - none (physmem)#define MEMORY_SYS 1// ADD_HERE, int, double, char[128], void*// BEFORE each declaration, write a short description.// ON THE SAME LINE as the declaration, write the default value// Example:// {//   // size of the input in bytes//   int size; // 2560// }typedef struct {  // How many blocks in one slot  int size_slot; // 128  // How many slots in one frame  int slots_frame; // 8  // Enable continous sampling  int continous; // 0  // The length of the buffer, in frames  int buffer_len; // 16  // The channel to receive from, odd or even  int channel; // 0}config_t;// ADD_HERE, int, double, char[128], void*// for the rest, the same definition as the confit_t is valid.typedef struct {  // The storage block  block_t storage;  // The sampling block  block_t sampling;  // The length in symbols  int samples;  // How many frames read  int frames_read;  // Whether it's done  int done;}stats_t;// ADD HERE anything you want!typedef struct {  int running;  int size_slot;  int slots_frame;  int channel;  int samples_slot;  int samples_frame;  int size_frame;  int ant_index;  int slots_rcvd;  QUAD_SYMBOL_ICS_AD *buffer_ics;  SYMBOL_COMPLEX *buffer;  int continous;  int buffer_len;  int buffer_pos;}private_t;/* * The initialisation function, or constructor,  * is called the first time this module is instantiated. */int spc_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->size_slot = 128;  config->slots_frame = 8;  config->continous = 0;  config->channel = 0;  config->buffer_len = 16;  private->slots_rcvd = 0;  private->buffer = 0;  private->buffer_ics = 0;  private->buffer_pos = 0;  private->buffer_len = 0;  private->running = 0;  stats->storage.type = SIG_SYMBOL_COMPLEX;  stats->sampling.type = SIG_QUAD_SYMBOL_ICS_AD;  stats->frames_read = 0;  stats->done = 0;  // Initialise one channel  private->ant_index = swr_ant_init( context->id );  swr_ant_set_flags( private->ant_index, ANTENNA_ONLY_RX  		     | ANTENNA_IS_COMPLEX );  // Reception#ifdef KERNEL_SPACE  swr_ant_ch_tx_enable( private->ant_index, 0 );#endif  // 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}/* * To configure the inputs * this is called when the output-sizes change. */int spc_configure_inputs( swr_sdb_t *context ) {  // Definition of variables - don't touch  config_t *config;  swr_sdb_get_config_struct( context->id, (void**)&config );  // Put you code here  // ADD HERE  // Definition - don't touch  swr_sdb_free_config_struct( context->id, (void**)&config );  return 0;}/* * To configure the outputs * this is called when the input-sizes change */int spc_configure_outputs( swr_sdb_t *context ) {  // Definition of variables - don't touch  config_t *config;  swr_sdb_get_config_struct( context->id, (void**)&config );  // Put you code here  // ADD HERE  // Definition - don't touch  swr_sdb_free_config_struct( context->id, (void**)&config );  return 0;}void gps_free( void ** b ){  if ( *b ){#if MEMORY_SYS == 2    PR_DBG( 4, "Good luck...\n" );#elif MEMORY_SYS == 1    PR_DBG( 2, "Freeing bigphys-pages at %p\n", *b );    bigphysarea_free_pages( *b );#else    swr_free( *b );#endif    *b = 0;  }}void gps_alloc( void **b, uint size ){#if MEMORY_SYS == 2  PR_DBG( 4, "Writing physical address\n" );  *b = (void*)0x4000000U;#elif MEMORY_SYS == 1  {    int pages = ( size + PAGE_SIZE - 1 ) / PAGE_SIZE;    PR_DBG( 3, "Allocating %i pages with Big-phys\n", pages );    *b = ( QUAD_SYMBOL_ICS_AD*)       bigphysarea_alloc_pages( pages, 1, GFP_KERNEL );  }#else  *b = ( QUAD_SYMBOL_ICS_AD*)swr_malloc ( size );#endif}/* * Every time modules from the outside change the value of a configuration parameter, * this function is called. */int spc_reconfig( swr_sdb_t *context ) {  // Definition of variables - don't touch  config_t *config;  stats_t *stats;    swr_sdb_get_config_struct( context->id, (void**)&config );  swr_sdb_get_stats_struct( context->id, (void**)&stats );  private->continous = config->continous;  private->channel = config->channel;  if ( private->size_slot != config->size_slot ||       private->slots_frame != config->slots_frame ||       private->buffer_len != config->buffer_len ){        if ( private->running ){      PR_DBG( 0, "I won't reconfigure the frame-sizes while running!\n" );    } else {      // Free the old memory      gps_free( (void**)&private->buffer );      gps_free( (void**)&private->buffer_ics );      // Calculate new sizes      private->size_slot = config->size_slot;      private->slots_frame = config->slots_frame;      private->size_frame = config->slots_frame * config->size_slot;      PR_DBG( 1, "Re-configuring ics: %i * %i = %i Slots\n",	      config->slots_frame, config->size_slot,	      private->size_frame );      private->samples_slot = private->size_slot * DAQ_DMA_BLOCK_SIZE_QI_SAMPLES;      private->samples_frame = private->samples_slot * private->slots_frame;      // There are 4 samples in one QUAD_SYMBOL_ICS_AD      gps_alloc( (void**)&private->buffer_ics, 		 sizeof( QUAD_SYMBOL_ICS_AD ) / 4 * private->samples_frame );      // How many frames in the buffer      private->buffer_len = config->buffer_len;      PR_DBG( 1, "Re-configuring storage: %i * %i = %i MSamples\n",	      config->buffer_len, config->slots_frame,	      config->buffer_len * private->samples_frame / ( 1 << 20 ) );      gps_alloc( (void**)&private->buffer,		 sizeof( SYMBOL_COMPLEX ) * private->buffer_len * private->samples_frame );                  PR_DBG( 3, "Address of requested buffer_ics: %p\n", private->buffer_ics );      PR_DBG( 3, "Address of requested buffer: %p\n", private->buffer );      stats->storage.size = private->samples_frame * private->buffer_len;      stats->storage.data = private->buffer;      stats->sampling.size = private->samples_frame / 4;      stats->sampling.data = private->buffer_ics;      stats->samples = private->samples_frame * private->buffer_len;      // set up the antenna      swr_ant_set_slot_len( private->ant_index, private->size_slot );      swr_ant_set_frame_params( private->ant_index, private->buffer_ics, 0 );    }  }    // Definition - don't touch  swr_sdb_free_config_struct( context->id, (void**)&config );  swr_sdb_free_stats_struct( context->id, (void**)&stats );  return 0;}/* * This is the function that implements the `main method' of the class * Every class has got just ONE method/working-mode. */int spc_pdata( swr_sdb_t *context ) {  // Definition of variables - don't touch  stats_t *stats;  swr_sdb_get_stats_struct( context->id, (void**)&stats );  if ( !private->running ){    if ( private->buffer && private->buffer_ics ){      private->running = 1;      private->slots_rcvd = 0;      stats->frames_read = 0;      stats->done = 0;      // Let's start it      swr_ant_start( private->size_frame );    } else {      PR_DBG( 0, "The memories are not correctly allocated:\n"		      "ics: %p    storage: %p\n"		      " I won't start like this\n",		      private->buffer_ics, private->buffer );    }  } else {    PR_DBG( 0, "Is already running\n" );  }  swr_sdb_free_stats_struct( context->id, (void**)&stats );  return(0);}/** * User messages */int spc_custom_msg( swr_sdb_t *context, swr_usr_msg_t *data, swr_msgq ret ) {  QUAD_SYMBOL_ICS_AD *in;  SYMBOL_COMPLEX *out;  int i;  stats_t *stats;  swr_sdb_get_stats_struct( context->id, (void**)&stats );  if ( !data ){    PR_DBG( 0, "Empty message???\n" );    return -1;  }  if ( !strcmp( data->id, "ANT" ) ){    // Do the calculations    // The input-vector points to 4 samples at a time, so we have to divide by 4    in = private->buffer_ics + private->slots_rcvd * private->samples_slot / 4;    // Get the pointer of where to store things    out = private->buffer + private->buffer_pos * private->samples_slot;    PR_DBG( 4, "Going to convert channel %i for %i samples\n", 	    private->channel, private->samples_slot );    PR_DBG( 4, "ICS-counter: %5i     Convert-counter: %5i\n",	    private->slots_rcvd, private->buffer_pos );    for ( i=0; i<private->samples_slot; i++ ){      out[i].real = in[i/4].ch[private->channel][i%4].real >> 8;      out[i].imag = in[i/4].ch[private->channel][i%4].imag >> 8;    }    private->slots_rcvd++;    private->buffer_pos++;    // Show some debugging messages    if ( !( private->buffer_pos % 100 ) ){      PR_DBG( 2, "Received frames %i\n", private->buffer_pos );    }    if ( private->slots_rcvd >= private->slots_frame ){      int i;      PR_DBG( 3, "Ended transfer of one frame\n" );      for ( i=0; i<8; i++ ){	PR_DBG( 4, "Block[%2i] = (%i,%i)\n", i,		private->buffer_ics[i/4].ch[0][i%4].real, 		private->buffer_ics[i/4].ch[0][i%4].imag );      }      private->slots_rcvd -= private->slots_frame;    }    // If we're finished, we stop if private->continous is 0    if ( private->buffer_pos >= private->buffer_len * private->slots_frame ){      if ( !private->continous ){	swr_ant_stop();	private->running = 0;	PR_DBG( 0, "*** Acquisition done ***\n" );	stats->done = 1;      } else {	private->buffer_pos = 0;	PR_DBG( 3, "Rolled around\n" );      }    }    swr_free( data->data );  }    stats->frames_read = private->buffer_pos;  swr_sdb_free_stats_struct( context->id, (void**)&stats );  return 0;}/* * This is the `destructor'. */int spc_finalize( swr_sdb_t *context ) {  if ( private->running ){    swr_ant_stop();  }  gps_free( (void**)&private->buffer_ics );  gps_free( (void**)&private->buffer );  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 cdb_id;int spc_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, 5 );  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,DOUBLE_COMPLEX,STRING128,POINTER}( "name" );   * UM_STATS_{INT,DOUBLE,DOUBLE_COMPLEX,STRING128,POINTER,BLOCK,IMAGE}( "name" );   */  UM_CONFIG_INT( "size_slot" );  UM_CONFIG_INT( "slots_frame" );  UM_CONFIG_INT( "continous" );  UM_CONFIG_INT( "buffer_len" );  UM_CONFIG_INT( "channel" );  UM_STATS_BLOCK( "storage" );  UM_STATS_BLOCK( "sampling" );  UM_STATS_INT( "samples" );  UM_STATS_INT( "frames_read" );  UM_STATS_INT( "done" );  /**   * 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,DOUBLE_{,COMPLEX}}, 0 );   * UM_OUTPUT( SIG_{U8,SYMBOL_{S16,COMPLEX,MMX},SAMPLE_S12,S32,DOUBLE_{,COMPLEX}}, 0 );   */  // Initialise the callback-functions. Delete the ones you don't use  desc->fn_init              = spc_init;  desc->fn_reconfigure       = spc_reconfig;  desc->fn_process_data      = spc_pdata;  desc->fn_configure_inputs  = spc_configure_inputs;  desc->fn_configure_outputs = spc_configure_outputs;  desc->fn_custom_msg        = spc_custom_msg;  desc->fn_finalize          = spc_finalize;  // And register the module in the SPM. Change the name!  cdb_id = swr_cdb_register_spc( &desc, "gps" );  if ( cdb_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 spc_module_exit( void ) {  PR_DBG( 4, "Freeing id: %i\n", cdb_id );  if ( swr_cdb_unregister_spc( cdb_id ) < 0 ) {    PR_DBG( 0, "Still in use somewhere\n" );  }}module_init( spc_module_init );module_exit( spc_module_exit );

⌨️ 快捷键说明

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