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

Subversion Repositories tv80

[/] [tv80/] [trunk/] [rtl/] [app_localcfg/] [lcfg_cfgo_driver.v] - Blame information for rev 116

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

Line No. Rev Author Line
1 101 ghutchis
/* Copyright (c) 2011, Guy Hutchison
2
   All rights reserved.
3
 
4
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
 
6
    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
    * Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9
 
10
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11
*/
12
 
13
module lcfg_cfgo_driver
14
  (/*AUTOARG*/
15
  // Outputs
16
  cd_rdata, cfgo_wait_n, cfgo_irdy, cfgo_addr, cfgo_write,
17
  cfgo_wr_data,
18
  // Inputs
19 109 ghutchis
  clk, reset_n, addr, cd_wdata, rd_n, wr_n, iorq_n, cfgo_trdy,
20 101 ghutchis
  cfgo_rd_data
21
  );
22
 
23
  parameter io_base_addr = 0;
24
  input          clk;
25
  input          reset_n;
26
 
27
  // TV80 processor interface
28
  input [15:0]   addr;
29
  output [7:0]   cd_rdata;
30
  input [7:0]    cd_wdata;
31
 
32
  input          rd_n, wr_n;
33
  input          iorq_n;
34
  output         cfgo_wait_n;
35
 
36
  // outgoing config interface to system
37
  // configuration bus
38
  output         cfgo_irdy;
39
  input          cfgo_trdy;
40
  output [15:0]  cfgo_addr;
41
  output         cfgo_write;
42
  output [31:0]  cfgo_wr_data;
43
  input [31:0]   cfgo_rd_data;
44
 
45
  wire           rf_irdy;
46
  wire           rf_write;
47
  /*AUTOWIRE*/
48
  // Beginning of automatic wires (for undeclared instantiated-module outputs)
49
  wire [7:0]            cfg_addr0;              // From cfgo_regs of lcfg_cfgo_regs.v
50
  wire [7:0]            cfg_addr1;              // From cfgo_regs of lcfg_cfgo_regs.v
51
  wire [7:0]            cfg_data0_wr_data;      // From cfgo_regs of lcfg_cfgo_regs.v
52
  wire [7:0]            cfg_data1_wr_data;      // From cfgo_regs of lcfg_cfgo_regs.v
53
  wire [7:0]            cfg_data2_wr_data;      // From cfgo_regs of lcfg_cfgo_regs.v
54
  wire [7:0]            cfg_data3_wr_data;      // From cfgo_regs of lcfg_cfgo_regs.v
55
  wire [3:0]            rd_stb;                 // From cfgo_regs of lcfg_cfgo_regs.v, ...
56
  wire [3:0]            wr_stb;                 // From cfgo_regs of lcfg_cfgo_regs.v, ...
57
  // End of automatics
58
 
59
  parameter s_idle = 0, s_write = 1, s_read = 2, s_ack = 3;
60
 
61
  reg [31:0]     chold, nxt_chold;
62
  reg [3:0]      state, nxt_state;
63
 
