OpenCores
URL https://opencores.org/ocsvn/gecko4/gecko4/trunk

Subversion Repositories gecko4

[/] [gecko4/] [trunk/] [GECKO4com/] [utils/] [c/] [generate_scpi_table.c] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 ktt1
/******************************************************************************/
2
/*            _   _            __   ____                                      */
3
/*           / / | |          / _| |  __|                                     */
4
/*           | |_| |  _   _  / /   | |_                                       */
5
/*           |  _  | | | | | | |   |  _|                                      */
6
/*           | | | | | |_| | \ \_  | |__                                      */
7
/*           |_| |_| \_____|  \__| |____| microLab                            */
8
/*                                                                            */
9
/*           Bern University of Applied Sciences (BFH)                        */
10
/*           Quellgasse 21                                                    */
11
/*           Room HG 4.33                                                     */
12
/*           2501 Biel/Bienne                                                 */
13
/*           Switzerland                                                      */
14
/*                                                                            */
15
/*           http://www.microlab.ch                                           */
16
/******************************************************************************/
17
/*   GECKO4com
18
 
19
     2010/2011 Dr. Theo Kluter
20
 
21
     This program is free software: you can redistribute it and/or modify
22
     it under the terms of the GNU General Public License as published by
23
     the Free Software Foundation, either version 3 of the License, or
24
     (at your option) any later version.
25
 
26
     This program is distributed in the hope that it will be useful,
27
     but WITHOUT ANY WARRANTY; without even the implied warranty of
28
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
     GNU General Public License for more details.
30
     You should have received a copy of the GNU General Public License
31
     along with these sources.  If not, see <http://www.gnu.org/licenses/>.
32
*/
33
#include <stdio.h>
34
#include <stdlib.h>
35
#include <string.h>
36
 
37
/* IMPORTANT: The below table list the already implemented SCPI commands. You
38
   can add more yourself, but must refrain from:
39
   1) Editing the ID values of the present SCPI commands.
40
   2) Using duplicate ID values or duplicate commands!
41
   3) Using commands longer than 14 chars
42
*/
43
 
44
#define nr_of_known_scpi_commands 36
45
const char *scpi_table[nr_of_known_scpi_commands*2] = {
46
/* ID , command */
47
"2","*CLS",
48
"6","*ESE",
49
"7","*ESE?",
50
"8","*ESR?",
51
"9","*IDN?",
52
"10","*IST?",
53
"11","*OPC",
54
"12","*OPC?",
55
"13","*PUD",
56
"14","*PUD?",
57
"15","*RST",
58
"16","*SRE",
59
"17","*SRE?",
60
"18","*STB?",
61
"20","*TST?",
62
"21","*WAI",
63
"22","BITFLASH",
64
"23","BITFLASH?",
65
"24","BOARD?",
66
"25","CONFIG",
67
"26","ERASE",
68
"27","FIFO",
69
"28","FIFO?",
70
"29","FPGA",
71
"30","FPGA?",
72
"35","HEXSWITCH",
73
"36","HEXSWITCH?",
74
"37","IDENTIFY",
75
"51","TRANS",
76
"58","USERRESET",
77
"59","VGA:BGCOL",
78
"60","VGA:CLEAR",
79
"61","VGA:CURSOR",
80
"62","VGA:CURSOR?",
81
"63","VGA:FGCOL",
82
"64","VGA:PUTSTR"};
83
 
84
typedef struct comand_type {
85
   unsigned char ID;
86
   char *command;
87
} comand_type_t;
88
 
89
unsigned char get_dec( char *str ) {
90
   unsigned int result;
91
   int loop,sort;
92
 
93
   result = 0;
94
   for (loop = 0 ; loop < strlen(str) ; loop++) {
95
      if ((str[loop] >= '0')&&
96
          (str[loop] <= '9')) {
97
         result *= 10;
98
         result += (str[loop]-'0');
99
      } else {
100
         printf("ERROR: invalid ID found!\n" );
101
         return 255;
102
      }
103
   }
104
   if (result > 128) {
105
      printf( "ERROR: Too big ID found!\n" );
106
      return 255;
107
   } else {
108
      return result;
109
   }
110
}
111
 
