1MB_ SRAM Test für FPGA über PCIExpress

OP #3028854
Lesenswert?

Hallo zusammen,

Für mein Lattice Versa Eval Board habe ich ein Referenz Design mit 
folgende Memory Map:
GPIO= 32'h0000
EBR= 32'h1000

Ein Beispiel Code zum EBR Memory Test sieht wie folgende aus:
1
#define POSIX_SOURCE 199309
2

3
#include <unistd.h>
4
#include <stdio.h>
5
#include <stdlib.h>
6
#include <stdint.h>
7
#include <sys/types.h>
8
#include <string.h>
9
#include <fcntl.h>
10
#include <time.h>
11

12
#include <errno.h>
13
#include <sys/mman.h>
14

15
#include "Ioctl.h"
16

17

18
#define EBR_SIZE    (16384)
19
#define EBR_DW_SIZE (16384 / 4)
20
  
21
#define PCI_DEV_MEM_SIZE 0x5000  // Basic: GPIO + 16KB EBR
22

23
uint32_t *lscpcie_open(char *region, size_t l);
24
int lscpcie_close(void *pmem);
25
void memTest(uint32_t *pMem);
26

27
size_t BarSize;
28
int Board_fd = -1;
29

30

31

32
int main(int argc, char *argv[])
33
{
34
  int i;
35
  char s[1024];
36
  uint32_t *p0;
37
  uint16_t *ps;
38
  char *brd;
39
  char filename[256];
40
  int fdBoard;
41
  PCIResourceInfo_t info;
42
  ExtraResourceInfo_t extra;
43

44
  printf("User Space Lattice PCIe device driver using mmap\n");
45

46
  if (argc < 2)
47
  {
48
    printf("usage: test <brd>_<demo>_<num> <size>\n");
49
    exit(-1);
50
  }
51

52
  if (argc >= 2)
53
  {
54
    brd = argv[1];
55
    printf("Board %s\n", brd);
56
  }
57
  else
58
  {
59
    brd = "SC_Basic_1";
60
    printf("Using Default: Board %s\n", brd);
61
  }
62

63
  if (argc == 3)
64
  {
65
    BarSize = atoi(argv[2]);
66
    printf("BAR size %d\n", BarSize);
67
  }
68
  else
69
  {
70
    BarSize = PCI_DEV_MEM_SIZE;   // default for our demo BAR1
71
  }
72

73
  printf("Opening access to lscpcie/%s\n", brd);
74
  sprintf(filename, "/dev/LSC_PCIe/%s", brd);
75
  p0 = lscpcie_open(filename, BarSize);
76
  printf("*p0 = %x\n", (long)p0);
77

78
  if (p0 == NULL)
79
    exit(-1);
80

81
  printf("Displaying first 8 GPIO registers\n");
82
  for (i = 0; i < 8; i++)
83
  {
84
    if ((i % 4) == 0)
85
      printf("\n%04x: ", i*4);
86
    printf("%08x  ", p0[i]);
87
  }
88
  printf("\n");
89

90
  printf("Blink LEDs\n");
91
  for (i = 0; i < 16; i++)
92
  {
93
    p0[2] = 1<<i;
94
    sleep(1);
95
  }
96
  
97

98

99
  printf("\n\nEBR Memory access tests\n");
100
  memTest(p0 + (0x1000/4));
101

102

103
  printf("ioctl() get Resources...\n");
104
  if (Board_fd != -1)
105
  {
106
    
107
    if (ioctl(Board_fd, IOCTL_LSCPCIE_GET_RESOURCES, &info) != 0)
108
      perror("ioctl");
109
    else
110
    {
111
      printf("PCIinfo.hasInterrupt = %d\n", info.hasInterrupt);
112
      printf("PCIinfo.intrVector = %d\n", info.intrVector);
113
      printf("PCIinfo.numBARs = %d\n", info.numBARs);
114
      printf("CFG0:");
115
      for (i = 0; i < 0x40; i++)
116
      {
117
        if ((i % 16) == 0)
118
          printf("\n%02x: ", i);
119
        printf("%02x ", info.PCICfgReg[i]);
120
      }
121
      printf("\n");
122

123
      for (i = 0; i < MAX_PCI_BARS; i++)
124
      {
125
        printf("BAR[%d]:\n", info.BAR[i].nBAR);
126
        printf("\tphyStartAddr = %x\n", info.BAR[i].physStartAddr);
127
        printf("\tsize = %d\n", info.BAR[i].size);
128
        printf("\tmemMapped = %d\n", info.BAR[i].memMapped);
129
        printf("\tflags = %d\n", info.BAR[i].flags);
130
        printf("\ttype = %d\n", info.BAR[i].type);
131
      }
132

133
    }
134

135

136
  }
137

138

139
  printf("\n\nioctl() get ExtraInfo...\n");
140
  if (Board_fd != -1)
141
  {
142
    
143
    if (ioctl(Board_fd, IOCTL_LSCPCIE2_GET_EXTRA_INFO, &extra) != 0)
144
      perror("ioctl: extra info");
145
    else
146
    {
147
      printf("devID = %d\n", extra.devID);
148
      printf("busNum = %d\n", extra.busNum);
149
      printf("deviceNum = %d\n", extra.deviceNum);
150
      printf("functionNum = %d\n", extra.functionNum);
151
      printf("UINumber = %d\n", extra.UINumber);
152
      printf("hasDmaBuf = %d\n", extra.hasDmaBuf);
153
      printf("DmaBufSize = %d (0x%x)\n", extra.DmaBufSize, extra.DmaBufSize);
154
      printf("DmaAddr64 = %d\n", extra.DmaAddr64);
155
      printf("DmaPhyAddrHi = 0x%08x\n", extra.DmaPhyAddrHi);
156
      printf("DmaPhyAddrLo = 0x%08x\n", extra.DmaPhyAddrLo);
157
      printf("DriverName = %s\n", extra.DriverName);
158
    }
159

160
  }
161

162

163

164
  printf("Press Enter to close...\n");
165
  fgets(s,2,stdin);
166

167

168
  lscpcie_close(p0);
169

170
  return(0);
171
}
172

