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

📄 rf_control.c

📁 This a framework to test new ideas in transmission technology. Actual development is a LDPC-coder in
💻 C
字号:
/***************************************************************************             rf_control.c  -  To start/stop the RF                            -------------------    begin                :  2002    authors              :  Linus Gasser    emails               :  linus.gasser@epfl.ch ***************************************************************************//***************************************************************************                                 Changes                                 ------- date - name - description 02-10-02 - ineiti - create 02-12-12 - ineiti - introduced in antenna/rf   **************************************************************************//*************************************************************************** *                                                                         * *   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.                                   * *                                                                         * ***************************************************************************/#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/ioctl.h>#include <fcntl.h>#include <sys/mman.h>#include <errno.h>#include <math.h>//#include <signal.h>#include <string.h>#include <mmx.h>#include <stdlib.h>#include <unistd.h>#include "channel_rf.h"extern int errno;int loadFPGA2(unsigned int rf_fd,const char *fname) {  int i, j;  int bitf;  char *map;  unsigned char *fpga_buf;  int fpga_size;  int pos = 0;  struct stat statbuf;  char line[1024];  printf("Loading %s\n",fname);  if ((bitf = open(fname,O_RDONLY)) < 0) {    printf("Could not open %s\n",fname);    return -1;  }  if(fstat(bitf, &statbuf ) == -1 ) {    perror("fstat");    exit(1);  }  fpga_size = statbuf.st_size;  /* We need 4 bytes to put the size of the buffer at the beginning */  if((fpga_buf = (unsigned char *) malloc(fpga_size)) == NULL) {    fprintf(stderr, "can't malloc %d bytes\n", fpga_size + 4);    exit(1);  }  map = mmap(0, fpga_size, PROT_READ, MAP_PRIVATE, bitf, 0);  if (map == (caddr_t)-1) {    perror("mmap failed");    exit(-1);  }  j = 0;  i = 7;   /* skip first seven lines */  while(i) {    if(map[j++] == '\n')      i--;    line[j-1] = map[j-1];  }  line[j] = 0;  puts(line);  /* As there is some space left in fpga_buf[], put the size of the buffer     in the 4 first bytes. */  fpga_buf[0] = fpga_size & 0x000000FF;  fpga_buf[1] = (fpga_size & 0x0000FF00) >> 8;  fpga_buf[2] = (fpga_size & 0x00FF0000) >> 16;  fpga_buf[3] = (fpga_size & 0xFF000000) >> 24;  pos = 4;			/* Protect the integer value  */  /* Now fills the buffer. The method is ridiculous (we use 8 times the     size needed in the fpga_buf), but works. */  while(j < fpga_size) {		/* size must be 1751840 for XCV300 */    switch(map[j++]) {	/* The bit */    case '0':      fpga_buf[pos++] = 0;      break;    case '1':      fpga_buf[pos++] = 1;      break;    case '\n':      continue;    default:      printf("Error in file format");      return -1;    }  }  close(bitf);  munmap(map, fpga_size);  printf("%d bits read", pos - 4);  printf("FPGA RESET");  if(ioctl(rf_fd, RF_FPGA_RESET, 0) == -1) {    perror("ioctl");  }  usleep(100000);  printf("FPGA PROGRAMMING\n");  if(ioctl(rf_fd, RF_FPGA_PROGRAM, fpga_buf) == -1) {    perror("ioctl");  }  free(fpga_buf);  return 0;}int resetFPGA2(unsigned int rf_fd) {  printf("Resetting FPGA, ioctl=%x\n",RF_FPGA_RESET);  if(ioctl(rf_fd, RF_FPGA_RESET) == -1)    perror("ioctl");  return 0;}int main(int argc, char *argv[]) {  int rf_fd;  int arg, retval,i,slots = 100;  if (argc<2) {    printf( "usage: rf_test file.rbt\n" );    printf( "  -dump : dumps some registers\n" );    printf( "  -test : does some testing\n" );    return -1;  }  printf("Opening /dev/rf0\n");  if ((rf_fd = open("/dev/rf0", O_RDONLY)) <0) {    printf("Error %d opening /dev/rf0\n",rf_fd);    return -1;  }  for ( arg = 1; arg < argc; arg++ ) {    if ( arg == 1 ) {      if ( !strcmp( argv[ arg ], "-eeprom_read" ) ) {        // Only read the eeprom        ioctl( rf_fd, RF_EEPROM_READ );        return 0;      } else if ( !strcmp( argv[ arg ], "-eeprom" ) ) {        // Program the eeprom        ioctl( rf_fd, RF_EEPROM_WRITE );        ioctl( rf_fd, RF_EEPROM_READ );        return 0;      } else {        // Load the FPGA into memory;        resetFPGA2(rf_fd);        if (loadFPGA2(rf_fd,argv[1])<0) {          close(rf_fd);          return -1;        }      }    } else if ( !strcmp( argv[ arg ], "-dump" ) ) {      // Dumps the registers      printf("rf_fd=%d\n",rf_fd);      printf("Dumping Registers, ioctl =%x\n",RF_DUMP_PLX_REGS);      ioctl(rf_fd,RF_DUMP_PLX_REGS,0);    } else if ( !strcmp( argv[ arg ], "-test" ) ) {      // DAC, ADC and other tests      printf("Testing FPGA memory ...\n");      retval = ioctl(rf_fd,RF_TEST_FPGA_MEM,0);      if (retval == -1) {        switch (errno) {        case -TEST_FAILURE_DAC_MEM:          printf("DAC memory failure\n");          break;        case -TEST_FAILURE_ADC_MEM:          printf("ADC memory failure\n");          break;        default:          printf("Unknown error %d\n",errno);          break;        }      } else {        printf("FPGA Memory ok!\n");      }#if 1      retval = (int)ioctl(rf_fd,RF_TEST_ADC_DMA,&slots);      if (retval == -1) {        switch (errno) {        case -TEST_FAILURE_ADC_DMA:          printf("ADC DMA failure (check clock input)\n");          break;        default:          printf("Unknown errno %d\n",errno);          break;        }      } else {        printf("FPGA ADC DMA ok!\n");      }      retval = ioctl(rf_fd,RF_TEST_DAC_DMA,&slots);      if (retval == -1) {        switch (errno) {        case -TEST_FAILURE_DAC_DMA:          printf("DAC DMA failure(check clock input)\n");          break;        default:          printf("Unknown errno %d\n",errno);          break;        }      } else {        printf("FPGA DAC DMA ok!\n");      }#endif      printf("Testing MMX\n");      for (i=0;i<100;i++)        pxor_r2r(mm0,mm0);    }  }  close(rf_fd);  return 0;}

⌨️ 快捷键说明

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