|
|
1 class uart_sb {
2 integer tx;
3 integer rx;
4
5 task new() {
6 tx = alloc(MAILBOX,0,1);
7 rx = alloc(MAILBOX,0,1);
8 }
9
10 task txAdd(bit [7:0] data) {
11 mailbox_put(tx,data);
12 printf("%dns : txAdd : Added data %x\n",get_cycle(), data);
13 }
14
15 task rxAdd(bit [7:0] data) {
16 mailbox_put(rx,data);
17 printf("%dns : rxAdd : Added data %x\n",get_cycle(), data);
18 }
19
20 task txCompare(bit [7:0] data) {
21 bit [7:0] org_data;
22 mailbox_get (WAIT,tx,org_data);
23 if (data ! = org_data) {
24 printf("%dns : txCompare : Error : Expected data %x, Got %x\n",
25 get_cycle(), org_data, data);
26 } else {
27 printf("%dns : txCompare : Match : Expected data %x, Got %x\n",
28 get_cycle(), org_data, data);
29 }
30 }
31
32 task rxCompare(bit [7:0] data) {
33 bit [7:0] org_data;
34 mailbox_get (WAIT,rx,org_data);
35 if (data ! = org_data) {
36 printf("%dns : rxCompare : Error : Expected data %x, Got %x\n",
37 get_cycle(), org_data, data);
38 } else {
39 printf("%dns : rxCompare : Match : Expected data %x, Got %x\n",
40 get_cycle(), org_data, data);
41 }
42 }
43 }
You could download file vera_examples here
|
|
|
1 class uart_txgen {
2 uart_sb sb;
3 uart_ports ports;
4 bit tx_done;
5 bit rx_done;
6
7 // Connects the transmitter output to recevier input
8 bit loopback;
9 // Number of frames to send to transmitter
10 integer no_tx_cmds;
11 // Number of frames to send to receiver
12 integer no_rx_cmds;
13 // Delay the reading of data from receiver
14 bit rx_over_flow;
15 // Send frame to transmitter before it has sent out last frame
16 bit tx_over_flow;
17 // Insert framming error (stop bit) in frame sent to receiver
18 bit rx_frame_err;
19
20 task new () {
21 this.ports = uart_p;
22 sb = new();
23 tx_done = 0;
24 rx_done = 0;
25 no_tx_cmds = 5;
26 no_rx_cmds = 5;
27 rx_over_flow = 0;
28 rx_frame_err = 0;
29 ports.$rx_tb_in = 1;
30 ports.$uld_rx_data = 0;
31 }
32
33 // Main method, which starts rest of methods
34 task goTxgen() {
35 tx_done = 0;
36 rx_done = 0;
37 assertReset();
38 fork
39 { txDriver(); }
40 { rxDriver(); }
41 { txMonitor(); }
42 { rxMonitor(); }
43 join none
44 }
45 // This method asserts method
46 task assertReset() {
47 @ (posedge ports.$rxclk);
48 ports.$reset = 1;
49 printf("%dns : Asserting reset to Uart\n",get_cycle());
50 repeat (5) @ (posedge ports.$rxclk);
51 ports.$reset = 0;
52 }
53
54 task txDriver() {
55 integer i = 0;
56 integer tx_timeout = 0;
57 bit [7:0] tx_data = 0;
58 ports.$tx_enable = 1;
59 for (i = 0; i < no_tx_cmds; i ++) {
60 tx_data = random();
61 sb.txAdd(tx_data);
62 if (loopback == 1) {
63 sb.rxAdd(tx_data);
64 }
65 // Check if uart is ready to accept data for transmission
66 while (ports.$tx_empty == 0) {
67 @ (posedge ports.$txclk);
68 tx_timeout ++ ;
69 if (tx_timeout > 10) {
70 printf("%dns : txDriver : Warning : tx_empty is 0 for more then 10 clocks\n",
71 get_cycle());
72 }
73 }
74 tx_timeout = 0;
75 // Drive the data in UART for transmitting
76 @ (posedge ports.$txclk);
77 ports.$ld_tx_data = 1;
78 ports.$tx_data = tx_data;
79 printf("%dns : txDriver : Transmitting data %x\n",get_cycle(), tx_data);
80 @ (posedge ports.$txclk);
81 ports.$ld_tx_data = 0;
82 ports.$tx_data = 0;
83 while (ports.$tx_empty == 1) {
84 @ (posedge ports.$txclk);
85 tx_timeout ++ ;
86 if (tx_timeout > 10) {
87 printf("%dns : txDriver : Warning : tx_empty is 1 for more then 10 clocks\n",
88 get_cycle());
89 }
90 }
91 tx_timeout = 0;
92 }
93 tx_done = 1;
94 }
95
96 task rxDriver() {
97 bit [7:0] rx_data = 0;
98 integer i,j = 0;
99 ports.$rx_enable = 1;
100 if (loopback == 1) {
101 ports.$loopback = 1;
102 } else {
103 ports.$loopback = 0;
104 for (i = 0; i < no_rx_cmds; i++) {
105 rx_data = random();
106 sb.rxAdd(rx_data);
107 printf("%dns : rxDriver : Transmitting data %x\n",get_cycle(), rx_data);
108 @ (posedge ports.$txclk);
109 ports.$rx_in = 0;
110 for (j = 0; j < 8; j ++) {
111 @ (posedge ports.$txclk);
112 ports.$rx_in = rx_data[j];
113 }
114 @ (posedge ports.$txclk);
115 ports.$rx_in = 1;
116 @ (posedge ports.$txclk);
117 }
118 }
119 rx_done = 1;
120 }
121
122 task txMonitor() {
123 bit [7:0] tx_data = 0;
124 integer i = 0;
125 while (1) {
126 @ (posedge ports.$txclk async);
127 if (ports.$tx_out == 0) {
128 printf("%dns : txMonitor : Found start of frame\n",get_cycle());
129 for (i = 0; i < 8; i ++) {
130 @ (posedge ports.$txclk async);
131 tx_data[i] = ports.$tx_out;
132 }
133 @ (posedge ports.$txclk async);
134 if (ports.$tx_out == 0) {
135 printf("%dns : txMonitor Error : Framing error detecting\n",get_cycle());
136 sb.txCompare(8'b0);
137 } else {
138 printf("%dns : txMonitor : Sampled data %x\n",get_cycle(), tx_data);
139 sb.txCompare(tx_data);
140 }
141 }
142 }
143 }
144
145 task rxMonitor() {
146 bit [7:0] rx_data = 0;
147 while (1) {
148 @ (posedge ports.$txclk);
149 if (ports.$rx_empty == 0) {
150 ports.$uld_rx_data = 1;
151 @ (posedge ports.$txclk);
152 rx_data = ports.$rx_data;
153 ports.$uld_rx_data = 0;
154 printf("%dns : rxMonitor : Sampled data %x\n",get_cycle(), rx_data);
155 sb.rxCompare(rx_data);
156 @ (posedge ports.$txclk);
157 }
158 }
159 }
160
161 function bit isDone() {
162 if (tx_done == 1 && rx_done == 1) {
163 isDone = 1;
164 } else {
165 isDone = 0;
166 }
167 }
168 }
You could download file vera_examples here
|