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

📄 dbg_kernel.c

📁 This a framework to test new ideas in transmission technology. Actual development is a LDPC-coder in
💻 C
字号:
/***************************************************************************             dbg_kernel.c  -  Kernel setup-routines for dbg                            -------------------    begin                :  2003    authors              :  Linus Gasser    emails               :  linus.gasser@epfl.ch ***************************************************************************//***************************************************************************                                 Changes                                 ------- date - name - description 03-08-07 - ineiti - start  **************************************************************************//*************************************************************************** *                                                                         * *   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.                                   * *                                                                         * ***************************************************************************/#ifdef KERNEL_SPACE/** * sets up two fifos: * 0) command * 1) data user->kernel * 2) data kernel->user *//** * sets up two fifos: * 0) command * 1) data kernel->user */#define DBG_LVL 2#include <rtl_fifo.h>#include "std.h"#include "system.h"#include "debugging.h"#include "sdb.h"#include "cdb.h"#include "dbg.h"#include "dbg_common.h"struct thread thr_cmd, thr_reply;pthread_mutex_t fifo_mutex = PTHREAD_MUTEX_INITIALIZER;pthread_cond_t fifo_cond = PTHREAD_COND_INITIALIZER;void *fifo_data = NULL;uint fifo_len;int fifo_quit = 0;uint fifo_pos = 0;int fifo_data_reply( unsigned int fifo ) {  int wrote;  PR_DBG( 3, "Data-reply got called for buffer at %p with len %i and pos %i\n",          fifo_data, fifo_len, fifo_pos );  if ( fifo_pos < fifo_len ) {    if ( !fifo_data ) {      PR_DBG( 2, "Fifo_data is still NULL\n" );      return 0;    }    wrote = rtf_put( 1, fifo_data + fifo_pos,                     min( fifo_len - fifo_pos, FIFO_SIZE ) );    PR_DBG( 4, "Pos: %i, Wrote: %i\n", fifo_pos, wrote );    if ( wrote < 0 ) {      PR_DBG( 0, "Error %i, Couldn't write at %i from %i\n",              wrote, fifo_pos, fifo_len );      return -1;    }    fifo_pos += wrote;    if ( fifo_pos == fifo_len ) {      PR_DBG( 3, "Finished writing\n" );      swr_free( fifo_data );      fifo_data = NULL;      fifo_len = 0;      fifo_pos = 0;    }  } else if ( fifo_pos ) {    PR_DBG( 0, "FifoPos >= FifoLen: %i > %i\n",            fifo_pos, fifo_len );  }  return 0;}char *buf;int fifo_command( unsigned int fifo ) {  int size, size_cmd;  // First read the 2-digit decimal size + LF  if ( fifo_pos > 0 ) {    PR_DBG( 0, "*** Trying to write new command while queue is not empty\n" );    return -1;  }  PR_DBG( 3, "Going to read size\n" );  size = rtf_get( 0, buf, 3 );  if ( size > 0 ) {    buf[ size ] = 0;    sscanf( buf, "%i", &size_cmd );    PR_DBG( 4, "Going to read a command of size %i\n", size_cmd );    size = rtf_get( 0, buf, size_cmd );    buf[ size ] = 0;    if ( size != size_cmd ) {      PR_DBG( 0, "Strange, read bytes (%i) don't match cmd-size (%i)\n",              size, size_cmd );    } else {      PR_DBG( 4, "Got cmd (%i bytes): %s\n", size, buf );      parse_command( buf );      PR_DBG( 4, "Parsed command, reply is %i bytes\n", fifo_len );      size = snprintf( buf, 16, "%10i\n", fifo_len );      rtf_put( 1, buf, size );      fifo_pos = 0;    }  }  PR_DBG( 3, "fifo_cmd end\n" );  return 0;}int setup_fifos() {  fifo_data = NULL;  if ( rtf_create( 0, FIFO_SIZE ) < 0 ) {    PR_DBG( 0, "Couldn't setup fifo #0\n" );    return -1;  }  if ( rtf_create( 1, FIFO_SIZE ) < 0 ) {    PR_DBG( 0, "Couldn't setup fifo #1\n" );    rtf_destroy( 0 );    return -1;  }  if ( rtf_create_handler( 0, &fifo_command ) < 0 ) {    PR_DBG( 0, "Couldn't install the fifo-handler\n" );    rtf_destroy( 0 );    rtf_destroy( 1 );    return -3;  }  if ( rtf_create_handler( 1, &fifo_data_reply ) < 0 ) {    PR_DBG( 0, "Couldn't install the fifo-reply-handler\n" );    rtf_destroy( 0 );    rtf_destroy( 1 );    return -3;  }  buf = swr_malloc( FIFO_SIZE );  return 0;}int destroy_fifos() {  PR_DBG( 4, "Going to delete the FIFOs\n" );  rtf_destroy( 1 );  rtf_destroy( 0 );  swr_free( buf );  return 0;}#endif

⌨️ 快捷键说明

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