Line 1... |
Line 1... |
`include "include.h"
|
/******************************************************************
|
|
* *
|
|
* Author: Liwei *
|
|
* *
|
|
* This file is part of the "mips789" project. *
|
|
* Downloaded from: *
|
|
* http://www.opencores.org/pdownloads.cgi/list/mips789 *
|
|
* *
|
|
* If you encountered any problem, please contact me via *
|
|
* Email:mcupro@opencores.org or mcupro@163.com *
|
|
* *
|
|
******************************************************************/
|
|
|
|
`include "mips789_defs.v"
|
|
|
module rxd_d(input clr,input clk,input d,output reg q );
|
module rxd_d(input clr,input clk,input d,output reg q );
|
|
|
always @(posedge clk or posedge clr)
|
always @(posedge clk)
|
|
|
if (clr) q<=0;
|
if (clr) q<=0;
|
else q<=d|q;
|
else q<=d|q;
|
|
|
endmodule
|
endmodule
|
Line 33... |
Line 46... |
output [7:0] dout;
|
output [7:0] dout;
|
wire [7:0] dout;
|
wire [7:0] dout;
|
|
|
wire clk_uart=clk;
|
wire clk_uart=clk;
|
wire w_rxd_rdy;
|
wire w_rxd_rdy;
|
wire w_rxd_clr;
|
|
|
|
uart_read uart_rd_tak(
|
uart_read uart_rd_tak(
|
.sync_reset(rst),
|
.sync_reset(rst),
|
.clk(clk),
|
.clk(clk),
|
.rxd(ser_rxd),
|
.rxd(ser_rxd),
|
Line 64... |
Line 76... |
.write_busy(txd_busy)
|
.write_busy(txd_busy)
|
);
|
);
|
|
|
endmodule
|
endmodule
|
|
|
|
//These modules below are modified slight by Liwei based on YACC,an CPU core in opencores.
|
|
//Thank you TAK
|
|
|
module uart_write( sync_reset, clk, txd, data_in , write_request,write_done,write_busy);
|
module uart_write( sync_reset, clk, txd, data_in , write_request,write_done,write_busy);
|
input sync_reset,clk;
|
input sync_reset,clk;
|
input [7:0] data_in;
|
input [7:0] data_in;
|
input write_request;
|
input write_request;
|
Line 85... |
Line 99... |
//________|--|___write_request (upper module : its period should be 1clock time.)
|
//________|--|___write_request (upper module : its period should be 1clock time.)
|
//__________________________|-|______write_done (Responds by this module posedge interrupt)
|
//__________________________|-|______write_done (Responds by this module posedge interrupt)
|
//With 512Bytes FIFO.
|
//With 512Bytes FIFO.
|
//No error handling is supported.
|
//No error handling is supported.
|
|
|
reg [15:0] clk_ctr;
|
reg [15:0] clk_ctr;//liwei
|
reg [2:0] bit_ctr;
|
reg [2:0] bit_ctr;
|
reg [2:0] ua_state;
|
reg [2:0] ua_state;
|
reg [7:0] tx_sr;
|
reg [7:0] tx_sr;
|
reg write_done_n;
|
|
reg txd;
|
reg txd;
|
|
|
wire clk_ctr_equ15, clk_ctr_equ31, bit_ctr_equ7,
|
wire clk_ctr_equ15, clk_ctr_equ31, bit_ctr_equ7,
|
clk_ctr_enable_state, bit_ctr_enable_state ;
|
clk_ctr_enable_state, bit_ctr_enable_state ;
|
wire tx_state;
|
wire tx_state;
|
Line 109... |
Line 122... |
assign read_request = queing && ua_state==3'b000;//Jul.14.2004
|
assign read_request = queing && ua_state==3'b000;//Jul.14.2004
|
|
|
assign write_done=ua_state==3'b101;
|
assign write_done=ua_state==3'b101;
|
|
|
`ifdef ALTERA
|
`ifdef ALTERA
|
fifo512_cyclone fifo(
|
fifo512_cyclone alt_fifo(
|
.data(data_in),
|
.data(data_in),
|
.wrreq(write_request),
|
.wrreq(write_request),
|
.rdreq(read_request),
|
.rdreq(read_request),
|
.clock(clk),
|
.clock(clk),
|
.q(queue_data),
|
.q(queue_data),
|
.full(queue_full),
|
.full(queue_full),
|
.empty(empty));
|
.empty(empty));
|
`else//XILINX coregen
|
`else//debug model in simulations
|
|
|
fifo fifo(
|
sim_fifo512_cyclone sim_fifo(
|
.clk(clk),
|
.data(data_in),
|
.sinit(sync_reset),
|
.wrreq(write_request),
|
.din(data_in),
|
.rdreq(read_request),
|
.wr_en(write_request),
|
.clock(clk),
|
.rd_en(read_request),
|
.q(queue_data),
|
.dout(queue_data),
|
|
.full(queue_full),
|
.full(queue_full),
|
.empty(empty));
|
.empty(empty),
|
|
.rst(sync_reset));
|
`endif
|
`endif
|
|
|
|
|
|
|
// 7bit counter
|
// 7bit counter
|
|
// I set the regerster lenth as 16 .Sufficent but not waste.Liwei
|
always @(posedge clk ) begin
|
always @(posedge clk ) begin
|
if (~sync_reset)
|
if (~sync_reset)
|
clk_ctr <= 0;
|
clk_ctr <= 0;
|
else if (clk_ctr_enable_state && clk_ctr_equ31) clk_ctr<=0;
|
else if (clk_ctr_enable_state && clk_ctr_equ31) clk_ctr<=0;
|
else if (clk_ctr_enable_state) clk_ctr <= clk_ctr + 1;
|
else if (clk_ctr_enable_state) clk_ctr <= clk_ctr + 1;
|
Line 172... |
Line 186... |
3'b000: if (queing) ua_state <= 3'b001; //wait write_request
|
3'b000: if (queing) ua_state <= 3'b001; //wait write_request
|
3'b001: if ( clk_ctr_equ15) ua_state <= 3'b010; // write start bit
|
3'b001: if ( clk_ctr_equ15) ua_state <= 3'b010; // write start bit
|
3'b010: if (bit_ctr_equ7 & clk_ctr_equ15) ua_state <= 3'b011; // start bit, bit0-7 data send
|
3'b010: if (bit_ctr_equ7 & clk_ctr_equ15) ua_state <= 3'b011; // start bit, bit0-7 data send
|
3'b011: if (clk_ctr_equ15) ua_state <= 3'b100; // bit7 data send
|
3'b011: if (clk_ctr_equ15) ua_state <= 3'b100; // bit7 data send
|
3'b100: if (clk_ctr_equ15) ua_state <= 3'b101; // stop bit // stop bit send
|
3'b100: if (clk_ctr_equ15) ua_state <= 3'b101; // stop bit // stop bit send
|
3'b101: if (clk_ctr_equ15) ua_state <= 3'b110; //LIWEI // stop bit // stop bit send
|
3'b101: if (clk_ctr_equ15) ua_state <= 3'b110; //LIWEI // stop bit send
|
3'b110: if (clk_ctr_equ15) ua_state <= 3'b111; //LIWEI
|
3'b110: if (clk_ctr_equ15) ua_state <= 3'b111; //LIWEI
|
3'b111: ua_state <= 3'h0; // TAK // byte read cycle end
|
3'b111: ua_state <= 3'h0; // TAK // byte read cycle end
|
default: ua_state <= 3'h0;
|
default: ua_state <= 3'h0;
|
endcase
|
endcase
|
end
|
end
|
Line 268... |
Line 282... |
|
|
|
|
assign clk_ctr_enable_state = ua_state !=3'b000 && ua_state<=3'b011;
|
assign clk_ctr_enable_state = ua_state !=3'b000 && ua_state<=3'b011;
|
assign bit_ctr_enable_state = ua_state==3'h2;
|
assign bit_ctr_enable_state = ua_state==3'h2;
|
|
|
//
|
|
always @(posedge clk ) begin
|
always @(posedge clk ) begin
|
if (~sync_reset) ua_state <= 3'h0;
|
if (~sync_reset) ua_state <= 3'h0;
|
else begin
|
else begin
|
case (ua_state)
|
case (ua_state)
|
3'h0: if (rxq1==0) ua_state <= 3'h1; // if rxd==0 then goto next state and enable clock // start bit search
|
3'h0: if (rxq1==0) ua_state <= 3'h1; // if rxd==0 then goto next state and enable clock // start bit search
|
Line 293... |
Line 306... |
end
|
end
|
|
|
//int_req
|
//int_req
|
always @(posedge clk ) begin
|
always @(posedge clk ) begin
|
if (~sync_reset) int_req<=1'b0;
|
if (~sync_reset) int_req<=1'b0;
|
else if (ua_state==3'h4 ) int_req<=1'b1; //
|
else if (ua_state==3'h4 ) int_req<=1'b1;
|
else int_req<=1'b0;
|
else int_req<=1'b0;
|
end
|
end
|
|
|
|
|
// rx shift reg.
|
// rx shift reg.
|