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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [boards/] [actel/] [ordb1a3pe1500/] [rtl/] [verilog/] [sdc_controller/] [sdc_controller.v] - Blame information for rev 544

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 544 julius
`include "sd_defines.v"
2
//////////////////////////////////////////////////////////////////////
3
////                                                              ////
4
////  sd_controller.v                                             ////
5
////                                                              ////
6
////  This file is part of the SD Card IP core project            ////
7
////  http://www.opencores.org/?do=project&who=sdcard_mass_storage_controller  ////
8
////                                                              ////
9
////  Author(s):                                                  ////
10
////      - Adam Edvardsson (adam.edvardsson@orsoc.se)            ////
11
////                                                              ////
12
////                                                              ////
13
//////////////////////////////////////////////////////////////////////
14
////                                                              ////
15
//// Copyright (C) 2009 Authors                                   ////
16
////                                                              ////
17
//// This source file may be used and distributed without         ////
18
//// restriction provided that this copyright statement is not    ////
19
//// removed from the file and that any derivative work contains  ////
20
//// the original copyright notice and the associated disclaimer. ////
21
////                                                              ////
22
//// This source file is free software; you can redistribute it   ////
23
//// and/or modify it under the terms of the GNU Lesser General   ////
24
//// Public License as published by the Free Software Foundation; ////
25
//// either version 2.1 of the License, or (at your option) any   ////
26
//// later version.                                               ////
27
////                                                              ////
28
//// This source is distributed in the hope that it will be       ////
29
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
30
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
31
//// PURPOSE.  See the GNU Lesser General Public License for more ////
32
//// details.                                                     ////
33
////                                                              ////
34
//// You should have received a copy of the GNU Lesser General    ////
35
//// Public License along with this source; if not, download it   ////
36
//// from http://www.opencores.org/lgpl.shtml                     ////
37
////                                                              ////
38
//////////////////////////////////////////////////////////////////////
39
 
40
 
41
 
42
 
43
module sdc_controller
44
  (
45
 
46
   // WISHBONE common
47
   wb_clk_i, wb_rst_i, wb_dat_i, wb_dat_o,
48
 
49
   // WISHBONE slave
50
   wb_adr_i, wb_sel_i, wb_we_i, wb_cyc_i, wb_stb_i, wb_ack_o,
51
 
52
   // WISHBONE master
53
   m_wb_adr_o, m_wb_sel_o, m_wb_we_o,
54
   m_wb_dat_o, m_wb_dat_i, m_wb_cyc_o,
55
   m_wb_stb_o, m_wb_ack_i,
56
   m_wb_cti_o, m_wb_bte_o,
57
   //SD BUS
58
 
59
   sd_cmd_dat_i,sd_cmd_out_o,  sd_cmd_oe_o, card_detect,
60
   sd_dat_dat_i, sd_dat_out_o , sd_dat_oe_o, sd_clk_o_pad
61
 
62
   ,sd_clk_i_pad
63
 
64
   ,int_a, int_b, int_c
65
 
66
   );
67
 
68
 
69
 
70
   // WISHBONE common
71
   input           wb_clk_i;     // WISHBONE clock
72
   input           wb_rst_i;     // WISHBONE reset
73
   input [31:0]    wb_dat_i;     // WISHBONE data input
74
   output [31:0]   wb_dat_o;     // WISHBONE data output
75
   // WISHBONE error output
76
   input           card_detect;
77
   // WISHBONE slave
78
   input [7:0]      wb_adr_i;     // WISHBONE address input
79
   input [3:0]      wb_sel_i;     // WISHBONE byte select input
80
   input           wb_we_i;      // WISHBONE write enable input
81
   input           wb_cyc_i;     // WISHBONE cycle input
82
   input           wb_stb_i;     // WISHBONE strobe input
83
 
84
   output          wb_ack_o;     // WISHBONE acknowledge output
85
 
86
   // WISHBONE master
87
   output [31:0]   m_wb_adr_o;
88
   output [3:0]    m_wb_sel_o;
89
   output          m_wb_we_o;
90
 
91
   input [31:0]    m_wb_dat_i;
92
   output [31:0]   m_wb_dat_o;
93
   output          m_wb_cyc_o;
94
   output          m_wb_stb_o;
95
   input           m_wb_ack_i;
96
   output [2:0]    m_wb_cti_o;
97
   output [1:0]    m_wb_bte_o;
98
   //SD port
99
 
100
   input  wire [3:0] sd_dat_dat_i;   //Data in from SDcard
101
   output wire [3:0] sd_dat_out_o; //Data out to SDcard
102
   output wire       sd_dat_oe_o; //SD Card tristate Data Output enable (Connects on the SoC TopLevel)
103
 
104
   input  wire       sd_cmd_dat_i; //Command in from SDcard
105
   output wire       sd_cmd_out_o; //Command out to SDcard
106
   output wire       sd_cmd_oe_o; //SD Card tristate CMD Output enable (Connects on the SoC TopLevel)
107
   output            sd_clk_o_pad;
108
 
109
   input wire        sd_clk_i_pad;
110
 
111
   //IRQ
112
   output            int_a, int_b, int_c ;
113
 
114
 
115
   wire              int_busy;
116
 
117
 
118
 
119
   //Wires from SD_CMD_MASTER Module 
120
   wire [15:0]        status_reg_w;
121
   wire [31:0]        cmd_resp_1_w;
122
   wire [15:0]        normal_int_status_reg_w;
123
   wire [4:0]         error_int_status_reg_w;
124
 
125
 
126
   wire [31:0]        argument_reg;
127
   wire [15:0]        cmd_setting_reg;
128
   reg [15:0]         status_reg;
129
   reg [31:0]         cmd_resp_1;
130
   wire [7:0]         software_reset_reg;
131
   wire [15:0]        time_out_reg;
132
   reg [15:0]         normal_int_status_reg;
133
   reg [15:0]         error_int_status_reg;
134
   wire [15:0]        normal_int_signal_enable_reg;
135
   wire [15:0]        error_int_signal_enable_reg;
136
   wire [7:0]         clock_divider;
137
   reg [15:0]         Bd_Status_reg;
138
   reg [7:0]          Bd_isr_reg;
139
   wire [7:0]         Bd_isr_enable_reg;
140
 
141
 
142
   //Rx Buffer  Descriptor internal signals
143
 
144
 
145
 
146
   wire [`BD_WIDTH-1 :0] free_bd_rx_bd; //NO free Rx_bd
