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

📄 cdb.c

📁 This a framework to test new ideas in transmission technology. Actual development is a LDPC-coder in
💻 C
📖 第 1 页 / 共 2 页
字号:
  }  return 0;}/** * Define a configuration parameter. */int swr_spc_define_config_parameter(swr_spc_desc_t *desc,                                    parameter_type_t type,				    unsigned long flags,                                    const char *name) {  if (!desc) {    PR_DBG(0, "desc == NULL");    return -1;  }  return add_parameter(&desc->config, type, flags, name);}/** * Define a statistics parameter. */int swr_spc_define_stats_parameter(swr_spc_desc_t *desc,                                   parameter_type_t type,				   unsigned long flags,                                   const char *name) {  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return -1;  }  return add_parameter(&desc->stats, type, flags, name);}/** * Define an input. */int swr_spc_define_input(swr_spc_desc_t *desc,                         swr_signal_type_t signal_type,                         unsigned long flags) {  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return -1;  }  return add_port(&desc->inputs, signal_type, flags);}/** * Define an output. */int swr_spc_define_output(swr_spc_desc_t *desc,                          swr_signal_type_t signal_type,                          unsigned long flags) {  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return -1;  }  return add_port(&desc->outputs, signal_type, flags);}//-------------------------------------------------------------------// USE OF SPMs//-------------------------------------------------------------------/** * Get a reference to a SPM */int swr_cdb_get_reference(const swr_spc_desc_t **ref, swr_spc_id_t id) {  int error = 0;  pthread_mutex_lock(&database->mutex);  error = cdb_get_reference(ref, id);  pthread_mutex_unlock(&database->mutex);  if (error)    PR_DBG(0, "Error occured\n");  return error;}/** * Free a reference to a SPM */int swr_cdb_free_reference(const swr_spc_desc_t **ref) {  int error = 0;  pthread_mutex_lock(&database->mutex);  cdb_free_reference(ref);  pthread_mutex_unlock(&database->mutex);  if (error)    PR_DBG(0, "Error occured\n");  return error;}/** * Get the name of an SPM module. */int swr_cdb_get_name(swr_spc_id_t id, char *buffer) {  int error = 0;  pthread_mutex_lock(&database->mutex);  error = cdb_get_name(id, buffer);  pthread_mutex_unlock(&database->mutex);  if (error)    PR_DBG(0, "Error occured\n");  return 0;}/** * Get the ID of a SPM. */swr_spc_id_t swr_cdb_get_id(const char *name) {  swr_spc_id_t id;  pthread_mutex_lock(&database->mutex);  id = get_id(name);  pthread_mutex_unlock(&database->mutex);  if (!validate_id(id))    PR_DBG(0, "Couldn't find SPM with name %s\n", name);  return id;}/** * Get the IDs of all stored in the database */int swr_cdb_get_all_ids(swr_spc_id_t *buffer, int nbr) {  int error;  pthread_mutex_lock(&database->mutex);  error = get_all_ids(buffer, nbr);  pthread_mutex_unlock(&database->mutex);  if (error)    PR_DBG(0, "Error occured\n");  return error;}//-------------------------------------------------------------------// HANDLING CONFIGURATION & STATISTICS//-------------------------------------------------------------------/** * Get the number of parameters in a config/stats block */inline int swr_spc_get_config_size(const swr_spc_desc_t *desc) {  return desc->config.nbr_params;}inline int swr_spc_get_stats_size(const swr_spc_desc_t *desc) {  return desc->stats.nbr_params;}/** * Get the size that a memory block must have in order to store all * parameters of the configuration/statistics parameter * description. This is the size which has to be passed to a memory * allocation function. */inline int swr_spc_get_config_memory_size(const swr_spc_desc_t *desc) {  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return -1;  }  return get_memory_size(desc->config);}inline int swr_spc_get_stats_memory_size(const swr_spc_desc_t *desc) {  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return -1;  }  return get_memory_size(desc->stats);}/** * Get the number of a config/stats parameter, given its name. */int swr_spc_get_config_parameter_nbr(const swr_spc_desc_t *desc, const char *name) {#ifndef FAST  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return -1;  }#endif  return get_parameter_nbr(desc->config, name);}int swr_spc_get_stats_parameter_nbr (const swr_spc_desc_t *desc, const char *name) {#ifndef FAST  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return -1;  }#endif  return get_parameter_nbr(desc->stats, name);}/** * Get a type of a config/stats parameter, given its index */parameter_type_t swr_spc_get_config_type(const swr_spc_desc_t *desc, int param) {#ifndef FAST  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return UNDEFINED;  }#endif  return get_parameter_type( desc->config, param );}parameter_type_t swr_spc_get_stats_type (const swr_spc_desc_t *desc, int param) {#ifndef FAST  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return UNDEFINED;  }#endif  return get_parameter_type( desc->stats, param );}/** * Get the flags of a config/stats parameter, given its index */unsigned long swr_spc_get_config_flags(const swr_spc_desc_t *desc, int param) {#ifndef FAST  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return UNDEFINED;  }#endif  return get_parameter_flags( desc->config, param );}unsigned long swr_spc_get_stats_flags (const swr_spc_desc_t *desc, int param) {#ifndef FAST  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return UNDEFINED;  }#endif  return get_parameter_flags( desc->stats, param );}/** * Get a single config/stats parameter-name */int swr_spc_get_config_parameter_name(const swr_spc_desc_t *desc,                                      char *str, int index) {#ifndef FAST  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return -1;  }#endif  if ( index < desc->config.nbr_params ) {    strcpy( str, desc->config.descs[index].name );  } else {    return -1;  }  return 0;}int swr_spc_get_stats_parameter_name(const swr_spc_desc_t *desc,                                     char *str, int index) {#ifndef FAST  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return -1;  }#endif  if ( index < desc->stats.nbr_params ) {    strcpy( str, desc->stats.descs[index].name );  } else {    return -1;  }  return 0;}/** * Get a list of all config/stats parameters */int swr_spc_get_config_parameter_names(const swr_spc_desc_t *desc, char *str, int len) {#ifndef FAST  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return -1;  }#endif  return get_parameter_names(desc->config, str, len);}int swr_spc_get_stats_parameter_names (const swr_spc_desc_t *desc, char *str, int len) {#ifndef FAST  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return -1;  }#endif  return get_parameter_names(desc->stats, str, len);}/** * Set a parameter value on the config/stats parameter segment. */inline void *swr_spc_set_config_parameter_value(const swr_spc_desc_t *desc,    void *segment,    int parameter,    const void *value) {#ifndef FAST  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return NULL;  }#endif  return set_parameter_value(desc->config, segment, parameter, value);}inline void *swr_spc_set_stats_parameter_value (const swr_spc_desc_t *desc,    void *segment,    int parameter,    const void *value) {#ifndef FAST  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return NULL;  }#endif  return set_parameter_value(desc->stats, segment, parameter, value);}/** * Get a parameter from a config/stats parameter memory segment. */inline void *swr_spc_get_config_parameter_value(const swr_spc_desc_t *desc,    const void *segment,    int parameter,    void *value) {#ifndef FAST  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return NULL;  }#endif  return get_parameter_value(desc->config, segment, parameter, value);}inline void *swr_spc_get_stats_parameter_value (const swr_spc_desc_t *desc,    const void *segment,    int parameter,    void *value) {#ifndef FAST  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return NULL;  }#endif  return get_parameter_value(desc->stats, segment, parameter, value);}/** * Get a pointer to a config/stats parameter in the specified segment. */inline void *swr_spc_get_config_parameter_pointer(const swr_spc_desc_t *desc,    void *segment,    int parameter) {#ifndef FAST  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return NULL;  }#endif  return get_parameter_pointer(desc->config, segment, parameter);}inline void *swr_spc_get_stats_parameter_pointer (const swr_spc_desc_t *desc,    void *segment,    int parameter) {#ifndef FAST  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return NULL;  }#endif  return get_parameter_pointer(desc->stats, segment, parameter);}/** * Get the offset of a config/stats parameter */inline int swr_spc_get_config_parameter_offset(const swr_spc_desc_t *desc,    int parameter) {#ifndef FAST  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return -1;  }#endif  return get_parameter_offset(desc->config, parameter);}inline int swr_spc_get_stats_parameter_offset (const swr_spc_desc_t *desc,    int parameter) {#ifndef FAST  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return -1;  }#endif  return get_parameter_offset(desc->stats, parameter);}/** * Wrapper function for get_parameter_value, see there */inline void *swr_spc_get_parameter_value(const swr_parameters_desc_t desc,    const void *segment,    int parameter,    void *value) {  return get_parameter_value( desc, segment, parameter, value );}//-------------------------------------------------------------------// HANDLING INPUTS & OUTPUTS//-------------------------------------------------------------------/** * Get the number of input/output ports */inline int swr_spc_get_input_count(const swr_spc_desc_t *desc ) {#ifndef FAST  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return -1;  }#endif  return desc->inputs.nbr_ports;}inline int swr_spc_get_output_count(const swr_spc_desc_t *desc ) {#ifndef FAST  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return -1;  }#endif  return desc->outputs.nbr_ports;}/** * Get the signal type of the specified port in the ports description. * * @param desc The ports description. * * @param port_nbr The number of the port. * * @return The signal type of the port, or NO_SIGNAL when the signal * is unspecified or in case of an error. */inline swr_signal_type_t swr_spc_get_input_signal_type(const swr_spc_desc_t *desc,    int port) {#ifndef FAST  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return NO_SIGNAL;  }#endif  return get_signal_type(desc->inputs, port);}inline swr_signal_type_t swr_spc_get_output_signal_type(const swr_spc_desc_t *desc,    int port)  {#ifndef FAST  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return NO_SIGNAL;  }#endif  return get_signal_type(desc->outputs, port);}/** * Get the size of a signal-type */inline int swr_spc_get_type_size( swr_signal_type_t type ) {  return get_signal_type_size( type );}/** * Get the size of a parameter-type */inline int swr_spc_get_param_type_size( parameter_type_t type ) {  return get_size( type );}/** * Get the signal type of the specified port in the ports description. * * @param desc The ports description. * * @param port_nbr The number of the port. * * @return The signal type of the port, or NO_SIGNAL when the signal * is unspecified or in case of an error. */inline unsigned long swr_spc_get_input_flags(const swr_spc_desc_t *desc,    int port) {#ifndef FAST  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return 0;  }#endif  return get_flags(desc->inputs, port);}inline unsigned long swr_spc_get_output_flags(const swr_spc_desc_t *desc,    int port) {#ifndef FAST  if (!desc) {    PR_DBG(0, "desc == NULL\n");    return 0;  }#endif  return get_flags(desc->outputs, port);}//-------------------------------------------------------------------// KERNEL MODULE FUNCTIONS//-------------------------------------------------------------------/** * This function is called when the SPM database module is loaded into * the kernel. */int swr_cdb_database_init(void) {  int ret;  ret = initialize();  return ret;}/** * This function is called when the SPM database module is unloaded * from the kernel. The database must be empty, else we can't clean up * correctly! */void swr_cdb_database_free(void) {  finalize();}module_init(swr_cdb_database_init);module_exit(swr_cdb_database_free);EXPORT_SYMBOL(swr_spc_get_new_desc);EXPORT_SYMBOL(swr_spc_free_desc);EXPORT_SYMBOL(swr_cdb_register_spc);EXPORT_SYMBOL(swr_cdb_unregister_spc);EXPORT_SYMBOL(swr_spc_define_config_parameter);EXPORT_SYMBOL(swr_spc_define_stats_parameter);EXPORT_SYMBOL(swr_spc_define_input);EXPORT_SYMBOL(swr_spc_define_output);EXPORT_SYMBOL(swr_cdb_get_reference);EXPORT_SYMBOL(swr_cdb_free_reference);EXPORT_SYMBOL(swr_cdb_get_id);EXPORT_SYMBOL(swr_cdb_get_name);EXPORT_SYMBOL(swr_cdb_get_all_ids);EXPORT_SYMBOL(swr_spc_get_config_size);EXPORT_SYMBOL(swr_spc_get_stats_size);EXPORT_SYMBOL(swr_spc_get_config_memory_size);EXPORT_SYMBOL(swr_spc_get_stats_memory_size);EXPORT_SYMBOL(swr_spc_get_config_parameter_nbr);EXPORT_SYMBOL(swr_spc_get_stats_parameter_nbr);EXPORT_SYMBOL(swr_spc_get_config_type);EXPORT_SYMBOL(swr_spc_get_stats_type);EXPORT_SYMBOL(swr_spc_get_config_flags);EXPORT_SYMBOL(swr_spc_get_stats_flags);EXPORT_SYMBOL(swr_spc_set_config_parameter_value);EXPORT_SYMBOL(swr_spc_set_stats_parameter_value);EXPORT_SYMBOL(swr_spc_get_config_parameter_value);EXPORT_SYMBOL(swr_spc_get_stats_parameter_value);EXPORT_SYMBOL(swr_spc_get_config_parameter_pointer);EXPORT_SYMBOL(swr_spc_get_stats_parameter_pointer);EXPORT_SYMBOL(swr_spc_get_config_parameter_offset);EXPORT_SYMBOL(swr_spc_get_stats_parameter_offset);EXPORT_SYMBOL(swr_spc_get_parameter_value);EXPORT_SYMBOL(swr_spc_get_input_count);EXPORT_SYMBOL(swr_spc_get_input_signal_type);EXPORT_SYMBOL(swr_spc_get_output_count);EXPORT_SYMBOL(swr_spc_get_output_signal_type);EXPORT_SYMBOL(swr_spc_get_type_size);EXPORT_SYMBOL(swr_spc_get_config_parameter_names);EXPORT_SYMBOL(swr_spc_get_stats_parameter_names);EXPORT_SYMBOL(swr_spc_get_config_parameter_name);EXPORT_SYMBOL(swr_spc_get_stats_parameter_name);EXPORT_SYMBOL(swr_spc_get_param_type_size);

⌨️ 快捷键说明

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