You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.3 KiB
Coq

5 months ago
module stark_machine(
input sys_clk ,
input sys_rst_n ,
input rx ,
output tx ,
output [3: 0] led ,
output beep ,
output [7: 0] seg_led ,
output [5: 0] sel_led ,
output dout
);
reg [23: 0] instruction_reg;//
wire [7: 0] opcode;//
wire [7: 0] slave_id;//id
wire [7: 0] data;//
wire [7: 0] rx_byte;//
wire rx_vld;//
wire [23: 0] instruction;//
reg [1: 0] byte_num;//
wire tx_vld;
// assign instruction = 24'h01020f;
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
instruction_reg <= 24'h000000;
end
else if(rx_vld)begin
instruction_reg <= {instruction_reg[15: 0], rx_byte};
end
else begin
instruction_reg <= instruction_reg;
end
end
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
byte_num <= 2'd0;
end
else if(rx_vld)begin
byte_num <= byte_num + 1'd1;
end
else if(byte_num == 2'd3)begin
byte_num <= 2'd0;
end
else begin
byte_num <= byte_num;
end
end
assign instruction = (byte_num == 2'd3) ? instruction_reg: 24'h000000;
//
uart_rx uart_rx_inst(
.sys_clk (sys_clk),
.sys_rst_n (sys_rst_n),
.rx_din (rx),//
.rx_dout (rx_byte),//
.rx_vld (rx_vld)//
);
uart_tx uart_tx_inst(
.sys_clk (sys_clk),
.sys_rst_n (sys_rst_n),
.tx_din (rx_byte),//
.rx_vld (rx_vld),//
.tx_vld (tx_vld),
.tx_dout (tx)//
);
instr_decode instr_decode_inst(
.instruction (instruction),//
.opcode (opcode),//
.slave_id (slave_id),//id
.data (data) //
);
circuit_arb circuit_arb_inst(//
.sys_clk (sys_clk),
.sys_rst_n (sys_rst_n),
.slave_id (slave_id),
.opcode (opcode),
.data (data),
.led (led),
.beep (beep),
.seg_led (seg_led),
.sel_led (sel_led),
.dout (dout)
);
endmodule