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

Subversion Repositories 8051

[/] [8051/] [trunk/] [rtl/] [verilog/] [oc8051_uart.v] - Diff between revs 2 and 4

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

Rev 2 Rev 4
Line 1... Line 1...
module oc8051_uart (rst, clk, bit_in, rd_addr, data_in, bit_out, wr, wr_bit, wr_addr, data_out,
module oc8051_uart (rst, clk, bit_in, rd_addr, data_in, bit_out, wr, wr_bit, wr_addr, data_out,
                   rxd, txd, int, t1_ow);
                   rxd, txd, intr, t1_ow);
 
 
input rst, clk, bit_in, wr, rxd, wr_bit, t1_ow;
input rst, clk, bit_in, wr, rxd, wr_bit, t1_ow;
input [7:0] rd_addr, data_in, wr_addr;
input [7:0] rd_addr, data_in, wr_addr;
 
 
output txd, int, bit_out;
output txd, intr, bit_out;
output [7:0] data_out;
output [7:0] data_out;
 
 
reg txd, bit_out;
reg txd, bit_out;
reg [7:0] data_out;
reg [7:0] data_out;
 
 
Line 24... Line 24...
 
 
//
//
// sam_cnt      sample counter
// sam_cnt      sample counter
reg [2:0] sam_cnt, sample;
reg [2:0] sam_cnt, sample;
 
 
assign int = scon[1] | scon [0];
assign intr = scon[1] | scon [0];
 
 
//
//
//serial port control register
//serial port control register
//
//
always @(posedge clk or posedge rst)
always @(posedge clk or posedge rst)
Line 52... Line 52...
  end
  end
 
 
end
end
 
 
//
//
//serial port buffer (receive)
 
//
 
always @(posedge clk or posedge rst)
 
begin
 
  if (rst)
 
  begin
 
    sbuf_rxd <= #1 `OC8051_RST_SBUF;
 
  end
 
end
 
 
 
//
 
//serial port buffer (transmit)
//serial port buffer (transmit)
//
//
always @(posedge clk or posedge rst)
always @(posedge clk or posedge rst)
begin
begin
  if (rst) begin
  if (rst) begin
    sbuf_txd <= #1 `OC8051_RST_SBUF;
    sbuf_txd <= #1 `OC8051_RST_SBUF;
    tr_start <= 1'b0;
    tr_start <= #1 1'b0;
  end else if ((wr_addr==`OC8051_SFR_SBUF) & (wr) & !(wr_bit)) begin
  end else if ((wr_addr==`OC8051_SFR_SBUF) & (wr) & !(wr_bit)) begin
    sbuf_txd <= #1 data_in;
    sbuf_txd <= #1 data_in;
    tr_start <= #1 1'b1;
    tr_start <= #1 1'b1;
   end else
   end else
    tr_start <= #1 1'b0;
    tr_start <= #1 1'b0;
