Subversion Repositories pentevo

Rev

Rev 668 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed | ?url?

  1. // ZX-Evo Base Configuration (c) NedoPC 2008,2009,2010,2011,2012,2013,2014
  2. //
  3. // SPI hub: arbitrating between AVR and Z80 accesses to SDcard via SPI.
  4.  
  5. /*
  6.     This file is part of ZX-Evo Base Configuration firmware.
  7.  
  8.     ZX-Evo Base Configuration firmware is free software:
  9.     you can redistribute it and/or modify it under the terms of
  10.     the GNU General Public License as published by
  11.     the Free Software Foundation, either version 3 of the License, or
  12.     (at your option) any later version.
  13.  
  14.     ZX-Evo Base Configuration firmware is distributed in the hope that
  15.     it will be useful, but WITHOUT ANY WARRANTY; without even
  16.     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17.     See the GNU General Public License for more details.
  18.  
  19.     You should have received a copy of the GNU General Public License
  20.     along with ZX-Evo Base Configuration firmware.
  21.     If not, see <http://www.gnu.org/licenses/>.
  22. */
  23.  
  24. `include "../include/tune.v"
  25.  
  26. module spihub(
  27.  
  28.         input  wire       fclk,
  29.         input  wire       rst_n,
  30.  
  31.         // pins to SDcard
  32.         output reg        sdcs_n,
  33.         output wire       sdclk,
  34.         output wire       sddo,
  35.         input  wire       sddi,
  36.  
  37.         // zports SDcard iface
  38.         input  wire       zx_sdcs_n_val,
  39.         input  wire       zx_sdcs_n_stb,
  40.         input  wire       zx_sd_start,
  41.         input  wire [7:0] zx_sd_datain,
  42.         output wire [7:0] zx_sd_dataout,
  43.  
  44.         // slavespi SDcard iface
  45.         input  wire       avr_lock_in,
  46.         output reg        avr_lock_out,
  47.         input  wire       avr_sdcs_n,
  48.         input  wire       avr_sd_start,
  49.         input  wire [7:0] avr_sd_datain,
  50.         output wire [7:0] avr_sd_dataout
  51. );
  52.  
  53.         // spi2 module control
  54.         wire [7:0] sd_datain;
  55.         wire [7:0] sd_dataout;
  56.         wire       sd_start;
  57.  
  58.  
  59.         // single dataout to all ifaces
  60.         assign zx_sd_dataout  = sd_dataout;
  61.         assign avr_sd_dataout = sd_dataout;
  62.  
  63.  
  64.         // spi2 module itself
  65.         spi2 spi2(
  66.                 .clock(fclk),
  67.  
  68.                 .sck(sdclk),
  69.                 .sdo(sddo ),
  70.                 .sdi(sddi ),
  71.  
  72.                 .start(sd_start  ),
  73.                 .din  (sd_datain ),
  74.                 .dout (sd_dataout),
  75.  
  76.                 .speed(2'b00)
  77.         );
  78.  
  79.  
  80.         // control locking/arbitrating between ifaces
  81.         always @(posedge fclk, negedge rst_n)
  82.         if( !rst_n )
  83.                 avr_lock_out <= 1'b0;
  84.         else // posedge fclk
  85.         begin
  86.                 if( sdcs_n )
  87.                         avr_lock_out <= avr_lock_in;
  88.         end
  89.  
  90.  
  91.  
  92.         // control cs_n to SDcard
  93.         always @(posedge fclk, negedge rst_n)
  94.         if( !rst_n )
  95.                 sdcs_n <= 1'b1;
  96.         else // posedge fclk
  97.         begin
  98.                 if( avr_lock_out )
  99.                         sdcs_n <= avr_sdcs_n;
  100.                 else // !avr_lock_out
  101.                         if( zx_sdcs_n_stb )
  102.                                 sdcs_n <= zx_sdcs_n_val;
  103.         end
  104.  
  105.  
  106.         // control start and outgoing data to spi2
  107.         assign sd_start = avr_lock_out ? avr_sd_start : zx_sd_start;
  108.         //
  109.         assign sd_datain = avr_lock_out ? avr_sd_datain : zx_sd_datain;
  110.  
  111.  
  112. endmodule
  113.  
  114.