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

Subversion Repositories m16c5x

[/] [m16c5x/] [trunk/] [RTL/] [Sim/] [tb_M16C5x.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 MichaelA
`timescale 1ns / 1ps
2
 
3
////////////////////////////////////////////////////////////////////////////////
4
// Company:         M. A. Morris & Associates
5
// Engineer:        Michael A. Morris
6
//
7
// Create Date:     08:46:12 07/04/2013
8
// Design Name:     M16C5x
9
// Module Name:     C:/XProjects/ISE10.1i/M16C5x/tb_M16C5x.v
10
// Project Name:    M16C5x
11
// Target Device:   SRAM FPGAs: XC3S50A-4VQG100I, XC3S200A-4VQG100I
12
// Tool versions:   Xilinx ISE 10.1i SP3
13
 
14
// Description: 
15
//
16
// Verilog Test Fixture created by ISE for module: M16C5x
17
//
18
// Dependencies:
19
// 
20
// Revision:
21
//
22
//  0.01    13G07   MAM     File Created
23
//
24
// Additional Comments:
25
// 
26
////////////////////////////////////////////////////////////////////////////////
27
 
28
module tb_M16C5x;
29
 
30
reg     ClkIn;
31
reg     Clk_UART;
32
//
33
reg     nMCLR;
34
//
35
reg     nT0CKI;
36
reg     nWDTE;
37
reg     PROM_WE;
38
//
39
wire    TD;
40
wire    RD;
41
wire    nRTS;
42
reg     nCTS;
43
//
44
wire    [2:0] nCS;
45
wire    SCK;
46
wire    MOSI;
47
reg     MISO;
48
//
49
wire    [2:0] nCSO;
50
wire    nWait;
51
 
52
//  Simulation Structures
53
 
54
reg     [3:0] Clk_Div;
55
reg     Clk_16x;
56
 
57
reg     TF_EF;
58
reg     [7:0] THR;
59
wire    TF_RE;
60
wire    Idle;
61
 
62
// Instantiate the Unit Under Test (UUT)
63
 
64
M16C5x  #(
65
            .pUserProg("Src/M16C5x_Tst4.coe")
66
        ) uut (
67
            .ClkIn(ClkIn),
68
 
69
            .nMCLR(nMCLR),
70
 
71
            .nT0CKI(nT0CKI),
72
            .nWDTE(nWDTE),
73
            .PROM_WE(PROM_WE),
74
 
75
            .TD(TD),
76
            .RD(RD),
77
            .nRTS(nRTS),
78
            .nCTS(nCTS),
79
            .DE(DE),
80
 
81
            .nCS(nCS),
82
            .SCK(SCK),
83
            .MOSI(MOSI),
84
            .MISO(MISO),
85
 
86
            .nCSO(nCSO),
87
            .nWait(nWait)
88
        );
89
 
90
//  Instantiate a UART Transmitter for testing UART Receiver in M16C5x
91
 
92
UART_TXSM   RxD (
93
                .Rst(~nMCLR),   // Reset
94
                .Clk(Clk_UART), // UART Clock - 29.4912 MHz
95
 
96
                .CE_16x(Clk_16x),   // 16x Clock Enable - Baud Rate x16
97
 
98
                .Len(1'b0),     // Word length: 0 - 8-bits; 1 - 7 bits
99
                .NumStop(1'b0), // Number Stop Bits: 0 - 1 Stop; 1 - 2 Stop
100
                .ParEn(1'b0),   // Parity Enable
101
                .Par(2'b00),    // 0 - Odd;       1 - Even;
102
                                // 2 - Space (0); 3 - Mark (1)
103
 
104
                .TF_EF(TF_EF),  // Transmit THR Empty Flag
105
 
106
                .THR(THR),      // Transmit Holding Register
107
                .TF_RE(TF_RE),  // Transmit THR Read Enable Strobe
108
 
109
                .CTSi(1'b1),    // RS232 Mode CTS input
110
 
111
                .TxD(RD),       // Serial Data Out, LSB First, Start bit = 0
112
 
113
                .TxIdle(Idle),  // Transmit SM - Idle State
114
                .TxStart(),     // Transmit SM - Start State - CTS wait
115
                .TxShift(),     // Transmit SM - Shift State
116
                .TxStop()       // Transmit SM - Stop State - RTS clear
117
            );
118
 
119
 
120
initial begin
121
    // Initialize Inputs
122
    ClkIn    = 1;
123
    Clk_UART = 1;
124
    nMCLR    = 0;
125
    nT0CKI   = 0;
126
    nWDTE    = 1;
127
    PROM_WE  = 0;
128
 
129
    nCTS     = 0;
130
    MISO     = 1;
131
 
132
    Clk_Div = ~0;
133
    Clk_16x =  0;
134
    TF_EF   =  1;
135
    THR     =  8'h00;
136
 
137
    // Wait 100 ns for global reset to finish
138
 
139
    #201 nMCLR = 1;
140
 
141
    // Add stimulus here
142
 
143
    @(negedge nRTS);
144
 
145
    #20000 PutCh(8'hFF);
146
    #20000 PutCh(8'h80);
147
    #20000 PutCh(8'h7B);
148
    #20000 PutCh(8'h7A);
149
    #20000 PutCh(8'h61);
150
    #20000 PutCh(8'h60);
151
    #20000 PutCh(8'h5B);
152
    #20000 PutCh(8'h5A);
153
    #20000 PutCh(8'h41);
154
    #20000 PutCh(8'h40);
155
    #20000 PutCh(8'h39);
156
    #20000 PutCh(8'h31);
157
    #20000 PutCh(8'h00);
158
 
159
end
160
 
161
////////////////////////////////////////////////////////////////////////////////
162
 
163
always #33.908 ClkIn = ~ClkIn;          // Reference Clock - 14.7456 MHz
164
 
165
////////////////////////////////////////////////////////////////////////////////
166
 
167
always #16.954 Clk_UART = ~Clk_UART;    // UART Clock      - 29.4912 MHz
168
 
169
////////////////////////////////////////////////////////////////////////////////
170
 
171
always @(posedge Clk_UART or negedge nMCLR)
172
begin
173
    if(~nMCLR) begin
174
        Clk_Div <= #1 ~0;
175
        Clk_16x <= #1  0;
176
    end else begin
177
        Clk_Div <= #1 (Clk_Div - 1);
178
        Clk_16x <= #1 ~|Clk_Div;
179
    end
180
end
181
 
182
////////////////////////////////////////////////////////////////////////////////
183
 
184
task PutCh;
185
    input   [7:0] ch;
186
 
187
    begin
188
        @(posedge Clk_UART) #1;
189
        TF_EF = 0; THR = ch;
190
        @(posedge TF_RE);
191
        @(posedge Clk_UART) #1;
192
        TF_EF = 1;
193
    end
194
 
195
endtask
196
 
197
endmodule
198
 

powered by: WebSVN 2.1.0

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