147
   wire                  new_rx_bd;  // New Bd writen
148
   wire [`RAM_MEM_WIDTH-1:0] dat_out_s_rx_bd; //Data out from Rx_bd to Slave
149
 
150
   //Tx Buffer Descriptor internal signals
151
   wire [`RAM_MEM_WIDTH-1:0] dat_in_m_rx_bd; //Data in to Rx_bd from Master
152
   wire [`RAM_MEM_WIDTH-1:0] dat_in_m_tx_bd;
153
   wire [`BD_WIDTH-1 :0]     free_bd_tx_bd;
154
   wire                      new_tx_bd;
155
   wire [`RAM_MEM_WIDTH-1:0] dat_out_s_tx_bd;
156
   wire [7:0]                 bd_int_st_w; //Wire to BD status register
157
 
158
   //Wires for connecting Bd registers with the SD_Data_master module
159
   wire                      re_s_tx_bd_w;
160
   wire                      a_cmp_tx_bd_w;
161
   wire                      re_s_rx_bd_w;
162
   wire                      a_cmp_rx_bd_w;
163
   wire                      write_req_s; //SD_Data_master want acces to the CMD line.
164
   wire                      cmd_busy; //CMD line busy no access granted
165
 
166
   wire [31:0]                cmd_arg_s; //SD_Data_master CMD Argument
167
   wire [15:0]                cmd_set_s; //SD_Data_master Settings Argument
168
   wire [31:0]                sys_adr; //System addres the DMA whil Read/Write to/from
169
   wire [1:0]                 start_dat_t; //Start data transfer
170
 
171
   //Signals to Syncronize busy signaling betwen Wishbone access and SD_Data_master access to the CMD line (Also manage the status reg uppdate)
172
 
173
   assign cmd_busy = int_busy | status_reg[0];
174
   wire                      status_reg_busy;
175
 
176
 
177
   //Wires from SD_DATA_SERIAL_HOST_1 to the FIFO
178
   wire [`SD_BUS_W -1 : 0 ]  data_in_rx_fifo;
