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

Subversion Repositories gecko4

[/] [gecko4/] [trunk/] [GECKO4com/] [utils/] [c/] [generate_id_string.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
const unsigned char ID_STR[] = "HUCE-microlab,GECKO4COM,0,1.0";
38
 
39
void to_bin( int value ) {
40
   int mask;
41
 
42
   mask = 1<<4;
43
   while (mask > 0) {
44
      if ((value&mask) != 0)
45
         printf("1");
46
      else
47
         printf("0");
48
      mask >>= 1;
49
   }
50
}
51
 
52
int main() {
53
   int loop,index,len,mask;
54
   unsigned char buffer[32];
55
 
56
   len = strlen(ID_STR);
57
   if (len > 31) {
58
      printf( "ERROR: ID string too long!\n" );
59
      return -1;
60
   }
61
   index = 0;
62
   buffer[index]=len;
63
   for (loop = 0 ; loop < len ; loop++)
64
      buffer[loop+1] = ID_STR[loop];
65
   index = len;
66
   printf( "   done     <= s_done;\n" );
67
   printf( "   push     <= '1' WHEN s_rom_index(5) = '0' ELSE '0';\n" );
68
   printf( "   size_bit <= '1' WHEN s_rom_index = \"000000\" ELSE '0';\n\n " );
69
   printf( "   s_done <= '1' WHEN s_rom_index = \"0");
70
   to_bin(index);
71
   printf( "\" ELSE '0';\n\n" );
72
   printf( "   make_rom_index : PROCESS( clock , start , reset , s_done )\n" );
73
   printf( "   BEGIN\n      IF (clock'event AND (clock = '1')) THEN\n" );
74
   printf( "         IF (reset = '1' OR s_done = '1') THEN \n" );
75
   printf( "            s_rom_index <= (OTHERS => '1');\n" );
76
   printf( "         ELSIF (start = '1') THEN\n" );
77
   printf( "            s_rom_index <= (OTHERS => '0');\n" );
78
   printf( "         ELSEIF (s_rom_index(5) = '0') THEN \n" );
79
   printf( "            s_rom_index <= unsigned(s_rom_index) + 1;\n" );
80
   printf( "         END IF;\n      END IF;\n   END PROCESS make_rom_index;\n\n");
81
   printf( "   make_rom_data : PROCESS( s_rom_index )\n" );
82
   printf( "   BEGIN\n      CASE (s_rom_index) IS\n" );
83
   while (index > -1) {
84
      printf( "         WHEN \"0" );
85
      to_bin(index);
86
      printf( "\" => push_data <= X\"%02X\";\n" , buffer[index--] );
87
   }
88
   printf( "         WHEN OTHERS   => push_data <= X\"00\";\n" );
89
   printf( "      END CASE;\n   END PROCESS make_rom_data;\n" );
90
}

powered by: WebSVN 2.1.0

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