📄 copy.c
字号:
/*************************************************************************** copy.c - RTLinux kernel module for a simple copy-module ------------------- begin : 2002 authors : Linus Gasser emails : linus.gasser@epfl.ch ***************************************************************************//*************************************************************************** Changes ------- date - name - description 02-09-19 - ineiti- begin 04/01/26 - ineiti - make two outputs **************************************************************************//*************************************************************************** * * * 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. * * * ***************************************************************************//** * As the software-radio doesn't accept one output that is connected * to multiple inputs, you have to put this copy-module in between. */#include "spc.h"#define DBG_LVL 0typedef struct {}config_t;typedef struct {}stats_t;typedef struct {}private_t;/** * The initialisation part that is only called the first time this module * is instantiated. */int spc_init( swr_sdb_t *context ) { config_t *config; stats_t *stats; MOD_INC_USE_COUNT; swr_sdb_get_config_struct( context->id, (void**)&config ); swr_sdb_get_stats_struct( context->id, (void**)&stats ); context->private_data = swr_malloc( sizeof( private_t ) ); swr_sdb_free_config_struct( context->id, (void**)&config ); swr_sdb_free_stats_struct( context->id, (void**)&stats ); return 0;}/** * To configure the inputs */int spc_configure_inputs( swr_sdb_t *context ) { config_t *config; swr_sdb_get_config_struct( context->id, (void**)&config ); size_in(0) = size_out(0); PR_DBG( 0, "Config_in: %i\n", size_in(0) ); swr_sdb_free_config_struct( context->id, (void**)&config ); return 0;}/** * To configure the outputs */int spc_configure_outputs( swr_sdb_t *context ) { config_t *config; swr_sdb_get_config_struct( context->id, (void**)&config ); PR_DBG( 0, "Config_out\n" ); size_out(0) = size_out(1) = size_in(0); swr_sdb_free_config_struct( context->id, (void**)&config ); return 0;}/** * Every time somebody from the outside changes a configuration value, * this function is called just before the working-function */int spc_reconfig( swr_sdb_t *context ) { config_t *config; int ret = 0; swr_sdb_get_config_struct( context->id, (void**)&config ); swr_sdb_free_config_struct( context->id, (void**)&config ); return ret;}/** * The actual working function */int spc_pdata( swr_sdb_t *context ) { U8 *out[2], *in; // Have some easy definitions in = buffer_in( 0 ); out[0] = buffer_out( 0 ); out[1] = buffer_out( 1 ); // Do the copying memcpy( out[0], in, size_in(0) ); memcpy( out[1], in, size_in(0) ); return 0;}int spc_finalize( swr_sdb_t *context ) { swr_free( private ); MOD_DEC_USE_COUNT; return 0;}swr_spc_id_t cdb_id;/** * This function is called upon "insmod" and is used to register the * different parts of the module to the SPM. */int spc_module_init(void) { swr_spc_desc_t *desc; // Get a description-part from SPM desc = swr_spc_get_new_desc( 1, 2, 0, 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 UM_INPUT( SIG_U8, 0 ); UM_OUTPUT( SIG_U8, 0 ); UM_OUTPUT( SIG_U8, 0 ); // Initialise the callback-functions. NULL for not-used functions 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 = NULL; desc->fn_finalize = spc_finalize; // And register the module in the SPM cdb_id = swr_cdb_register_spc( &desc, "copy" ); 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 to copy your data with id %i\n", cdb_id ); return 0;}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 + -