OpenCores
URL https://opencores.org/ocsvn/fade_ether_protocol/fade_ether_protocol/trunk

Subversion Repositories fade_ether_protocol

[/] [fade_ether_protocol/] [trunk/] [stable_jumbo_frames_version/] [linux/] [receiver3.c] - Blame information for rev 40

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 15 wzab
/*
2
 * fpga_l3_fade - driver for L3 communication protocol with FPGA based system
3
 * Copyright (C) 2012 by Wojciech M. Zabolotny
4
 * Institute of Electronic Systems, Warsaw University of Technology
5
 *
6
 *  This code is PUBLIC DOMAIN
7
 */
8
 
9
#include<termios.h>
10
#include <sys/types.h>
11
#include <sys/stat.h>
12
#include <sys/mman.h>
13
#include <sys/ioctl.h>
14
#include <fcntl.h>
15
#include <poll.h>
16
#include <unistd.h>
17
#include <stdio.h>
18
#include <strings.h>
19
#include <stdlib.h>
20
#include <stdint.h>
21
#include <endian.h>
22
#include <sys/socket.h>
23
#include <linux/serial.h>
24
#include <sched.h>
25
#include "fpga_l3_fade.h"
26
#include <sys/time.h>
27
 
28
 
29
void main(int argc, char * argv[])
30
{
31
  int active[3]={0,0,0};
32
  struct l3_v1_buf_pointers bp;
33
  struct l3_v1_slave sl[3] = {
34
    {
35
      .mac = {0xde, 0xad, 0xba, 0xbe, 0xbe,0xef},
36
      .devname = "p4p1"
37
    },
38
    {
39
      .mac = {0xde, 0xad, 0xba, 0xbe, 0xbe,0xe1},
40
      .devname = "p4p1"
41
    },
42
    {
43
      .mac = {0xde, 0xad, 0xba, 0xbe, 0xbe,0xe2},
44
      .devname = "p4p1"
45
    }
46
   };
47
  int i,j;
48
  int res;
49
  int blen[3];
50
  uint64_t data[3] = {0,0,0};
51
  long long total_len[3]={0,0,0};
52
  unsigned char * v[3];
53
  int frs[3]={-1,-1,-1};
54
  struct timeval tv;
55
  double tstart=0.0 , tend=0.0;
56
  int stop;
57
  struct sched_param s;
58
  s.sched_priority = 90;
59
  //Read active channels
60
  for(i=1;i<argc;i++) {
61
    int n = atoi(argv[i]);
62
    if ((n>=0) && (n<=2))
63
      active[n]=1;
64
  }
65
  printf("sched=%d\n",sched_setscheduler(0,SCHED_RR,&s));
66
  //Prepare all slaves to work
67
  for(i=0;i<3;i++) {
68
    char devname[30];
69
    sprintf(devname,"/dev/l3_fpga%d",i);
70
    frs[i]=open(devname,O_RDONLY);
71
    if(frs[i]<0) {
72
      printf("I can't open device %s\b",devname);
73
      perror("");
74
      exit(1);
75
    }
76
    //Get the length of the buffer
77
    blen[i] = ioctl(frs[i],L3_V1_IOC_GETBUFLEN,NULL);
78
    //Set the wakeup threshold
79
    res=ioctl(frs[i],L3_V1_IOC_SETWAKEUP,2000000);
80
    printf("length of buffer: %d, result of set wakeup: %d\n",blen[i],res);
81
    v[i]=(unsigned char *)mmap(0,blen[i],PROT_READ,MAP_PRIVATE,frs[i],0);
82
    if(!v[i]) {
83
      printf("mmap for device %s failed\n",devname);
84
      exit(1);
85
    }
86
  }
87
  //Connect devices
88
  gettimeofday(&tv, NULL);
89
  tstart=tv.tv_sec+1.0e-6*tv.tv_usec;
90
  stop=tv.tv_sec+300;
91
  for(i=0;i<=2;i++) {
92
    if(active[i]) {
93
       res = ioctl(frs[i],L3_V1_IOC_GETMAC,&sl[i]);
94
       printf("Result of get for slave %d : %d\n",i,res);
95
       }
96
  }
97
  //Send user command
98
  for(i=0;i<=2;i++) {
99
    if(active[i]) {
100
       int j;
101
       struct l3_v1_usercmd uc;
102
       uc.cmd=0x0112;
103
       uc.arg=0x56789abc;
104
       uc.timeout=2;
105
       uc.nr_of_retries=20;
106
       res = ioctl(frs[i],L3_V1_IOC_USERCMD,&uc);
107
       printf("Result of usercmd for slave %d : %d\n",i,res);
108
       for(j=0;j<12;j++) {
109
         printf("%2.2x",(int)(uc.resp[j]));
110
         }
111
       printf("\n");
112
       }
113
  }
114
  for(i=0;i<=2;i++) {
115
    res = ioctl(frs[i],L3_V1_IOC_FREEMAC,0);
116
    munmap(v[i],blen[i]);
117
    close(frs[i]);
118
  }
119
 
120
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.