Subversion Repositories pentevo

Rev

Blame | Last modification | View Log | Download | RSS feed | ?url?

  1. // PentEvo project (c) NedoPC 2008-2009
  2. //
  3. // Z80 clocking module, also contains some wait-stating when 14MHz
  4. //
  5. // IDEAL:
  6. // fclk    _/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\_/`\
  7. //          |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
  8. // zclk     /```\___/```\___/```\___/```````\_______/```````\_______/```````````````\_______________/```````````````\_______________/`
  9. //          |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
  10. // zpos     `\___/```\___/```\___/```\___________/```\___________/```\___________________________/```\___________________________/```\
  11. //          |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
  12. // zneg     _/```\___/```\___/```\_______/```\___________/```\___________________/```\___________________________/```\________________
  13.  
  14. // clock phasing:
  15. // cend must be zpos for 7mhz, therefore post_cbeg - zneg
  16. // for 3.5 mhz, cend is both zpos and zneg (alternating)
  17.  
  18.  
  19. //    FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME
  20. // CURRENTLY ONLY 3.5 and 7 MHz!!!! FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME
  21. //    FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME
  22.  
  23. `include "../include/tune.v"
  24.  
  25. module zclock(
  26.  
  27.         input fclk,
  28.         input rst_n,
  29.  
  30.         input zclk, // Z80 clock, buffered via act04 and returned back to the FPGA
  31.  
  32.         input rfsh_n, // switch turbo modes in RFSH part of m1
  33.  
  34.  
  35.         output reg zclk_out, // generated Z80 clock - passed through inverter externally!
  36.  
  37.         output reg zpos,
  38.         output reg zneg,
  39.  
  40.  
  41.         input [1:0] turbo, // 2'b00 -  3.5 MHz
  42.                            // 2'b01 -  7.0 MHz
  43.                            // 2'b1x - 14.0 MHz
  44.  
  45.  
  46.         input cbeg,
  47.         input pre_cend // syncing signals, taken from arbiter.v and dram.v
  48. );
  49.  
  50.  
  51.         reg precend_cnt;
  52.         wire h_precend_1; // to take every other pulse of pre_cend
  53.         wire h_precend_2; // to take every other pulse of pre_cend
  54.  
  55.         reg [2:0] zcount; // counter for generating 3.5 and 7 MHz z80 clocks
  56.         reg [1:0] int_turbo; // internal turbo, controlling muxes
  57.  
  58.  
  59.         reg old_rfsh_n;
  60.  
  61.  
  62.  
  63. `ifdef SIMULATE
  64.         initial // simulation...
  65.         begin
  66.                 precend_cnt = 1'b0;
  67.                 int_turbo   = 2'b00;
  68.                 old_rfsh_n  = 1'b1;
  69.         end
  70. `endif
  71.  
  72.         // take every other pulse of pre_cend (make half pre_cend)
  73.         always @(posedge fclk) if( pre_cend )
  74.                 precend_cnt <= ~precend_cnt;
  75.  
  76.         assign h_precend_1 =  precend_cnt && pre_cend;
  77.         assign h_precend_2 = !precend_cnt && pre_cend;
  78.  
  79. /*      // phase zcount to take from it proper 3.5 or 7 MHz clock
  80.         always @(posedge fclk)
  81.         begin
  82.                 if( half_precend )
  83.                         zcount <= 3'd7;
  84.                 else
  85.                         zcount <= zcount - 3'd1;
  86.         end
  87. */
  88.  
  89.         // switch between 3.5 and 7 only at predefined time
  90.         always @(posedge fclk) if(zpos)
  91.         begin
  92.                 old_rfsh_n <= rfsh_n;
  93.  
  94.                 if( old_rfsh_n && !rfsh_n )
  95.                         int_turbo <= turbo;
  96.         end
  97.  
  98. /*      always @(posedge fclk) if( h_precend_1 )
  99.                 int_turbo <= turbo;
  100. */
  101.  
  102.         always @(posedge fclk)
  103.         begin
  104.                 if( (pre_cend && int_turbo[0]) || (h_precend_2 && !int_turbo[0]) )
  105.                         zpos <= 1'b1;
  106.                 else
  107.                         zpos <= 1'b0;
  108.         end
  109.  
  110.         always @(posedge fclk)
  111.         begin
  112.                 if( (cbeg && int_turbo[0]) || (h_precend_1 && !int_turbo[0]) )
  113.                         zneg <= 1'b1;
  114.                 else
  115.                         zneg <= 1'b0;
  116.         end
  117.  
  118.  
  119.  
  120.  
  121.         // make Z80 clock: account for external inversion and make some leading of clock
  122.         // 9.5 ns propagation delay: from fclk posedge to zclk returned back any edge
  123.         // (1/28)/2=17.9ns half a clock lead
  124.         // 2.6ns lag because of non-output register emitting of zclk_out
  125.         // total: 5.8 ns lead of any edge of zclk relative to posedge of fclk => ACCOUNT FOR THIS WHEN DOING INTER-CLOCK DATA TRANSFERS
  126.         //
  127. /*      always @(negedge fclk)
  128.                 if( int_turbo[0] ) // 7 MHz
  129.                         zclk_out <= ~zcount[1];
  130.                 else // 3.5 MHz
  131.                         zclk_out <= ~zcount[2];
  132. */
  133.  
  134.         always @(negedge fclk)
  135.         begin
  136.                 if( zpos )
  137.                         zclk_out <= 1'b0;
  138.  
  139.                 if( zneg )
  140.                         zclk_out <= 1'b1;
  141.         end
  142.  
  143.  
  144. endmodule
  145.  
  146.