source: drsdaq/VME/struck/sis1100/V2.02/examples/sdram_eeprom/sis3100_sdram_eeprom.c@ 23

Last change on this file since 23 was 22, checked in by ogrimm, 16 years ago
First commit of drsdaq program
  • Property svn:executable set to *
File size: 8.6 KB
Line 
1#include <stdio.h>
2#include <errno.h>
3#include <string.h>
4#include <sys/types.h>
5#include <fcntl.h>
6#include <sys/mman.h>
7#include <sys/ioctl.h>
8
9
10
11#include "../../dev/pci/sis1100_var.h"
12
13#include "../../sis3100_calls/sis3100_vme_calls.h"
14
15
16#define SHARCRAM 0x01200000
17#define D48REG 0x01300000
18
19#define SDRAM_EEPROM_CTRL_STAT 0x40000400
20
21
22#define SDRAM_SCL 0x1
23#define SDRAM_SDA 0x2
24#define SDRAM_SDA_OE 0x4
25
26
27/****************************************************************************/
28
29int sdram_eeprom_stop (int p) ;
30int sdram_eeprom_start (int p) ;
31int sdram_eeprom_write (int p, u_int32_t write_data) ;
32int sdram_eeprom_read (int p, u_int32_t* read_data) ;
33int sdram_eeprom_read_noack (int p, u_int32_t* read_data) ;
34
35/****************************************************************************/
36int main(int argc, char* argv[])
37{
38int i;
39int p_sharc;
40u_int32_t data ;
41u_int32_t addr ;
42
43int no_of_Mbyte ;
44
45/* open SDRAM */
46 if ((p_sharc=open("/tmp/sis1100_00dsp", O_RDWR, 0))<0) {
47 printf("error on sdram open");
48 return -1;
49 }
50
51 addr = SDRAM_EEPROM_CTRL_STAT ;
52
53/* write 0x3100 to address 0x90/0x91 */
54
55 sdram_eeprom_start (p_sharc) ;
56 sdram_eeprom_write (p_sharc, 0xA0) ; /* device Write cmd */
57 sdram_eeprom_write (p_sharc, 0x90) ; /* write address */
58 sdram_eeprom_write (p_sharc, 0x31) ; /* write data */
59 sdram_eeprom_stop (p_sharc) ;
60 usleep(100000) ;
61
62 sdram_eeprom_start (p_sharc) ;
63 sdram_eeprom_write (p_sharc, 0xA0) ; /* device Write cmd */
64 sdram_eeprom_write (p_sharc, 0x91) ; /* write address */
65 sdram_eeprom_write (p_sharc, 0x00) ; /* write data */
66 sdram_eeprom_stop (p_sharc) ;
67 usleep(100000) ;
68
69
70 sdram_eeprom_start (p_sharc) ;
71 sdram_eeprom_write (p_sharc, 0xA0) ; /* device Write cmd */
72 sdram_eeprom_write (p_sharc, 0x00) ; /* write address */
73
74
75 sdram_eeprom_start (p_sharc) ;
76
77 sdram_eeprom_write (p_sharc, 0xA1) ; /* device Read cmd */
78
79 for (i=0;i<20;i++)
80 {
81 printf("i = %4d ", i * 8);
82 sdram_eeprom_read (p_sharc, &data) ;
83 printf(" 0x%02x ", data );
84 sdram_eeprom_read (p_sharc, &data) ;
85 printf(" 0x%02x ", data );
86 sdram_eeprom_read (p_sharc, &data) ;
87 printf(" 0x%02x ", data );
88 sdram_eeprom_read (p_sharc, &data) ;
89 printf(" 0x%02x ", data );
90 sdram_eeprom_read (p_sharc, &data) ;
91 printf(" 0x%02x ", data );
92 sdram_eeprom_read (p_sharc, &data) ;
93 printf(" 0x%02x ", data );
94 sdram_eeprom_read (p_sharc, &data) ;
95 printf(" 0x%02x ", data );
96 sdram_eeprom_read (p_sharc, &data) ;
97 printf(" 0x%02x \n", data );
98
99 }
100
101 sdram_eeprom_read_noack (p_sharc, &data) ;
102 sdram_eeprom_stop (p_sharc) ;
103
104close(p_sharc);
105
106return 0;
107}
108
109
110
111
112
113
114/***************************************************************************************************************/
115/***************************************************************************************************************/
116
117
118int sdram_eeprom_stop (int p)
119{
120 int return_code ;
121 u_int32_t data ;
122 u_int32_t addr ;
123
124 addr = SDRAM_EEPROM_CTRL_STAT;
125
126/* STOP: */
127 data = 0x0 ;
128 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
129
130 data = SDRAM_SDA_OE ;
131 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
132
133 data = SDRAM_SDA_OE + SDRAM_SCL ;
134 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
135
136 data = SDRAM_SDA_OE + SDRAM_SDA + SDRAM_SCL ;
137 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
138
139 data = SDRAM_SDA_OE + SDRAM_SDA ;
140 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
141
142 data = 0x0 ;
143 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
144
145 return 0 ;
146}
147
148
149
150/***************************************************************************************************************/
151/***************************************************************************************************************/
152
153int sdram_eeprom_start (int p)
154{
155 int return_code ;
156 u_int32_t data ;
157 u_int32_t addr ;
158
159 addr = SDRAM_EEPROM_CTRL_STAT ;
160 /* START: */
161 data = 0x0 ;
162 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
163
164 data = SDRAM_SDA_OE + SDRAM_SDA ;
165 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
166
167 data = SDRAM_SDA_OE + SDRAM_SDA + SDRAM_SCL ;
168 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
169
170 data = SDRAM_SDA_OE + SDRAM_SCL ;
171 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
172
173 data = SDRAM_SDA_OE ;
174 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
175
176 data = 0x0 ;
177 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
178
179 return 0 ;
180}
181
182
183
184/***************************************************************************************************************/
185/***************************************************************************************************************/
186
187int sdram_eeprom_write (int p, u_int32_t write_data)
188{
189 int return_code ;
190 u_int32_t data ;
191 u_int32_t help_data ;
192 u_int32_t addr ;
193 int i ;
194
195 for (i=0;i<0x2000;i++)
196 {
197 addr = addr + i ;
198 }
199
200 addr = SDRAM_EEPROM_CTRL_STAT;
201
202 help_data = write_data ;
203
204 for (i=0;i<8;i++)
205 {
206 if ((write_data & 0x80) == 0x80) {
207 data = SDRAM_SDA_OE + SDRAM_SDA ;
208 }
209 else {
210 data = SDRAM_SDA_OE ;
211 }
212 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
213 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
214
215 data = data + SDRAM_SCL ;
216 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
217
218 data = data - SDRAM_SCL ;
219 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
220 write_data = write_data << 1 ;
221 }
222
223 data = 0x0 ;
224 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
225 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
226
227 data = SDRAM_SCL ;
228 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
229 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
230
231 data = 0x0 ;
232 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
233
234 return 0 ;
235}
236
237
238
239
240/***************************************************************************************************************/
241/***************************************************************************************************************/
242
243int sdram_eeprom_read (int p, u_int32_t* read_data)
244{
245 int return_code ;
246 u_int32_t data ;
247 u_int32_t help_data ;
248 u_int32_t addr ;
249 int i ;
250
251 for (i=0;i<0x2000;i++)
252 {
253 addr = addr + i ;
254 }
255
256 addr = SDRAM_EEPROM_CTRL_STAT;
257
258 help_data = 0 ;
259
260 for (i=0;i<8;i++)
261 {
262 data = 0x0 ;
263 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
264 data = SDRAM_SCL ;
265 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
266 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
267
268 return_code = s3100_sharc_read(p, addr, &data, 0x1) ;
269
270 help_data = help_data << 1 ;
271 help_data = help_data + ((data & 0x100) >> 8) ;
272 }
273
274 *read_data = help_data ;
275
276 data = SDRAM_SDA_OE ;
277 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
278 data = SDRAM_SDA_OE + SDRAM_SCL ;
279 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
280 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
281 data = SDRAM_SDA_OE ;
282 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
283
284 data = 0x0 ;
285 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
286
287 return 0 ;
288}
289
290/***************************************************************************************************************/
291/***************************************************************************************************************/
292
293int sdram_eeprom_read_noack (int p, u_int32_t* read_data)
294{
295 int return_code ;
296 u_int32_t data ;
297 u_int32_t help_data ;
298 u_int32_t addr ;
299 int i ;
300
301 for (i=0;i<0x2000;i++)
302 {
303 addr = addr + i ;
304 }
305
306 addr = SDRAM_EEPROM_CTRL_STAT;
307
308 help_data = 0 ;
309
310 for (i=0;i<8;i++)
311 {
312 data = 0x0 ;
313 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
314 data = SDRAM_SCL ;
315 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
316 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
317
318 return_code = s3100_sharc_read(p, addr, &data, 0x1) ;
319 help_data = help_data << 1 ;
320 help_data = help_data + ((data & 0x100) >> 8) ;
321 }
322
323 *read_data = help_data ;
324
325 data = SDRAM_SDA_OE + SDRAM_SDA ;
326 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
327 data = SDRAM_SDA_OE + SDRAM_SDA + SDRAM_SCL ;
328 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
329 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
330 data = SDRAM_SDA_OE + SDRAM_SDA ;
331 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
332 data = 0x0 ;
333 return_code = s3100_sharc_write(p, addr, &data, 0x1) ;
334
335 return 0 ;
336}
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
Note: See TracBrowser for help on using the repository browser.