1 | /*===========================================================================*/
|
---|
2 | /* */
|
---|
3 | /* File: sharc_utils.c */
|
---|
4 | /* */
|
---|
5 | /* OS: LINUX (Kernel >= 2.4.4 */
|
---|
6 | /* */
|
---|
7 | /* Description: */
|
---|
8 | /* */
|
---|
9 | /* Version: 1.0 */
|
---|
10 | /* */
|
---|
11 | /* */
|
---|
12 | /* Generated: 18.12.01 */
|
---|
13 | /* */
|
---|
14 | /* Author: TH */
|
---|
15 | /* */
|
---|
16 | /* Last Change: Installation */
|
---|
17 | /*---------------------------------------------------------------------------*/
|
---|
18 | /* SIS GmbH */
|
---|
19 | /* Harksheider Str. 102A */
|
---|
20 | /* 22399 Hamburg */
|
---|
21 | /* */
|
---|
22 | /* http://www.struck.de */
|
---|
23 | /* */
|
---|
24 | /*===========================================================================*/
|
---|
25 |
|
---|
26 | #define _GNU_SOURCE
|
---|
27 |
|
---|
28 | /*===========================================================================*/
|
---|
29 | /* Headers */
|
---|
30 | /*===========================================================================*/
|
---|
31 | #include <stdio.h>
|
---|
32 | #include <errno.h>
|
---|
33 | #include <string.h>
|
---|
34 | #include <sys/types.h>
|
---|
35 | #include <unistd.h>
|
---|
36 | #include <fcntl.h>
|
---|
37 | #include <sys/mman.h>
|
---|
38 | #include <sys/ioctl.h>
|
---|
39 |
|
---|
40 | /* sis1100/3100 PCI to VME specific */
|
---|
41 | #include "dev/pci/sis1100_var.h" /* pfad im Makefile angeben */
|
---|
42 |
|
---|
43 | #include "sis3100_vme_calls.h"
|
---|
44 |
|
---|
45 | /* SIS9200 DSP */
|
---|
46 | #include "header/sis9200.h"
|
---|
47 |
|
---|
48 |
|
---|
49 |
|
---|
50 | /*===========================================================================*/
|
---|
51 | /* Prototypes */
|
---|
52 | /*===========================================================================*/
|
---|
53 |
|
---|
54 |
|
---|
55 | #include "sharc_utils.h"
|
---|
56 |
|
---|
57 |
|
---|
58 | /*===========================================================================*/
|
---|
59 | /* Load DSP */
|
---|
60 | /*===========================================================================*/
|
---|
61 |
|
---|
62 | int load_dsp(int p, int p_sharc, char* dsppath){
|
---|
63 | int retcode=1;
|
---|
64 | int count=0,loadcount=0;
|
---|
65 | int offset;
|
---|
66 | int currentaddress ;
|
---|
67 | char line_in[128];
|
---|
68 | FILE *loaderfile;
|
---|
69 | unsigned int tempword[0x10000];
|
---|
70 | unsigned int read_tempword[0x10000];
|
---|
71 | u_int32_t data ;
|
---|
72 | u_int32_t addr ;
|
---|
73 |
|
---|
74 | /* Enable Optical Control of SHARC */
|
---|
75 | offset = 0x00000300 ;
|
---|
76 | if ((retcode = s3100_control_write(p, offset, 0x00000800)) != 0) {
|
---|
77 | printf("s3100_control_write: retcode = 0x%08x\n", retcode );
|
---|
78 | return -1;
|
---|
79 | }
|
---|
80 |
|
---|
81 | /* set SHARC in Reset state */
|
---|
82 | offset = 0x00000300 ;
|
---|
83 | if ((retcode = s3100_control_write(p, offset, 0x01000000)) != 0) {
|
---|
84 | printf("s3100_control_write: retcode = 0x%08x\n", retcode );
|
---|
85 | return -1;
|
---|
86 | }
|
---|
87 |
|
---|
88 |
|
---|
89 |
|
---|
90 |
|
---|
91 | loaderfile=fopen(dsppath,"r");
|
---|
92 | retcode = 1 ;
|
---|
93 | if (loaderfile>0) {
|
---|
94 | printf("loader file %s opened\n",dsppath);
|
---|
95 | while (retcode>0) {
|
---|
96 | tempword[count]= strtoul(line_in,NULL,16);
|
---|
97 | retcode=fscanf(loaderfile,"0x%4x\n",&tempword[count]);
|
---|
98 | if (count<0x10000) {
|
---|
99 | count++;
|
---|
100 | }
|
---|
101 | else {
|
---|
102 | printf("load file size too big\n");
|
---|
103 | return -1;
|
---|
104 | }
|
---|
105 | }
|
---|
106 | printf("load file length: %d\n",count);
|
---|
107 |
|
---|
108 | }
|
---|
109 | else {
|
---|
110 | printf("loader file %s not found\n",dsppath);
|
---|
111 | return -1;
|
---|
112 | }
|
---|
113 | fclose(loaderfile);
|
---|
114 |
|
---|
115 | printf("loading SHARC DSP\n");
|
---|
116 |
|
---|
117 | currentaddress=SHARCRAM;
|
---|
118 | printf("currentaddress = 0x%08x\n", currentaddress );
|
---|
119 |
|
---|
120 |
|
---|
121 |
|
---|
122 | loadcount=0 ;
|
---|
123 | while (loadcount<count) {
|
---|
124 | addr = D48REG;
|
---|
125 | data = tempword[loadcount];
|
---|
126 |
|
---|
127 | if ((retcode = s3100_sharc_write(p_sharc, addr, &data, 0x1))!= 4) {
|
---|
128 | printf("s3100_sharc_write: retcode = 0x%08x\n", retcode );
|
---|
129 | return -1;
|
---|
130 | }
|
---|
131 | loadcount++;
|
---|
132 |
|
---|
133 | addr = currentaddress;
|
---|
134 | data = ((tempword[loadcount+1] << 16 ) & 0xFFFF0000) + (tempword[loadcount] & 0x0000FFFF);
|
---|
135 |
|
---|
136 | if ((retcode = s3100_sharc_write(p_sharc, addr, &data, 0x1)) != 4) {
|
---|
137 | printf("s3100_sharc_write: retcode = 0x%08x\n", retcode );
|
---|
138 | return -1;
|
---|
139 | }
|
---|
140 | currentaddress+=4;
|
---|
141 | loadcount+=2;
|
---|
142 | }
|
---|
143 |
|
---|
144 |
|
---|
145 | /* read */
|
---|
146 | currentaddress=SHARCRAM;
|
---|
147 | loadcount=0 ;
|
---|
148 | while (loadcount<count) {
|
---|
149 |
|
---|
150 | addr = currentaddress;
|
---|
151 | if ((retcode = s3100_sharc_read(p_sharc, addr, &data, 0x1))!= 4) {
|
---|
152 | printf("s3100_sharc_read: retcode = 0x%08x\n", retcode );
|
---|
153 | return -1;
|
---|
154 | }
|
---|
155 |
|
---|
156 | read_tempword[loadcount+1] = (data) & 0x0000FFFF ;
|
---|
157 | read_tempword[loadcount+2] = (data >> 16) & 0x0000FFFF ;
|
---|
158 |
|
---|
159 | addr = D48REG;
|
---|
160 | if ((retcode = s3100_sharc_read(p_sharc, addr, &data, 0x1))!= 4) {
|
---|
161 | printf("s3100_sharc_read: retcode = 0x%08x\n", retcode );
|
---|
162 | return -1;
|
---|
163 | }
|
---|
164 | read_tempword[loadcount] = (data) & 0x0000FFFF ;
|
---|
165 | currentaddress+=4;
|
---|
166 | loadcount+=3;
|
---|
167 | }
|
---|
168 |
|
---|
169 | /* verifier */
|
---|
170 | loadcount=0 ;
|
---|
171 | while (loadcount<count) {
|
---|
172 |
|
---|
173 | if (read_tempword[loadcount] != tempword[loadcount]) {
|
---|
174 | printf("Verifier ERROR i = 0x%08x written = 0x%08x read = 0x%08x \n",
|
---|
175 | loadcount, tempword[loadcount], read_tempword[loadcount] );
|
---|
176 | return -1;
|
---|
177 | }
|
---|
178 | loadcount++;
|
---|
179 | }
|
---|
180 |
|
---|
181 |
|
---|
182 |
|
---|
183 |
|
---|
184 |
|
---|
185 |
|
---|
186 | /* start SHARC */
|
---|
187 | printf("starting SHARC DSP\n");
|
---|
188 | offset = 0x00000300 ;
|
---|
189 | if ((retcode = s3100_control_write(p, offset, 0x0100)) != 0) {
|
---|
190 | printf("s3100_control_write: retcode = 0x%08x\n", retcode );
|
---|
191 | return -1;
|
---|
192 | }
|
---|
193 | return 0 ;
|
---|
194 | }
|
---|
195 |
|
---|
196 |
|
---|
197 |
|
---|
198 |
|
---|
199 |
|
---|
200 |
|
---|
201 | /*===========================================================================*/
|
---|
202 | /* reset DSP */
|
---|
203 | /*===========================================================================*/
|
---|
204 | int reset_dsp(int p) {
|
---|
205 | int retcode;
|
---|
206 | int offset;
|
---|
207 | /* Reset SHARC */
|
---|
208 | printf("resetting SHARC DSP\n");
|
---|
209 | offset = 0x00000300 ;
|
---|
210 | /* Enable Optical Control of SHARC */
|
---|
211 | if ((retcode = s3100_control_write(p, offset, 0x00000800)) != 0) {
|
---|
212 | printf("s3100_control_write: retcode = 0x%08x\n", retcode );
|
---|
213 | return -1;
|
---|
214 | }
|
---|
215 |
|
---|
216 | /* set SHARC in Reset state */
|
---|
217 | if ((retcode = s3100_control_write(p, offset, 0x01000000)) != 0) {
|
---|
218 | printf("s3100_control_write: retcode = 0x%08x\n", retcode );
|
---|
219 | return -1;
|
---|
220 | }
|
---|
221 | return 0;
|
---|
222 | }
|
---|
223 |
|
---|
224 |
|
---|
225 |
|
---|
226 |
|
---|
227 |
|
---|
228 |
|
---|
229 |
|
---|
230 |
|
---|
231 |
|
---|
232 |
|
---|
233 |
|
---|
234 |
|
---|
235 |
|
---|
236 |
|
---|
237 |
|
---|
238 |
|
---|
239 |
|
---|
240 |
|
---|
241 |
|
---|
242 |
|
---|
243 |
|
---|
244 |
|
---|
245 |
|
---|
246 |
|
---|
247 |
|
---|
248 |
|
---|
249 |
|
---|
250 |
|
---|