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

Subversion Repositories 8051

[/] [8051/] [tags/] [rel_12/] [rtl/] [verilog/] [oc8051_uart.v] - Diff between revs 82 and 115

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

Rev 82 Rev 115
Line 42... Line 42...
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//
//
// CVS Revision History
// CVS Revision History
//
//
// $Log: not supported by cvs2svn $
// $Log: not supported by cvs2svn $
 
// Revision 1.10  2003/01/13 14:14:41  simont
 
// replace some modules
 
//
// Revision 1.9  2002/09/30 17:33:59  simont
// Revision 1.9  2002/09/30 17:33:59  simont
// prepared header
// prepared header
//
//
//
//
 
 
Line 53... Line 56...
`include "oc8051_timescale.v"
`include "oc8051_timescale.v"
// synopsys translate_on
// synopsys translate_on
 
 
`include "oc8051_defines.v"
`include "oc8051_defines.v"
 
 
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,
                   rxd, txd, intr, t1_ow);
             bit_in, data_in,
 
             rd_addr, wr_addr,
input rst, clk, bit_in, wr, rxd, wr_bit, t1_ow;
             bit_out, data_out,
input [7:0] rd_addr, data_in, wr_addr;
             wr, wr_bit,
 
             rxd, txd,
output txd, intr, bit_out;
             intr,
 
             brate2, t1_ow, pres_ow,
 
             rclk, tclk);
 
 
 
input        rst,
 
             clk,
 
             bit_in,
 
             wr,
 
             rxd,
 
             wr_bit,
 
             t1_ow,
 
             brate2,
 
             pres_ow,
 
             rclk,
 
             tclk;
 
input [7:0]  rd_addr,
 
             data_in,
 
             wr_addr;
 
 
 
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;
 
 
reg tr_start, trans, trans_buf, t1_ow_buf;
reg t1_ow_buf;
reg [5:0] smod_cnt_r, smod_cnt_t;
//reg tr_start, trans, trans_buf, t1_ow_buf;
reg receive, receive_buf, rxd_buf, r_int;
//reg [5:0] smod_cnt_r, smod_cnt_t;
 
//reg receive, receive_buf, rxd_buf, r_int;
//
//
reg [7:0] sbuf_rxd, sbuf_txd, scon, pcon;
reg [7:0] /*sbuf_rxd, sbuf_txd, */scon, pcon;
reg [10:0] sbuf_rxd_tmp;
//reg [10:0] sbuf_rxd_tmp;
//
//
//tr_count      trancive counter
//tr_count      trancive counter
//re_count      receive counter
//re_count      receive counter
reg [3:0] tr_count, re_count, re_count_buff;
//reg [3:0] tr_count, re_count, re_count_buff;
 
 
 
 
 
reg        txd,
 
           trans,
 
           receive,
 
           tx_done,
 
           rx_done,
 
           rxd_r,
 
           shift_tr,
 
           shift_re;
 
reg [1:0]  rx_sam;
 
reg [3:0]  tr_count,
 
           re_count;
 
reg [7:0]  sbuf_rxd;
 
reg [11:0] sbuf_rxd_tmp;
 
reg [12:0] sbuf_txd;
 
 
 
 
assign intr = scon[1] | scon [0];
assign intr = scon[1] | scon [0];
 
 
//
//
//serial port control register
//serial port control register
//
//
 
wire ren, tb8, rb8, ri;
 
assign ren = scon[4];
 
assign tb8 = scon[3];
 
assign rb8 = scon[2];
 
