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

Subversion Repositories mod_mult_exp

[/] [mod_mult_exp/] [trunk/] [bench/] [vhdl/] [communication/] [ModExpComm512bitTB.vhd] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 gajos
----                                                               ----
2
---- This file is part of the Montgomery modular multiplier        ----
3
---- and exponentiator                                             ----
4
---- https://opencores.org/projects/mod_mult_exp                   ----
5
----                                                               ----
6
---- Description:                                                  ----
7
----     Test bench for Montgomery multiplier and exponentiator    ----
8
----     with 512 bit word length enclosed in RS232 communication  ----
9
----     with computer. Some kind of demo application of the       ----
10
----     project. Due to it uses serial communication, demo of     ----
11
----     this part is somewhat tricky. Most convienient way is to  ----
12
----     use graphical window. It is simulated all communication   ----
13
----     - sending data and exponentiation.                        ----
14
---- To Do:                                                        ----
15
----                                                               ----
16
---- Author(s):                                                    ----
17
---- - Krzysztof Gajewski, gajos@opencores.org                     ----
18
----                       k.gajewski@gmail.com                    ----
19
----                                                               ----
20
-----------------------------------------------------------------------
21
----                                                               ----
22
---- Copyright (C) 2019 Authors and OPENCORES.ORG                  ----
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
LIBRARY ieee;
47
USE ieee.std_logic_1164.ALL;
48
USE std.textio.all;
49
USE work.txt_util.all;
50
USE ieee.std_logic_textio.all;
51
 
52
-- Uncomment the following library declaration if using
53
-- arithmetic functions with Signed or Unsigned values
54
--USE ieee.numeric_std.ALL;
55
 
56
ENTITY ModExpComm512bitTB IS
57
END ModExpComm512bitTB;
58
 
59
ARCHITECTURE behavior OF ModExpComm512bitTB IS
60
 
61
    -- Component Declaration for the Unit Under Test (UUT)
62
 
63
    COMPONENT ModExpComm
64
    port (
65
             DATA_RXD : in  STD_LOGIC;
66
                  CLK      : in  STD_LOGIC;
67
                  RESET    : in  STD_LOGIC;
68
                  DATA_TXD : out STD_LOGIC
69
         );
70
    END COMPONENT;
71
 
72
 
73
   --Inputs
74
   signal DATA_RXD : STD_LOGIC := '0';
75
   signal CLK      : STD_LOGIC := '0';
76
   signal RESET    : STD_LOGIC := '0';
77
 
78
        --Outputs
79
   signal DATA_TXD : STD_LOGIC;
80
 
81
   -- Clock period definitions
82
   constant CLK_period : time := 20 ns;
83
 
84
BEGIN
85
 
86
        -- Instantiate the Unit Under Test (UUT)
87
   uut: ModExpComm
88
            PORT MAP (
89
           DATA_RXD => DATA_RXD,
90
           CLK => CLK,
91
           RESET => RESET,
92
           DATA_TXD => DATA_TXD
93
       );
94
 
95
   -- Clock process definitions
96
   CLK_process :process
97
   begin
98
                CLK <= '0';
99
                wait for CLK_period/2;
100
                CLK <= '1';
101
                wait for CLK_period/2;
102
   end process;
103
 
104
   -- Stimulus process
105
   stim_proc: process
106
 
107
        -- All data sent are prepared in files listed below. Data are stored 
108
        -- in sim/rtl_sim/bin folder . Data are grouped in packets of bytes. 
109
        -- Data from the files are explained in the Result.txt folder.
110
        file BaseFile     :text is in "testData512bit/Base.txt";
111
        file ModulusFile  :text is in "testData512bit/Modulus.txt";
112
        file ExponentFile :text is in "testData512bit/Exponent.txt";
113
        file ResiduumFile :text is in "testData512bit/Residuum.txt";
114
 
115
        variable line_in      : line;
116
        variable line_content : string(1 to 8);
117
        variable data         : STD_LOGIC;
118
 
119
   begin
120
                DATA_RXD <= '1';
121
                RESET <= '1';
122
      wait for 1000 ns;
123
                RESET <= '0';
124
 
125
      wait for CLK_period*10;
126
 
127
      -- Data transmission
128
          -- All data are sent in direction from LSB to MSB
129
          -- 8.75 us is due to estimation of period of time needed for sending
130
          -- one bit in RS-232 with 115 200 bps bandwith
131
 
132
      -- Command mn_read_base 00000 000
133
                DATA_RXD <= '0'; -- start bit
134
                wait for 8.75 us;
135
                DATA_RXD <= '0';
136
                wait for 8.75 us;
137
                DATA_RXD <= '0';
138
                wait for 8.75 us;
139
                DATA_RXD <= '0';
140
                wait for 8.75 us;
141
                DATA_RXD <= '0';
142
                wait for 8.75 us;