179
   wire [31: 0 ]              data_out_tx_fifo;
180
   wire [31:0]                m_wb_dat_o_rx;
181
   wire [3:0]                 m_wb_sel_o_tx;
182
   wire [31:0]                m_wb_adr_o_tx;
183
   wire [31:0]                m_wb_adr_o_rx;
184
 
185
   //SD clock 
186
   wire                      sd_clk_i; //Sd_clk provided to the system
187
   wire                      sd_clk_o; //Sd_clk used in the system
188
 
189
   wire [2:0]                 m_wb_cti_o_rx;
190
   wire [2:0]                 m_wb_cti_o_tx;
191
   wire [1:0]                 m_wb_bte_o_rx;
192
   wire [1:0]                 m_wb_bte_o_tx;
193
 
194
 
195
 
196
 
197
   //sd_clk_o to be used i set here
198
`ifdef SDC_CLK_BUS_CLK
199
   assign sd_clk_i = wb_clk_i;
200
`endif
201
`ifdef SDC_CLK_SEP
202
   assign sd_clk_i = sd_clk_i_pad;
203
`endif
204
 
205
`ifdef SDC_CLK_STATIC
206
   assign sd_clk_o = sd_clk_i;
207
`endif
208
 
209
`ifdef SDC_CLK_DYNAMIC
210
   sd_clock_divider clock_divider_1
211
     (
212
      .CLK (sd_clk_i),
213
      .DIVIDER (clock_divider),
214
      .RST  (wb_rst_i | software_reset_reg[0]),
215
      .SD_CLK  (sd_clk_o)
216
      );
217
`endif
218
   assign sd_clk_o_pad  = sd_clk_o ;
219
 
220
   wire [15:0]                settings;
221
   wire [7:0]                 serial_status;
222
   wire [39:0]                cmd_out_master;
223
   wire [39:0]                cmd_in_host;
224
 
225
   sd_cmd_master cmd_master_1
226
     (
227
      .CLK_PAD_IO     (wb_clk_i),
228
      .RST_PAD_I      (wb_rst_i | software_reset_reg[0]),
229
      .New_CMD        (new_cmd),
230
      .data_write     (d_write),
231
      .data_read      (d_read),
232
      .ARG_REG        (argument_reg),
233
      .CMD_SET_REG    (cmd_setting_reg[13:0]),
234
      .STATUS_REG     (status_reg_w),
235
      .TIMEOUT_REG    (time_out_reg),
236
      .RESP_1_REG     (cmd_resp_1_w),
237
      .ERR_INT_REG    (error_int_status_reg_w),
238
      .NORMAL_INT_REG (normal_int_status_reg_w),
239
      .ERR_INT_RST    (error_isr_reset),
240
      .NORMAL_INT_RST (normal_isr_reset),
241
      .settings       (settings),
242
      .go_idle_o      (go_idle),
243
      .cmd_out        (cmd_out_master ),
244
      .req_out        (req_out_master ),
245
      .ack_out        (ack_out_master ),
246
      .req_in         (req_in_host),
247
      .ack_in         (ack_in_host),
248
      .cmd_in         (cmd_in_host),
249
      .serial_status (serial_status),
250
      .card_detect (card_detect)
251
 
252
      );
253
 
254
 
255
   sd_cmd_serial_host cmd_serial_host_1
