CodeMirror: Verilog mode

1
/* Verilog demo code */
2
 
3
//////////////////////////////////////////////////////////////////////
4
////                                                              ////
5
////  wb_master_model.v                                           ////
6
////                                                              ////
7
////  This file is part of the SPI IP core project                ////
8
////  http://www.opencores.org/projects/spi/                      ////
9
////                                                              ////
10
////  Author(s):                                                  ////
11
////      - Simon Srot (simons@opencores.org)                     ////
12
////                                                              ////
13
////  Based on:                                                   ////
14
////      - i2c/bench/verilog/wb_master_model.v                   ////
15
////        Copyright (C) 2001 Richard Herveille                  ////
16
////                                                              ////
17
////  All additional information is avaliable in the Readme.txt   ////
18
////  file.                                                       ////
19
////                                                              ////
20
//////////////////////////////////////////////////////////////////////
21
////                                                              ////
22
//// Copyright (C) 2002 Authors                                   ////
23
////                                                              ////
24
//// This source file may be used and distributed without         ////
25
//// restriction provided that this copyright statement is not    ////
26
//// removed from the file and that any derivative work contains  ////
27
//// the original copyright notice and the associated disclaimer. ////
28
////                                                              ////
29
//// This source file is free software; you can redistribute it   ////
30
//// and/or modify it under the terms of the GNU Lesser General   ////
31
//// Public License as published by the Free Software Foundation; ////
32
//// either version 2.1 of the License, or (at your option) any   ////
33
//// later version.                                               ////
34
////                                                              ////
35
//// This source is distributed in the hope that it will be       ////
36
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
37
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
38
//// PURPOSE.  See the GNU Lesser General Public License for more ////
39
//// details.                                                     ////
40
////                                                              ////
41
//// You should have received a copy of the GNU Lesser General    ////
42
//// Public License along with this source; if not, download it   ////
43
//// from http://www.opencores.org/lgpl.shtml                     ////
44
////                                                              ////
45
//////////////////////////////////////////////////////////////////////
46
 
47
`include "timescale.v"
48
 
49
module wb_master_model(clk, rst, adr, din, dout, cyc, stb, we, sel, ack, err, rty);
50
 
51
  parameter dwidth = 32;
52
  parameter awidth = 32;
53
  
54
  input                  clk, rst;
55
  output [awidth   -1:0] adr;
56
  input  [dwidth   -1:0] din;
57
  output [dwidth   -1:0] dout;
58
  output                 cyc, stb;
59
  output                 we;
60
  output [dwidth/8 -1:0] sel;
61
  input                  ack, err, rty;
62
  
63
  // Internal signals
64
  reg    [awidth   -1:0] adr;
65
  reg    [dwidth   -1:0] dout;
66
  reg                    cyc, stb;
67
  reg                    we;
68
  reg    [dwidth/8 -1:0] sel;
69
         
70
  reg    [dwidth   -1:0] q;
71
  
72
  // Memory Logic
73
  initial
74
    begin
75
      adr  = {awidth{1'bx}};
76
      dout = {dwidth{1'bx}};
77
      cyc  = 1'b0;
78
      stb  = 1'bx;
79
      we   = 1'hx;
80
      sel  = {dwidth/8{1'bx}};
81
      #1;
82
    end
83
  
84
  // Wishbone write cycle
85
  task wb_write;
86
    input   delay;
87
    integer delay;
88
  
89
    input [awidth -1:0] a;
90
    input [dwidth -1:0] d;
91
  
92
    begin
93
  
94
      // wait initial delay
95
      repeat(delay) @(posedge clk);
96
  
97
      // assert wishbone signal
98
      #1;
99
      adr  = a;
100
      dout = d;
101
      cyc  = 1'b1;
102
      stb  = 1'b1;
103
      we   = 1'b1;
104
      sel  = {dwidth/8{1'b1}};
105
      @(posedge clk);
106
  
107
      // wait for acknowledge from slave
108
      while(~ack) @(posedge clk);
109
  
110
      // negate wishbone signals
111
      #1;
112
      cyc  = 1'b0;
113
      stb  = 1'bx;
114
      adr  = {awidth{1'bx}};
115
      dout = {dwidth{1'bx}};
116
      we   = 1'hx;
117
      sel  = {dwidth/8{1'bx}};
118
  
119
    end
120
  endtask
121
  
122
  // Wishbone read cycle
123
  task wb_read;
124
    input   delay;
125
    integer delay;
126
  
127
    input  [awidth -1:0]  a;
128
    output  [dwidth -1:0] d;
129
  
130
    begin
131
  
132
      // wait initial delay
133
      repeat(delay) @(posedge clk);
134
  
135
      // assert wishbone signals
136
      #1;
137
      adr  = a;
138
      dout = {dwidth{1'bx}};
139
      cyc  = 1'b1;
140
      stb  = 1'b1;
141
      we   = 1'b0;
142
      sel  = {dwidth/8{1'b1}};
143
      @(posedge clk);
144
  
145
      // wait for acknowledge from slave
146
      while(~ack) @(posedge clk);
147
  
148
      // negate wishbone signals
149
      #1;
150
      cyc  = 1'b0;
151
      stb  = 1'bx;
152
      adr  = {awidth{1'bx}};
153
      dout = {dwidth{1'bx}};
154
      we   = 1'hx;
155
      sel  = {dwidth/8{1'bx}};
156
      d    = din;
157
  
158
    end
159
  endtask
160
  
161
  // Wishbone compare cycle (read data from location and compare with expected data)
162
  task wb_cmp;
163
    input   delay;
164
    integer delay;
165
  
166
    input [awidth -1:0] a;
167
    input [dwidth -1:0] d_exp;
168
  
169
    begin
170
      wb_read (delay, a, q);
171
 
172
      if (d_exp !== q) begin
173
        $display("\n--- ERROR: At address 0x%0x, got 0x%0x, expected 0x%0x at time %t", a, q, d_exp, $time);
174
        $stop;
175
      end
176
    end
177
  endtask
178
  
179
endmodule
180
 
 
 

Simple mode that tries to handle Verilog-like languages as well as it can. Takes one configuration parameters: keywords, an object whose property names are the keywords in the language.

MIME types defined: text/x-verilog (Verilog code).