source: drsdaq/VME/struck/sis1100/V2.02/test/sdram_rw_a1.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: 2.6 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
17static int do_write(int p, int start, int size, int* data)
18{
19 off_t pos;
20 int res;
21
22 pos=lseek(p, sizeof(int)*start, SEEK_SET);
23 if (pos==(off_t)-1) {
24 perror("do_write::lseek");
25 return 1;
26 }
27 res=write(p, data, size*sizeof(int));
28 if (res!=size*sizeof(int)) {
29 u_int32_t error;
30 ioctl(p, SIS1100_LAST_ERROR, &error);
31 if (res<0) {
32 fprintf(stderr, "write: %s; error=0x%x\n", strerror(errno), error);
33 } else {
34 fprintf(stderr, "write: res=%d; error=0x%x\n", res, error);
35 }
36 return 1;
37 }
38 return 0;
39}
40
41static int do_read(int p, int start, int size, int* data)
42{
43 off_t pos;
44 int res;
45
46 pos=lseek(p, sizeof(int)*start, SEEK_SET);
47 if (pos==(off_t)-1) {
48 perror("do_read::lseek");
49 return 1;
50 }
51 res=read(p, data, size*sizeof(int));
52 if (res!=size*sizeof(int)) {
53 u_int32_t error;
54 ioctl(p, SIS1100_LAST_ERROR, &error);
55 if (res<0) {
56 fprintf(stderr, "read: %s; error=0x%x\n", strerror(errno), error);
57 } else {
58 fprintf(stderr, "read: res=%d; error=0x%x\n", res, error);
59 }
60 return 1;
61 }
62 return 0;
63}
64
65static void
66set_break(int p, int size)
67{
68 struct vmespace space;
69 int res;
70 space.am=0xb;
71 space.datasize=4;
72 space.swap=1;
73 space.mapit=0;
74 space.mindmalen=size;
75 res=ioctl(p, SETVMESPACE, &space);
76 if (res<0)
77 fprintf(stderr, "ioctl(SETVMESPACE): %s\n", strerror(errno));
78}
79
80int main(int argc, char* argv[])
81{
82 int p, i, *ibuf, *obuf;
83 off_t max;
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=calloc(max, sizeof(int));
105 obuf=calloc(max, sizeof(int));
106 if (!ibuf || !obuf) {
107 perror("calloc");
108 return 1;
109 }
110 for (i=0; i<1000; i++) obuf[i]=i;
111
112 if (do_write(p, 0, 32, obuf)) {
113 printf("write failed\n");
114 return 1;
115 }
116
117 free(obuf);
118 free(ibuf);
119 close(p);
120 return 0;
121}
Note: See TracBrowser for help on using the repository browser.