256
     (
257
      .SD_CLK_IN  (sd_clk_o),
258
      .RST_IN     (wb_rst_i | software_reset_reg[0] | go_idle),
259
      .SETTING_IN (settings),
260
      .CMD_IN     (cmd_out_master),
261
      .REQ_IN     (req_out_master),
262
      .ACK_IN     (ack_out_master),
263
      .REQ_OUT    (req_in_host),
264
      .ACK_OUT    (ack_in_host),
265
      .CMD_OUT    (cmd_in_host),
266
      .STATUS     (serial_status),
267
      .cmd_dat_i  (sd_cmd_dat_i),
268
      .cmd_out_o  (sd_cmd_out_o),
269
      .cmd_oe_o   ( sd_cmd_oe_o),
270
      .st_dat_t   (start_dat_t)
271
      );
272
 
273
 
274
   sd_data_master data_master_1
275
     (
276
      .clk            (wb_clk_i),
277
      .rst            (wb_rst_i | software_reset_reg[0]),
278
      .dat_in_tx      (dat_out_s_tx_bd),
279
      .free_tx_bd     (free_bd_tx_bd),
280
      .ack_i_s_tx     (ack_o_s_tx ),
281
      .re_s_tx        (re_s_tx_bd_w),
282
      .a_cmp_tx       (a_cmp_tx_bd_w),
283
      .dat_in_rx      (dat_out_s_rx_bd),
284
      .free_rx_bd     (free_bd_rx_bd),
285
      .ack_i_s_rx     (ack_o_s_rx),
286
      .re_s_rx        (re_s_rx_bd_w),
287
      .a_cmp_rx       (a_cmp_rx_bd_w),
288
      .cmd_busy       (cmd_busy),
289
      .we_req         (write_req_s),
290
      .we_ack         (we_ack),
291
      .d_write        (d_write),
292
      .d_read         (d_read),
293
      .cmd_arg        (cmd_arg_s),
294
      .cmd_set        (cmd_set_s),
295
      .cmd_tsf_err    (normal_int_status_reg[15]) ,
296
      .card_status    (cmd_resp_1[12:8])   ,
297
      .start_tx_fifo  (start_tx_fifo),
298
      .start_rx_fifo  (start_rx_fifo),
299
      .sys_adr        (sys_adr),
300
      .tx_empt        (tx_e ),
301
      .tx_full        (tx_f ),
302
      .rx_full        (full_rx ),
303
      .busy_n         (busy_n),
304
      .transm_complete(trans_complete ),
305
      .crc_ok         (crc_ok),
306
      .ack_transfer   (ack_transfer),
307
      .Dat_Int_Status (bd_int_st_w),
308
      .Dat_Int_Status_rst (Bd_isr_reset),
309
      .CIDAT           (cidat_w),
310
      .transfer_type  (cmd_setting_reg[15:14])
311
      );
312
 
313
   sd_data_serial_host sd_data_serial_host_1
314
     (
315
      .sd_clk         (sd_clk_o),
316
      .rst            (wb_rst_i | software_reset_reg[0]),
317
      .data_in        (data_out_tx_fifo),
318
      .rd             (rd),
319
      .data_out       (data_in_rx_fifo),
320
      .we             (we_rx),
321
      .DAT_oe_o       (sd_dat_oe_o),
322
      .DAT_dat_o      (sd_dat_out_o),
323
      .DAT_dat_i      (sd_dat_dat_i),
324
      .start_dat      (start_dat_t),
325
      .ack_transfer   (ack_transfer),
326
      .busy_n         (busy_n),
327
      .transm_complete(trans_complete ),
328
      .crc_ok         (crc_ok)
329
      );
330
 
331
 
332
   sd_bd rx_bd
333
     (
334
      .clk        (wb_clk_i),
335
      .rst       (wb_rst_i | software_reset_reg[0]),
336
      .we_m      (we_m_rx_bd),
337
      .dat_in_m  (dat_in_m_rx_bd),
338
      .free_bd   (free_bd_rx_bd),
339
      .re_s      (re_s_rx_bd_w),
340
      .ack_o_s   (ack_o_s_rx),
341
      .a_cmp     (a_cmp_rx_bd_w),
342
      .dat_out_s (dat_out_s_rx_bd)
343
 
344
      );
