1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
/*
* TOP2049 Open Source programming suite
*
* FPGA bottom half - common macros
*
* Copyright (c) 2012 Michael Buesch <m@bues.ch>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/** ADDR_OK_BIT - The "address OK" bit */
`define ADDR_OK_BIT 4
/** ADDR - Create a command address.
* @BASE: The address base.
*/
`define ADDR(BASE) ((BASE) | (8'h01 << `ADDR_OK_BIT))
/** BOTTOMHALF_BEGIN - Begin bottom-half module
* @NAME: The bitfile name
* @ID_MAJOR: Major runtime ID (16 bit). Allocated in file 'RUNTIME_IDS'.
* @ID_MINOR: Minor runtime ID (8 bit)
*/
`define BOTTOMHALF_BEGIN(NAME, ID_MAJOR, ID_MINOR) \
module NAME(__data, __ale, __write, __read, __osc, zif); \
inout [7:0] __data; \
input __ale; \
input __write; \
input __read; \
input __osc; \
inout [48:1] zif; \
\
parameter __id_major = ID_MAJOR; \
parameter __id_minor = ID_MINOR; \
\
reg [7:0] __addr_latch; \
reg [7:0] out_data; \
wire [7:0] in_data; \
assign in_data = __data; \
\
wire __ale_signal; \
IBUFG __ale_ibufg(.I(__ale), .O(__ale_signal)); \
\
/* constant low/high signals */ \
wire low, high; \
assign low = 0; \
assign high = 1; \
\
/* Delay counter, based on 24MHz __osc. */ \
reg [15:0] __delay_count; \
wire osc_signal; \
IBUF __osc_ibuf(.I(__osc), .O(osc_signal)); \
\
/* Command state */ \
reg [1:0] __cmd_running; \
reg [7:0] __cmd; \
reg [7:0] __cmd_state;
/** BOTTOMHALF_END - End bottom-half module */
`define BOTTOMHALF_END \
initial begin \
__addr_latch <= 0; \
out_data <= 0; \
__delay_count <= 0; \
__cmd_running <= 0; \
__cmd <= 0; \
__cmd_state <= 0; \
end \
\
always @(negedge __ale_signal) begin \
__addr_latch <= __data; \
end \
\
wire __data_oe; \
assign __data_oe = !__read && __addr_latch[`ADDR_OK_BIT]; \
\
bufif0(__data[0], out_data[0], !__data_oe); \
bufif0(__data[1], out_data[1], !__data_oe); \
bufif0(__data[2], out_data[2], !__data_oe); \
bufif0(__data[3], out_data[3], !__data_oe); \
bufif0(__data[4], out_data[4], !__data_oe); \
bufif0(__data[5], out_data[5], !__data_oe); \
bufif0(__data[6], out_data[6], !__data_oe); \
bufif0(__data[7], out_data[7], !__data_oe); \
endmodule
/** ASYNCPROC_BEGIN - Begin asynchronous OSC-based processing section. */
`define ASYNCPROC_BEGIN \
always @(posedge osc_signal) begin \
if (__delay_count == 0) begin \
/* Payload code follows... */
/** ASYNCPROC_END - End asynchronous section. */
`define ASYNCPROC_END \
end else begin \
__delay_count <= __delay_count - 1; \
end /* if */ \
end /* always */
/** ASYNCPROC_NONE - Defines a dummy asynchronous section. */
`define ASYNCPROC_NONE \
`ASYNCPROC_BEGIN \
`ASYNCPROC_END
/** UDELAY - Microsecond delay.
* @USEC: Number of microseconds to delay. Maximum is 2730.
*/
`define UDELAY(USEC) __delay_count <= (24 * USEC) - 1;
/** DATAWRITE_BEGIN - Begin "write" section.
* The section body is the body of a "case" statement on the address.
*/
`define DATAWRITE_BEGIN \
always @(posedge __write) begin \
case (__addr_latch)
/** DATAWRITE_END - End "write" section. */
`define DATAWRITE_END \
default: begin end /* nothing */ \
endcase \
end /* always */
/** DATAREAD_BEGIN - Begin "read" section.
* The section body is the body of a "case" statement on the address.
*/
`define DATAREAD_BEGIN \
always @(negedge __read) begin \
case (__addr_latch)
/** DATAREAD_END - End "read" section. */
`define DATAREAD_END \
8'hFD: out_data <= __id_major; \
8'hFE: out_data <= __id_major >> 8; \
8'hFF: out_data <= __id_minor; \
default: out_data <= 0; \
endcase \
end /* always */
/** ZIF_UNUSED - Declare a ZIF pin as unused.
* @PIN: The pin number.
* The ZIF pin is tied low.
*/
`define ZIF_UNUSED(PIN) \
bufif0(zif[PIN], low, low);
/** CMD_RUN - Run a command.
* @NR: The command number.
*/
`define CMD_RUN(NR) \
__cmd <= (NR); \
__cmd_running[0] <= ~__cmd_running[1];
/** CMD_RUNFLG_SYNC - Returns the synchronous run flag. */
`define CMD_RUNFLG_SYNC __cmd_running[0]
/** CMD_RUNFLG_ASYNC - Returns the asynchronous run flag. */
`define CMD_RUNFLG_ASYNC __cmd_running[1]
/** CMD_IS_RUNNING - Returns a boolean whether a command is running. */
`define CMD_IS_RUNNING (`CMD_RUNFLG_SYNC ^ `CMD_RUNFLG_ASYNC)
/** CMD_NR - Returns the current command number. */
`define CMD_NR __cmd
/** CMD_IS - Returns a boolean whether a certain command is running.
* @NR: The command number to check.
*/
`define CMD_IS(NR) (`CMD_IS_RUNNING && `CMD_NR == (NR))
/** CMD_FINISH - Finishes a command. */
`define CMD_FINISH \
__cmd_running[1] <= __cmd_running[0]; \
__cmd_state <= 0;
/** CMD_STATE - Get command state. */
`define CMD_STATE __cmd_state
/** CMD_STATE_SET - Set command state.
* @VALUE: New value.
*/
`define CMD_STATE_SET(VALUE) \
__cmd_state <= (VALUE);
/* vim: filetype=verilog:shiftwidth=8:tabstop=8:softtabstop=8
*/
|