aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/vests/vhdl-93/ashenden/non_compliant/ch_02_ch_02_01.vhd
blob: 56e80b5fc3a5362731de1eaba713ff47a569c035 (plain)
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
-- Copyright (C) 1996 Morgan Kaufmann Publishers, Inc

-- This file is part of VESTs (Vhdl tESTs).

-- VESTs 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. 

-- VESTs 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 VESTs; if not, write to the Free Software Foundation,
-- Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 

-- ---------------------------------------------------------------------
--
-- $Id: ch_02_ch_02_01.vhd,v 1.2 2001-10-26 16:29:37 paw Exp $
-- $Revision: 1.2 $
--
-- ---------------------------------------------------------------------

entity ch_02_01 is

end entity ch_02_01;


----------------------------------------------------------------


architecture test of ch_02_01 is
begin


  section_2_1_a : process is

                            -- code from book:

                            constant number_of_bytes : integer := 4;
                          constant number_of_bits : integer := 8 * number_of_bytes;
                          constant e : real := 2.718281828;
                          constant prop_delay : time := 3 ns;
                          constant size_limit, count_limit : integer := 255;

                          --

                          variable index : integer := 0;
                          variable sum, average, largest : real;
                          variable start, finish : time := 0 ns; 

                          -- end of code from book

  begin
    wait;
  end process section_2_1_a;


  ----------------


  section_2_1_b : process is

                            -- code from book:

                            variable start : time := 0 ns; 
                          variable finish : time := 0 ns; 

                          -- end of code from book

                          variable program_counter : integer;
                          variable index : integer;

  begin

    -- code from book:

    program_counter := 0;
    index := index + 1;

    -- end of code from book

    wait;
  end process section_2_1_b;


  ----------------


  section_2_2_a : process is

                            -- code from book:

                            type apples is range 0 to 100;
                          type oranges is range 0 to 100;

                          --

                          type day_of_month is range 0 to 31;
                          type year is range 0 to 2100;

                          variable today : day_of_month := 9;
                          variable start_year : year := 1987;

                          --

                          constant number_of_bits : integer := 32;
                          type bit_index is range 0 to number_of_bits - 1;

                          --

                          type set_index_range is range 21 downto 11;
                          type mode_pos_range is range 5 to 7;
                          variable set_index : set_index_range;
                          variable mode_pos : mode_pos_range;

                          --

                          type input_level is range -10.0 to +10.0;
                          type probability is range 0.0 to 1.0;

                          --

                          variable input_A : input_level;

                          -- end of code from book

  begin

    -- code from book:

    -- error: Incompatible types for assignment
    -- start_year := today;

    -- end of code from book

    wait;
  end process section_2_2_a;


  ----------------


  section_2_2_b : process is

                            -- code from book:

                            type resistance is range 0 to 1E9
                          units
                            ohm;
                          end units resistance;

                          -- end of code from book

  begin
    wait;
  end process section_2_2_b;


  ----------------


  section_2_2_c : process is

                            -- code from book:

                            type resistance is range 0 to 1E9
                          units
                            ohm;
                            kohm = 1000 ohm;
                            Mohm = 1000 kohm;
                          end units resistance;

                          -- end of code from book

  begin
    wait;
  end process section_2_2_c;


  ----------------


  section_2_2_d : process is

                            -- code from book:

                            type length is range 0 to 1E9
                          units
                            um;			-- primary unit: micron
                            mm = 1000 um;		-- metric units
                            m = 1000 mm;
                            mil = 254 um;		-- imperial units
                            inch = 1000 mil;
                          end units length;

                          -- end of code from book

  begin
    wait;
  end process section_2_2_d;


  ----------------


  section_2_2_e : process is

                            -- code from book:

                            -- type time is range implementation_defined
                            type time is range integer'low to integer'high
                          units
                            fs;
                            ps = 1000 fs;
                            ns = 1000 ps;
                            us = 1000 ns;
                            ms = 1000 us;
                            sec = 1000 ms;
                            min = 60 sec;
                            hr = 60 min;
                          end units;

                          -- end of code from book

  begin
    wait;
  end process section_2_2_e;


  ----------------


  section_2_2_f : process is

                            -- code from book:

                            type alu_function is (disable, pass, add, subtract, multiply, divide);

                          --

                          type octal_digit is ('0', '1', '2', '3', '4', '5', '6', '7');

                          --

                          variable alu_op : alu_function;
                          variable last_digit : octal_digit := '0';

                          --

                          type logic_level is (unknown, low, undriven, high);
                          variable control : logic_level;
                          type water_level is (dangerously_low, low, ok);
                          variable water_sensor : water_level;

                          -- end of code from book

  begin

    -- code from book:

    alu_op := subtract;
    last_digit := '7';

    --

    control := low;
    water_sensor := low;

    -- end of code from book

    wait;
  end process section_2_2_f;


  ----------------


  section_2_2_g : process is

                            -- code from book:

                            type severity_level is (note, warning, error, failure);

                          -- end of code from book

  begin
    wait;
  end process section_2_2_g;


  ----------------


  section_2_2_h : process is

                            -- code from book:

                            variable cmd_char, terminator : character;

                          -- end of code from book

  begin

    -- code from book:

    cmd_char := 'P';
    terminator := cr;

    -- end of code from book

    wait;
  end process section_2_2_h;


  ----------------


  section_2_2_i : process is

                            -- code from book:

                            type boolean is (false, true);

                          --

                          type bit is ('0', '1');

                          -- end of code from book

  begin
    wait;
  end process section_2_2_i;


  ----------------


  section_2_2_j : process is

                            variable write_enable_n, select_reg_n, write_reg_n : bit;

  begin

    -- code from book:

    write_reg_n := not ( not write_enable_n and not select_reg_n );

    -- end of code from book

    wait;
  end process section_2_2_j;


  ----------------


  section_2_2_k : process is

                            -- code from book:

                            type std_ulogic is ( 'U',	-- Uninitialized
                                                 'X',	-- Forcing Unknown
                                                 '0',	-- Forcing zero
                                                 '1',	-- Forcing one
                                                 'Z',	-- High Impedance
                                                 'W',	-- Weak Unknown
                                                 'L',	-- Weak zero
                                                 'H',	-- Weak one
                                                 '-' );	-- Don't care

                          -- end of code from book

  begin
    wait;
  end process section_2_2_k;


  ----------------


  section_2_3_a : process is

                            -- code from book:

                            subtype small_int is integer range -128 to 127;

                          --

                          variable deviation : small_int;
                          variable adjustment : integer;

                          --

                          subtype bit_index is integer range 31 downto 0;

                          -- end of code from book

  begin

    deviation := 0;
    adjustment := 0;

    -- code from book:

    deviation := deviation + adjustment;

    -- end of code from book

    wait;
  end process section_2_3_a;


  ----------------


  section_2_3_b : process is

                            constant highest_integer : integer := integer'high;

                          constant highest_time : time := time'high;

                          -- code from book:

                          subtype natural is integer range 0 to highest_integer;
                          subtype positive is integer range 1 to highest_integer;

                          --

                          subtype delay_length is time range 0 fs to highest_time;

                          -- end of code from book

  begin
    wait;
  end process section_2_3_b;


  ----------------


  section_2_3_c : process is

                            -- code from book:

                            type logic_level is (unknown, low, undriven, high);
                          type system_state is (unknown, ready, busy);

                          --

                          subtype valid_level is logic_level range low to high;

                          -- end of code from book

  begin
    wait;
  end process section_2_3_c;


  ----------------


  section_2_4_a : process is

                            -- code from book:

                            type resistance is range 0 to 1E9
                          units
                            ohm;
                            kohm = 1000 ohm;
                            Mohm = 1000 kohm;
                          end units resistance;

                          type set_index_range is range 21 downto 11;

                          type logic_level is (unknown, low, undriven, high);

                          -- end of code from book

  begin

    -- output from vsim: "2000"
    report resistance'image(2 kohm);

    -- code from book:

    assert resistance'left = 0 ohm;
    assert resistance'right = 1E9 ohm;
    assert resistance'low = 0 ohm;
    assert resistance'high = 1E9 ohm;
    assert resistance'ascending = true;
    assert resistance'image(2 kohm) = "2000 ohm";
    assert resistance'value("5 Mohm") = 5_000_000 ohm;

    assert set_index_range'left = 21;
    assert set_index_range'right = 11;
    assert set_index_range'low = 11;
    assert set_index_range'high = 21;
    assert set_index_range'ascending = false;
    assert set_index_range'image(14) = "14";
    assert set_index_range'value("20") = 20;

    assert logic_level'left = unknown;
    assert logic_level'right = high;
    assert logic_level'low = unknown;
    assert logic_level'high = high;
    assert logic_level'ascending = true;
    assert logic_level'image(undriven) = "undriven";
    assert logic_level'value("Low") = low;

    --

    assert logic_level'pos(unknown) = 0;
    assert logic_level'val(3) = high;
    assert logic_level'succ(unknown) = low;
    assert logic_level'pred(undriven) = low;

    --

    assert time'pos(4 ns) = 4_000_000;

    -- end of code from book

    wait;
  end process section_2_4_a;


  ----------------


  section_2_4_b : process is

                            -- code from book:

                            type length is range integer'low to integer'high
                          units
                            mm;
                          end units length;

                          type area is range integer'low to integer'high
                            units
                              square_mm;
                            end units area;

                          --

                          variable L1, L2 : length;
                          variable A : area;

                          -- end of code from book

  begin
    -- TG: avoid overflow in multiplication
    L1 := 1 mm;

    -- code from book:

    -- error: No feasible entries for infix op: "*"
    -- A := L1 * L2;      -- this is incorrect

    --

    A := area'val( length'pos(L1) * length'pos(L2) );

    -- end of code from book

    wait;
  end process section_2_4_b;


  ----------------


  section_2_4_c : process is

                            -- code from book:

                            type opcode is (nop, load, store, add, subtract, negate, branch, halt);
                          subtype arith_op is opcode range add to negate;

                          -- end of code from book

  begin

    -- code from book:

    assert arith_op'base'left = nop;
    assert arith_op'base'succ(negate) = branch;

    -- end of code from book

    wait;
  end process section_2_4_c;


end architecture test;