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

Subversion Repositories sudoku

[/] [sudoku/] [trunk/] [verif/] [tb_search.v] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dsheffie
module tb_search();
2
   reg clk;
3
   reg rst;
4
   reg start;
5
   wire done;
6 4 dsheffie
 
7
   reg [1023:0] puz_filename;
8
   integer      fh;
9
 
10 2 dsheffie
   wire [728:0] outGrid;
11
   wire [728:0] inGrid;
12
 
13
   reg [8:0]     mem [80:0];
14
 
15
 
16
   initial
17
     begin
18
        clk = 0;
19
        rst = 1;
20
 
21 4 dsheffie
        if($value$plusargs("puz=%s", puz_filename))
22
          begin
23
             $readmemh(puz_filename, mem);
24
          end
25
        else
26
          begin
27
             $display("no puzzle filename, use +puz=!");
28
             $finish();
29
          end
30
 
31 2 dsheffie
        #1000
32
          rst = 0;
33
     end
34
 
35
   always@(posedge clk)
36
     begin
37
        if(rst)
38
          start <= 1'b1;
39
        else
40
          start <= start ? 1'b0 : start;
41
     end
42
 
43
   always
44
     clk = #5 !clk;
45
 
46
 
47
 
48
   sudoku_search uut (
49
               // Outputs
50
               .outGrid                 (outGrid[728:0]),
51
               .done                    (done),
52
               .error                   (),
53
               // Inputs
54
               .clk                     (clk),
55
               .rst                     (rst),
56
               .start                   (start),
57
               .inGrid                  (inGrid[728:0])
58
               );
59
 
60 5 dsheffie
   genvar     i;
61
   generate
62
      for(i=0;i<81;i=i+1)
63
        begin: inGridGen
64
           assign inGrid[(9*(i+1)-1):(9*i)] = mem[i];
65
 
66
        end
67
   endgenerate
68
 
69 2 dsheffie
 
70
   reg [31:0] r_cnt;
71
 
72
 
73
   wire [8:0] result [80:0];
74
   wire [8:0] result_dec [80:0];
75
 
76 5 dsheffie
 
77 2 dsheffie
   integer    y,x;
78
 
79
   generate
80
      for(i=0;i<81;i=i+1)
81
        begin: unflatten
82
           assign result[i] = outGrid[(9*(i+1))-1:9*i];
83
           hot2dec h (.hot(result[i]), .dec(result_dec[i]));
84
        end
85
   endgenerate
86
 
87
 
88
   always@(posedge clk)
89
     begin
90
        if(rst)
91
          begin
92
             r_cnt <= 32'd0;
93
          end
94
        else
95
          begin
96
             r_cnt <= start ? 32'd0 : r_cnt + 32'd1;
97
             if(done)
98
               begin
99
                  $write("\n");
100
                  for(y=0;y<9;y=y+1)
101
                    begin
102
                       for(x=0;x<9;x=x+1)
103
                         begin
104
                            $write("%d ", result_dec[y*9+x]);
105
                         end
106
                       $write("\n");
107
                    end
108
                  $display("solved in %d cycles", r_cnt);
109
                  $finish();
110
               end // if (done)
111
          end // else: !if(rst)
112
     end // always@ (posedge clk)
113
 
114
 
115
endmodule // tb_search
116
 
117
 
118
module hot2dec(input [8:0] hot, output [8:0] dec);
119
   assign dec = (hot == 9'd1) ? 9'd1 :
120
                (hot == 9'd2) ? 9'd2 :
121
                (hot == 9'd4) ? 9'd3 :
122
                (hot == 9'd8) ? 9'd4 :
123
                (hot == 9'd16) ? 9'd5 :
124
                (hot == 9'd32) ? 9'd6 :
125
                (hot == 9'd64) ? 9'd7 :
126
                (hot == 9'd128) ? 9'd8 :
127
                (hot == 9'd256) ? 9'd9 :
128
                9'd0;
129
endmodule

powered by: WebSVN 2.1.0

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