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

Subversion Repositories apb_slave

[/] [apb_slave/] [trunk/] [src/] [base/] [apb_slave.v] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 eyalhoc
<##//////////////////////////////////////////////////////////////////
2 2 eyalhoc
////                                                             ////
3
////  Author: Eyal Hochberg                                      ////
4
////          eyal@provartec.com                                 ////
5
////                                                             ////
6
////  Downloaded from: http://www.opencores.org                  ////
7
/////////////////////////////////////////////////////////////////////
8
////                                                             ////
9
//// Copyright (C) 2010 Provartec LTD                            ////
10
//// www.provartec.com                                           ////
11
//// info@provartec.com                                          ////
12
////                                                             ////
13
//// This source file may be used and distributed without        ////
14
//// restriction provided that this copyright statement is not   ////
15
//// removed from the file and that any derivative work contains ////
16
//// the original copyright notice and the associated disclaimer.////
17
////                                                             ////
18
//// This source file is free software; you can redistribute it  ////
19
//// and/or modify it under the terms of the GNU Lesser General  ////
20
//// Public License as published by the Free Software Foundation.////
21
////                                                             ////
22
//// This source is distributed in the hope that it will be      ////
23
//// useful, but WITHOUT ANY WARRANTY; without even the implied  ////
24
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR     ////
25
//// PURPOSE.  See the GNU Lesser General Public License for more////
26
//// details. http://www.gnu.org/licenses/lgpl.html              ////
27
////                                                             ////
28 9 eyalhoc
//////////////////////////////////////////////////////////////////##>
29 2 eyalhoc
 
30
//////////////////////////////////////
31
//
32
// General:
33
//   The APB slave can use APB or APB3 protocol (APB3 is with pslverr and pready)
34
//   APB3 is set by DEFINE in def_apb_slave.txt
35
//   All following tasks regard APB3 only.
36
//
37
//
38
// Tasks:
39
//
40
// set_random_delay(input min_delay, input max_delay)
41
//   Description: Set random wait states on pready
42
//   Parameters: min_delay - minimum delay
43
//               max_delay = maximum delay
44
//
45
// set_fixed_delay(input delay)
46
//   Description: Set fixed wait states on pready
47
//   Parameters: delay - fixed delay on pready
48
//
49
// set_slverr(input address)
50
//   Description: Set address to return slave error (pslverr)
51
//   Parameters: address - address will return pslverr
52
// 
53
// 
54
//////////////////////////////////////
55
 
56
 
57
OUTFILE PREFIX.v
58
 
59
INCLUDE def_apb_slave.txt
60
 
61
module PREFIX(PORTS);
62
 
63 3 eyalhoc
CREATE prgen_rand.v DEFCMD(DEFINE NOT_IN_LIST)
64 2 eyalhoc
`include "prgen_rand.v"
65
 
66
   parameter                  SLAVE_NUM = 0;
67
 
68
   input                      clk;
69
   input                      reset;
70
 
71
   revport                    GROUP_STUB_APB;
72
 
73
 
74
 
75
   wire                       GROUP_STUB_MEM;
76
 
77
IFDEF APB3
78
  reg                busy_rand_enable = 0; //enable random busy
79
  integer            busy_min         = 0; //min busy cycles
80
  integer            busy_max         = 5; //max busy cycles
81
   integer           busy_delay       = 1; //fixed delay for pready
82
 
83
   reg               err_enable = 0;
84
   reg [ADDR_BITS-1:0] err_addr = {ADDR_BITS{1'b1}}; //error address
85
 
86
 
87
   wire               pslverr   = err_enable && (paddr == err_addr);
88
   reg                pready = 1'b1;
89
 
90
   always @(negedge clk)
91
     begin
92
        #FFD;
93
        if (psel)
94
          begin
95
             if (busy_rand_enable)
96
               begin
97
                  busy_delay = rand(busy_min, busy_max);
98
               end
99
             if (busy_delay > 0)
100
               begin
101
                  pready = 1'b0;
102
                  repeat (busy_delay)
103
                    begin
104
                       @(posedge clk); #FFD;
105
                    end
106
                  pready = 1'b1;
107
                  @(posedge clk); #FFD;
108
               end
109
          end
110
     end
111
 
112
 
113
   task set_random_delay;
114
      input [31:0] delay_min;
115
      input [31:0] delay_max;
116
      begin
117
         busy_rand_enable = 1;
118
         busy_min = delay_min;
119
         busy_max = delay_max;
120
      end
121
   endtask
122
 
123
   task set_fixed_delay;
124
      input [31:0] delay;
125
      begin
126
         busy_rand_enable = 0;
127
         busy_delay = delay;
128
      end
129
   endtask
130
 
131
   task set_slverr;
132
      input [31:0] addr;
133
      begin
134
         err_enable = 1;
135
         err_addr = addr;
136
      end
137
   endtask
138
 
139
 
140
 
141
ELSE APB3
142
   wire  pready  = 1'b1;
143
   wire  pslverr = 1'b0;
144
ENDIF APB3
145
 
146
 
147
 
148
   assign WR      = psel & penable & pwrite;
149
   assign RD      = psel & (~penable) & (~pwrite);
150
   assign ADDR_WR = paddr;
151
   assign ADDR_RD = paddr;
152
   assign DIN     = pwdata;
153
   assign BSEL    = 4'b1111;
154
   assign prdata  = pready ? DOUT : {DATA_BITS{1'bx}};
155
 
156
 
157
 
158
   CREATE apb_slave_mem.v
159
   PREFIX_mem PREFIX_mem(
160
                         .clk(clk),
161
                         .reset(reset),
162
                         .GROUP_STUB_MEM(GROUP_STUB_MEM),
163
                         STOMP ,
164
                         );
165
 
166
 
167
 
168
   IFDEF TRACE
169
     CREATE apb_slave_trace.v
170
       PREFIX_trace #(SLAVE_NUM)
171
         PREFIX_trace(
172
                      .clk(clk),
173
                      .reset(reset),
174
                      .GROUP_STUB_MEM(GROUP_STUB_MEM),
175
                      STOMP ,
176
                      );
177
 
178
   ENDIF TRACE
179
 
180
endmodule
181
 
182
 

powered by: WebSVN 2.1.0

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