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

Subversion Repositories 8051

[/] [8051/] [trunk/] [bench/] [verilog/] [oc8051_serial.v] - Blame information for rev 186

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 184 simont
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  8051 test serial interface                                  ////
4
////                                                              ////
5
////  This file is part of the 8051 cores project                 ////
6
////  http://www.opencores.org/cores/8051/                        ////
7
////                                                              ////
8
////  Description                                                 ////
9
////   submodul of oc8051_tb, used to comunicate with 8051        ////
10
////   serial potr                                                ////
11
////                                                              ////
12
////  To Do:                                                      ////
13
////   nothing                                                    ////
14
////                                                              ////
15
////  Author(s):                                                  ////
16
////      - Simon Teran, simont@opencores.org                     ////
17
////                                                              ////
18
//////////////////////////////////////////////////////////////////////
19
////                                                              ////
20
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
21
////                                                              ////
22
//// This source file may be used and distributed without         ////
23
//// restriction provided that this copyright statement is not    ////
24
//// removed from the file and that any derivative work contains  ////
25
//// the original copyright notice and the associated disclaimer. ////
26
////                                                              ////
27
//// This source file is free software; you can redistribute it   ////
28
//// and/or modify it under the terms of the GNU Lesser General   ////
29
//// Public License as published by the Free Software Foundation; ////
30
//// either version 2.1 of the License, or (at your option) any   ////
31
//// later version.                                               ////
32
////                                                              ////
33
//// This source is distributed in the hope that it will be       ////
34
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
35
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
36
//// PURPOSE.  See the GNU Lesser General Public License for more ////
37
//// details.                                                     ////
38
////                                                              ////
39
//// You should have received a copy of the GNU Lesser General    ////
40
//// Public License along with this source; if not, download it   ////
41
//// from http://www.opencores.org/lgpl.shtml                     ////
42
////                                                              ////
43
//////////////////////////////////////////////////////////////////////
44
//
45
// CVS Revision History
46
//
47
// $Log: not supported by cvs2svn $
48
//
49
//
50
 
51
// synopsys translate_off
52
`include "oc8051_timescale.v"
53
// synopsys translate_on
54
 
55
 
56
module oc8051_serial (clk, rst, rxd, txd);
57
 
58
parameter FREQ  = 25000;
59
parameter BRATE = 9.6;
60
 
61
parameter DELAY = FREQ/BRATE;
62
 
63
input        clk,
64
             rst,
65
             rxd;
66
 
67
output       txd;
68
 
69
reg          txd,
70
             transmit;
71
reg          txd_start;
72
reg   [8:0]  txd_data;
73
reg   [15:0] count;
74
reg   [8:0]  txd_buf;
75
reg   [63:0] wait_t;
76
reg   [7:0]  buff [0:65535];
77
 
78
reg          receive;
79
reg   [7:0]  rxd_buf;
80
reg   [63:0] wait_r;
81
 
82
reg   [7:0] tmp;
83
 
84
reg receive_r;
85
reg rxd_r;
86
 
87
initial
88
begin
89
  $readmemh("../../../serial.txt", buff);
90
end
91
 
92
/*
93
always @(posedge clk or posedge rst)
94
  if (rst) begin
95
    count <= #1 16'h0;
96
  end else begin
97
    count <= #1 count + 16'h1;
98
    $display (" serial h: %h   d: %d    count: %h", buff[count],  buff[count], count);
99
  end
100
*/
101
 
102
always @(posedge clk or posedge rst)
103
  if (rst) begin
104
    wait_t   <= #1 64'h0;
105
    txd_buf  <= #1 9'h1ff;
106
    txd      <= #1 1'b1;
107
    transmit <= #1 1'b0;
108
  end else if (txd_start) begin
109
    transmit <= #1 1'b1;
110
    txd_buf  <= #1 {txd_data, 1'b0};
111
  end else if ((wait_t >= DELAY) & transmit) begin
112
    wait_t         <= #1 64'h0;
113
    {txd_buf, txd} <= #1 {1'b1, txd_buf};
114
    transmit       <= #1 ~&{txd_buf, txd};
115
  end else begin
116
    wait_t  <= #1 wait_t + 64'h1;
117
  end
118
 
119
always @(posedge clk or posedge rst)
120
  if (rst) begin
121
    wait_r    <= #1 64'h0;
122
    rxd_buf   <= #1 8'hff;
123
    rxd_r     <= #1 1'b0;
124
    receive   <= #1 1'b0;
125
  end else if (rxd_r & !rxd & !receive) begin
126
    wait_r  <= #1 DELAY / 2;
127
    rxd_r <= #1 1'b0;
128
    receive <= #1 1'b1;
129
    rxd_buf <= #1 8'hff;
130
  end else if ((wait_r >= DELAY) & receive) begin
131
    wait_r  <= #1 64'h0;
132
    {rxd_buf, receive} <= #1 {rxd, rxd_buf};
133
  end else if (receive) begin
134
    wait_r  <= #1 wait_r + 64'h1;
135
  end else begin
136
    rxd_r <= #1 rxd;
137
  end
138
 
139
 
140
always @(posedge clk or posedge rst)
141
begin
142
  if (rst) begin
143
    receive_r <= #1 1'b0;
144
    txd_start <= #1 1'b0;
145
    txd_data  <= #1 8'h0;
146
    tmp       <= #1 8'h0;
147
  end else if (!receive & receive_r) begin
148
    receive_r <= #1 1'b0;
149
    if ((tmp==8'h3f) && (rxd_buf==8'h20)) begin
150
      txd_start <= #1 1'b1;
151
      txd_data  <= #1 8'h33;
152
    end else if (rxd_buf==8'h33) begin
153
      txd_start <= #1 1'b1;
154
      txd_data  <= #1 8'h36;
155
    end else if (rxd_buf==8'h36) begin
156
      txd_start <= #1 1'b1;
157
      txd_data  <= #1 8'h0a;
158
    end
159
    tmp         <= #1 rxd_buf;
160
    $display (" receive:  %s , %h", rxd_buf, rxd_buf);
161
  end else begin
162
    txd_start   <= #1 1'b0;
163
    receive_r   <= #1 receive;
164
  end
165
end
166
 
167
endmodule

powered by: WebSVN 2.1.0

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