Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

VrGuppiBuffer.h

Go to the documentation of this file.
00001 /* -*- Mode: c++ -*- */ 00002 /* 00003 * Copyright 2001 Free Software Foundation, Inc. 00004 * 00005 * This file is part of GNU Radio 00006 * 00007 * GNU Radio is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2, or (at your option) 00010 * any later version. 00011 * 00012 * GNU Radio is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with GNU Radio; see the file COPYING. If not, write to 00019 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00020 * Boston, MA 02111-1307, USA. 00021 */ 00022 /* 00023 * Copyright 1997 Massachusetts Institute of Technology 00024 * 00025 * Permission to use, copy, modify, distribute, and sell this software and its 00026 * documentation for any purpose is hereby granted without fee, provided that 00027 * the above copyright notice appear in all copies and that both that 00028 * copyright notice and this permission notice appear in supporting 00029 * documentation, and that the name of M.I.T. not be used in advertising or 00030 * publicity pertaining to distribution of the software without specific, 00031 * written prior permission. M.I.T. makes no representations about the 00032 * suitability of this software for any purpose. It is provided "as is" 00033 * without express or implied warranty. 00034 * 00035 */ 00036 00037 #ifndef _VRGUPPIBUFFER_H_ 00038 #define _VRGUPPIBUFFER_H_ 00039 00040 #include <unistd.h> 00041 #include <sys/mman.h> 00042 00043 template<class T> class VrGuppiBuffer; 00044 00045 #include <VrSigProc.h> 00046 #include <VrConnect.h> 00047 #include <VrBuffer.h> 00048 #include <guppi.h> 00049 00050 template<class T> class VrGuppiBuffer : public VrBuffer { 00051 private: 00052 int guppi_fd; 00053 unsigned long bufferSize_bytes; 00054 virtual void allocateBuffer(unsigned int arg_type_size); 00055 public: 00056 VrGuppiBuffer(VrSigProc *m,int gupfd) : VrBuffer(m) {guppi_fd=gupfd; } 00057 }; 00058 00059 template<class T> void 00060 VrGuppiBuffer<T>::allocateBuffer(unsigned int arg_type_size) 00061 { 00062 bufferSize = 0; // FIXME should allow user to set this somehow 00063 type_size = arg_type_size; 00064 if(bufferSize<3*1024*PAGE_SIZE/sizeof(T)) 00065 bufferSize=3*1024*PAGE_SIZE/sizeof(T); //minimum for Guppi 00066 00067 bufferSize_bytes = bufferSize*sizeof(T); 00068 00069 //Integral # of pages 00070 if((bufferSize_bytes % PAGE_SIZE) != 0) { 00071 bufferSize_bytes = (bufferSize_bytes/PAGE_SIZE + 1) * PAGE_SIZE; 00072 00073 bufferSize = bufferSize_bytes/sizeof(T); 00074 } 00075 00076 if((ioctl(guppi_fd, GIOCSETBUFSIZE, bufferSize_bytes/PAGE_SIZE)) < 0) { 00077 perror("VrGuppiBuffer(allocateBuffer): Failed to set buffersize"); 00078 exit(-1); 00079 } 00080 00081 if((ioctl(guppi_fd, GIOCSTART)) < 0) { 00082 perror("VrGuppiBuffer(allocateBuffer): start receive failed"); 00083 exit(-1); 00084 } 00085 00086 //Find a place big enough for the buffer 00087 char *start = NULL; 00088 int fdz = open("/dev/zero",O_RDONLY); 00089 if((start=(char *) mmap(0,bufferSize_bytes*2,PROT_NONE,MAP_SHARED,fdz,0)) == MAP_FAILED || 00090 munmap(start,bufferSize_bytes*2) == -1) { 00091 perror("Could not allocate mmap memory for guppi buffer"); 00092 exit(-1); 00093 return; 00094 } 00095 close(fdz); 00096 00097 //MMap the buffer in twice 00098 if((mmap(start,bufferSize_bytes,PROT_READ,MAP_FIXED|MAP_SHARED,guppi_fd,0)) == MAP_FAILED || 00099 (mmap(start+bufferSize_bytes,bufferSize_bytes,PROT_READ,MAP_FIXED|MAP_SHARED,guppi_fd,0)) == MAP_FAILED) { 00100 perror("Could not mmap Guppi buffer"); 00101 exit(-1); 00102 return; 00103 } 00104 00105 bufferDupStart = ((char *)start) + bufferSize * type_size; 00106 // cerr << upstream->name() <<" (guppi)bufferDupStart = "<<(void *) bufferDupStart<<endl; 00107 } 00108 #endif

Generated on Wed Aug 4 02:22:05 2004 for GNU Radio by doxygen 1.3.8