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

Subversion Repositories t6507lp

[/] [t6507lp/] [trunk/] [rtl/] [verilog/] [t6507lp_fsm.v] - Diff between revs 82 and 83

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 82 Rev 83
Line 50... Line 50...
 
 
module t6507lp_fsm(clk, reset_n, alu_result, alu_status, data_in, address, control, data_out, alu_opcode, alu_a, alu_enable);
module t6507lp_fsm(clk, reset_n, alu_result, alu_status, data_in, address, control, data_out, alu_opcode, alu_a, alu_enable);
        parameter DATA_SIZE = 4'h8;
        parameter DATA_SIZE = 4'h8;
        parameter ADDR_SIZE = 4'hd;
        parameter ADDR_SIZE = 4'hd;
 
 
        localparam DATA_SIZE_ = DATA_SIZE - 1'b1;
        localparam DATA_SIZE_ = DATA_SIZE - 4'b0001;
        localparam ADDR_SIZE_ = ADDR_SIZE - 1'b1;
        localparam ADDR_SIZE_ = ADDR_SIZE - 4'b0001;
 
 
        input clk;
        input clk;
        input reset_n;
        input reset_n;
        input [DATA_SIZE_:0] alu_result;
        input [DATA_SIZE_:0] alu_result;
        input [DATA_SIZE_:0] alu_status;
        input [DATA_SIZE_:0] alu_status;