345
 
346
   sd_bd tx_bd
347
     (
348
      .clk       (wb_clk_i),
349
      .rst       (wb_rst_i | software_reset_reg[0]),
350
      .we_m      (we_m_tx_bd),
351
      .dat_in_m  (dat_in_m_tx_bd),
352
      .free_bd   (free_bd_tx_bd),
353
      .ack_o_s   (ack_o_s_tx),
354
      .re_s      (re_s_tx_bd_w),
355
      .a_cmp     (a_cmp_tx_bd_w),
356
      .dat_out_s (dat_out_s_tx_bd)
357
      );
358
 
359
 
360
   sd_fifo_tx_filler fifo_filer_tx
361
     (
362
      .clk        (wb_clk_i),
363
      .rst        (wb_rst_i | software_reset_reg[0]),
364
      .m_wb_adr_o (m_wb_adr_o_tx),
365
      .m_wb_we_o  (m_wb_we_o_tx),
366
      .m_wb_dat_i (m_wb_dat_i),
367
      .m_wb_cyc_o (m_wb_cyc_o_tx),
368
      .m_wb_stb_o (m_wb_stb_o_tx),
369
      .m_wb_ack_i (m_wb_ack_i),
370
      .m_wb_cti_o (m_wb_cti_o_tx),
371
      .m_wb_bte_o (m_wb_bte_o_tx),
372
      .en         (start_tx_fifo),
373
      .adr        (sys_adr),
374
      .sd_clk     (sd_clk_o),
375
      .dat_o      (data_out_tx_fifo   ),
376
      .rd         (rd),
377
      .empty      (tx_e),
378
      .fe         (tx_f)
379
      );
380
 
381
   sd_fifo_rx_filler fifo_filer_rx
382
     (
383
      .clk        (wb_clk_i),
384
      .rst        (wb_rst_i | software_reset_reg[0]),
385
      .m_wb_adr_o (m_wb_adr_o_rx),
386
      .m_wb_we_o  (m_wb_we_o_rx),
387
      .m_wb_dat_o (m_wb_dat_o),
388
      .m_wb_cyc_o (m_wb_cyc_o_rx),
389
      .m_wb_stb_o (m_wb_stb_o_rx),
390
      .m_wb_ack_i (m_wb_ack_i),
391
      .m_wb_cti_o (m_wb_cti_o_rx),
392
      .m_wb_bte_o (m_wb_bte_o_rx),
393
      .en         (start_rx_fifo),
394
      .adr        (sys_adr),
395
      .sd_clk     (sd_clk_o),
396
      .dat_i      (data_in_rx_fifo   ),
397
      .wr         (we_rx),
398
      .full       (full_rx)
399
      );
400
 
401
   sd_controller_wb sd_controller_wb0
