| 1 |
6 |
julius |
//////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
//// ////
|
| 3 |
|
|
//// ORPSoC Testbench UART Decoder ////
|
| 4 |
|
|
//// ////
|
| 5 |
|
|
//// Description ////
|
| 6 |
|
|
//// ORPSoC Testbench UART output decoder ////
|
| 7 |
|
|
//// ////
|
| 8 |
|
|
//// To Do: ////
|
| 9 |
|
|
//// ////
|
| 10 |
|
|
//// ////
|
| 11 |
|
|
//// Author(s): ////
|
| 12 |
|
|
//// - jb, jb@orsoc.se ////
|
| 13 |
|
|
//// ////
|
| 14 |
|
|
//// ////
|
| 15 |
|
|
//////////////////////////////////////////////////////////////////////
|
| 16 |
|
|
//// ////
|
| 17 |
|
|
//// Copyright (C) 2009 Authors and OPENCORES.ORG ////
|
| 18 |
|
|
//// ////
|
| 19 |
|
|
//// This source file may be used and distributed without ////
|
| 20 |
|
|
//// restriction provided that this copyright statement is not ////
|
| 21 |
|
|
//// removed from the file and that any derivative work contains ////
|
| 22 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
| 23 |
|
|
//// ////
|
| 24 |
|
|
//// This source file is free software; you can redistribute it ////
|
| 25 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
| 26 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
| 27 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
| 28 |
|
|
//// later version. ////
|
| 29 |
|
|
//// ////
|
| 30 |
|
|
//// This source is distributed in the hope that it will be ////
|
| 31 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
| 32 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
| 33 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
| 34 |
|
|
//// details. ////
|
| 35 |
|
|
//// ////
|
| 36 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
| 37 |
|
|
//// Public License along with this source; if not, download it ////
|
| 38 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
| 39 |
|
|
//// ////
|
| 40 |
|
|
//////////////////////////////////////////////////////////////////////
|
| 41 |
|
|
|
| 42 |
|
|
// Decodes UART signals sent over the line defined by UART_TX_LINE
|
| 43 |
|
|
|
| 44 |
|
|
// `include this file in the testbench and define UART_TX_LINE
|
| 45 |
|
|
// Uses define CLOCK_RATE as the frequency of the clock in Hz
|
| 46 |
|
|
|
| 47 |
|
|
// Receieves and decodes 8-bit, 1 stop bit, no parity UART signals.
|
| 48 |
|
|
|
| 49 |
|
|
// Requires definition of:
|
| 50 |
|
|
// CLK_RATE - frequency of system clock in Hz
|
| 51 |
|
|
// CLK_PERIOD - period of clock frequency in ns
|
| 52 |
|
|
// UART_BAUDRATE - otherwise defaults to 115200
|
| 53 |
|
|
// UART_TX_LINE - name of the UART output signal (normally a wire)
|
| 54 |
|
|
|
| 55 |
|
|
// if it's not already defined, uses UART_BAUDRATE as baud to receive
|
| 56 |
|
|
// bytes at
|
| 57 |
|
|
`ifndef UART_BAUDRATE
|
| 58 |
|
|
`define UART_BAUDRATE 115200
|
| 59 |
|
|
`endif
|
| 60 |
|
|
|
| 61 |
|
|
`ifndef CLOCK_RATE
|
| 62 |
|
|
initial
|
| 63 |
|
|
begin
|
| 64 |
|
|
$display("* WARNING: uart_decoder included but CLOCK_RATE not defined.");
|
| 65 |
|
|
end
|
| 66 |
|
|
`else
|
| 67 |
|
|
`ifdef UART_TX_LINE
|
| 68 |
|
|
parameter UART_TX_WAIT = (`CLOCK_RATE / `UART_BAUDRATE) * `CLOCK_PERIOD;
|
| 69 |
|
|
|
| 70 |
|
|
// Something to trigger the task
|
| 71 |
|
|
always @(posedge clk)
|
| 72 |
|
|
uart_decoder;
|
| 73 |
|
|
|
| 74 |
|
|
task uart_decoder;
|
| 75 |
|
|
reg [7:0] tx_byte;
|
| 76 |
|
|
begin
|
| 77 |
|
|
|
| 78 |
|
|
// Wait for start bit
|
| 79 |
|
|
while (`UART_TX_LINE == 1'b1)
|
| 80 |
|
|
@(`UART_TX_LINE);
|
| 81 |
|
|
#(UART_TX_WAIT+(UART_TX_WAIT/2));
|
| 82 |
|
|
tx_byte[0] = `UART_TX_LINE;
|
| 83 |
|
|
#UART_TX_WAIT;
|
| 84 |
|
|
tx_byte[1] = `UART_TX_LINE;
|
| 85 |
|
|
#UART_TX_WAIT;
|
| 86 |
|
|
tx_byte[2] = `UART_TX_LINE;
|
| 87 |
|
|
#UART_TX_WAIT;
|
| 88 |
|
|
tx_byte[3] = `UART_TX_LINE;
|
| 89 |
|
|
#UART_TX_WAIT;
|
| 90 |
|
|
tx_byte[4] = `UART_TX_LINE;
|
| 91 |
|
|
#UART_TX_WAIT;
|
| 92 |
|
|
tx_byte[5] = `UART_TX_LINE;
|
| 93 |
|
|
#UART_TX_WAIT;
|
| 94 |
|
|
tx_byte[6] = `UART_TX_LINE;
|
| 95 |
|
|
#UART_TX_WAIT;
|
| 96 |
|
|
tx_byte[7] = `UART_TX_LINE;
|
| 97 |
|
|
#UART_TX_WAIT;
|
| 98 |
|
|
//Check for stop bit
|
| 99 |
|
|
if (`UART_TX_LINE == 1'b0)
|
| 100 |
|
|
begin
|
| 101 |
|
|
//$display("* WARNING: user stop bit not received when expected at time %d__", $time);
|
| 102 |
|
|
// Wait for return to idle
|
| 103 |
|
|
while (`UART_TX_LINE == 1'b0)
|
| 104 |
|
|
@(`UART_TX_LINE);
|
| 105 |
|
|
//$display("* USER UART returned to idle at time %d",$time);
|
| 106 |
|
|
end
|
| 107 |
|
|
// display the char
|
| 108 |
|
|
$write("%c", tx_byte);
|
| 109 |
|
|
end
|
| 110 |
|
|
endtask // user_uart_read_byte
|
| 111 |
|
|
`else // !`ifdef UART_TX_LINE
|
| 112 |
|
|
// If this file was included but not setup properly
|
| 113 |
|
|
initial
|
| 114 |
|
|
begin
|
| 115 |
|
|
$display("* WARNING: uart_decoder included but UART_TX_LINE not defined.");
|
| 116 |
|
|
end
|
| 117 |
|
|
`endif // !`ifdef UART_TX_LINE
|
| 118 |
|
|
`endif // !`ifndef CLOCK_RATE
|