112
int main() {
113
   comand_type_t *commands[128],*dummy;
114
   unsigned char rom[2048];
115
   int loop,sort,offset;
116
 
117
   if (nr_of_known_scpi_commands > 128) {
118
      printf( "ERROR: Too many SCPI commands defined!\n" );
119
      return -1;
120
   }
121
 
122
   for (loop = 0 ; loop < 128 ; loop++) {
123
      commands[loop] = NULL;
124
   }
125
 
126
   for (loop = 0 ; loop < nr_of_known_scpi_commands ; loop++) {
127
      commands[loop] = (comand_type_t *) malloc( sizeof( comand_type_t ) );
128
      if (commands[loop] == NULL) {
129
         printf( "ERROR: Unable to allocate memory!\n" );
130
         return -1;
131
      }
132
      commands[loop]->ID = get_dec(scpi_table[loop*2]);
133
      if ((strlen(scpi_table[(loop*2)+1]) < 15)&&
134
          (strlen(scpi_table[(loop*2)+1]) > 0)) {
135
         commands[loop]->command = (char*) malloc(
136
               (strlen(scpi_table[(loop*2)+1])+1)*sizeof(char));
137
         if (commands[loop]->command == NULL) {
138
            printf( "ERROR: Unable to allocate memory!\n" );
139
            return -1;
140
         }
141
         strcpy(commands[loop]->command , scpi_table[(loop*2)+1]);
142
         for (sort = 0 ; sort < strlen(commands[loop]->command) ; sort++) {
143
            if ((commands[loop]->command[sort] >= 'a')&&
144
                (commands[loop]->command[sort] <= 'z')) {
145
               commands[loop]->command[sort] -= ('a'-'A');
146
            }
147
         }
148
      } else {
149
         printf("ERROR: Too long SCPI command \"%s\" found!" ,
150
                 scpi_table[(loop*2)+1] );
151
         return -1;
152
      }
153
   }
154
 
155
   for (loop = 0 ; loop < nr_of_known_scpi_commands-1 ; loop++) {
156
      for (sort = loop+1 ; sort < nr_of_known_scpi_commands ; sort++) {
157
         if (commands[loop]->ID == commands[sort]->ID) {
158
            printf( "ERROR: Duplicate ID found!\n" );
159
            return -1;
160
         }
161
         if (strcmp(commands[loop]->command,commands[sort]->command) == 0) {
162
            printf( "ERROR: Duplicate SCPI command found!\n" );
163
            return -1;
164
         }
165
         if (strcmp(commands[loop]->command,commands[sort]->command) > 0) {
166
            dummy = commands[loop];
167
            commands[loop] = commands[sort];
168
            commands[sort] = dummy;
169
         }
170
      }
171
   }
172
   printf( "      -- Command ID <=> Command\n" );
173
   for (loop = 0 ; loop < nr_of_known_scpi_commands ; loop++) {
174
      printf( "      --     0x%02X   <=> \"%s\"\n" , commands[loop]->ID , commands[loop]->command );
175
      offset=loop*16;
176
      sort = 0;
177
      while (sort < strlen(commands[loop]->command)) {
178
         rom[offset+sort] = commands[loop]->command[sort];
179
         sort++;
180
      }
181
      rom[offset+sort] = 0;
182
      sort++;
183
      rom[offset+sort] = commands[loop]->ID;
184
      sort++;
185
      while (sort < 16) {
186
         rom[offset+sort] = 0xFF;
187
         sort++;
188
      }
189
   }
190
   for (loop = nr_of_known_scpi_commands ; loop < 128 ; loop++) {
191
      offset = loop*16;
192
      for (sort = 0 ; sort < 16 ; sort++)
193
         rom[offset+sort] = 0xFE;
194
   }
195
   for (loop = 0 ; loop < 64 ; loop++) {
196
      if (loop == 0) {
197
         printf( "      GENERIC MAP ( INIT_00 => X\"" );
198
      } else {
199
         printf( "                    INIT_%02X => X\"" , loop );
200
      }
201
      for (sort = 31 ; sort > -1 ; sort--) {
202
         printf("%02X",rom[loop*32+sort] );
203
      }
204
      if (loop != 63) {
205
         printf( "\",\n" );
206
      } else {
207
         printf( "\")\n" );
208
      }
209
   }
210
   return 0;
211
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.