⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 command.v

📁 SDRAM读写控制的实现与Modelsim仿真
💻 V
📖 第 1 页 / 共 2 页
字号:
// For normal burst write he duration of OE is dependent on the configured burst length.
// For page mode accesses(SC_PM=1) the OE signal is turned on at the start of the write command
// and is left on until a PRECHARGE(page burst terminate) is detected.
//
always @(posedge CLK or negedge RESET_N)
begin
        if (RESET_N == 0)
        begin
                oe_shift <= 0;
                oe1      <= 0;
                oe2      <= 0;
                oe3 	 <= 0;
		oe4      <= 0;
                OE       <= 12'b0;
        end
        else
       /* begin
                if (SC_PM == 0)
                begin
                   if (do_writea1 == 1)
                   begin
                        if (SC_BL == 1)                       //  Set the shift register to the appropriate
                           oe_shift <= 0;   
                         // value based on burst length.
                        else if (SC_BL == 2)
                                        oe_shift <= 1;
                        else if (SC_BL == 4)
                                        oe_shift <= 7;
                        else if (SC_BL == 8)
                                        oe_shift <= 127;
                            oe1 <= 1;
                   end
                   else 
                   begin
                        oe_shift[6:0] <= oe_shift[7:1];       // Do the shift operation
                        oe_shift[7]   <= 0;
                        oe1  <= oe_shift[0];
                        oe2  <= oe1;
                        oe3  <= oe2;
                        oe4   <= oe3;
                        if (SC_RC == 2)
                            OE <= {12{oe3}};
                        else
                            OE <= {12{oe4}};
                   end
                end
                else*/
                begin
                        if (do_writea1 == 1)                                    // OE generation for page mode accesses
                                oe4   <= 1;
                        else if (do_precharge == 1 | do_reada == 1 | do_refresh)
                                oe4   <= 0;
                        OE <= {12{oe4}};
                end
                               
       // end
end




// This always block tracks the time between the activate command and the
// subsequent WRITEA or READA command, RC.  The shift register is set using
// the configuration register setting SC_RC. The shift register is loaded with
// a single '1' with the position within the register dependent on SC_RC.
// When the '1' is shifted out of the register it sets so_rw which triggers
// a writea or reada command
//
always @(posedge CLK or negedge RESET_N)
begin
        if (RESET_N == 0)
        begin
                rw_shift <= 0;
                do_rw    <= 0;
        end
        
        else
        begin
                
                if ((do_reada == 1) | (do_writea == 1))
                begin
                /*        if (SC_RC == 1)                          // Set the shift register
                                do_rw <= 1;
                        else if (SC_RC == 2)
                                rw_shift <= 1;
                        else if (SC_RC == 3)
                */                rw_shift <= 2;
                end
                else
                begin
                        rw_shift[2:0] <= rw_shift[3:1];          // perform the shift operation
                        rw_shift[3]   <= 0;
                        do_rw         <= rw_shift[0];
                end 
        end
end              

// This always block generates the command acknowledge, CM_ACK, signal.
// It also generates the acknowledge signal, REF_ACK, that acknowledges
// a refresh request that was generated by the internal refresh timer circuit.
always @(posedge CLK or negedge RESET_N) 
begin

        if (RESET_N == 0) 
        begin
                CM_ACK   <= 0;
                REF_ACK  <= 0;
        end
        
        else
        begin
                if (do_refresh == 1 & REF_REQ == 1)                   // Internal refresh timer refresh request
                        REF_ACK <= 1;
                else if ((do_refresh == 1) | (do_reada == 1) | (do_writea == 1) | (do_precharge == 1)   // externa  commands
                         | (do_load_mode))
                        CM_ACK <= 1;
                else
                begin
                        REF_ACK <= 0;
                        CM_ACK  <= 0;
                end
        end
end 
                    






// This always block generates the address, cs, cke, and command signals(ras,cas,wen)
// 
always @(posedge CLK ) begin
        if (RESET_N==0) begin
                SA    <= 0;
                BA    <= 0;
                CS_N  <= 1;
                RAS_N <= 1;
                CAS_N <= 1;
                WE_N  <= 1;
                CKE   <= 0;
        end
        else begin
                CKE  <= 1;
                CS_N <= 0;			                   // Chip is always selected


// Generate SA 	
                if (do_writea == 1 | do_reada == 1)    // ACTIVATE command is being issued, so present the row address
                        SA <= rowaddr;
                else
                        SA <= coladdr;                 // else alway present column address
              
		if ((do_rw==1) | (do_precharge))
                        SA[10] <= !SC_PM;              // set SA[10] for autoprecharge read/write or for a precharge all command
                                                       // don't set it if the controller is in page mode.           
              //  if (do_precharge==1 | do_load_mode==1) // Use only BANK0,always precharege bank00
                if (do_load_mode==1)
                        BA <= 0;                       // Set BA=0 if performing a precharge or load_mode command
                else
                        BA <= bankaddr[1:0];           // else set it with the appropriate address bits
		
           //     if (do_refresh==1 | do_precharge==1 | do_load_mode==1)
           //             CS_N <= 0;                                    // Select both chip selects if performing
          //      else                                                  // refresh, precharge(all) or load_mode
          //      begin
                      //  CS_N[0] <= SADDR[`ASIZE-1];                   // else set the chip selects based off of the
                      //  CS_N[1] <= ~SADDR[`ASIZE-1];                  // msb address bit
         //        CS_N <= 0;			                   // Chip is always selected
        //       end


//Generate the appropriate logic levels on RAS_N, CAS_N, and WE_N
//depending on the issued command.
//		
                if (do_refresh==1) begin                        // Refresh: S=00, RAS=0, CAS=0, WE=1
                        RAS_N <= 0;
                        WE_N  <= 1;
                        CAS_N <= 0;																						                  end
                else if ((do_precharge==1) & ((oe4 == 1) | (rw_flag == 1))) begin      // burst terminate if write is active
                        RAS_N <= 1;
                        CAS_N <= 1;
                        WE_N  <= 0;
                end
                else if (do_precharge==1) begin                 // Precharge All: S=00, RAS=0, CAS=1, WE=0
                        RAS_N <= 0;
                        CAS_N <= 1;
                        WE_N  <= 0;
                end
                else if (do_load_mode==1) begin                 // Mode Write: S=00, RAS=0, CAS=0, WE=0
                        RAS_N <= 0;
                        CAS_N <= 0;
                        WE_N  <= 0;
                end
                else if (do_reada == 1 | do_writea == 1) begin  // Activate: S=01 or 10, RAS=0, CAS=1, WE=1
                        RAS_N <= 0;
                        CAS_N <= 1;
                        WE_N  <= 1;
                end
                else if (do_rw == 1) begin                      // Read/Write: S=01 or 10, RAS=1, CAS=0, WE=0 or 1
                        RAS_N <= 1;
                        CAS_N <= 0;
                        WE_N  <= rw_flag;
                end
                else begin                                      // No Operation: RAS=1, CAS=1, WE=1
                        RAS_N <= 1;
                        CAS_N <= 1;
                        WE_N  <= 1;
                end
        end 
end

endmodule

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -