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

📄 dbg.c

📁 This a framework to test new ideas in transmission technology. Actual development is a LDPC-coder in
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************             dbg.c  -  RTLinux kernel module for debugging                            -------------------    begin                :  2002    authors              :  Linus Gasser    emails               :  linus.gasser@epfl.ch ***************************************************************************//***************************************************************************                                 Changes                                 ------- date - name - description 02-10-07 - ineiti - begin 03-08-07 - ineiti - tear out proc/ and replace with rtfifo 04/03/01 - ineiti - cmd_get_output checks for empty port 04/03/03 - ineiti - added DOUBLE_COMPLEX for set_value  04/05/13 - ineiti - added get_profiling 04/05/13 - ineiti - added list_new_modules                     change list to list_modules  **************************************************************************//*************************************************************************** *                                                                         * *   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 module allows for interaction with the available and instantiated * modules in the system, as well as the connection. It works through * entries in the /proc filesystem where you can retreive and set the * different configuration and statistical options. */#define DBG_LVL 0#include "system.h"#include "debugging.h"#include "sdb.h"#include "memory.h"#include "parameters.h"#include "cdb.h"#include "dbg.h"#include "dbg_common.h"#include "std.h"//----------------------------------------------------------------------// globals//----------------------------------------------------------------------// In some cases fifo_data doesn't need to be freed!int fifo_data_nofree = 0;//----------------------------------------------------------------------// Local functions//----------------------------------------------------------------------void put_fifo_msg( char *msg ) {  fifo_len = strlen( msg ) + 1;  fifo_data = swr_malloc( fifo_len );  strcpy( fifo_data, msg );}void cmd_list_modules( int tag, int show_old ) {  swr_sdb_t *sdb;  swr_sdb_id *list_id;  char cdb_name[ SWR_CDB_MAX_NAME_LENGTH ];  int sdb_count, i;  sdb_count = swr_sdb_list( NULL, 0 );  if ( !sdb_count ) {    // Oops, no entries yet...    put_fifo_msg( "Empty\n" );    return;  }  list_id = swr_malloc( sizeof( swr_sdb_id ) * sdb_count );  swr_sdb_list( list_id, sdb_count );  // Get enough room for 5-digit id with 1 comma and 1 LF per entry  fifo_data = swr_malloc( sdb_count * ( SWR_CDB_MAX_NAME_LENGTH + 7 ) );  *(char*)fifo_data = 0;  for ( i=0; i<sdb_count; i++ ) {    sdb = swr_sdb_get_struct( list_id[i] );    if ( !( sdb->status & SUBS_STATUS_LISTED ) || show_old ){      swr_cdb_get_name( swr_sdb_spm( list_id[i] ), cdb_name );      if ( tag ){	sdb->status |= SUBS_STATUS_LISTED;      }      fifo_len = sprintf( fifo_data, "%s%i,%s\n",			  (char*)fifo_data, list_id[i], cdb_name );    }  }  swr_free( list_id );}// Writes the value of param "index" from description (params,strct) at the end// of string fifo_dataint wr_param( void *strct, swr_parameters_desc_t params, int index ) {  swr_parameter_desc_t *p;  int val_int, len;  double val_double;  double_complex val_double_complex;  SYMBOL_COMPLEX val_co;  char val_str128[128];  block_t val_block;  image_t val_image;  len = strlen( fifo_data );  p = &params.descs[index];  switch( p->type ) {  case INT:    swr_spc_get_parameter_value( params, strct, index, &val_int );    len += sprintf( fifo_data + len, "%i\n", val_int );    break;  case DOUBLE:    swr_spc_get_parameter_value( params, strct, index, &val_double );    len += swr_ftoa( fifo_data + len, val_double, 1, 5 );    len += sprintf( fifo_data + len, "\n" );    break;  case DOUBLE_COMPLEX:    swr_spc_get_parameter_value( params, strct, index, &val_double_complex );    len += swr_ftoa( fifo_data + len, val_double_complex.real, 1, 5 );    len += sprintf( fifo_data + len, "/" );    len += swr_ftoa( fifo_data + len, val_double_complex.imag, 1, 5 );    len += sprintf( fifo_data + len, "\n" );    break;  case STRING128:    swr_spc_get_parameter_value( params, strct, index, &val_str128 );    len += sprintf( fifo_data + len, "%s\n", val_str128 );    break;  case BLOCK:    swr_spc_get_parameter_value( params, strct, index, &val_block );    len += sprintf( fifo_data + len, "%i, %i\n",                    val_block.type, val_block.size );    break;  case IMAGE:    swr_spc_get_parameter_value( params, strct, index, &val_image );    len += sprintf( fifo_data + len, "%i, %i, %i\n",                    val_image.width, val_image.depth, val_image.bpp );    break;  case COMPLEX:    swr_spc_get_parameter_value( params, strct, index, &val_co );    len += sprintf( fifo_data + len, "%i/%i\n",                    val_co.real, val_co.imag );    break;  default:    len += sprintf( fifo_data + len, "N/A\n" );    break;  }  return len;}#define SHOW_INPUT 1#define SHOW_OUTPUT 2#define SHOW_CONFIG 4#define SHOW_STATS 8void cmd_show( char *p, int show ) {  int nbr_input, nbr_output, nbr_config, nbr_stats;  const swr_spc_desc_t *spc;  swr_sdb_t *sdb;  swr_sdb_id snd, rcv, ref;  swr_signal_type_t sig_type;  parameter_type_t param_type;  int i, in, out, sig_size;  char *buf, param_name[ SWR_CDB_MAX_NAME_LENGTH ];  void *strct;  unsigned long param_flags;  // Try to get the reference and see whether it's valid  sscanf( p, "%i", &ref );  sdb = swr_sdb_get_struct( ref );  if ( !sdb ) {    PR_DBG( 4, "Got wrong reference-#%i...\n", ref );    put_fifo_msg( "Wrong reference\n" );    return;  }  spc = sdb->cdb_desc;  // Get the different sizes of the different parts  nbr_input = SHOW_INPUT & show ? swr_spc_get_input_count( spc ) : 0;  nbr_output = SHOW_OUTPUT & show ? swr_spc_get_output_count( spc ) : 0;  nbr_config = SHOW_CONFIG & show ? swr_spc_get_config_size( spc ) : 0;  nbr_stats = SHOW_STATS & show ? swr_spc_get_stats_size( spc ) : 0;  // Add up all sizes....  fifo_data = swr_malloc( 6 +                          ( ( nbr_input + nbr_output ) *                            ( 6 + 6 + 6 + 3 + 8 + 1 ) ) +                          ( ( nbr_config + nbr_stats ) *                            ( 6 + SWR_CDB_MAX_NAME_LENGTH + 3 + 128 ) ) );  buf = fifo_data;  *buf = 0;  // Let's fill in things...  if ( SHOW_INPUT & show ) {    // Start with input-ports    sprintf( buf, "%s%i\n", buf, nbr_input );    for ( i=0; i<nbr_input; i++ ) {      swr_conn_detail_sender( ref, i, &snd, &out );      sig_type = swr_spc_get_input_signal_type( spc, i );      sig_size = swr_sdb_get_input_port_size( ref, i );      fifo_len = sprintf( buf, "%s%i,%i,%i,%i\n",                          buf, snd, out, sig_type, sig_size );    }  }  if ( SHOW_OUTPUT & show ) {    // Then output-ports    sprintf( buf, "%s%i\n", buf, nbr_output );    for ( i=0; i<nbr_output; i++ ) {      swr_conn_detail_receiver( ref, i, &rcv, &in );      sig_type = swr_spc_get_output_signal_type( spc, i );      sig_size = swr_sdb_get_output_port_size( ref, i );      fifo_len = sprintf( buf, "%s%i,%i,%i,%i\n",                          buf, rcv, in, sig_type, sig_size );    }  }  if ( SHOW_CONFIG & show ) {    // Config-entries    sprintf( buf, "%s%i\n", buf, nbr_config );    for ( i=0; i<nbr_config; i++ ) {      swr_spc_get_config_parameter_name( spc, param_name, i );      param_type = swr_spc_get_config_type( spc, i );      param_flags = swr_spc_get_config_flags( spc, i );      fifo_len = sprintf( buf, "%s%s,%i,%lu,",                          buf, param_name, param_type, param_flags );      swr_sdb_get_config_struct( sdb->id, &strct );      fifo_len = wr_param( strct, spc->config, i );      swr_sdb_free_config_struct( sdb->id, &strct );    }  }  if ( SHOW_STATS & show ) {    // Stats-entries    fifo_len = sprintf( buf, "%s%i\n", buf, nbr_stats );    for ( i=0; i<nbr_stats; i++ ) {      swr_spc_get_stats_parameter_name( spc, param_name, i );      param_type = swr_spc_get_stats_type( spc, i );      param_flags = swr_spc_get_stats_flags( spc, i );      fifo_len = sprintf( buf, "%s%s,%i,%lu,",                          buf, param_name, param_type, param_flags );      swr_sdb_get_stats_struct( sdb->id, &strct );      fifo_len = wr_param( strct, spc->stats, i );      swr_sdb_free_stats_struct( sdb->id, &strct );    }  }}void cmd_get_output( char *p ) {  int port, size_t, size_byte, type;  swr_sdb_id ref;  const swr_spc_desc_t *spc;  swr_sdb_t *sdb;  // Try to get the reference and see whether it's valid  sscanf( p, "%i,%i", &ref, &port );  sdb = swr_sdb_get_struct( ref );  if ( !sdb ) {    PR_DBG( 4, "Got wrong reference-#%i...\n", ref );    put_fifo_msg( "Wrong reference\n" );    return;  }  spc = sdb->cdb_desc;  if ( port >= swr_spc_get_output_count( spc ) ) {    PR_DBG( 4, "Port-# is too big.\n" );    put_fifo_msg( "No such port\n" );    return;  }  type = swr_spc_get_output_signal_type( spc, port );  size_t = swr_sdb_get_output_port_size( ref, port );  size_byte = size_t * swr_spc_get_type_size( type );  if ( !size_byte ){    PR_DBG( 4, "This port is empty\n" );    put_fifo_msg( "Port Empty\n" );    return;  }  fifo_data = swr_malloc( size_byte );  swr_sdb_get_output_port_data( ref, port, fifo_data );  fifo_len = size_byte;}void cmd_set_config( char *p ) {  int param, read_b, size, i;  parameter_type_t param_type;  swr_sdb_id ref;  const swr_spc_desc_t *spc;  swr_sdb_t *sdb;  char *buf;  double f;  void *d;  SYMBOL_COMPLEX co;  complex double cod;  char cod_real[16], cod_imag[16];  void *strct;  // Try to get the reference and see whether it's valid  sscanf( p, "%i,%i,%n", &ref, &param, &read_b );  sdb = swr_sdb_get_struct( ref );  if ( !sdb ) {    PR_DBG( 4, "Got wrong reference-#%i...\n", ref );    put_fifo_msg( "Wrong reference\n" );    return;  }  spc = sdb->cdb_desc;  if ( param >= swr_spc_get_config_size( spc ) ) {    PR_DBG( 4, "No such parameter\n" );    put_fifo_msg( "Parameter out of range\n" );    return;  }  param_type = swr_spc_get_config_type( spc, param );  buf = p + read_b;  switch( param_type ) {  case INT:    i = atoi( buf );    d = &i;    size = sizeof( int );    break;  case DOUBLE:    f = swr_atof( buf );    d = &f;    size = sizeof( double );    break;  case STRING128:    d = buf;    size = 128;    break;  case COMPLEX:    sscanf( buf, "%hi/%hi", &co.real, &co.imag );    d = &co;    size = sizeof( co );    break;  case DOUBLE_COMPLEX:    sscanf( buf, "%16s/%16s", cod_real, cod_imag );    cod = swr_atof( cod_real ) + I * swr_atof( cod_imag );    d = &cod;    size = sizeof( cod );    break;  default:    put_fifo_msg( "Type not known\n" );    return;  }  swr_sdb_get_config_struct( sdb->id, &strct );  memcpy( swr_spc_get_config_parameter_pointer( spc, strct, param ),          d, size );  sdb->status |= SUBS_STATUS_RECONF;  swr_sdb_free_config_struct( sdb->id, &strct );  swr_sdb_send_msg( ref, SUBS_MSG_RECONFIG, NULL, -1 );  put_fifo_msg( "Reconfigured" );}void cmd_get_block( char *p ) {  int param, type;  uint size_t, size_byte;  swr_sdb_id ref;  const swr_spc_desc_t *spc;  swr_sdb_t *sdb;  block_t val;  void *strct;  // Try to get the reference and see whether it's valid  sscanf( p, "%i,%i", &ref, &param );  sdb = swr_sdb_get_struct( ref );  if ( !sdb ) {    PR_DBG( 4, "Got wrong reference-#%i...\n", ref );    put_fifo_msg( "Wrong reference\n" );    return;  }  spc = sdb->cdb_desc;  if ( param >= swr_spc_get_stats_size( spc ) ) {    PR_DBG( 4, "Stats-# is too big.\n" );    put_fifo_msg( "No such stats\n" );    return;  }  type = swr_spc_get_stats_type( spc, param );  if ( type != BLOCK ) {    PR_DBG( 4, "Asked for something not a block\n" );    put_fifo_msg( "Param is not a block\n" );    return;  }  swr_sdb_get_stats_struct( sdb->id, &strct );  swr_spc_get_parameter_value( spc->stats, strct, param, &val );  swr_sdb_free_stats_struct( sdb->id, &strct );  size_t = val.size;  size_byte = size_t * swr_spc_get_type_size( val.type );  fifo_data = swr_malloc_noerr( size_byte );  if ( !fifo_data ){    PR_DBG( 0, "Couldn't allocate %i! Passing pointer directly\n",	    size_byte );    fifo_data = val.data;    // What an ugly hack, but sometimes the data doesn't need to be    // freed...    fifo_data_nofree = 1;  } else {    memcpy( fifo_data, val.data, size_byte );  }  fifo_len = size_byte;}void cmd_get_image( char *p ) {  int param, size_byte, type;  swr_sdb_id ref;  const swr_spc_desc_t *spc;  swr_sdb_t *sdb;  image_t val;  void *strct;  // Try to get the reference and see whether it's valid  sscanf( p, "%i,%i", &ref, &param );

⌨️ 快捷键说明

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