143
                DATA_RXD <= '0';
144
                wait for 8.75 us;
145
                DATA_RXD <= '0';
146
                wait for 8.75 us;
147
                DATA_RXD <= '0';
148
                wait for 8.75 us;
149
                DATA_RXD <= '0';
150
                wait for 8.75 us;
151
                DATA_RXD <= '1'; -- parity bit
152
                wait for 8.75 us;
153
                DATA_RXD <= '1'; -- stop bit
154
                wait for 100 us;
155
 
156
      -- READ base - 512-bit number from the file
157
 
158
                while not (endfile(BaseFile)) loop
159
                        readline(BaseFile, line_in);  -- info line
160
                        read(line_in, line_content);
161
                        report line_content;
162
 
163
                        DATA_RXD <= '0'; -- start bit
164
                        wait for 8.75 us;
165
 
166
                        readline(BaseFile, line_in);
167
                        read(line_in, data);
168
                        DATA_RXD <= data;
169
                        wait for 8.75 us;
170
 
171
                        readline(BaseFile, line_in);
172
                        read(line_in, data);
173
                        DATA_RXD <= data;
174
                        wait for 8.75 us;
175
 
176
                        readline(BaseFile, line_in);
177
                        read(line_in, data);
178
                        DATA_RXD <= data;
179
                        wait for 8.75 us;
180
 
181
                        readline(BaseFile, line_in);
182
                        read(line_in, data);
183
                        DATA_RXD <= data;
184
                        wait for 8.75 us;
185
 
186
                        readline(BaseFile, line_in);
187
                        read(line_in, data);
188
                        DATA_RXD <= data;
189
                        wait for 8.75 us;
190
 
191
                        readline(BaseFile, line_in);
192
                        read(line_in, data);
193
                        DATA_RXD <= data;
194
                        wait for 8.75 us;
195
 
196
                        readline(BaseFile, line_in);
197
                        read(line_in, data);
198
                        DATA_RXD <= data;
199
                        wait for 8.75 us;
200
 
201
                        readline(BaseFile, line_in);
202
                        read(line_in, data);
203
                        DATA_RXD <= data;
204
                        wait for 8.75 us;
205
 
206
                        readline(BaseFile, line_in);
207
                        read(line_in, data);
208
                        DATA_RXD <= data; -- parity bit
209
                        wait for 8.75 us;
210
 
211
                        report "End of byte";
212
                        DATA_RXD <= '1'; -- stop bit
213
                        wait for 100 us;
214
                end loop;
215
 
216
      -- Command mn_read_modulus 00000 001
217
                DATA_RXD <= '0'; -- start bit
218
                wait for 8.75 us;
219
                DATA_RXD <= '1';
220
                wait for 8.75 us;
221
                DATA_RXD <= '0';
222
                wait for 8.75 us;
223
                DATA_RXD <= '0';
224
                wait for 8.75 us;
225
                DATA_RXD <= '0';
226
                wait for 8.75 us;
227
                DATA_RXD <= '0';
228
                wait for 8.75 us;
229
                DATA_RXD <= '0';
230
                wait for 8.75 us;
231
                DATA_RXD <= '0';
232
                wait for 8.75 us;
233
                DATA_RXD <= '0';
234
                wait for 8.75 us;
235
                DATA_RXD <= '0'; -- parity bit
236
                wait for 8.75 us;
237
                DATA_RXD <= '1'; -- stop bit
238
                wait for 100 us;
239
 
240
                -- READ modulus - 512-bit number from the file
241
 
242
                while not (endfile(ModulusFile)) loop
243
                        readline(ModulusFile, line_in);  -- info line
244
                        read(line_in, line_content);
245
                        report line_content;
246
 
247
                        DATA_RXD <= '0'; -- start bit
248
                        wait for 8.75 us;
249
 
250
                        readline(ModulusFile, line_in);
251
                        read(line_in, data);
252
                        DATA_RXD <= data;
253
                        wait for 8.75 us;
254
 
255
                        readline(ModulusFile, line_in);
256
                        read(line_in, data);
257
                        DATA_RXD <= data;
258
                        wait for 8.75 us;
259
 
260
                        readline(ModulusFile, line_in);
261
                        read(line_in, data);
262
                        DATA_RXD <= data;
263
                        wait for 8.75 us;
264
 
265
                        readline(ModulusFile, line_in);
266
                        read(line_in, data);
267
                        DATA_RXD <= data;
268
                        wait for 8.75 us;
269
 
270
                        readline(ModulusFile, line_in);
271
                        read(line_in, data);
272
                        DATA_RXD <= data;
273
                        wait for 8.75 us;
274
 
275
                        readline(ModulusFile, line_in);
276
                        read(line_in, data);
277
                        DATA_RXD <= data;
278
                        wait for 8.75 us;
279
 