64 109 ghutchis
  assign rf_irdy = !iorq_n & ((addr[7:0] & 8'hF8) == io_base_addr);
65 101 ghutchis
  assign rf_write = ~wr_n;
66
  assign cfgo_addr = { cfg_addr1, cfg_addr0 };
67
  assign cfgo_wr_data = chold;
68
  assign cfgo_irdy = state[s_write] | state[s_read];
69
  assign cfgo_write = state[s_write];
70
 
71
  always @*
72
    begin
73
      nxt_chold = chold;
74
      nxt_state = state;
75
 
76 105 ghutchis
      case (1'b1) /* verilator lint_off CASEINCOMPLETE */
77 101 ghutchis
        state[s_idle] :
78
          begin
79
            case (wr_stb)
80
              4'b0001 : nxt_chold[7:0] = cfg_data0_wr_data;
81
              4'b0010 : nxt_chold[15:8] = cfg_data1_wr_data;
82
              4'b0100 : nxt_chold[23:16] = cfg_data2_wr_data;
83
              4'b1000 : nxt_chold[31:24] = cfg_data3_wr_data;
84
            endcase // case (wr_stb)
85
 
86
            if (rd_stb[0])
87
              nxt_state = 1 << s_read;
88
            else if (wr_stb[3])
89
              nxt_state = 1 << s_write;
90
          end // case: state[s_idle]
91
 
92
        state[s_write] :
93
          begin
94
            if (cfgo_trdy)
95
              nxt_state = 1 << s_idle;
96
          end
97
 
98
        state[s_read] :
99
          begin
100
            if (cfgo_trdy)
101
              begin
102
                nxt_state = 1 << s_ack;
103
                nxt_chold = cfgo_rd_data;
104
              end
105
          end
106
 
107
        state[s_ack] :
108
          begin
109
            nxt_state = 1 << s_idle;
110
          end
111 105 ghutchis
      endcase // verilator lint_on CASEINCOMPLETE
112 101 ghutchis
    end // always @ *
113 105 ghutchis
 
114
  always @(posedge clk or negedge reset_n)
115
    begin
116
      if (~reset_n)
117
        begin
118
          state <= 1 << s_idle;
119
          chold <= 0;
120
        end
121
      else
122
        begin
123
          state <= nxt_state;
124
          chold <= nxt_chold;
125
        end
126
    end
127 101 ghutchis
 
128
/* lcfg_cfgo_regs AUTO_TEMPLATE
129
 (
130
     .rf_trdy                           (cfgo_wait_n),
131
     .rf_rd_data                        (cd_rdata[]),
132
     .rf_addr                           (addr[]),
133
     .rf_wr_data                        (cd_wdata[]),
134
     .cfg_data\([0-3]\)_rd_data         (chold[@"(+ (* 8 @) 7)":@"(* 8 @)"]),
135
     .cfg_data0_rd_data (chold[7:0]),
136
     .cfg_data1_rd_data (chold[15:8]),
137
     .cfg_data2_rd_data (chold[23:16]),
138
     .cfg_data3_rd_data (chold[31:24]),
139
     .cfg_data0_rd_ack                  (state[s_ack]),
140 105 ghutchis
     .cfg_status                        ({4'h0, state}),
141 101 ghutchis
     .cfg_data[1-3]_rd_ack              (1'b1),
142
     .cfg_data[0-3]_wr_ack              (state[s_idle]),
143
     .cfg_data\([0-3]\)_wr_stb          (wr_stb[\1]),
144
     .cfg_data\([0-3]\)_rd_stb          (rd_stb[\1]),
145 103 ghutchis
     .cfg_status ({4'h0,state}),
146 101 ghutchis
 );
147
 */
148
  lcfg_cfgo_regs cfgo_regs
149
    (/*AUTOINST*/
150
     // Outputs
151
     .rf_trdy                           (cfgo_wait_n),           // Templated
152
     .rf_rd_data                        (cd_rdata[7:0]),         // Templated
153
     .cfg_addr0                         (cfg_addr0[7:0]),
154
     .cfg_addr1                         (cfg_addr1[7:0]),
155
     .cfg_data0_wr_stb                  (wr_stb[0]),             // Templated
156
     .cfg_data0_rd_stb                  (rd_stb[0]),             // Templated
157
     .cfg_data0_wr_data                 (cfg_data0_wr_data[7:0]),
158
     .cfg_data1_wr_stb                  (wr_stb[1]),             // Templated
159
     .cfg_data1_rd_stb                  (rd_stb[1]),             // Templated
160
     .cfg_data1_wr_data                 (cfg_data1_wr_data[7:0]),
161
     .cfg_data2_wr_stb                  (wr_stb[2]),             // Templated
162
     .cfg_data2_rd_stb                  (rd_stb[2]),             // Templated
163
     .cfg_data2_wr_data                 (cfg_data2_wr_data[7:0]),
164
     .cfg_data3_wr_stb                  (wr_stb[3]),             // Templated
165
     .cfg_data3_rd_stb                  (rd_stb[3]),             // Templated
166
     .cfg_data3_wr_data                 (cfg_data3_wr_data[7:0]),
167
     // Inputs
168
     .clk                               (clk),
169
     .reset_n                           (reset_n),
170
     .rf_irdy                           (rf_irdy),
171
     .rf_write                          (rf_write),
172
     .rf_addr                           (addr[3:0]),             // Templated
173
     .rf_wr_data                        (cd_wdata[7:0]),         // Templated
174
     .cfg_data0_rd_data                 (chold[7:0]),            // Templated
175
     .cfg_data0_rd_ack                  (state[s_ack]),          // Templated
176
     .cfg_data0_wr_ack                  (state[s_idle]),         // Templated
177
     .cfg_data1_rd_data                 (chold[15:8]),           // Templated
178
     .cfg_data1_rd_ack                  (1'b1),                  // Templated
179
     .cfg_data1_wr_ack                  (state[s_idle]),         // Templated
180
     .cfg_data2_rd_data                 (chold[23:16]),          // Templated
181
     .cfg_data2_rd_ack                  (1'b1),                  // Templated
182
     .cfg_data2_wr_ack                  (state[s_idle]),         // Templated
183
     .cfg_data3_rd_data                 (chold[31:24]),          // Templated
184
     .cfg_data3_rd_ack                  (1'b1),                  // Templated
185
     .cfg_data3_wr_ack                  (state[s_idle]),         // Templated
186 109 ghutchis
     .cfg_status                        ({4'h0,state}));          // Templated
187 105 ghutchis
endmodule

powered by: WebSVN 2.1.0

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