402
     (
403
      .wb_clk_i          (wb_clk_i),
404
      .wb_rst_i          (wb_rst_i),
405
      .wb_dat_i          (wb_dat_i),
406
      .wb_dat_o          (wb_dat_o),
407
      .wb_adr_i          (wb_adr_i[7:0]),
408
      .wb_sel_i          (wb_sel_i),
409
      .wb_we_i           (wb_we_i),
410
      .wb_stb_i          (wb_stb_i),
411
      .wb_cyc_i          (wb_cyc_i),
412
      .wb_ack_o          (wb_ack_o),
413
      .we_m_tx_bd        (we_m_tx_bd),
414
      .new_cmd           (new_cmd),
415
      .we_m_rx_bd        (we_m_rx_bd),
416
      .we_ack             (we_ack),
417
      .int_ack            (int_ack),
418
      .cmd_int_busy       (cmd_int_busy),
419
      .Bd_isr_reset       (Bd_isr_reset),
420
      .normal_isr_reset   (normal_isr_reset),
421
      .error_isr_reset    (error_isr_reset),
422
      .int_busy           (int_busy),
423
      .dat_in_m_tx_bd     (dat_in_m_tx_bd),
424
      .dat_in_m_rx_bd     (dat_in_m_rx_bd),
425
      .write_req_s        (write_req_s),
426
      .cmd_set_s          (cmd_set_s),
427
      .cmd_arg_s          (cmd_arg_s),
428
      .argument_reg       (argument_reg),
429
      .cmd_setting_reg    (cmd_setting_reg),
430
      .status_reg         (status_reg),
431
      .cmd_resp_1         (cmd_resp_1),
432
      .software_reset_reg (software_reset_reg ),
433
      .time_out_reg       (time_out_reg ),
434
      .normal_int_status_reg  (normal_int_status_reg),
435
      .error_int_status_reg   (error_int_status_reg ),
436
      .normal_int_signal_enable_reg   (normal_int_signal_enable_reg),
437
      .error_int_signal_enable_reg    (error_int_signal_enable_reg),
438
      .clock_divider                  (clock_divider ),
439
      .Bd_Status_reg                  (Bd_Status_reg),
440
      .Bd_isr_reg                     (Bd_isr_reg ),
441
      .Bd_isr_enable_reg              (Bd_isr_enable_reg)
442
      );
443
 
444
   //MUX For WB master acces granted to RX or TX FIFO filler
445
   assign m_wb_cyc_o = start_tx_fifo ? m_wb_cyc_o_tx :
446
                       start_rx_fifo ? m_wb_cyc_o_rx: 0;
447
   assign m_wb_stb_o = start_tx_fifo ? m_wb_stb_o_tx :
448
                       start_rx_fifo ? m_wb_stb_o_rx: 0;
449
 
450
   assign m_wb_cti_o = start_tx_fifo ? m_wb_cti_o_tx :
451
                       start_rx_fifo ? m_wb_cti_o_rx : 0;
452
   assign m_wb_bte_o = start_tx_fifo ? m_wb_bte_o_tx :
453
                       start_rx_fifo ? m_wb_bte_o_rx : 0;
454
 
455
   assign m_wb_we_o = start_tx_fifo ? m_wb_we_o_tx :
456
                      start_rx_fifo ? m_wb_we_o_rx : 0;
457
   assign m_wb_adr_o = start_tx_fifo ? m_wb_adr_o_tx :
458
                       start_rx_fifo ? m_wb_adr_o_rx : 0;
459
 
460
`ifdef SDC_IRQ_ENABLE
461
   assign int_a =  |(normal_int_status_reg &  normal_int_signal_enable_reg) ;
462
   assign int_b =  |(error_int_status_reg & error_int_signal_enable_reg);
463
   assign int_c =  |(Bd_isr_reg & Bd_isr_enable_reg);
464
`else
465
   assign int_a = 0;
466
   assign int_b = 0;
467
   assign int_c = 0;
468
`endif
469
 
470
   assign m_wb_sel_o = 4'b1111;
471
 
472
   //Set Bd_Status_reg
473
   always @ (posedge wb_clk_i ) begin
474
      Bd_Status_reg[15:8]=free_bd_rx_bd;
475
      Bd_Status_reg[7:0]=free_bd_tx_bd;
476
      cmd_resp_1<= cmd_resp_1_w;
477
      normal_int_status_reg<= normal_int_status_reg_w  ;
478
      error_int_status_reg<= error_int_status_reg_w  ;
479
      status_reg[0]<= status_reg_busy;
480
      status_reg[15:1]<=  status_reg_w[15:1];
481
      status_reg[1] <= cidat_w;
482
      Bd_isr_reg<=bd_int_st_w;
483
 
484
   end
485
 
486
 
487
 
488
   //cmd_int_busy is set when an internal access to the CMD buss is granted then immidetly uppdate the status busy bit to prevent buss access to cmd
489
   assign status_reg_busy = cmd_int_busy ? 1'b1: status_reg_w[0];
490
 
491
 
492
 
493
 
494
 
495
endmodule

powered by: WebSVN 2.1.0

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