source: drsdaq/VME/struck/sis1100/V2.02/test/sdram_rw_4_test.c@ 23

Last change on this file since 23 was 22, checked in by ogrimm, 16 years ago
First commit of drsdaq program
File size: 3.0 KB
Line 
1#define _GNU_SOURCE
2#define _LARGEFILE_SOURCE
3#define _LARGEFILE64_SOURCE
4#define _FILE_OFFSET_BITS 64
5#include <stdio.h>
6#include <errno.h>
7#include <string.h>
8#include <sys/types.h>
9#include <time.h>
10#include <unistd.h>
11#include <stdlib.h>
12#include <fcntl.h>
13#include <sys/ioctl.h>
14
15#include "dev/pci/sis1100_var.h"
16
17/****************************************************************************/
18static int* alloc_buf(int num)
19{
20 unsigned long int p;
21 int pagesize, pagemask;
22
23 pagesize=getpagesize();
24 pagemask=pagesize-1;
25 printf("pagesize=%d\n", pagesize);
26 p=(unsigned long int)calloc(num+pagesize, 1);
27 if (!p) return (int*)p;
28 printf("p_0=0x%08lx\n", p);
29 p=(p+pagesize-1)&(~pagemask);
30 printf("p_1=0x%08lx\n", p);
31 return (int*)p;
32}
33/****************************************************************************/
34static int do_read(int p, int start, int size, int* data)
35{
36 off_t pos;
37 int res;
38
39 pos=lseek(p, sizeof(int)*start, SEEK_SET);
40 if (pos==(off_t)-1) {
41 perror("do_read::lseek");
42 return 1;
43 }
44 res=read(p, data, size*sizeof(int));
45 if (res!=size*sizeof(int)) {
46 u_int32_t error;
47 ioctl(p, SIS1100_LAST_ERROR, &error);
48 if (res<0) {
49 fprintf(stderr, "read: %s; error=0x%x\n", strerror(errno), error);
50 } else {
51 fprintf(stderr, "read: res=%d; error=0x%x\n", res, error);
52 }
53 return 1;
54 }
55 return 0;
56}
57/****************************************************************************/
58static int test_buf(int size, int* ibuf)
59{
60 int i, n, res, state;
61
62 n=0; state=0;
63 for (i=0; (i<size)&&(n<5); i+=4) {
64 res=(ibuf[i]!=0x12345678)||(ibuf[i+1]!=i);
65 if (res!=state) {
66 int start, j;
67 printf("\n~~~~~~~~~~~~~~~~~~~~~~~%d~~~~~~~~~~~~~~~~~~~~~~~\n", res);
68 start=i-20; if (start<0) start=0;
69 for (j=start; j<start+40; j+=4)
70 printf("[%08X]: %08X %08X %08X %08X\n",
71 j, ibuf[j], ibuf[j+1], ibuf[j+2], ibuf[j+3]);
72 state=res;
73 n++;
74 }
75 }
76 return n;
77}
78/****************************************************************************/
79int main(int argc, char* argv[])
80{
81 int *ibuf;
82 off_t max;
83 int p;
84
85 if (argc!=2) {
86 fprintf(stderr, "usage: %s path\n", argv[0]);
87 return 1;
88 }
89
90 if ((p=open(argv[1], O_RDWR, 0))<0) {
91 perror("open");
92 return 1;
93 }
94
95 max=lseek(p, 0, SEEK_END);
96 if (max==(off_t)-1) {
97 perror("lseek(0, SEEK_END)");
98 return 1;
99 }
100 fprintf(stderr, "size of sdram is %08Lx (%Ld MByte)\n", max, max/(1<<20));
101
102 max/=sizeof(int);
103
104 ibuf=alloc_buf(max*sizeof(int));
105 if (!ibuf) {
106 perror("calloc");
107 return 1;
108 }
109
110 if (do_read(p, 0, max, ibuf)) {
111 printf("\nread failed\n");
112 return 1;
113 }
114
115 test_buf(max, ibuf);
116
117 close(p);
118
119 return 0;
120}
121/****************************************************************************/
122/****************************************************************************/
Note: See TracBrowser for help on using the repository browser.