173

174
uint32_t  *lscpcie_open(char *region, size_t len)
175
{
176
  int fd;
177
  int sysErr;
178
  uint32_t *pmem;
179

180
  /* Open the kernel mem object to gain access
181
   */
182
  fd = open(region, O_RDWR, 0666); 
183
  if (fd == -1)
184
  {
185
    perror("ERROR open(): ");
186
    return(NULL);
187
  }
188
  printf("fd = %d\n");
189

190

191
  pmem = mmap(0,             /* choose any user address */
192
        len,           /* This big */
193
        PROT_READ | PROT_WRITE, /* access control */
194
        MAP_SHARED,             /* access control */
195
        fd,                  /* the object */
196
        0);                  /* the offset from beginning */
197

198
// Need for ioctl calls so why close????
199
  // close(fd);  /* not needed any more */
200
  if (pmem == MAP_FAILED)
201
  {
202
    perror("mmap: ");
203
    return(NULL);
204
  }
205
  printf("pmem=0x%x\n", (long)pmem);
206

207
  Board_fd = fd;
208

209

210
  return(pmem);
211
}
212

213

214
int lscpcie_close(void *pmem)
215
{
216
  int sysErr;
217

218

219
  /* Release the shared memory.  It won't go away but we're done with it */
220
  sysErr = munmap(pmem, BarSize);
221
  if (sysErr == -1)
222
  {
223
    perror("munmap: ");
224
    return(-1);
225
  }
226

227
  close(Board_fd);
228

229
  return(0);
230
}
231

232

233
void memTest(uint32_t *pMem)
234
{
235
  int i;
236

237
  printf("EBR Memory Access Tests\n");
238

239
  printf("Clearing to 0's...\n");
240
  memset(pMem, 0, EBR_SIZE);
241

242
  for (i = 0; i < EBR_DW_SIZE; i++)
243
  {
244
    if (pMem[i] != 0)
245
    {
246
      printf("ERROR! EBR not cleared!\n");
247
      return;
248
    }
249
  }
250

251
  printf("Setting to 0xa5...\n");
252
  memset(pMem, 0xa5, EBR_SIZE);
253

254
  for (i = 0; i < EBR_DW_SIZE; i++)
255
  {
256
    if (pMem[i] != 0xa5a5a5a5)
257
    {
258
      printf("ERROR! EBR not set to 0xa5!\n");
259
      return;
260
    }
261
  }
262

263

264
  printf("Setting to pattern...\n");
265
  for (i = 0; i < EBR_DW_SIZE; i++)
266
  {
267
    pMem[i] = 0xcafe0000 | i;
268
  }
269

270
  for (i = 0; i < EBR_DW_SIZE; i++)
271
  {
272
    if (pMem[i] != (0xcafe0000 | i))
273
    {
274
      printf("ERROR! EBR not set to pattern!\n");
275
      return;
276
    }
277
  }
278

279
  printf("PASS\n\n");
280
}
281
      
282

283
Mein Ziel ist es für mein Design mit Memory Map:
284
EBR= 32'h0000
285
GPIO= 32'h1000
286
SRAM= 32'h2000
287

288
Ein SRAM Test zu implementieren. Nur habe ich alles probiert und es ist mir nicht gelungen, Zugriff auf gesamten SRAM Größe zu haben.(eher nur 4KBx 32 Bits).
289

290
Was fehlt mir noch bitte um Hinweis!

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren