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

📄 user_dl.c

📁 This a framework to test new ideas in transmission technology. Actual development is a LDPC-coder in
💻 C
字号:
/***************************************************************************             user.c  -  Implements all the necessary functions for user-space                            -------------------    begin                :  2002    authors              :  Linus Gasser    emails               :  linus.gasser@epfl.ch ***************************************************************************//***************************************************************************                                 Changes                                 ------- date - name - description 02-10-09 - ineiti- begin 02-12-09 - ineiti - added userprocfs  **************************************************************************//*************************************************************************** *                                                                         * *   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 is the library a user-space-test program has to link against. * It offers all kinds of different functions that are available in * RTLinux kernel-space and that need to be emulated in user-space. * Have fun... */#include <stdlib.h>#include <dlfcn.h>#include "debugging.h"#define DBG_LVL 0typedef struct modlist_t {  char name[256];  void *handle;  struct modlist_t *next, *prev;}modlist;modlist *first;modlist *addList( char *name ) {  modlist *n;  n = malloc( sizeof( modlist ) );  strncpy( n->name, name, 256 );  n->next = first;  n->prev = first->prev;  n->prev->next = n;  first->prev = n;  return n;}void *rmList( char *name ) {  modlist *n;  void *handle = NULL;  for ( n = first->next; n != first; n = n->next ) {    if ( strcmp( n->name, name ) == 0 ) {      handle = n->handle;      n->prev->next = n->next;      n->next->prev = n->prev;      free( n );    }  }  return handle;}/** * Gets the module 'name' and returns 0 on success. This also * initialises the module. */int loadModule( char *name ) {  void *handle;  char path[256];  int (*daq_start)(int);  // Our name convention, so as to distinct from other things  if ( sprintf( path, "libswr_%s.so", name ) >= 256 ) {    PR_DBG( 0, "OOPS, the name %s is toooo long\n", name );    return -1;  }  // All symbols should be checked for NOW and should be available  // also later  handle = dlopen( path, RTLD_NOW | RTLD_GLOBAL );  if ( !handle ) {    PR_DBG( 0, "Error on loading: %s\n", dlerror() );    return -1;  }  if ( strcmp( name, "emul" ) == 0 ) {    daq_start = dlsym( handle, "swr_daq_dma_start" );  }  addList( name )->handle = handle;  return 0;}/** * Frees a loaded module, calling the 'exit'-function */int freeModule( char *n ) {  void *handle;  char name[256];  strncpy( name, n, 256 );  handle = rmList( name );  if ( handle ) {    PR_DBG( 4, "removing %s\n", name );    dlclose( handle );    return 0;  } else {    PR_DBG( 0, "couldn't find %s for freeing\n", name );    return -1;  }}/** * Delete all resting modules */void freeAll() {  // Getting rid of all modules  while ( first->next != first->prev ) {    PR_DBG( 4, "Freeing %s\n", first->prev->name );    freeModule( first->prev->name );    //    sleep( 1 );  }}int user_dl_init( void ) {  PR_DBG( 4, "Initialising user\n" );  // Initialise the modules-list  first = malloc( sizeof( modlist ) );  first->prev = first->next = first;  return 0;}void user_dl_fini( void ) {  PR_DBG( 4, "Stopping user, cleaning up modules\n" );  freeAll();  free( first );}

⌨️ 快捷键说明

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