assign ri  = scon[0];
 
 
always @(posedge clk or posedge rst)
always @(posedge clk or posedge rst)
begin
begin
  if (rst)
  if (rst)
    scon <= #1 `OC8051_RST_SCON;
    scon <= #1 `OC8051_RST_SCON;
  else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_SCON))
  else if ((wr) & !(wr_bit) & (wr_addr==`OC8051_SFR_SCON))
    scon <= #1 data_in;
    scon <= #1 data_in;
  else if ((wr) & (wr_bit) & (wr_addr[7:3]==`OC8051_SFR_B_SCON))
  else if ((wr) & (wr_bit) & (wr_addr[7:3]==`OC8051_SFR_B_SCON))
    scon[wr_addr[2:0]] <= #1 bit_in;
    scon[wr_addr[2:0]] <= #1 bit_in;
  else if ((trans_buf) & !(trans))
  else if (tx_done)
    scon[1] <= #1 1'b1;
    scon[1] <= #1 1'b1;
  else if ((receive_buf) & !(receive) & !(sbuf_rxd_tmp[0])) begin
  else if (!rx_done) begin
    case (scon[7:6])
    if (scon[7:6]==2'b00) begin
      2'b00: scon[0] <= #1 1'b1;
      scon[0] <= #1 1'b1;
      default: begin
    end else if ((sbuf_rxd_tmp[11]) | !(scon[5])) begin
        if ((sbuf_rxd_tmp[9]) | !(scon[5])) scon[0] <= #1 1'b1;
      scon[0] <= #1 1'b1;
        scon[2] <= #1 sbuf_rxd_tmp[9];
      scon[2] <= #1 sbuf_rxd_tmp[11];
      end
    end else
    endcase
      scon[2] <= #1 sbuf_rxd_tmp[11];
  end
  end
 
 
end
end
 
 
//
//
//serial port buffer (transmit)
//power control register
//
//
 
wire smod;
 
assign smod = pcon[7];
always @(posedge clk or posedge rst)
always @(posedge clk or posedge rst)
begin
begin
  if (rst) begin
  if (rst)
    sbuf_txd <= #1 `OC8051_RST_SBUF;
  begin
    tr_start <= #1 1'b0;
    pcon <= #1 `OC8051_RST_PCON;
  end else if ((wr_addr==`OC8051_SFR_SBUF) & (wr) & !(wr_bit)) begin
  end else if ((wr_addr==`OC8051_SFR_PCON) & (wr) & !(wr_bit))
    sbuf_txd <= #1 data_in;
    pcon <= #1 data_in;
    tr_start <= #1 1'b1;
 
  end else tr_start <= #1 1'b0;
 
end
end
 
 
 
 
//
//
// transmit
//serial port buffer (transmit)
//
//
 
 
 
wire wr_sbuf;
 
assign wr_sbuf = (wr_addr==`OC8051_SFR_SBUF) & (wr) & !(wr_bit);
 
 
always @(posedge clk or posedge rst)
always @(posedge clk or posedge rst)
begin
begin
  if (rst) begin
  if (rst) begin
    txd <= #1 1'b1;
    txd <= #1 1'b1;
    tr_count <= #1 4'd0;
    tr_count <= #1 4'd0;
    trans <= #1 1'b0;
    trans <= #1 1'b0;
    smod_cnt_t <= #1 6'h0;
    sbuf_txd <= #1 11'h00;
 
    tx_done  <= #1 1'b0;
//
//
// start transmiting
// start transmiting
//
//
  end else if (tr_start) begin
  end else if (wr_sbuf) begin
    case (scon[7:6])
    case (scon[7:6])
      2'b00: begin  // mode 0
      2'b00: begin  // mode 0
        txd <= #1 sbuf_txd[0];
        sbuf_txd <= #1 {3'b001, data_in};
        tr_count <= #1 4'd1;
 
      end
      end
      2'b10: begin
      2'b01: begin // mode 1
        txd <= #1 1'b0;
        sbuf_txd <= #1 {2'b01, data_in, 1'b0};
        tr_count <= #1 4'd0;
 
      end
      end
      default: begin  // mode 1 and mode 3
      default: begin  // mode 2 and mode 3
        tr_count <= #1 4'b1111;
        sbuf_txd <= #1 {1'b1, tb8, data_in, 1'b0};
      end
      end
    endcase
    endcase
    trans <= #1 1'b1;
    trans <= #1 1'b1;
    smod_cnt_t <= #1 6'h0;
    tr_count <= #1 4'd0;
 
    tx_done  <= #1 1'b0;
//
//
// transmiting/
// transmiting
//
//
  end else if (trans)
  end else if (trans & (scon[7:6] == 2'b00) & pres_ow) // mode 0
  begin
 
    case (scon[7:6])
 
      2'b00: begin //mode 0
 
        if (smod_cnt_t == 6'd12) begin
 
          if (tr_count==4'd8)
 
          begin
          begin
 
    if (~|sbuf_txd[10:1]) begin
 
      trans   <= #1 1'b0;
 
      tx_done <= #1 1'b1;
 
    end else begin
 
      {sbuf_txd, txd} <= #1 {1'b0, sbuf_txd};
 
      tx_done         <= #1 1'b0;
 
    end
 
  end else if (trans & (scon[7:6] != 2'b00) & shift_tr) begin // mode 1, 2, 3
 
    tr_count <= #1 tr_count + 4'd1;
 
    if (~|tr_count) begin
 
      if (~|sbuf_txd[10:0]) begin
                  trans <= #1 1'b0;
                  trans <= #1 1'b0;
 
        tx_done <= #1 1'b1;
                  txd <= #1 1'b1;
                  txd <= #1 1'b1;
                end else begin
                end else begin
            txd <= #1 sbuf_txd[tr_count];
        {sbuf_txd, txd} <= #1 {1'b0, sbuf_txd};
                  tr_count <= #1 tr_count + 4'b1;
        tx_done         <= #1 1'b0;
                end
                end
          smod_cnt_t <= #1 6'h0;
 
              end else smod_cnt_t <= #1 smod_cnt_t + 6'h01;
 
      end
      end
      2'b01: begin // mode 1
  end else if (!trans) begin
        if ((t1_ow) & !(t1_ow_buf))
    txd     <= #1 1'b1;
        begin
    tx_done <= #1 1'b0;
                if (((pcon[7]) &  (smod_cnt_t == 6'd15))| (!(pcon[7]) & (smod_cnt_t==6'd31)))
 
                begin
 
            case (tr_count)
 
              4'd8: txd <= #1 1'b1;  // stop bit
 
                    4'd9: trans <= #1 1'b0;
 
                    4'b1111: txd <= #1 1'b0; //start bit
 
                    default: txd <= #1 sbuf_txd[tr_count];
 
                  endcase
 
            tr_count <= #1 tr_count + 4'b1;
 
                  smod_cnt_t <= #1 6'h0;
 
                end else smod_cnt_t <= #1 smod_cnt_t + 6'h01;
 
              end
              end
      end
      end
      2'b10: begin // mode 2
 
//
//
// if smod (pcon[7]) is 1 count to 4 else count to 6
 
//
//
        if (((pcon[7]) & (smod_cnt_t==6'd31)) | (!(pcon[7]) & (smod_cnt_t==6'd63))) begin
reg sc_clk_tr, smod_clk_tr;
            case (tr_count)
always @(brate2 or t1_ow or t1_ow_buf or scon[7:6] or tclk)
            4'd8: begin
begin
                    txd <= #1 scon[3];
  if (scon[7:6]==8'b10) begin //mode 2
                  end
    sc_clk_tr = 1'b1;
            4'd9: begin
  end else if (tclk) begin //
                    txd <= #1 1'b1; //stop bit
    sc_clk_tr = brate2;
 
  end else begin //
 
    sc_clk_tr = !t1_ow_buf & t1_ow;
                  end
                  end
            4'd10: begin
 
                    trans <= #1 1'b0;
 
                  end
                  end
 
 
                  default: begin
always @(posedge clk or posedge rst)
                    txd <= #1 sbuf_txd[tr_count];
 
                  end
 
                endcase
 
          tr_count <= #1 tr_count+1'b1;
 
                smod_cnt_t <= #1 6'h00;
 
              end else begin
 
          smod_cnt_t <= #1 smod_cnt_t + 6'h01;
 
              end
 
      end
 
      default: begin // mode 3
 
        if ((t1_ow) & !(t1_ow_buf))
 
        begin
 
      if (((pcon[7]) &  (smod_cnt_t == 6'd15))| (!(pcon[7]) & (smod_cnt_t==6'd31)))
 
          begin
          begin
            case (tr_count)
  if (rst) begin
              4'd8: begin
    smod_clk_tr <= #1 1'b0;
                txd <= #1 scon[3];
    shift_tr    <= #1 1'b0;
              end
  end else if (sc_clk_tr) begin
              4'd9: begin
    if (smod) begin
                txd <= #1 1'b1; //stop bit
      shift_tr <= #1 1'b1;
              end
    end else begin
              4'd10: begin
      shift_tr    <= #1  smod_clk_tr;
          trans <= #1 1'b0;
      smod_clk_tr <= #1 !smod_clk_tr;
        end
 
              4'b1111: txd <= #1 1'b0; //start bit
 
              default: begin
 
                txd <= #1 sbuf_txd[tr_count];
 
              end
 
            endcase
 
            tr_count <= #1 tr_count+1'b1;
 
            smod_cnt_t <= #1 6'h00;
 
          end else smod_cnt_t <= #1 smod_cnt_t + 6'h01;
 
        end
        end
 
  end else begin
 
    shift_tr <= #1 1'b0;
      end
      end
    endcase
 
  end else
 
    txd <= #1 1'b1;
 
end
end
 
 
//
/*
//power control register
//
//
// transmit
always @(posedge clk or posedge rst)
//
begin
always @(posedge clk or posedge rst)
  if (rst)
begin
  begin
  if (rst) begin
    pcon <= #1 `OC8051_RST_PCON;
    txd <= #1 1'b1;
  end else if ((wr_addr==`OC8051_SFR_PCON) & (wr) & !(wr_bit))
    tr_count <= #1 4'd0;
    pcon <= #1 data_in;
    trans <= #1 1'b0;
end
    smod_cnt_t <= #1 6'h0;
 
//
 
// start transmiting
 
//
 
  end else if (tr_start) begin
 
    case (scon[7:6])
 
      2'b00: begin  // mode 0
 
        txd <= #1 sbuf_txd[0];
 
        tr_count <= #1 4'd1;
 
      end
 
      2'b10: begin
 
        txd <= #1 1'b0;
 
        tr_count <= #1 4'd0;
 
      end
 
      default: begin  // mode 1 and mode 3
 
        tr_count <= #1 4'b1111;
 
      end
 
    endcase
 
    trans <= #1 1'b1;
 
    smod_cnt_t <= #1 6'h0;
 
//
 
// transmiting/
 
//
 
  end else if (trans)
 
  begin
 
    case (scon[7:6])
 
      2'b00: begin //mode 0
 
        if (smod_cnt_t == 6'd12) begin
 
          if (tr_count==4'd8)
 
          begin
 
                  trans <= #1 1'b0;
 
                  txd <= #1 1'b1;
 
                end else begin
 
            txd <= #1 sbuf_txd[tr_count];
 
                  tr_count <= #1 tr_count + 4'b1;
 
                end
 
          smod_cnt_t <= #1 6'h0;
 
              end else smod_cnt_t <= #1 smod_cnt_t + 6'h01;
 
      end
 
      2'b01: begin // mode 1
 
        if ((t1_ow) & !(t1_ow_buf))
 
        begin
 
                if (((pcon[7]) &  (smod_cnt_t == 6'd15))| (!(pcon[7]) & (smod_cnt_t==6'd31)))
 
                begin
 
            case (tr_count)
 
              4'd8: txd <= #1 1'b1;  // stop bit
 
                    4'd9: trans <= #1 1'b0;
 
                    4'b1111: txd <= #1 1'b0; //start bit
 
                    default: txd <= #1 sbuf_txd[tr_count];
 
                  endcase
 
            tr_count <= #1 tr_count + 4'b1;
 
                  smod_cnt_t <= #1 6'h0;
 
                end else smod_cnt_t <= #1 smod_cnt_t + 6'h01;
 
              end
 
      end
 
      2'b10: begin // mode 2
 
//
 
// if smod (pcon[7]) is 1 count to 4 else count to 6
 
//
 
        if (((pcon[7]) & (smod_cnt_t==6'd31)) | (!(pcon[7]) & (smod_cnt_t==6'd63))) begin
 
            case (tr_count)
 
            4'd8: begin
 
                    txd <= #1 scon[3];
 
                  end
 
            4'd9: begin
 
                    txd <= #1 1'b1; //stop bit
 
                  end
 
            4'd10: begin
 
                    trans <= #1 1'b0;
 
                  end
 
 
 
                  default: begin
 
                    txd <= #1 sbuf_txd[tr_count];
 
                  end
 
                endcase
 
          tr_count <= #1 tr_count+1'b1;
 
                smod_cnt_t <= #1 6'h00;
 
              end else begin
 
          smod_cnt_t <= #1 smod_cnt_t + 6'h01;
 
              end
 
      end
 
      default: begin // mode 3
 
        if ((t1_ow) & !(t1_ow_buf))
 
        begin
 
      if (((pcon[7]) &  (smod_cnt_t == 6'd15))| (!(pcon[7]) & (smod_cnt_t==6'd31)))
 
          begin
 
            case (tr_count)
 
              4'd8: begin
 
                txd <= #1 scon[3];
 
              end
 
              4'd9: begin
 
                txd <= #1 1'b1; //stop bit
 
              end
 
              4'd10: begin
 
          trans <= #1 1'b0;
 
        end
 
              4'b1111: txd <= #1 1'b0; //start bit
 
              default: begin
 
                txd <= #1 sbuf_txd[tr_count];
 
              end
 
            endcase
 
            tr_count <= #1 tr_count+1'b1;
 
            smod_cnt_t <= #1 6'h00;
 
          end else smod_cnt_t <= #1 smod_cnt_t + 6'h01;
 
        end
 
      end
 
    endcase
 
  end else
 
    txd <= #1 1'b1;
 
end
 
*/
 
 
//
//
//serial port buffer (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
    re_count <= #1 4'd0;
    re_count <= #1 4'd0;
    receive <= #1 1'b0;
    receive <= #1 1'b0;
    sbuf_rxd <= #1 8'h00;
    sbuf_rxd <= #1 8'h00;
    sbuf_rxd_tmp <= #1 11'd0;
    sbuf_rxd_tmp <= #1 12'd0;
    smod_cnt_r <= #1 6'h00;
    rx_done      <= #1 1'b1;
    r_int <= #1 1'b0;
    rxd_r        <= #1 1'b1;
  end else if (receive) begin
    rx_sam       <= #1 2'b00;
    case (scon[7:6])
  end else if (!rx_done) begin
      2'b00: begin // mode 0
 
        if (smod_cnt_r==6'd12) begin
 
          if (re_count==4'd8) begin
 
                  receive <= #1 1'b0;
                  receive <= #1 1'b0;
                  r_int <= #1 1'b1;
    rx_done <= #1 1'b1;
                  sbuf_rxd <= #1 sbuf_rxd_tmp[8:1];
//    if (scon[7:6]==2'b00) begin
              end else begin
      sbuf_rxd <= #1 sbuf_rxd_tmp[10:3];
            sbuf_rxd_tmp[re_count + 4'd1] <= #1 rxd;
//    end else begin
                  r_int <= #1 1'b0;
//      sbuf_rxd <= #1 sbuf_rxd_tmp[8:1];
                end
//    end
 
  end else if (receive & (scon[7:6]==2'b00) & pres_ow) begin //mode 0
 
    {sbuf_rxd_tmp, rx_done} <= #1 {rxd, sbuf_rxd_tmp};
 
  end else if (receive & (scon[7:6]!=2'b00) & shift_re) begin //mode 1, 2, 3
          re_count <= #1 re_count + 4'd1;
          re_count <= #1 re_count + 4'd1;
          smod_cnt_r <= #1 6'h00;
    case (re_count)
        end else smod_cnt_r <= #1 smod_cnt_r + 6'h01;
      4'h7: rx_sam[0] <= #1 rxd;
      end
      4'h8: rx_sam[1] <= #1 rxd;
      2'b01: begin // mode 1
      4'h9: begin
        if ((t1_ow) & !(t1_ow_buf))
        {sbuf_rxd_tmp, rx_done} <= #1 {(rxd==rx_sam[0] ? rxd : rx_sam[1]), sbuf_rxd_tmp};
        begin
 
          if (((pcon[7]) &  (smod_cnt_r == 6'd15))| (!(pcon[7]) & (smod_cnt_r==6'd31)))
 
                begin
 
            r_int <= #1 1'b0;
 
            re_count <= #1 re_count + 4'd1;
 
            smod_cnt_r <= #1 6'h00;
 
            sbuf_rxd_tmp[re_count_buff] <= #1 rxd;
 
            if ((re_count==4'd0) && (rxd))
 
              receive <= #1 1'b0;
 
 
 
                end else smod_cnt_r <= #1 smod_cnt_r + 6'h01;
 
              end else begin
 
              r_int <= #1 1'b1;
 
            if (re_count == 4'd10)
 
          begin
 
              sbuf_rxd <= #1 sbuf_rxd_tmp[8:1];
 
            receive <= #1 1'b0;
 
              r_int <= #1 1'b1;
 
          end else r_int <= #1 1'b0;
 
        end
        end
 
    endcase
 
//
 
//start receiving
 
//
 
  end else if (scon[7:6]==2'b00) begin //start mode 0
 
    rx_done <= #1 1'b1;
 
    if (ren && !ri && !receive) begin
 
      receive      <= #1 1'b1;
 
      sbuf_rxd_tmp <= #1 10'h0ff;
      end
      end
      2'b10: begin // mode 2
  end else if (ren & shift_re) begin
        if (((pcon[7]) & (smod_cnt_r==6'd31)) | (!(pcon[7]) & (smod_cnt_r==6'd63))) begin
    rxd_r <= #1 rxd;
          r_int <= #1 1'b0;
    rx_done <= #1 1'b1;
            re_count <= #1 re_count + 4'd1;
    re_count <= #1 4'h0;
          smod_cnt_r <= #1 6'h00;
    receive <= #1 (rxd_r & !rxd);
          sbuf_rxd_tmp[re_count_buff] <= #1 rxd;
    sbuf_rxd_tmp <= #1 10'h1ff;
          re_count <= #1 re_count + 4'd1;
 
              end else begin
 
          smod_cnt_r <= #1 smod_cnt_r + 6'h1;
 
                if (re_count==4'd11) begin
 
                  sbuf_rxd <= #1 sbuf_rxd_tmp[8:1];
 
                  r_int <= #1 sbuf_rxd_tmp[0] | !scon[5];
 
                  receive <= #1 1'b0;
 
                end else
                end else
                  r_int <= #1 1'b0;
    rx_done <= #1 1'b1;
        end
        end
      end
 
      default: begin // mode 3
//
        if ((t1_ow) & !(t1_ow_buf))
//
        begin
reg sc_clk_re, smod_clk_re;
          if (((pcon[7]) &  (smod_cnt_r == 6'd15))| (!(pcon[7]) & (smod_cnt_r==6'd31)))
always @(brate2 or t1_ow or t1_ow_buf or scon[7:6] or rclk)
                begin
                begin
            sbuf_rxd_tmp[re_count] <= #1 rxd;
  if (scon[7:6]==8'b10) begin //mode 2
                  r_int <= #1 1'b0;
    sc_clk_re = 1'b1;
                re_count <= #1 re_count + 4'd1;
  end else if (rclk) begin //
                  smod_cnt_r <= #1 6'h00;
    sc_clk_re = brate2;
                end else smod_cnt_r <= #1 smod_cnt_r + 6'h01;
  end else begin //
              end else begin
    sc_clk_re = !t1_ow_buf & t1_ow;
          if (re_count==4'd11) begin
 
            sbuf_rxd <= #1 sbuf_rxd_tmp[8:1];
 
            receive <= #1 1'b0;
 
                  r_int <= #1 sbuf_rxd_tmp[0] | !scon[5];
 
                end else begin
 
            r_int <= #1 1'b0;
 
          end
 
              end
              end
      end
      end
    endcase
 
 
always @(posedge clk or posedge rst)
 
begin
 
  if (rst) begin
 
    smod_clk_re <= #1 1'b0;
 
    shift_re    <= #1 1'b0;
 
  end else if (sc_clk_re) begin
 
    if (smod) begin
 
      shift_re <= #1 1'b1;
  end else begin
  end else begin
    case (scon[7:6])
      shift_re    <= #1  smod_clk_re;
      2'b00: begin
      smod_clk_re <= #1 !smod_clk_re;
        if ((scon[4]) && !(scon[0]) && !(r_int)) begin
 
          receive <= #1 1'b1;
 
          smod_cnt_r <= #1 6'h6;
 
        end
 
      end
 
      2'b10: begin
 
        if ((scon[4]) && !(rxd)) begin
 
          receive <= #1 1'b1;
 
          if (pcon[7])
 
            smod_cnt_r <= #1 6'd15;
 
          else smod_cnt_r <= #1 6'd31;
 
        end
        end
      end
  end else begin
      default: begin
    shift_re <= #1 1'b0;
        if ((scon[4]) && (!rxd)) begin
 
          if (pcon[7])
 
            smod_cnt_r <= #1 6'd7;
 
          else smod_cnt_r <= #1 6'd15;
 
          receive <= #1 1'b1;
 
        end
        end
      end
      end
    endcase
 
 
 
    sbuf_rxd_tmp <= #1 11'd0;
 
    re_count <= #1 4'd0;
/*
    r_int <= #1 1'b0;
always @(posedge clk or posedge rst)
  end
begin
end
  if (rst) begin
 
    re_count <= #1 4'd0;
 
    receive <= #1 1'b0;
 
    sbuf_rxd <= #1 8'h00;
 
    sbuf_rxd_tmp <= #1 11'd0;
 
    smod_cnt_r <= #1 6'h00;
 
    r_int <= #1 1'b0;
 
  end else if (receive) begin
 
    case (scon[7:6])
 
      2'b00: begin // mode 0
 
        if (smod_cnt_r==6'd12) begin
 
          if (re_count==4'd8) begin
 
                  receive <= #1 1'b0;
 
                  r_int <= #1 1'b1;
 
                  sbuf_rxd <= #1 sbuf_rxd_tmp[8:1];
 
              end else begin
 
            sbuf_rxd_tmp[re_count + 4'd1] <= #1 rxd;
 
                  r_int <= #1 1'b0;
 
                end
 
          re_count <= #1 re_count + 4'd1;
 
          smod_cnt_r <= #1 6'h00;
 
        end else smod_cnt_r <= #1 smod_cnt_r + 6'h01;
 
      end
 
      2'b01: begin // mode 1
 
        if ((t1_ow) & !(t1_ow_buf))
 
        begin
 
          if (((pcon[7]) &  (smod_cnt_r == 6'd15))| (!(pcon[7]) & (smod_cnt_r==6'd31)))
 
                begin
 
            r_int <= #1 1'b0;
 
            re_count <= #1 re_count + 4'd1;
 
            smod_cnt_r <= #1 6'h00;
 
            sbuf_rxd_tmp[re_count_buff] <= #1 rxd;
 
            if ((re_count==4'd0) && (rxd))
 
              receive <= #1 1'b0;
 
 
 
                end else smod_cnt_r <= #1 smod_cnt_r + 6'h01;
 
              end else begin
 
              r_int <= #1 1'b1;
 
            if (re_count == 4'd10)
 
          begin
 
              sbuf_rxd <= #1 sbuf_rxd_tmp[8:1];
 
            receive <= #1 1'b0;
 
              r_int <= #1 1'b1;
 
          end else r_int <= #1 1'b0;
 
        end
 
      end
 
      2'b10: begin // mode 2
 
        if (((pcon[7]) & (smod_cnt_r==6'd31)) | (!(pcon[7]) & (smod_cnt_r==6'd63))) begin
 
          r_int <= #1 1'b0;
 
            re_count <= #1 re_count + 4'd1;
 
          smod_cnt_r <= #1 6'h00;
 
          sbuf_rxd_tmp[re_count_buff] <= #1 rxd;
 
          re_count <= #1 re_count + 4'd1;
 
              end else begin
 
          smod_cnt_r <= #1 smod_cnt_r + 6'h1;
 
                if (re_count==4'd11) begin
 
                  sbuf_rxd <= #1 sbuf_rxd_tmp[8:1];
 
                  r_int <= #1 sbuf_rxd_tmp[0] | !scon[5];
 
                  receive <= #1 1'b0;
 
                end else
 
                  r_int <= #1 1'b0;
 
        end
 
      end
 
      default: begin // mode 3
 
        if ((t1_ow) & !(t1_ow_buf))
 
        begin
 
          if (((pcon[7]) &  (smod_cnt_r == 6'd15))| (!(pcon[7]) & (smod_cnt_r==6'd31)))
 
                begin
 
            sbuf_rxd_tmp[re_count] <= #1 rxd;
 
                  r_int <= #1 1'b0;
 
                re_count <= #1 re_count + 4'd1;
 
                  smod_cnt_r <= #1 6'h00;
 
                end else smod_cnt_r <= #1 smod_cnt_r + 6'h01;
 
              end else begin
 
          if (re_count==4'd11) begin
 
            sbuf_rxd <= #1 sbuf_rxd_tmp[8:1];
 
            receive <= #1 1'b0;
 
                  r_int <= #1 sbuf_rxd_tmp[0] | !scon[5];
 
                end else begin
 
            r_int <= #1 1'b0;
 
          end
 
              end
 
      end
 
    endcase
 
  end else begin
 
    case (scon[7:6])
 
      2'b00: begin
 
        if ((scon[4]) && !(scon[0]) && !(r_int)) begin
 
          receive <= #1 1'b1;
 
          smod_cnt_r <= #1 6'h6;
 
        end
 
      end
 
      2'b10: begin
 
        if ((scon[4]) && !(rxd)) begin
 
          receive <= #1 1'b1;
 
          if (pcon[7])
 
            smod_cnt_r <= #1 6'd15;
 
          else smod_cnt_r <= #1 6'd31;
 
        end
 
      end
 
      default: begin
 
        if ((scon[4]) && (!rxd)) begin
 
          if (pcon[7])
 
            smod_cnt_r <= #1 6'd7;
 
          else smod_cnt_r <= #1 6'd15;
 
          receive <= #1 1'b1;
 
        end
 
      end
 
    endcase
 
 
 
    sbuf_rxd_tmp <= #1 11'd0;
 
    re_count <= #1 4'd0;
 
    r_int <= #1 1'b0;
 
  end
 
end
 
*/
 
 
//
//
//
//
//
//
always @(posedge clk or posedge rst)
always @(posedge clk or posedge rst)
Line 393... Line 606...
 
 
 
 
always @(posedge clk or posedge rst)
always @(posedge clk or posedge rst)
begin
begin
  if (rst) begin
  if (rst) begin
    trans_buf <= #1 1'b0;
//    trans_buf <= #1 1'b0;
    receive_buf <= #1 1'b0;
//    receive_buf <= #1 1'b0;
    t1_ow_buf <= #1 1'b0;
    t1_ow_buf <= #1 1'b0;
    rxd_buf <= #1 1'b0;
//    rxd_buf <= #1 1'b0;
  end else begin
  end else begin
    trans_buf <= #1 trans;
//    trans_buf <= #1 trans;
    receive_buf <= #1 receive;
//    receive_buf <= #1 receive;
    t1_ow_buf <= #1 t1_ow;
    t1_ow_buf <= #1 t1_ow;
    rxd_buf <= #1 rxd;
//    rxd_buf <= #1 rxd;
  end
  end
end
end
 
 
 
 
always  @(posedge clk or posedge rst)
always  @(posedge clk or posedge rst)
begin
begin
  if (rst) bit_out <= #1 1'b0;
  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
  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
 
 
always @(posedge clk or posedge rst)
/*
  if (rst)
always @(posedge clk or posedge rst)
    re_count_buff <= #1 4'h4;
  if (rst)
  else re_count_buff <= #1 re_count;
    re_count_buff <= #1 4'h4;
 
  else re_count_buff <= #1 re_count;
 
*/
 
 
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.