Line 114... Line 103...
//
//
  end else if (trans)
  end else if (trans)
  begin
  begin
    case (scon[7:6])
    case (scon[7:6])
      2'b00: begin //mode 0
      2'b00: begin //mode 0
        if (tr_count==9'd8)
        if (tr_count==4'd8)
        begin
        begin
          trans <= #1 1'b0;
          trans <= #1 1'b0;
          txd <= #1 1'b1;
          txd <= #1 1'b1;
        end else begin
        end else begin
          txd <= #1 sbuf_txd[tr_count];
          txd <= #1 sbuf_txd[tr_count];
          tr_count <= #1 tr_count +1'b1;
          tr_count <= #1 tr_count + 4'b1;
        end
        end
      end
      end
      2'b01: begin // mode 1
      2'b01: begin // mode 1
        if ((t1_ow) & !(t1_ow_buf))
        if ((t1_ow) & !(t1_ow_buf))
        begin
        begin
Line 134... Line 123...
              4'd8: txd <= #1 1'b1;  // stop bit
              4'd8: txd <= #1 1'b1;  // stop bit
              4'd9: trans <= #1 1'b0;
              4'd9: trans <= #1 1'b0;
              4'b1111: txd <= #1 1'b0; //start bit
              4'b1111: txd <= #1 1'b0; //start bit
              default: txd <= #1 sbuf_txd[tr_count];
              default: txd <= #1 sbuf_txd[tr_count];
            endcase
            endcase
            tr_count <= #1 tr_count +1'b1;
            tr_count <= #1 tr_count + 4'b1;
            smod_cnt_t <= #1 1'b0;
            smod_cnt_t <= #1 1'b0;
          end else smod_cnt_t <= #1 1'b1;
          end else smod_cnt_t <= #1 1'b1;
        end
        end
      end
      end
      2'b10: begin // mode 2
      2'b10: begin // mode 2
Line 157... Line 146...
            default: begin
            default: begin
              txd <= #1 sbuf_txd[tr_count];
              txd <= #1 sbuf_txd[tr_count];
            end
            end
          endcase
          endcase
          tr_count <= #1 tr_count+1'b1;
          tr_count <= #1 tr_count+1'b1;
          mode2_count <= #1 4'd0;
          mode2_count <= #1 3'd0;
        end else begin
        end else begin
          mode2_count <= #1 mode2_count + 1'b1;
          mode2_count <= #1 mode2_count + 3'b1;
        end
        end
      end
      end
      default: begin // mode 3
      default: begin // mode 3
        if ((t1_ow) & !(t1_ow_buf))
        if ((t1_ow) & !(t1_ow_buf))
        begin
        begin
Line 205... Line 194...
  end else if ((wr_addr==`OC8051_SFR_PCON) & (wr) & !(wr_bit))
  end else if ((wr_addr==`OC8051_SFR_PCON) & (wr) & !(wr_bit))
    pcon <= #1 data_in;
    pcon <= #1 data_in;
end
end
 
 
//
//
// receive
//serial port buffer (receive)
//
//
always @(posedge clk or posedge rst)
always @(posedge clk or posedge rst)
begin
begin
  if (rst) begin
  if (rst) begin
    sample <= #1 3'b000;
    sample <= #1 3'b000;
Line 230... Line 219...
          sbuf_rxd <= #1 sbuf_rxd_tmp[8:1];
          sbuf_rxd <= #1 sbuf_rxd_tmp[8:1];
        end else begin
        end else begin
          sbuf_rxd_tmp[re_count+1] <= #1 rxd;
          sbuf_rxd_tmp[re_count+1] <= #1 rxd;
          r_int <= #1 1'b0;
          r_int <= #1 1'b0;
        end
        end
        re_count <= #1 re_count + 1'b1;
        re_count <= #1 re_count + 4'b1;
      end
      end
      2'b01: begin // mode 1
      2'b01: begin // mode 1
        if ((t1_ow) & !(t1_ow_buf))
        if ((t1_ow) & !(t1_ow_buf))
        begin
        begin
          if ((pcon[7]) | (smod_cnt_r))
          if ((pcon[7]) | (smod_cnt_r))
          begin
          begin
            sam_cnt <= #1 3'b000;
            sam_cnt <= #1 3'b000;
            r_int <= #1 1'b0;
            r_int <= #1 1'b0;
 
 
            re_count <= #1 re_count +1'b1;
            re_count <= #1 re_count + 4'b1;
            smod_cnt_r <= #1 1'b0;
            smod_cnt_r <= #1 1'b0;
          end else smod_cnt_r <= #1 1'b1;
          end else smod_cnt_r <= #1 1'b1;
        end else begin
        end else begin
          if (sam_cnt==3'b011) begin
          if (sam_cnt==3'b011) begin
            if ((sample[0] % sample[1]) | (sample[0] % sample[2]))
            if ((sample[0] % sample[1]) | (sample[0] % sample[2]))
Line 273... Line 262...
          end else begin
          end else begin
            sam_cnt <= #1 3'b001;
            sam_cnt <= #1 3'b001;
            sample[0] <= #1 rxd;
            sample[0] <= #1 rxd;
            r_int <= #1 1'b0;
            r_int <= #1 1'b0;
          end
          end
    re_count <= #1 re_count + 1'b1;
    re_count <= #1 re_count + 4'b1;
        end else begin
        end else begin
          r_int <= #1 1'b0;
          r_int <= #1 1'b0;
 
 
          if (sam_cnt==3'b011) begin
          if (sam_cnt==3'b011) begin
            if ((sample[0] % sample[1]) | (sample[0] % sample[2]))
            if ((sample[0] % sample[1]) | (sample[0] % sample[2]))
Line 304... Line 293...
            end else begin
            end else begin
              sam_cnt <= #1 3'b000;
              sam_cnt <= #1 3'b000;
              r_int <= #1 1'b0;
              r_int <= #1 1'b0;
            end
            end
 
 
            re_count <= #1 re_count +1'b1;
            re_count <= #1 re_count + 4'b1;
            smod_cnt_r <= #1 1'b0;
            smod_cnt_r <= #1 1'b0;
          end else smod_cnt_r <= #1 1'b1;
          end else smod_cnt_r <= #1 1'b1;
        end else begin
        end else begin
          r_int <= #1 1'b0;
          r_int <= #1 1'b0;
          if (sam_cnt==3'b011)
          if (sam_cnt==3'b011)
Line 354... Line 343...
end
end
 
 
//
//
//
//
//
//
always @(posedge clk)
always @(posedge clk or posedge rst)
begin
begin
  if (wr & !wr_bit & (wr_addr==rd_addr) & ((wr_addr==`OC8051_SFR_PCON) |
  if (rst) data_out <= #1 8'h0;
 
  else if (wr & !wr_bit & (wr_addr==rd_addr) & ((wr_addr==`OC8051_SFR_PCON) |
     (wr_addr==`OC8051_SFR_SCON))) begin
     (wr_addr==`OC8051_SFR_SCON))) begin
    data_out <= #1 data_in;
    data_out <= #1 data_in;
  end else begin
  end else begin
    case (rd_addr)
    case (rd_addr)
      `OC8051_SFR_SBUF: data_out <= #1 sbuf_rxd;
      `OC8051_SFR_SBUF: data_out <= #1 sbuf_rxd;
Line 369... Line 359...
    endcase
    endcase
  end
  end
end
end
 
 
 
 
always @(posedge clk)
always @(posedge clk or posedge rst)
begin
begin
 
  if (rst) begin
 
    trans_buf <= #1 1'b0;
 
    receive_buf <= #1 1'b0;
 
    t1_ow_buf <= #1 1'b0;
 
    rxd_buf <= #1 1'b0;
 
  end else begin
  trans_buf <= #1 trans;
  trans_buf <= #1 trans;
end
 
 
 
always @(posedge clk)
 
begin
 
  receive_buf <= #1 receive;
  receive_buf <= #1 receive;
end
 
 
 
always @(posedge clk)
 
begin
 
  t1_ow_buf <= #1 t1_ow;
  t1_ow_buf <= #1 t1_ow;
end
 
 
 
always @(posedge clk)
 
begin
 
  rxd_buf <= #1 rxd;
  rxd_buf <= #1 rxd;
end
end
 
end
 
 
 
always  @(posedge clk or posedge rst)
always  @(posedge clk)
 
begin
begin
  if (wr & wr_bit & (rd_addr==wr_addr) & (wr_addr[7:3]==`OC8051_SFR_B_SCON)) begin
  if (rst) bit_out <= #1 1'b0;
 
  else if (wr & wr_bit & (rd_addr==wr_addr) & (wr_addr[7:3]==`OC8051_SFR_B_SCON)) begin
    bit_out <= #1 bit_in;
    bit_out <= #1 bit_in;
  end else
  end else
    bit_out <= #1 scon[rd_addr[2:0]];
    bit_out <= #1 scon[rd_addr[2:0]];
 
 
end
end
 
 
endmodule
endmodule
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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