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

📄 dbg.c

📁 This a framework to test new ideas in transmission technology. Actual development is a LDPC-coder in
💻 C
📖 第 1 页 / 共 2 页
字号:
  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 != IMAGE ) {    PR_DBG( 4, "Asked for something not an image\n" );    put_fifo_msg( "Param is not an image\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_byte = val.width * val.depth * ( val.bpp + 7 ) / 8;  fifo_data = swr_malloc( size_byte );  memcpy( fifo_data, val.data, size_byte );  fifo_len = size_byte;}void cmd_new_list( char *p ) {  int track_id, t, s[2], len;  swr_sdb_id m[2];  const swr_spc_desc_t *spc[2];  swr_sdb_t *sdb[2];  parameter_type_t pt[2];  struct swr_stats_track_t *st;  // Search for an empty list-id  for ( track_id = 0; track_id < MAX_TRACKS; track_id++ ) {    if ( swr_stats_track[ track_id ][ 0 ].counter == -1 ) {      break;    }  }  if ( track_id == MAX_TRACKS ) {    put_fifo_msg( "error" );    return;  }  // Fetch both module-id's and do some checks  sscanf( p, "%i,%i,%i,%i", &m[0], &s[0], &m[1], &s[1] );    // Do it for both sub-traacks  for ( t=0; t<2; t++ ){    if ( t && m[t] == -1 ){      // It's a 1-dimensional list,  this happens      sdb[t] = NULL;      spc[t] = NULL;      pt[t] = -1;      s[t] = -1;      break;    }    sdb[t] = swr_sdb_get_struct( m[t] );    if ( !sdb[t] ) {      PR_DBG( 0, "Got wrong reference-#%i...\n", m[t] );      put_fifo_msg( "error" );      return;    }    spc[t] = sdb[t]->cdb_desc;    pt[t] = swr_spc_get_stats_type( spc[t], s[t] );    if ( ( pt[t] != INT ) && ( pt[t] != DOUBLE ) &&	 ( pt[t] != COMPLEX ) ) {      PR_DBG( 0, "Wrong or non-existing stats-param 1: module(%i:%i) type:%i\n",	      m[t], s[t], pt[t] );      put_fifo_msg( "error" );      return;    }  }  // OK, everything seems to be legal, so set up the structure  st = swr_stats_track[ track_id ];  for ( t=0; t<2; t++ ){    st[t].counter = 0;    if ( m[t] >= 0 ){      // In the case of a 1D-list      len = swr_spc_get_param_type_size( pt[t] ) * TRACK_LENGTH;      st[t].data = swr_malloc( len );      memset( st[t].data, 0, len );      len = TRACK_LENGTH * sizeof( long int );      st[t].time_d = swr_malloc( len );      memset( st[t].time_d, 0, len );      // Initialise the first element of time with -1 -> this will      // never be overwritten, but is handy if we look at the time      // of index 0, which should always be invalid, thus -1...      st[t].time_d[0] = -1;    }    st[t].m = m[t];    st[t].pi = s[t];    st[t].pt = pt[t];        if ( m[t] >= 0 ){      // And confirm creation of a track-entry to the modules      swr_sdb_send_msg( m[t], SUBS_MSG_NEW_TRACK, NULL, -1 );    }  }  fifo_data = swr_malloc( 6 );  fifo_len = sprintf( fifo_data, "%i", track_id );}void cmd_read_list( char *p ) {  int track_id, index, d, counter;  struct swr_stats_track_t *st;  char *buf;  SYMBOL_COMPLEX d_complex;  // Fetch the track-id  sscanf( p, "%i", &track_id );  st = swr_stats_track[ track_id ];  if ( st[0].counter == -1 ) {    put_fifo_msg( "error" );    return;  }  if ( st[1].m >= 0 ){    counter = min( st[0].counter, st[1].counter );    // we want to keep at least one value-pair for comparisons, so    // we take one less, if there is something...    counter = max( 0, counter - 1 );    PR_DBG( 2, "Counters: %i, %i -> min %i\n",	    st[0].counter, st[1].counter, counter );    st[0].counter -= counter;    st[1].counter -= counter;  } else {    counter = st[0].counter;    st[0].counter = 0;  }  // malloc enough, 16 bytes per stats  buf = fifo_data = swr_malloc( 6 + counter * 16 * 2 );  fifo_len = 0;  // Now let's make a list of all values collected so far  fifo_len = sprintf( buf, "%i\n", counter );  for ( index = 1; index <= counter; index++ ) {    PR_DBG( 3, "Sending index %i over FIFO\n", index );    // Only do the loop twice if we have a 2D-list, else only do it    // for st[0].    for ( d=0; d<2 && st[d].m >= 0; d++ ) {      switch( st[d].pt ) {      case INT:        fifo_len += sprintf( buf + fifo_len, "%i", 			     ((int*)st[d].data)[index] );        break;      case DOUBLE:        fifo_len += swr_ftoa( buf + fifo_len, 			      ((double*)st[d].data)[index], 5, 5 );        break;      case COMPLEX:	d_complex = ((SYMBOL_COMPLEX*)st[d].data)[index];        fifo_len += sprintf( buf + fifo_len, "%i/%i",                             d_complex.real, d_complex.imag );        break;      default:        PR_DBG( 0, "Hmm, I thought I said that this doesn't exist\n" );        swr_free( fifo_data );        put_fifo_msg( "error" );        return;        break;      }      if ( st[1].m < 0 ){	// We have a 1D-list, so we put the time in the second field	fifo_len += sprintf( buf + fifo_len, ",%li",			     st[0].time_d[index] );      }      st[d].time_d[index] = -1;      // If we have a 1D-list, we write directly a \n, else we do a      // "," and then \n      if ( !d && st[1].m >= 0 ) {        fifo_len += sprintf( buf + fifo_len, "," );      } else if ( index < counter ) {        fifo_len += sprintf( buf + fifo_len, "\n" );      }    }  }  if ( counter ){    // And copy the not-to-be-published-yet values to the beginning.    for ( index=1; index<3; index++ ){      for ( d=0; d<2; d++ ){	if ( ( index == 1 || st[d].counter ) && st[d].m >= 0 ){	  PR_DBG( 4, "Keeping new values for %i: st[%i] = st[%i]\n",		  d, index, index+counter );	  st[d].time_d[index] = st[d].time_d[index+counter];	  st[d].time_d[index+counter] = -1;	  switch( st[d].pt ) {	  case INT:	    ((int*)st[d].data)[index] = ((int*)st[d].data)[index+counter];	    break;	  case DOUBLE:	    ((double*)st[d].data)[index] = 	      ((double*)st[d].data)[index+counter];	    break;	  case COMPLEX:	    ((SYMBOL_COMPLEX*)st[d].data)[index] = 	      ((SYMBOL_COMPLEX*)st[d].data)[index+counter];	    break;	  default:	    PR_DBG( 0, "Hmm, I thought I said that this doesn't exist\n" );	    swr_free( fifo_data );	    put_fifo_msg( "error" );	    return;	    break;	  }	}      }    }  }  PR_DBG( 4, "Buffer:\n%s\n-------\n", buf );}void cmd_close_list( char *p ) {  int track_id, d, m_still_used[2], i, j;  struct swr_stats_track_t *st;  // Fetch the track-id  sscanf( p, "%i", &track_id );  st = swr_stats_track[ track_id ];  if ( st[0].counter == -1 ) {    put_fifo_msg( "error" );    return;  }  // Is there another track that uses this module?  m_still_used[0] = m_still_used[1];  for ( d=0; d<MAX_TRACKS; d++ ) {    for ( i=0; i < 2; i++ ) {      for ( j=0; j < 2; j++ ) {        if ( swr_stats_track[ d ][ i ].m == st[ j ].m ) {          m_still_used[j] = 1;        }      }    }  }  // Send a message to the sdbs that aren't tracked anymore  for ( i=0; i<2; i++ ) {    if ( !m_still_used[ i ] ) {      swr_sdb_send_msg( st[i].m, SUBS_MSG_NO_TRACK, NULL, -1 );    }    // And clean up some    swr_free( st[i].data );  }  // And clean up this track  st[0].counter = -1;  put_fifo_msg( "OK" );}void cmd_process_data( char *id ){  swr_sdb_t *sdb;  int ref, port;  // Try to get the reference and see whether it's valid  sscanf( id, "%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;  }  if ( sdb->cdb_desc->inputs.nbr_ports ){	    for ( port=0; port<sdb->cdb_desc->inputs.nbr_ports; port++ ){      if ( sdb->port_in[port].sdb_id >= 0 ){#if DBG_LVL >= 4        char name[ SWR_CDB_MAX_NAME_LENGTH ];        swr_cdb_get_name( ref, name );        PR_DBG( 4, "Setting input-port #%i of %i(%s) to valid\n",  	    port, ref, name );#endif        sdb->port_in[port].flags |= SWR_PORT_DATA;      }    }  }  PR_DBG( 4, "Sending process_data to module %i\n", ref );  swr_sdb_send_msg( ref, SUBS_MSG_DATA, NULL, -1 );  put_fifo_msg( "OK" );}void cmd_get_profiling( char *id ){  int ref, profile;  long long int time, calls;  // Try to get the reference and see whether it's valid  sscanf( id, "%i", &ref );  if ( !swr_sdb_get_struct( ref ) ) {    PR_DBG( 4, "Got wrong reference-#%i...\n", ref );    put_fifo_msg( "Wrong reference\n" );    return;  }  fifo_data = swr_malloc( profiling_last_item * ( 2 * 22 + 2 ) );  fifo_len = 0;  for ( profile = 0; profile < profiling_last_item; profile++ ){    if ( swr_sdb_get_profile( ref, profile, &time, &calls ) < 0 ){      swr_free( fifo_data );      put_fifo_msg( "Error" );      return;    }    fifo_len += sprintf( fifo_data + fifo_len, "%lli %lli\n",			 time, calls );  }  PR_DBG( 4, "Profiling-list: %s\n", (char*)fifo_data );}//----------------------------------------------------------------------// Exported functions//----------------------------------------------------------------------void parse_command( char *cmd ) {  PR_DBG( 3, "Parsing command: %s\n", cmd );  if ( fifo_data ) {    if ( fifo_data_nofree ){      fifo_data_nofree = 0;    } else {      swr_free( fifo_data );    }  }  if ( strstr( cmd, "list_modules" ) == cmd ) {    cmd_list_modules( 0, 1 );  } else if ( strstr( cmd, "list_tag_modules" ) == cmd ) {    cmd_list_modules( 1, 1 );  } else if ( strstr( cmd, "list_new_modules" ) == cmd ) {    cmd_list_modules( 1, 0 );  } else if ( strstr( cmd, "show_all" ) == cmd ) {    cmd_show( cmd + 9, 	      SHOW_INPUT + SHOW_OUTPUT + SHOW_CONFIG + SHOW_STATS );  } else if ( strstr( cmd, "show_input" ) == cmd ) {    cmd_show( cmd + 11, SHOW_INPUT );  } else if ( strstr( cmd, "show_output" ) == cmd ) {    cmd_show( cmd + 12, SHOW_OUTPUT );  } else if ( strstr( cmd, "show_config" ) == cmd ) {    cmd_show( cmd + 12, SHOW_CONFIG );  } else if ( strstr( cmd, "show_stats" ) == cmd ) {    cmd_show( cmd + 11, SHOW_STATS );  } else if ( strstr( cmd, "get_output" ) == cmd ) {    cmd_get_output( cmd + 11 );  } else if ( strstr( cmd, "set_config" ) == cmd ) {    cmd_set_config( cmd + 11 );  } else if ( strstr( cmd, "get_block" ) == cmd ) {    cmd_get_block( cmd + 10 );  } else if ( strstr( cmd, "get_image" ) == cmd ) {    cmd_get_image( cmd + 10 );  } else if ( strstr( cmd, "new_list" ) == cmd ) {    cmd_new_list( cmd + 9 );  } else if ( strstr( cmd, "read_list" ) == cmd ) {    cmd_read_list( cmd + 10 );  } else if ( strstr( cmd, "close_list" ) == cmd ) {    cmd_close_list( cmd + 11 );  } else if ( strstr( cmd, "process_data" ) == cmd ) {    cmd_process_data( cmd + 13 );  } else if ( strstr( cmd, "get_profiling" ) == cmd ) {    cmd_get_profiling( cmd + 14 );  } else if ( strstr( cmd, "ping" ) == cmd ) {    fifo_data = swr_malloc( 16 );    fifo_len = sprintf( fifo_data, "pong" );  } else {    fifo_data = swr_malloc( 128 );    strcpy( fifo_data, "Error - Cmd not recognized\n" );    fifo_len = strlen( fifo_data );  }}//----------------------------------------------------------------------// Module-specific functions//----------------------------------------------------------------------/** * This function is called when the module is loaded */int swr_dbg_init(void) {  int i;  for ( i=0; i < MAX_TRACKS; i++ ) {    swr_stats_track[ i ][ 0 ].counter = -1;  }  if ( setup_fifos() ) {    PR_DBG( 0, "Couldn't initialize rt-fifos\n" );    return -1;  }  return 0;}/** * This function is called when the module is unloaded. */void swr_dbg_cleanup(void) {  destroy_fifos();  PR_DBG( 2, "Dbg cleaned up\n" );}/** * Kernel macros which define the initialization and finalization * function. */module_init(swr_dbg_init);module_exit(swr_dbg_cleanup);/** * The following symbols are exported: */

⌨️ 快捷键说明

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