280
                        readline(ModulusFile, line_in);
281
                        read(line_in, data);
282
                        DATA_RXD <= data;
283
                        wait for 8.75 us;
284
 
285
                        readline(ModulusFile, line_in);
286
                        read(line_in, data);
287
                        DATA_RXD <= data;
288
                        wait for 8.75 us;
289
 
290
                        readline(ModulusFile, line_in);
291
                        read(line_in, data);
292
                        DATA_RXD <= data; -- parity bit
293
                        wait for 8.75 us;
294
 
295
                        report "End of byte";
296
                        DATA_RXD <= '1'; -- stop bit
297
                        wait for 100 us;
298
                end loop;
299
 
300
      -- Command mn_read_exponent 00000 010
301
                DATA_RXD <= '0'; -- start bit
302
                wait for 8.75 us;
303
                DATA_RXD <= '0';
304
                wait for 8.75 us;
305
                DATA_RXD <= '1';
306
                wait for 8.75 us;
307
                DATA_RXD <= '0';
308
                wait for 8.75 us;
309
                DATA_RXD <= '0';
310
                wait for 8.75 us;
311
                DATA_RXD <= '0';
312
                wait for 8.75 us;
313
                DATA_RXD <= '0';
314
                wait for 8.75 us;
315
                DATA_RXD <= '0';
316
                wait for 8.75 us;
317
                DATA_RXD <= '0';
318
                wait for 8.75 us;
319
                DATA_RXD <= '0'; -- parity bit
320
                wait for 8.75 us;
321
                DATA_RXD <= '1'; -- stop bit
322
                wait for 100 us;
323
 
324
                -- READ exponent - 512-bit number from the file
325
 
326
                while not (endfile(ExponentFile)) loop
327
                        readline(ExponentFile, line_in);  -- info line
328
                        read(line_in, line_content);
329
                        report line_content;
330
 
331
                        DATA_RXD <= '0'; -- start bit
332
                        wait for 8.75 us;
333
 
334
                        readline(ExponentFile, line_in);
335
                        read(line_in, data);
336
                        DATA_RXD <= data;
337
                        wait for 8.75 us;
338
 
339
                        readline(ExponentFile, line_in);
340
                        read(line_in, data);
341
                        DATA_RXD <= data;
342
                        wait for 8.75 us;
343
 
344
                        readline(ExponentFile, line_in);
345
                        read(line_in, data);
346
                        DATA_RXD <= data;
347
                        wait for 8.75 us;
348
 
349
                        readline(ExponentFile, line_in);
350
                        read(line_in, data);
351
                        DATA_RXD <= data;
352
                        wait for 8.75 us;
353
 
354
                        readline(ExponentFile, line_in);
355
                        read(line_in, data);
356
                        DATA_RXD <= data;
357
                        wait for 8.75 us;
358
 
359
                        readline(ExponentFile, line_in);
360
                        read(line_in, data);
361
                        DATA_RXD <= data;
362
                        wait for 8.75 us;
363
 
364
                        readline(ExponentFile, line_in);
365
                        read(line_in, data);
366
                        DATA_RXD <= data;
367
                        wait for 8.75 us;
368
 
369
                        readline(ExponentFile, line_in);
370
                        read(line_in, data);
371
                        DATA_RXD <= data;
372
                        wait for 8.75 us;
373
 
374
                        readline(ExponentFile, line_in);
375
                        read(line_in, data);
376
                        DATA_RXD <= data; -- parity bit
377
                        wait for 8.75 us;
378
 
379
                        report "End of byte";
380
                        DATA_RXD <= '1'; -- stop bit
381
                        wait for 100 us;
382
                end loop;
383
 
384
                -- Command mn_read_residuum 00000 011
385
                DATA_RXD <= '0'; -- start bit
386
                wait for 8.75 us;
387
                DATA_RXD <= '1';
388
                wait for 8.75 us;
389
                DATA_RXD <= '1';
390
                wait for 8.75 us;
391
                DATA_RXD <= '0';
392
                wait for 8.75 us;
393
                DATA_RXD <= '0';
394
                wait for 8.75 us;
395
                DATA_RXD <= '0';
396
                wait for 8.75 us;
397
                DATA_RXD <= '0';
398
                wait for 8.75 us;
399
                DATA_RXD <= '0';
400
                wait for 8.75 us;
401
                DATA_RXD <= '0';
402
                wait for 8.75 us;
403
                DATA_RXD <= '1'; -- parity bit
404
                wait for 8.75 us;
405
                DATA_RXD <= '1'; -- stop bit
406
                wait for 100 us;
407
 
408
                -- READ residuum - 512-bit number from the file
409
 
410
                while not (endfile(ResiduumFile)) loop
411
                        readline(ResiduumFile, line_in);  -- info line
412
                        read(line_in, line_content);
413
                        report line_content;
