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

Subversion Repositories ssbcc

[/] [ssbcc/] [trunk/] [core/] [9x8/] [peripherals/] [UART_Tx.v] - Blame information for rev 5

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

Line No. Rev Author Line
1 2 sinclairrf
//
2
// PERIPHERAL UART_Tx:  @NAME@
3
//
4
localparam L__OUTFIFO_NBITS = $clog2(@OUTFIFO@);
5
localparam L__COUNT         = @BAUDMETHOD@-1;
6
localparam L__COUNT_NBITS   = $clog2(L__COUNT+1);
7
localparam L__NTX           = 1+8+@NSTOP@-1;
8
localparam L__NTX_NBITS     = $clog2((L__NTX==0)?1:L__NTX);
9
generate
10
reg  [7:0] s__Tx_data;
11
reg        s__Tx_go;
12
reg        s__Tx_uart_busy;
13
if (@OUTFIFO@ == 0) begin : gen__nooutfifo
14
  always @ (s__Tx_uart_busy)
15
    s__Tx_busy = s__Tx_uart_busy;
16
  always @ (s__Tx)
17
    s__Tx_data = s__Tx;
18
  always @ (s__Tx_wr)
19
    s__Tx_go = s__Tx_wr;
20
end else begin : gen__outfifo
21
  reg [7:0] s__Tx_fifo_mem[@OUTFIFO@-1:0];
22
  reg [L__OUTFIFO_NBITS:0] s__Tx_fifo_addr_in = {(L__OUTFIFO_NBITS+1){1'b0}};
23
  always @ (posedge i_clk)
24
    if (i_rst)
25
      s__Tx_fifo_addr_in <= {(L__OUTFIFO_NBITS+1){1'b0}};
26
    else if (s__Tx_wr) begin
27
      s__Tx_fifo_addr_in <= s__Tx_fifo_addr_in + { {(L__OUTFIFO_NBITS){1'b0}}, 1'b1 };
28
      s__Tx_fifo_mem[s__Tx_fifo_addr_in[0+:L__OUTFIFO_NBITS]] <= s__Tx;
29
    end else
30
      s__Tx_fifo_addr_in <= s__Tx_fifo_addr_in;
31
  reg [L__OUTFIFO_NBITS:0] s__Tx_fifo_addr_out;
32
  reg s__Tx_fifo_has_data = 1'b0;
33
  reg s__Tx_fifo_full = 1'b0;
34
  always @ (posedge i_clk)
35
    if (i_rst) begin
36
      s__Tx_fifo_has_data <= 1'b0;
37
      s__Tx_fifo_full <= 1'b0;
38
    end else begin
39
      s__Tx_fifo_has_data <= (s__Tx_fifo_addr_out != s__Tx_fifo_addr_in);
40
      s__Tx_fifo_full <= (s__Tx_fifo_addr_out == (s__Tx_fifo_addr_in ^ { 1'b1, {(L__OUTFIFO_NBITS){1'b0}} }));
41
    end
42
  initial s__Tx_go = 1'b0;
43
  always @ (posedge i_clk)
44
    if (i_rst)
45
      s__Tx_go <= 1'b0;
46
    else if (s__Tx_fifo_has_data && !s__Tx_uart_busy && !s__Tx_go)
47
      s__Tx_go <= 1'b1;
48
    else
49
      s__Tx_go <= 1'b0;
50
  initial s__Tx_fifo_addr_out = {(L__OUTFIFO_NBITS+1){1'b0}};
51
  always @ (posedge i_clk)
52
    if (i_rst)
53
      s__Tx_fifo_addr_out <= {(L__OUTFIFO_NBITS+1){1'b0}};
54
    else if (s__Tx_go)
55
      s__Tx_fifo_addr_out <= s__Tx_fifo_addr_out + { {(L__OUTFIFO_NBITS){1'b0}}, 1'b1 };
56
    else
57
      s__Tx_fifo_addr_out <= s__Tx_fifo_addr_out;
58
  initial s__Tx_data = 8'd0;
59
  always @ (posedge i_clk)
60
    if (i_rst)
61
      s__Tx_data <= 8'd0;
62
    else
63
      s__Tx_data <= s__Tx_fifo_mem[s__Tx_fifo_addr_out[0+:L__OUTFIFO_NBITS]];
64
  always @ (s__Tx_fifo_full)
65
    s__Tx_busy = s__Tx_fifo_full;
66
end
67
// Count the clock cycles to decimate to the desired baud rate.
68
reg [L__COUNT_NBITS-1:0] s__Tx_count = {(L__COUNT_NBITS){1'b0}};
69
reg s__Tx_count_is_zero = 1'b0;
70
always @ (posedge i_clk)
71
  if (i_rst) begin
72
    s__Tx_count <= {(L__COUNT_NBITS){1'b0}};
73
    s__Tx_count_is_zero <= 1'b0;
74
  end else if (s__Tx_go || s__Tx_count_is_zero) begin
75
    s__Tx_count <= L__COUNT[0+:L__COUNT_NBITS];
76
    s__Tx_count_is_zero <= 1'b0;
77
  end else begin
78
    s__Tx_count <= s__Tx_count - { {(L__COUNT_NBITS-1){1'b0}}, 1'b1 };
79
    s__Tx_count_is_zero <= (s__Tx_count == { {(L__COUNT_NBITS-1){1'b0}}, 1'b1 });
80
  end
81
// Latch the bits to output.
82
reg [7:0] s__Tx_stream = 8'hFF;
83
always @ (posedge i_clk)
84
  if (i_rst)
85
    s__Tx_stream <= 8'hFF;
86
  else if (s__Tx_go)
87
    s__Tx_stream <= s__Tx_data;
88
  else if (s__Tx_count_is_zero)
89
    s__Tx_stream <= { 1'b1, s__Tx_stream[1+:7] };
90
  else
91
    s__Tx_stream <= s__Tx_stream;
92
// Generate the output bit stream.
93
initial @NAME@ = 1'b1;
94
always @ (posedge i_clk)
95
  if (i_rst)
96
    @NAME@ <= 1'b1;
97
  else if (s__Tx_go)
98
    @NAME@ <= 1'b0;
99
  else if (s__Tx_count_is_zero)
100
    @NAME@ <= s__Tx_stream[0];
101
  else
102
    @NAME@ <= @NAME@;
103
// Count down the number of bits.
104
reg [L__NTX_NBITS-1:0] s__Tx_n = {(L__NTX_NBITS){1'b0}};
105
always @ (posedge i_clk)
106
  if (i_rst)
107
    s__Tx_n <= {(L__NTX_NBITS){1'b0}};
108
  else if (s__Tx_go)
109
    s__Tx_n <= L__NTX[0+:L__NTX_NBITS];
110
  else if (s__Tx_count_is_zero)
111
    s__Tx_n <= s__Tx_n - { {(L__NTX_NBITS-1){1'b0}}, 1'b1 };
112
  else
113
    s__Tx_n <= s__Tx_n;
114
// The status bit is 1 if the core is busy and 0 otherwise.
115
initial s__Tx_uart_busy = 1'b1;
116
always @ (posedge i_clk)
117
  if (i_rst)
118
    s__Tx_uart_busy <= 1'b0;
119
  else if (s__Tx_go)
120
    s__Tx_uart_busy <= 1'b1;
121
  else if (s__Tx_count_is_zero && (s__Tx_n == {(L__NTX_NBITS){1'b0}}))
122
    s__Tx_uart_busy <= 1'b0;
123
  else
124
    s__Tx_uart_busy <= s__Tx_uart_busy;
125
endgenerate

powered by: WebSVN 2.1.0

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