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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [fpga/] [mc/] [src/] [ser/] [ser.v] - Blame information for rev 318

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 117 hellwig
//
2
// ser.v -- serial line interface
3
//
4
 
5
 
6 290 hellwig
`timescale 1ns/10ps
7
`default_nettype none
8
 
9
 
10
module ser(clk, rst,
11
           stb, we, addr,
12 27 hellwig
           data_in, data_out,
13 290 hellwig
           ack, irq_r, irq_t,
14 27 hellwig
           rxd, txd);
15 117 hellwig
    // internal interface
16 27 hellwig
    input clk;
17 290 hellwig
    input rst;
18
    input stb;
19
    input we;
20 27 hellwig
    input [3:2] addr;
21
    input [7:0] data_in;
22
    output reg [7:0] data_out;
23 290 hellwig
    output ack;
24 27 hellwig
    output irq_r;
25
    output irq_t;
26 117 hellwig
    // external interface
27 27 hellwig
    input rxd;
28
    output txd;
29
 
30
  wire wr_rcv_ctrl;
31
  wire rd_rcv_data;
32
  wire wr_xmt_ctrl;
33
  wire wr_xmt_data;
34
 
35 290 hellwig
  wire rcv_rdy;
36 27 hellwig
  reg rcv_ien;
37
  wire [7:0] rcv_data;
38 290 hellwig
  wire xmt_rdy;
39 27 hellwig
  reg xmt_ien;
40
 
41 290 hellwig
  assign wr_rcv_ctrl = (stb == 1 && we == 1 && addr == 2'b00) ? 1 : 0;
42
  assign rd_rcv_data = (stb == 1 && we == 0 && addr == 2'b01) ? 1 : 0;
43
  assign wr_xmt_ctrl = (stb == 1 && we == 1 && addr == 2'b10) ? 1 : 0;
44
  assign wr_xmt_data = (stb == 1 && we == 1 && addr == 2'b11) ? 1 : 0;
45 27 hellwig
 
46 290 hellwig
  rcvbuf rcvbuf_1(clk, rst, rd_rcv_data, rcv_rdy, rcv_data, rxd);
47
  xmtbuf xmtbuf_1(clk, rst, wr_xmt_data, xmt_rdy, data_in, txd);
48 27 hellwig
 
49
  always @(posedge clk) begin
50 290 hellwig
    if (rst) begin
51 27 hellwig
      rcv_ien <= 0;
52
      xmt_ien <= 0;
53
    end else begin
54
      if (wr_rcv_ctrl) begin
55
        rcv_ien <= data_in[1];
56
      end
57
      if (wr_xmt_ctrl) begin
58
        xmt_ien <= data_in[1];
59
      end
60
    end
61
  end
62
 
63
  always @(*) begin
64
    case (addr[3:2])
65
      2'b00:
66
        // rcv ctrl
67 290 hellwig
        data_out = { 6'b000000, rcv_ien, rcv_rdy };
68 27 hellwig
      2'b01:
69
        // rcv data
70
        data_out = rcv_data;
71
      2'b10:
72
        // xmt ctrl
73 290 hellwig
        data_out = { 6'b000000, xmt_ien, xmt_rdy };
74 27 hellwig
      2'b11:
75
        // xmt data (cannot be read)
76
        data_out = 8'hxx;
77
      default:
78
        data_out = 8'hxx;
79
    endcase
80
  end
81
 
82 290 hellwig
  assign ack = stb;
83
  assign irq_r = rcv_ien & rcv_rdy;
84
  assign irq_t = xmt_ien & xmt_rdy;
85 27 hellwig
 
86
endmodule

powered by: WebSVN 2.1.0

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