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

Subversion Repositories bubblesortmodule

[/] [bubblesortmodule/] [trunk/] [rtl/] [verilog/] [bublesort.v] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 avramionut
//////////////////////////////////////////////////////////////////////
2
////
3
//// Copyright (C) 2014 avram ionut, avramionut@opencores.org
4
////
5
//// This source file may be used and distributed without
6
//// restriction provided that this copyright statement is not
7
//// removed from the file and that any derivative work contains
8
//// the original copyright notice and the associated disclaimer.
9
////
10
//// This source file is free software; you can redistribute it
11
//// and/or modify it under the terms of the GNU Lesser General
12
//// Public License as published by the Free Software Foundation;
13
//// either version 2.1 of the License, or (at your option) any
14
//// later version.
15
////
16
//// This source is distributed in the hope that it will be
17
//// useful, but WITHOUT ANY WARRANTY; without even the implied
18
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19
//// PURPOSE. See the GNU Lesser General Public License for more
20
//// details.
21
////
22
//// You should have received a copy of the GNU Lesser General
23
//// Public License along with this source; if not, download it
24
//// from http://www.opencores.org/lgpl.shtml
25
////
26
//
27
// Revisions: 
28
// Revision 0.01 - File Created
29
// Additional Comments: 
30
//                     Probably the best sorting module in the world.
31
//
32
//////////////////////////////////////////////////////////////////////////////////
33
module bublesort #(parameter N_BITS = 8, parameter K_NUMBERS =49)
34
    (
35
    input   clk,
36
    input   rst,
37
    input   [K_NUMBERS-1:0] load_i,
38
    input   [K_NUMBERS*N_BITS-1:0] writedata_i,
39
    output  [K_NUMBERS*N_BITS-1:0] readdata_o,
40
    input   start_i,
41
    output  done_o,
42
    output  interrupt_o,
43
    input   abort_i
44
    );
45
 
46
    genvar     i;
47
 
48
    reg [0:1]   r_value_66;
49
    reg [0:1]   r_run_late_66;
50
 
51
    wire w_runback;
52
    wire w_swapback;
53
    wire w_done;
54
    wire w_interrupt;
55
    wire [K_NUMBERS+1:0]    w_run_up;
56
    wire [K_NUMBERS:0]      w_swap_up;
57
    wire [K_NUMBERS:0]      w_bit_up;
58
    wire [K_NUMBERS:0]      w_value_down;
59
 
60
    rungenerator #(.N_BITS(N_BITS))
61
    run_module (
62
        .clk(clk),
63
        .rst(rst),
64
        .start_i(start_i),
65
        .all_sorted_i(w_done),
66
        .run_o(w_run)
67
    );
68
 
69
    intgenerator #(.N_BITS(N_BITS),.K_NUMBERS(K_NUMBERS))
70
    interrupt_module (
71
        .clk(clk),
72
        .rst(rst),
73
        .run_i(w_runback),
74
        .swap_i(w_swapback),
75
        .done_o(w_done),
76
        .interrupt_o(w_interrupt)
77
    );
78
 
79
generate
80
    for (i=0; i < K_NUMBERS; i=i+1) begin : STAGEN
81
        stageen #(.N_BITS(N_BITS))
82
        stage (
83
            .clk(clk),
84
            .load(load_i[i]),
85
            .data_i(writedata_i[(i+1)*N_BITS-1:(i+0)*N_BITS]),
86
            .data_o(readdata_o[(i+1)*N_BITS-1:(i+0)*N_BITS]),
87
            .swap_i(w_swap_up[i]),
88
            .swap_o(w_swap_up[i+1]),
89
            .run_i(w_run_up[i]),
90
            .run_late_i(w_run_up[i+2]),
91
            .run_o(w_run_up[i+1]),
92
            .bit_i(w_bit_up[i]),
93
            .bit_o(w_bit_up[i+1]),
94
            .value_i(w_value_down[i+1]),
95
            .value_o(w_value_down[i])
96
        );
97
    end
98
endgenerate
99
 
100
    always @(posedge clk)
101
        begin
102
            r_value_66[0] <= w_bit_up[K_NUMBERS];
103
            r_value_66[1] <= r_value_66[0];
104
        end
105
 
106
    always @(posedge clk)
107
        begin
108
            r_run_late_66[0] <= w_runback;
109
            r_run_late_66[1] <= r_run_late_66[0];
110
        end
111
 
112
    assign w_value_down[K_NUMBERS] = r_value_66[1];
113
    assign w_run_up[K_NUMBERS+1] = r_run_late_66[1];
114
    assign w_swap_up[0] = 1'b0;
115
    assign w_bit_up[0] = 1'b0;
116
    assign w_runback = w_run_up[K_NUMBERS];
117
    assign w_run_up[0] = w_run;
118
    assign w_swapback = w_swap_up[K_NUMBERS];
119
 
120
    assign done_o = w_done;
121
    assign interrupt_o = w_interrupt;
122
 
123
endmodule

powered by: WebSVN 2.1.0

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