/[VMELinux]/vmeutils/convert.cpp
ViewVC logotype

Contents of /vmeutils/convert.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Mon Jun 18 14:57:44 2001 UTC (18 years, 9 months ago) by astro
Branch: MAIN
CVS Tags: vmelinux-1_1_2, Linux2_4_x
Changes since 1.1: +4 -1 lines
Changed the device number from 70 to 221 as assigned by the Linux authorities.
1 #pragma hdrstop
2 #include <condefs.h>
3 #include <stdio.h>
4 //---------------------------------------------------------------------------
5 #pragma argsused
6
7
8 /***************************************************************************/
9 /* SRecord Loader for VME6U NOPI board. */
10 /* uses vme word writes and upper byte is 0 for DSP-2101 Boot code. */
11 /* MEMORY Tools for VME Testing of Dual Port Memory */
12 /* */
13 /* 8/5/96 - Michael J. Wyrick Interferometrics, Inc. */
14 /* */
15 /***************************************************************************/
16 // $Id: convert.cpp,v 1.2 2001/06/18 14:57:44 astro Exp $
17 //
18 //
19 #include <stdio.h>
20 #include <malloc.h>
21 #include <string.h>
22
23 #define ERROR 1
24 #define BUFFER_SIZE 4096
25 #define BYT(cp) ((Asc2Hex(cp[0]) << 4) | Asc2Hex(cp[1]))
26
27 static FILE *infile;
28 static char *buffer;
29 static char *goffset;
30
31 int size = 0;
32
33 unsigned char memory[10000];
34
35 /*-------------------------------------------------------------------------*/
36 /* Asc2Hex - convert a two byte ascii string to a byte */
37 /*-------------------------------------------------------------------------*/
38 static char Asc2Hex(char byt)
39 {
40 if ((byt < 0x3A) && (byt > 0x2F))
41 return(byt & 0x0F);
42 if ((byt < 'G') && (byt > '@'))
43 return((byt & 0x0F) + 9);
44 if ((byt < 'g') && (byt > 0x60))
45 return((byt & 0x0F) + 9);
46 return(0xEE); /* Return Error */
47 }
48
49 /*-------------------------------------------------------------------------*/
50 /* ComputeAddr - Get address from S Record */
51 /*-------------------------------------------------------------------------*/
52 static unsigned long ComputeAddr(char *cp, int siz)
53 {
54 unsigned long retval;
55
56 for (retval = 0L; siz > 0; siz--, cp += 2)
57 retval = (retval << 8) | BYT(cp);
58
59 return(retval);
60 }
61
62 /*-------------------------------------------------------------------------*/
63 /* checkwrite - Write a word to memory and read it back to check that it */
64 /* wrote correctly. */
65 /*---------------------------------------------------------------------mjw-*/
66 void checkwrite(unsigned short *a,unsigned char val)
67 {
68 memory[a] = val;
69 size++;
70 }
71
72 /*-------------------------------------------------------------------------*/
73 /* DecodeS1 - Decode and place in memory S1 type records */
74 /* Checks for correct checksum value and will not write if incorrect */
75 /*---------------------------------------------------------------------mjw-*/
76 static void DecodeS1(char *cp)
77 {
78 unsigned short *address, val;
79 unsigned char *datastart, cnt, cntr, chksum;
80 unsigned long addr;
81
82 cnt = BYT(cp) - 3; /* Get Length of Line */
83 chksum = BYT(cp);
84 cp += 2;
85
86 addr = ComputeAddr(cp,2) << 1;
87 printf("Address %X\n",addr);
88 address = (unsigned short *)(addr + (unsigned long) goffset);
89
90 chksum += BYT(cp); /* Checksum 1st address byte */
91 cp += 2;
92 chksum += BYT(cp); /* Checksum 2nd address byte */
93 cp += 2;
94
95 datastart = (unsigned char *)cp; /* Data starts here */
96
97 /* Calc rest of checksum please */
98 for (cntr = 0; cntr <= cnt; cntr++, cp += 2)
99 chksum += BYT(cp);
100
101 /* If checksum not valid, skip this line */
102 if (chksum != (unsigned char) 0xFF) {
103 printf("Checksum failed - Got %X\n",chksum);
104 return;
105 }
106
107 /* Every thing is cool, write data to memory */
108 for (cntr = 0; cntr < cnt; cntr++, datastart+=2, address++) {
109 val = BYT(datastart);
110 checkwrite(address,val);
111 }
112 }
113
114 /*-------------------------------------------------------------------------*/
115 /* dsp_srec */
116 /* int srec(char *filename, char *offset) */
117 /*---------------------------------------------------------------------mjw-*/
118 int dsp_srec(char *filename, char *offset)
119 {
120 char *cp;
121 int flag, pcount;
122 int count = 0;
123 int errcount = 0;
124 int scount[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
125
126 printf("\nLinux DSP-21xx VME Word Write S-record Loader, Ver 0.1\n\n");
127 buffer = (char *)malloc(BUFFER_SIZE);
128 if (buffer == (char *) 0) {
129 printf("\n\nLoad error: unable to get 4096 bytes of memory.\n\n\n");
130 return(ERROR);
131 }
132 infile = fopen(filename, "r");
133 if (infile == (FILE *) 0) {
134 printf("\n\nLoad error: unable to open file [%#X]\n\n\n");
135 free(buffer);
136 return(ERROR);
137 }
138
139 goffset = offset;
140 flag = pcount = 0;
141 while ((fgets(buffer, BUFFER_SIZE, infile) != (char *) 0) && (flag == 0)) {
142 cp = strtok(buffer, " \t\f\n");
143 if (cp == (char *) 0)
144 continue;
145
146 if (cp[0] != 'S') {
147 errcount++;
148 continue;
149 }
150
151 count++;
152 cp++; /* point to the record type */
153 switch (*cp) {
154 case '0': /* optional introduction record. */
155 scount[0]++;
156 break;
157 case '1': /* address count is 2 bytes long */
158 scount[1]++;
159 DecodeS1(++cp);
160 break;
161 case '2': /* address count is 3 bytes long */
162 scount[2]++;
163 break;
164 case '3': /* address is 4 bytes long */
165 scount[3]++;
166 break;
167 case '9': /* End-Of-File record */
168 scount[4]++;
169 flag = 1;
170 break;
171 } /* switch */
172 } /* while */
173
174 fclose(infile);
175 free(buffer);
176 printf("\n%d lines processed\n",count);
177 printf("S0 - %d\nS1 - %d\nS2 - %d\nS3 - %d\nS9 - %d\n\n\n",
178 scount[0], scount[1], scount[2], scount[3], scount[9]);
179 return(count);
180 }
181
182 //-----------------------------------------------------------------------------
183 //
184 //
185 //
186 //-----------------------------------------------------------------------------
187 int main(int argc, char **argv)
188 {
189 if (argc == 3)
190 dsp_srec(argv[1],0); // No offset yet
191 else
192 printf(" usage: upload filename offset\n\n");
193 }
194

  ViewVC Help
Powered by ViewVC 1.2-dev