问题
I have this VHDL code, it should work as a sine generator with lookup table.
I keep getting error "Missing EOF at function", or just "syntax error" in modelsim.
I have the syntax from some online tutorial, and it seems to be correct. What is wrong?
function WAVE(X : integer) -- here is the error marker
return integer is
variable foo: integer;
begin
WITH X SELECT
foo := 0 WHEN 0, 4 WHEN 1, 7 WHEN 2, 11 WHEN 3, 14 WHEN 4, 18 WHEN 5, 21 WHEN 6, 25 WHEN 7,
28 WHEN 8, 32 WHEN 9, 35 WHEN 10, 38 WHEN 11, 42 WHEN 12, 45 WHEN 13, 49 WHEN 14,
52 WHEN 15, 55 WHEN 16, 58 WHEN 17, 62 WHEN 18, 65 WHEN 19, 68 WHEN 20, 71 WHEN 21,
74 WHEN 22, 77 WHEN 23, 80 WHEN 24, 83 WHEN 25, 86 WHEN 26, 89 WHEN 27, 91 WHEN 28,
94 WHEN 29, 97 WHEN 30, 99 WHEN 31, 102 WHEN 32, 104 WHEN 33, 107 WHEN 34, 109 WHEN 35,
111 WHEN 36, 114 WHEN 37, 116 WHEN 38, 118 WHEN 39, 120 WHEN 40, 122 WHEN 41, 124 WHEN 42,
125 WHEN 43, 127 WHEN 44, 129 WHEN 45, 130 WHEN 46, 132 WHEN 47, 133 WHEN 48, 134 WHEN 49,
136 WHEN 50, 137 WHEN 51, 138 WHEN 52, 139 WHEN 53, 140 WHEN 54, 141 WHEN 55, 141 WHEN 56,
142 WHEN 57, 142 WHEN 58, 143 WHEN 59, 143 WHEN 60, 144 WHEN 61, 144 WHEN 62, 144 WHEN 63,
144 WHEN 64, 144 WHEN 65, 144 WHEN 66, 144 WHEN 67, 143 WHEN 68, 143 WHEN 69, 142 WHEN 70,
142 WHEN 71, 141 WHEN 72, 141 WHEN 73, 140 WHEN 74, 139 WHEN 75, 138 WHEN 76, 137 WHEN 77,
136 WHEN 78, 134 WHEN 79, 133 WHEN 80, 132 WHEN 81, 130 WHEN 82, 129 WHEN 83, 127 WHEN 84,
125 WHEN 85, 124 WHEN 86, 122 WHEN 87, 120 WHEN 88, 118 WHEN 89, 116 WHEN 90, 114 WHEN 91,
111 WHEN 92, 109 WHEN 93, 107 WHEN 94, 104 WHEN 95, 102 WHEN 96, 99 WHEN 97, 97 WHEN 98,
94 WHEN 99, 91 WHEN 100, 89 WHEN 101, 86 WHEN 102, 83 WHEN 103, 80 WHEN 104, 77 WHEN 105,
74 WHEN 106, 71 WHEN 107, 68 WHEN 108, 65 WHEN 109, 62 WHEN 110, 58 WHEN 111, 55 WHEN 112,
52 WHEN 113, 49 WHEN 114, 45 WHEN 115, 42 WHEN 116, 38 WHEN 117, 35 WHEN 118, 32 WHEN 119,
28 WHEN 120, 25 WHEN 121, 21 WHEN 122, 18 WHEN 123, 14 WHEN 124, 11 WHEN 125, 7 WHEN 126,
4 WHEN 127, 0 WHEN 128, -4 WHEN 129, -7 WHEN 130, -11 WHEN 131, -14 WHEN 132, -18 WHEN 133,
-21 WHEN 134, -25 WHEN 135, -28 WHEN 136, -32 WHEN 137, -35 WHEN 138, -38 WHEN 139, -42 WHEN 140,
-45 WHEN 141, -49 WHEN 142, -52 WHEN 143, -55 WHEN 144, -58 WHEN 145, -62 WHEN 146, -65 WHEN 147,
-68 WHEN 148, -71 WHEN 149, -74 WHEN 150, -77 WHEN 151, -80 WHEN 152, -83 WHEN 153, -86 WHEN 154,
-89 WHEN 155, -91 WHEN 156, -94 WHEN 157, -97 WHEN 158, -99 WHEN 159, -102 WHEN 160, -104 WHEN 161,
-107 WHEN 162, -109 WHEN 163, -111 WHEN 164, -114 WHEN 165, -116 WHEN 166, -118 WHEN 167,
-120 WHEN 168, -122 WHEN 169, -124 WHEN 170, -125 WHEN 171, -127 WHEN 172, -129 WHEN 173,
-130 WHEN 174, -132 WHEN 175, -133 WHEN 176, -134 WHEN 177, -136 WHEN 178, -137 WHEN 179,
-138 WHEN 180, -139 WHEN 181, -140 WHEN 182, -141 WHEN 183, -141 WHEN 184, -142 WHEN 185,
-142 WHEN 186, -143 WHEN 187, -143 WHEN 188, -144 WHEN 189, -144 WHEN 190, -144 WHEN 191,
-144 WHEN 192, -144 WHEN 193, -144 WHEN 194, -144 WHEN 195, -143 WHEN 196, -143 WHEN 197,
-142 WHEN 198, -142 WHEN 199, -141 WHEN 200, -141 WHEN 201, -140 WHEN 202, -139 WHEN 203,
-138 WHEN 204, -137 WHEN 205, -136 WHEN 206, -134 WHEN 207, -133 WHEN 208, -132 WHEN 209,
-130 WHEN 210, -129 WHEN 211, -127 WHEN 212, -125 WHEN 213, -124 WHEN 214, -122 WHEN 215,
-120 WHEN 216, -118 WHEN 217, -116 WHEN 218, -114 WHEN 219, -111 WHEN 220, -109 WHEN 221,
-107 WHEN 222, -104 WHEN 223, -102 WHEN 224, -99 WHEN 225, -97 WHEN 226, -94 WHEN 227,
-91 WHEN 228, -89 WHEN 229, -86 WHEN 230, -83 WHEN 231, -80 WHEN 232, -77 WHEN 233,
-74 WHEN 234, -71 WHEN 235, -68 WHEN 236, -65 WHEN 237, -62 WHEN 238, -58 WHEN 239,
-55 WHEN 240, -52 WHEN 241, -49 WHEN 242, -45 WHEN 243, -42 WHEN 244, -38 WHEN 245,
-35 WHEN 246, -32 WHEN 247, -28 WHEN 248, -25 WHEN 249, -21 WHEN 250, -18 WHEN 251,
-14 WHEN 252, -11 WHEN 253, -7 WHEN 254, -4 WHEN 255, 0 WHEN others;
return foo;
end WAVE;
回答1:
WITH-SELECT construction is a concurrent statement, it is only applicable directly in the architecture, outside of processes or functions. Inside a function you can use the CASE construct.
回答2:
A Selected Signal Assignment can be either a concurrent signal assignment or a sequential statement in VHDL-2008. Unfortunately the support among tool vendors is far from universal.
As an alternative, if your table of coefficients is constrained, you can declare an array type and use it to declare a constant used as a look up table:
entity wavey is
end entity;
architecture fum of wavey is
type waveform is array (natural range 0 to 255) of integer range -144 to 144;
constant wave: waveform := (
0 => 0, 1 => 4, 2 => 7, 3 => 11, 4 => 14, 5 => 18, 6 => 21, 7 => 25,
8 => 28, 9 => 32, 10 => 35, 11 => 38, 12 => 42, 13 => 45, 14 => 49, 15 => 52,
16 => 55, 17 => 58, 18 => 62, 19 => 65, 20 => 68, 21 => 71, 22 => 74, 23 => 77,
24 => 80, 25 => 83, 26 => 86, 27 => 89, 28 => 91, 29 => 94, 30 => 97, 31 => 99,
32 => 102, 33 => 104, 34 => 107, 35 => 109, 36 => 111, 37 => 114, 38 => 116, 39 => 118,
40 => 120, 41 => 122, 42 => 124, 43 => 125, 44 => 127, 45 => 129, 46 => 130, 47 => 132,
48 => 133, 49 => 134, 50 => 136, 51 => 137, 52 => 138, 53 => 139, 54 => 140, 55 => 141,
56 => 141, 57 => 142, 58 => 142, 59 => 143, 60 => 143, 61 => 144, 62 => 144, 63 => 144,
64 => 144, 65 => 144, 66 => 144, 67 => 144, 68 => 143, 69 => 143, 70 => 142, 71 => 142,
72 => 141, 73 => 141, 74 => 140, 75 => 139, 76 => 138, 77 => 137, 78 => 136, 79 => 134,
80 => 133, 81 => 132, 82 => 130, 83 => 129, 84 => 127, 85 => 125, 86 => 124, 87 => 122,
88 => 120, 89 => 118, 90 => 116, 91 => 114, 92 => 111, 93 => 109, 94 => 107, 95 => 104,
96 => 102, 97 => 99, 98 => 97, 99 => 94, 100 => 91, 101 => 89, 102 => 86, 103 => 83,
104 => 80, 105 => 77, 106 => 74, 107 => 71, 108 => 68, 109 => 65, 110 => 62, 111 => 58,
112 => 55, 113 => 52, 114 => 49, 115 => 45, 116 => 42, 117 => 38, 118 => 35, 119 => 32,
120 => 28, 121 => 25, 122 => 21, 123 => 18, 124 => 14, 125 => 11, 126 => 7, 127 => 4,
128 => 0, 129 => -4, 130 => -7, 131 => -11, 132 => -14, 133 => -18, 134 => -21, 135 => -25,
136 => -28, 137 => -32, 138 => -35, 139 => -38, 140 => -42, 141 => -45, 142 => -49, 143 => -52,
144 => -55, 145 => -58, 146 => -62, 147 => -65, 148 => -68, 149 => -71, 150 => -74, 151 => -77,
152 => -80, 153 => -83, 154 => -86, 155 => -89, 156 => -91, 157 => -94, 158 => -97, 159 => -99,
160 => -102, 161 => -104, 162 => -107, 163 => -109, 164 => -111, 165 => -114, 166 => -116, 167 => -118,
168 => -120, 169 => -122, 170 => -124, 171 => -125, 172 => -127, 173 => -129, 174 => -130, 175 => -132,
176 => -133, 177 => -134, 178 => -136, 179 => -137, 180 => -138, 181 => -139, 182 => -140, 183 => -141,
184 => -141, 185 => -142, 186 => -142, 187 => -143, 188 => -143, 189 => -144, 190 => -144, 191 => -144,
192 => -144, 193 => -144, 194 => -144, 195 => -144, 196 => -143, 197 => -143, 198 => -142, 199 => -142,
200 => -141, 201 => -141, 202 => -140, 203 => -139, 204 => -138, 205 => -137, 206 => -136, 207 => -134,
208 => -133, 209 => -132, 210 => -130, 211 => -129, 212 => -127, 213 => -125, 214 => -124, 215 => -122,
216 => -120, 217 => -118, 218 => -116, 219 => -114, 220 => -111, 221 => -109, 222 => -107, 223 => -104,
224 => -102, 225 => -99, 226 => -97, 227 => -94, 228 => -91, 229 => -89, 230 => -86, 231 => -83,
232 => -80, 233 => -77, 234 => -74, 235 => -71, 236 => -68, 237 => -65, 238 => -62, 239 => -58,
240 => -55, 241 => -52, 242 => -49, 243 => -45, 244 => -42, 245 => -38, 246 => -35, 247 => -32,
248 => -28, 249 => -25, 250 => -21, 251 => -18, 252 => -14, 253 => -11, 254 => -7, 255 => -4
);
signal foo: natural range 0 to 255;
signal fie: integer;
begin
fie <= wave(foo);
end architecture;
And of course the look up table and it's type declaration could go in a package, as an entity declarative item or even in a function.
来源:https://stackoverflow.com/questions/26955534/missing-eof-at-function