414
 
415
                        DATA_RXD <= '0'; -- start bit
416
                        wait for 8.75 us;
417
 
418
                        readline(ResiduumFile, line_in);
419
                        read(line_in, data);
420
                        DATA_RXD <= data;
421
                        wait for 8.75 us;
422
 
423
                        readline(ResiduumFile, line_in);
424
                        read(line_in, data);
425
                        DATA_RXD <= data;
426
                        wait for 8.75 us;
427
 
428
                        readline(ResiduumFile, line_in);
429
                        read(line_in, data);
430
                        DATA_RXD <= data;
431
                        wait for 8.75 us;
432
 
433
                        readline(ResiduumFile, line_in);
434
                        read(line_in, data);
435
                        DATA_RXD <= data;
436
                        wait for 8.75 us;
437
 
438
                        readline(ResiduumFile, line_in);
439
                        read(line_in, data);
440
                        DATA_RXD <= data;
441
                        wait for 8.75 us;
442
 
443
                        readline(ResiduumFile, line_in);
444
                        read(line_in, data);
445
                        DATA_RXD <= data;
446
                        wait for 8.75 us;
447
 
448
                        readline(ResiduumFile, line_in);
449
                        read(line_in, data);
450
                        DATA_RXD <= data;
451
                        wait for 8.75 us;
452
 
453
                        readline(ResiduumFile, line_in);
454
                        read(line_in, data);
455
                        DATA_RXD <= data;
456
                        wait for 8.75 us;
457
 
458
                        readline(ResiduumFile, line_in);
459
                        read(line_in, data);
460
                        DATA_RXD <= data; -- parity bit
461
                        wait for 8.75 us;
462
 
463
                        report "End of byte";
464
                        DATA_RXD <= '1'; -- stop bit
465
                        wait for 100 us;
466
                end loop;
467
 
468
                -- Command mn_count_power  -- 00000 100
469
                DATA_RXD <= '0'; -- start bit
470
                wait for 8.75 us;
471
                DATA_RXD <= '0';
472
                wait for 8.75 us;
473
                DATA_RXD <= '0';
474
                wait for 8.75 us;
475
                DATA_RXD <= '1';
476
                wait for 8.75 us;
477
                DATA_RXD <= '0';
478
                wait for 8.75 us;
479
                DATA_RXD <= '0';
480
                wait for 8.75 us;
481
                DATA_RXD <= '0';
482
                wait for 8.75 us;
483
                DATA_RXD <= '0';
484
                wait for 8.75 us;
485
                DATA_RXD <= '0';
486
                wait for 8.75 us;
487
                DATA_RXD <= '0'; -- parity bit
488
                wait for 8.75 us;
489
                DATA_RXD <= '1'; -- stop bit
490
                wait for 64 ms;
491
 
492
                -- Wait for exponentiation process
493
 
494
                -- Command mn_show_result -- 00000 101
495
                DATA_RXD <= '0'; -- start bit
496
                wait for 8.75 us;
497
                DATA_RXD <= '1';
498
                wait for 8.75 us;
499
                DATA_RXD <= '0';
500
                wait for 8.75 us;
501
                DATA_RXD <= '1';
502
                wait for 8.75 us;
503
                DATA_RXD <= '0';
504
                wait for 8.75 us;
505
                DATA_RXD <= '0';
506
                wait for 8.75 us;
507
                DATA_RXD <= '0';
508
                wait for 8.75 us;
509
                DATA_RXD <= '0';
510
                wait for 8.75 us;
511
                DATA_RXD <= '0';
512
                wait for 8.75 us;
513
                DATA_RXD <= '1'; -- parity bit
514
                wait for 8.75 us;
515
                DATA_RXD <= '1'; -- stop bit
516
                wait for 15 ms;
517
 
518
                -- Command mn_prepare_for_data -- 00000 111
519
                DATA_RXD <= '0'; -- start bit
520
                wait for 8.75 us;
521
                DATA_RXD <= '1';
522
                wait for 8.75 us;
523
                DATA_RXD <= '1';
524
                wait for 8.75 us;
525
                DATA_RXD <= '1';
526
                wait for 8.75 us;
527
                DATA_RXD <= '0';
528
                wait for 8.75 us;
529
                DATA_RXD <= '0';
530
                wait for 8.75 us;
531
                DATA_RXD <= '0';
532
                wait for 8.75 us;
533
                DATA_RXD <= '0';
534
                wait for 8.75 us;
535
                DATA_RXD <= '0';
536
                wait for 8.75 us;
537
                DATA_RXD <= '0'; -- parity bit
538
                wait for 8.75 us;
539
                DATA_RXD <= '1'; -- stop bit
540
                wait for 100 us;
541
 
542
                assert false severity failure;
543
 
544
   end process;
545
 
546
END;

powered by: WebSVN 2.1.0

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