Line 129... Line 129...
                        control <= MEM_READ;
                        control <= MEM_READ;
                        data_out <= 8'h00;
                        data_out <= 8'h00;
                end
                end
                else begin
                else begin
                        state <= next_state;
                        state <= next_state;
                        control <= MEM_READ;
 
                        data_out <= 8'h00;
 
                        case (state)
                        case (state)
                                RESET: begin
                                RESET: begin
                                        // The processor was reset
                                        // The processor was reset
                                        $write("under reset");
                                        $write("under reset");
                                end
                                end
                                FETCH_OP: begin // this state is the simplest one. it is a simple fetch that must be done when the cpu was reset or
                                FETCH_OP: begin // this state is the simplest one. it is a simple fetch that must be done when the cpu was reset or
                                                // the last cycle was a memory write.
                                                // the last cycle was a memory write.
                                        pc <= next_pc;
                                        pc <= next_pc;
                                        address <= next_pc;
                                        address <= next_pc;
 
                                        control <= MEM_READ;
                                        ir <= data_in;
                                        ir <= data_in;
                                end
                                end
                                FETCH_OP_CALC, FETCH_OP_CALC_PARAM: begin // this is the pipeline happening!
                                FETCH_OP_CALC, FETCH_OP_CALC_PARAM: begin // this is the pipeline happening!
                                        pc <= next_pc;
                                        pc <= next_pc;
                                        address <= next_pc;
                                        address <= next_pc;
 
                                        control <= MEM_READ;
                                        ir <= data_in;
                                        ir <= data_in;
                                end
                                end
                                FETCH_LOW: begin // in this state the opcode is already known so truly execution begins
                                FETCH_LOW: begin // in this state the opcode is already known so truly execution begins
                                        if (accumulator || implied) begin
                                        if (accumulator || implied) begin
                                                pc <= pc; // is this better?
                                                pc <= pc; // is this better?
                                                address <= pc;
                                                address <= pc;
 
                                                control <= MEM_READ;
                                        end
                                        end
                                        else if (immediate) begin
                                        else if (immediate) begin
                                                pc <= next_pc;
                                                pc <= next_pc;
                                                address <= next_pc;
                                                address <= next_pc;
 
                                                control <= MEM_READ;
                                                temp_data <= data_in; // the follow-up byte is saved in temp_data 
                                                temp_data <= data_in; // the follow-up byte is saved in temp_data 
                                        end
                                        end
                                        else if (absolute) begin
                                        else if (absolute) begin
                                                pc <= next_pc;
                                                pc <= next_pc;
                                                address <= next_pc;
                                                address <= next_pc;
 
                                                control <= MEM_READ;
                                                temp_addr[7:0] <= data_in;
                                                temp_addr[7:0] <= data_in;
                                        end
                                        end
                                        else if (zero_page) begin
                                        else if (zero_page) begin
                                                pc <= next_pc;
                                                pc <= next_pc;
                                                address <= {{5{1'b0}},data_in};
                                                address <= {{5{1'b0}},data_in};
Line 171... Line 175...
 
 
                                                if (write) begin
                                                if (write) begin
                                                        control <= MEM_WRITE;
                                                        control <= MEM_WRITE;
                                                        data_out <= alu_result;
                                                        data_out <= alu_result;
                                                end
                                                end
 
                                                else begin
 
                                                        control <= MEM_READ;
 
                                                        data_out <= 8'h00;
 
                                                end
                                        end
                                        end
                                end
                                end
                                FETCH_HIGH: begin
                                FETCH_HIGH: begin
                                        if (jump) begin
                                        if (jump) begin
                                                pc <= {data_in[4:0], temp_addr}; // PCL <= first byte, PCH <= second byte
                                                pc <= {data_in[4:0], temp_addr[7:0]}; // PCL <= first byte, PCH <= second byte
                                                address <= {data_in[4:0], temp_addr};
                                                address <= {data_in[4:0], temp_addr[7:0]};
 
                                                control <= MEM_READ;
 
                                                data_out <= 8'h00;
                                        end
                                        end
                                        else begin
                                        else begin
                                                if (write) begin
                                                if (write) begin
                                                        pc <= next_pc;
                                                        pc <= next_pc;
                                                        temp_addr[12:8] <= data_in[4:0];
                                                        temp_addr[12:8] <= data_in[4:0];
Line 190... Line 200...
                                                end
                                                end
                                                else begin // read_modify_write or just read
                                                else begin // read_modify_write or just read
                                                        pc <= next_pc;
                                                        pc <= next_pc;
                                                        temp_addr[12:8] <= data_in[4:0];
                                                        temp_addr[12:8] <= data_in[4:0];
                                                        address <= {data_in[4:0],temp_addr[7:0]};
                                                        address <= {data_in[4:0],temp_addr[7:0]};
 
                                                        control <= MEM_READ;
 
                                                        data_out <= 8'h00;
                                                end
                                                end
                                        end
                                        end
                                        //else begin
                                        //else begin
                                        //      $write("FETCHHIGH PROBLEM"); 
                                        //      $write("FETCHHIGH PROBLEM"); 
                                        //      $finish(0); 
                                        //      $finish(0); 
Line 209... Line 221...
                                        end
                                        end
                                        else begin
                                        else begin
                                                pc <= pc;
                                                pc <= pc;
                                                address <= pc;
                                                address <= pc;
                                                temp_data <= data_in;
                                                temp_data <= data_in;
 
                                                control <= MEM_READ;
 
                                                data_out <= 8'h00;
                                        end
                                        end
                                end
                                end
                                DUMMY_WRT_CALC: begin
                                DUMMY_WRT_CALC: begin
                                        pc <= pc;
                                        pc <= pc;
                                        address <= temp_addr;
                                        address <= temp_addr;
Line 220... Line 234...
                                        data_out <= alu_result;
                                        data_out <= alu_result;
                                end
                                end
                                WRITE_MEM: begin
                                WRITE_MEM: begin
                                        pc <= pc;
                                        pc <= pc;
                                        address <= pc;
                                        address <= pc;
 
                                        control <= MEM_READ;
 
                                        data_out <= 8'h00;
                                end
                                end
                                default: begin
                                default: begin
                                        $write("unknown state");        // TODO: check if synth really ignores this 2 lines. Otherwise wrap it with a `ifdef 
                                        $write("unknown state");        // TODO: check if synth really ignores this 2 lines. Otherwise wrap it with a `ifdef 
                                        $finish(0);
                                        $finish(0);
                                end
                                end

powered by: WebSVN 2.1.0

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