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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [fpga/] [mc/] [src/] [tmr/] [tmr.v] - Blame information for rev 69

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 68 hellwig
//
2
// tmr.v -- programmable timer
3
//
4
 
5
 
6 27 hellwig
module tmr(clk, reset,
7 67 hellwig
           en, wr, addr,
8 27 hellwig
           data_in, data_out,
9
           wt, irq);
10
    input clk;
11
    input reset;
12
    input en;
13
    input wr;
14 69 hellwig
    input [3:2] addr;
15 27 hellwig
    input [31:0] data_in;
16 69 hellwig
    output reg [31:0] data_out;
17 27 hellwig
    output wt;
18
    output irq;
19
 
20
  reg [31:0] counter;
21
  reg [31:0] divisor;
22
  reg divisor_loaded;
23
  reg expired;
24
  reg alarm;
25
  reg ien;
26
 
27
  always @(posedge clk) begin
28
    if (divisor_loaded == 1) begin
29
      counter <= divisor;
30
      expired <= 0;
31
    end else begin
32 69 hellwig
      if (counter == 32'h00000001) begin
33
        counter <= divisor;
34
        expired <= 1;
35 27 hellwig
      end else begin
36 69 hellwig
        counter <= counter - 1;
37 27 hellwig
        expired <= 0;
38
      end
39
    end
40
  end
41
 
42
  always @(posedge clk) begin
43
    if (reset == 1) begin
44
      divisor <= 32'hFFFFFFFF;
45
      divisor_loaded <= 1;
46
      alarm <= 0;
47
      ien <= 0;
48
    end else begin
49
      if (expired == 1) begin
50
        alarm <= 1;
51
      end else begin
52 69 hellwig
        if (en == 1 && wr == 1 && addr[3:2] == 2'b00) begin
53 27 hellwig
          alarm <= data_in[0];
54
          ien <= data_in[1];
55
        end
56 69 hellwig
        if (en == 1 && wr == 1 && addr[3:2] == 2'b01) begin
57 27 hellwig
          divisor <= data_in;
58
          divisor_loaded <= 1;
59
        end else begin
60
          divisor_loaded <= 0;
61
        end
62
      end
63
    end
64
  end
65
 
66 69 hellwig
  always @(*) begin
67
    case (addr[3:2])
68
      2'b00:
69
        // ctrl
70
        data_out = { 28'h0000000, 2'b00, ien, alarm };
71
      2'b01:
72
        // divisor
73
        data_out = divisor;
74
      2'b10:
75
        // counter
76
        data_out = counter;
77
      2'b11:
78
        // not used
79
        data_out = 32'hxxxxxxxx;
80
      default:
81
        data_out = 32'hxxxxxxxx;
82
    endcase
83
  end
84
 
85 27 hellwig
  assign wt = 0;
86
  assign irq = ien & alarm;
87
 
88
endmodule

powered by: WebSVN 2.1.0

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