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

Subversion Repositories apbtoaes128

[/] [apbtoaes128/] [trunk/] [pli/] [bfm_ecb/] [aes_bfm_decryption_dma_ecb.h] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 redbear
//////////////////////////////////////////////////////////////////
2
////
3
////
4
////    AES CORE BLOCK
5
////
6
////
7
////
8
//// This file is part of the APB to AES128 project
9
////
10
//// http://www.opencores.org/cores/apbtoaes128/
11
////
12
////
13
////
14
//// Description
15
////
16
//// Implementation of APB IP core according to
17
////
18
//// aes128_spec IP core specification document.
19
////
20
////
21
////
22
//// To Do: Things are right here but always all block can suffer changes
23
////
24
////
25
////
26
////
27
////
28
//// Author(s): - Felipe Fernandes Da Costa, fefe2560@gmail.com
29
////
30
///////////////////////////////////////////////////////////////// 
31
////
32
////
33
//// Copyright (C) 2009 Authors and OPENCORES.ORG
34
////
35
////
36
////
37
//// This source file may be used and distributed without
38
////
39
//// restriction provided that this copyright statement is not
40
////
41
//// removed from the file and that any derivative work contains
42
//// the original copyright notice and the associated disclaimer.
43
////
44
////
45
//// This source file is free software; you can redistribute it
46
////
47
//// and/or modify it under the terms of the GNU Lesser General
48
////
49
//// Public License as published by the Free Software Foundation;
50
//// either version 2.1 of the License, or (at your option) any
51
////
52
//// later version.
53
////
54
////
55
////
56
//// This source is distributed in the hope that it will be
57
////
58
//// useful, but WITHOUT ANY WARRANTY; without even the implied
59
////
60
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
61
////
62
//// PURPOSE. See the GNU Lesser General Public License for more
63
//// details.
64
////
65
////
66
////
67
//// You should have received a copy of the GNU Lesser General
68
////
69
//// Public License along with this source; if not, download it
70
////
71
//// from http://www.opencores.org/lgpl.shtml
72
////
73
////
74
///////////////////////////////////////////////////////////////////
75
static int aes_bfm_decryption_ecb_dma_calltf(char*user_data)
76
{
77
 
78
        vpiHandle PRESETn = vpi_handle_by_name("AES_GLADIC_tb.PRESETn", NULL);
79
        vpiHandle PWDATA = vpi_handle_by_name("AES_GLADIC_tb.PWDATA", NULL);
80
        vpiHandle PENABLE = vpi_handle_by_name("AES_GLADIC_tb.PENABLE", NULL);
81
        vpiHandle PSEL = vpi_handle_by_name("AES_GLADIC_tb.PSEL", NULL);
82
        vpiHandle PWRITE = vpi_handle_by_name("AES_GLADIC_tb.PWRITE", NULL);
83
        vpiHandle PADDR = vpi_handle_by_name("AES_GLADIC_tb.PADDR", NULL);
84
        vpiHandle PRDATA = vpi_handle_by_name("AES_GLADIC_tb.PRDATA", NULL);
85
        vpiHandle PREADY = vpi_handle_by_name("AES_GLADIC_tb.PREADY", NULL);
86
        vpiHandle PSLVERR = vpi_handle_by_name("AES_GLADIC_tb.PSLVERR", NULL);
87
        vpiHandle int_ccf = vpi_handle_by_name("AES_GLADIC_tb.int_ccf", NULL);
88
        vpiHandle int_err = vpi_handle_by_name("AES_GLADIC_tb.int_err", NULL);
89
        vpiHandle dma_req_wr = vpi_handle_by_name("AES_GLADIC_tb.dma_req_wr", NULL);
90
        vpiHandle dma_req_rd = vpi_handle_by_name("AES_GLADIC_tb.dma_req_rd", NULL);
91
 
92
        std::random_device rd;
93
        std::uniform_int_distribution<long int> data_in(0,4294967295);
94
 
95
        v_ecb.format=vpiIntVal;
96
 
97
        vpi_get_value(PRESETn, &v_ecb);
98
 
99
 
100
        //printf("%i\n",STATE);
101
 
102
 
103
        if(type_bfm == ECB_DECRYPTION_DMA && v_ecb.value.integer == 1)
104
        {
105
 
106
                switch(STATE)
107
                {
108
 
109
                  case IDLE:
110
 
111
                                if(PACKETS_GENERATED >= MAX_ITERATIONS)
112
                                {
113
 
114
                                        STATE = IDLE;
115
                                        type_bfm = 0;
116
 
117
                                }else
118
                                {
119
                                        STATE = WRITE;
120
 
121
                                        counter = 0;
122
 
123
 
124
                                        v_ecb.value.integer = 0;
125
                                        vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
126
 
127
                                        v_ecb.value.integer = vector_address[0];
128
                                        vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
129
 
130
                                        v_ecb.value.integer = 0;
131
                                        vpi_put_value(PWDATA, &v_ecb, NULL, vpiNoDelay);
132
 
133
                                        v_ecb.value.integer = 1;
134
                                        vpi_put_value(PWRITE, &v_ecb, NULL, vpiNoDelay);
135
 
136
                                        v_ecb.value.integer = 1;
137
                                        vpi_put_value(PSEL, &v_ecb, NULL, vpiNoDelay);
138
                                }
139
 
140
                  break;
141
 
142
                  case WRITE:
143 9 redbear
 
144
 
145 4 redbear
                                if(counter == 0)
146
                                {
147
 
148
 
149
 
150 9 redbear
                                        if(counter_write == 10 || counter_write == 11 || counter_write == 12 || counter_write == 13 )
151
                                        {
152 4 redbear
 
153 9 redbear
                                                v_ecb.value.integer = 0;
154
                                                vpi_get_value(dma_req_wr,&v_ecb);
155 4 redbear
 
156 9 redbear
 
157
                                                if(v_ecb.value.integer == 1)
158
                                                {
159
                                                        v_ecb.value.integer = 1;
160
                                                        vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
161
                                                        counter_write++;
162
                                                        counter++;
163
                                                }
164
 
165
                                        }
166
 
167
                                        if(counter_write < 10)
168
                                        {
169
                                                counter_write++;
170
                                                counter++;
171
 
172
                                                v_ecb.value.integer = 1;
173
                                                vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
174
 
175
                                        }
176
 
177 4 redbear
                                }else if(counter == 1)
178
                                {
179
 
180
                                        v_ecb.value.integer = 0;
181
                                        vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
182
 
183
 
184
 
185
                                        if(counter_write < 9)
186
                                        {
187
 
188
                                                v_ecb.value.integer = vector_address[counter_write];
189
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
190
 
191
                                                t_ecb.type = vpiScaledRealTime;
192
                                                t_ecb.real = 0;
193
                                                v_ecb.format=vpiIntVal;
194
                                                if(FIPS_ENABLE == FIPS)
195
                                                {
196
 
197
                                                        if(vector_address[counter_write] == ADDR_AES_KEYR3 || vector_address[counter_write] == ADDR_AES_IVR3)
198
                                                        {
199
                                                                a = a | KEY_FIPS_DERIVATED[0];
200
                                                                a = a << 8;
201
                                                                a = a | KEY_FIPS_DERIVATED[1];
202
                                                                a = a << 8;
203
                                                                a = a | KEY_FIPS_DERIVATED[2];
204
                                                                a = a << 8;
205
                                                                a = a | KEY_FIPS_DERIVATED[3];
206
                                                                v_ecb.value.integer = a;
207
                                                        }
208
 
209
 
210
                                                        if(vector_address[counter_write] == ADDR_AES_KEYR2 || vector_address[counter_write] == ADDR_AES_IVR2)
211
                                                        {
212
                                                                b = b | KEY_FIPS_DERIVATED[4];
213
                                                                b = b << 8;
214
                                                                b = b | KEY_FIPS_DERIVATED[5];
215
                                                                b = b << 8;
216
                                                                b = b | KEY_FIPS_DERIVATED[6];
217
                                                                b = b << 8;
218
                                                                b = b | KEY_FIPS_DERIVATED[7];
219
                                                                v_ecb.value.integer = b;
220
                                                        }
221
 
222
                                                        if(vector_address[counter_write] == ADDR_AES_KEYR1 || vector_address[counter_write] == ADDR_AES_IVR1)
223
                                                        {
224
 
225
                                                                c = c | KEY_FIPS_DERIVATED[8];
226
                                                                c = c << 8;
227
                                                                c = c | KEY_FIPS_DERIVATED[9];
228
                                                                c = c << 8;
229
                                                                c = c | KEY_FIPS_DERIVATED[10];
230
                                                                c = c << 8;
231
                                                                c = c | KEY_FIPS_DERIVATED[11];
232
                                                                v_ecb.value.integer = c;
233
 
234
                                                        }
235
 
236
                                                        if(vector_address[counter_write] == ADDR_AES_KEYR0 || vector_address[counter_write] == ADDR_AES_IVR0)
237
                                                        {
238
                                                                d = d | KEY_FIPS_DERIVATED[12];
239
                                                                d = d << 8;
240
                                                                d = d | KEY_FIPS_DERIVATED[13];
241
                                                                d = d << 8;
242
                                                                d = d | KEY_FIPS_DERIVATED[14];
243
                                                                d = d << 8;
244
                                                                d = d | KEY_FIPS_DERIVATED[15];
245
                                                                v_ecb.value.integer = d;
246
                                                        }
247
 
248
 
249
 
250
                                                }else if(FIPS_ENABLE == RANDOM_DATA)
251
                                                {
252
                                                        v_ecb.value.integer = data_in(rd);
253
                                                }
254
 
255
                                                //vpi_put_value(PWDATA, &v_ecb, NULL, vpiNoDelay);                                              
256
                                                vpi_put_value(PWDATA, &v_ecb, &t_ecb, vpiTransportDelay);
257
 
258
 
259
                                                a = 0;
260
                                                b = 0;
261
                                                c = 0;
262
                                                d = 0;
263
                                        }
264
 
265
 
266
                                        if(counter_write == 9)
267
                                        {
268
 
269 12 redbear
                                                if(DATATYPE == TYPE_00)// NO DINR DOUTR SWAP DATA
270
                                                {
271
                                                        v_ecb.value.integer = ADDR_AES_CR;
272
                                                        vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
273 4 redbear
 
274 12 redbear
                                                        v_ecb.value.integer = 6161;
275
                                                        vpi_put_value(PWDATA, &v_ecb, &t_ecb, vpiTransportDelay);
276
 
277
                                                }else if(DATATYPE == TYPE_01)// 16 BIT DINR DOUTR SWAP DATA
278
                                                {
279
                                                        v_ecb.value.integer = ADDR_AES_CR;
280
                                                        vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
281
 
282
                                                        v_ecb.value.integer = 6163;
283
                                                        vpi_put_value(PWDATA, &v_ecb, &t_ecb, vpiTransportDelay);
284
 
285
                                                }else if(DATATYPE == TYPE_02)// 8 BIT DINR DOUTR SWAP DATA
286
                                                {
287
                                                        v_ecb.value.integer = ADDR_AES_CR;
288
                                                        vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
289
 
290
                                                        v_ecb.value.integer = 6165;
291
                                                        vpi_put_value(PWDATA, &v_ecb, &t_ecb, vpiTransportDelay);
292
 
293
                                                }else if(DATATYPE == TYPE_03)// BIT DINR DOUTR SWAP DATA
294
                                                {
295
                                                        v_ecb.value.integer = ADDR_AES_CR;
296
                                                        vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
297
 
298
                                                        v_ecb.value.integer = 6167;
299
                                                        vpi_put_value(PWDATA, &v_ecb, &t_ecb, vpiTransportDelay);
300
                                                }
301 4 redbear
 
302
                                        }
303
 
304
 
305
                                        if(counter_write > 9  &&  counter_write < 14) //WRITE DINR
306
                                        {
307
 
308
                                                v_ecb.value.integer = ADDR_AES_DINR;
309
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
310
 
311
 
312
                                                if(FIPS_ENABLE == FIPS)
313
                                                {
314
 
315 12 redbear
                                                        if(DATATYPE == TYPE_00)
316 4 redbear
                                                        {
317
 
318 12 redbear
                                                                if(counter_write == 10)
319
                                                                {
320
                                                                        a = a | TEXT_FIPS_DERIVATED[0];
321
                                                                        a = a << 8;
322
                                                                        a = a | TEXT_FIPS_DERIVATED[1];
323
                                                                        a = a << 8;
324
                                                                        a = a | TEXT_FIPS_DERIVATED[2];
325
                                                                        a = a << 8;
326
                                                                        a = a | TEXT_FIPS_DERIVATED[3];
327
                                                                        v_ecb.value.integer = a;
328
 
329
                                                                }else if(counter_write == 11)
330
                                                                {
331
                                                                        b = b | TEXT_FIPS_DERIVATED[4];
332
                                                                        b = b << 8;
333
                                                                        b = b | TEXT_FIPS_DERIVATED[5];
334
                                                                        b = b << 8;
335
                                                                        b = b | TEXT_FIPS_DERIVATED[6];
336
                                                                        b = b << 8;
337
                                                                        b = b | TEXT_FIPS_DERIVATED[7];
338
                                                                        v_ecb.value.integer = b;
339
 
340
                                                                }else if(counter_write == 12 )
341
                                                                {
342
 
343
                                                                        c = c | TEXT_FIPS_DERIVATED[8];
344
                                                                        c = c << 8;
345
                                                                        c = c | TEXT_FIPS_DERIVATED[9];
346
                                                                        c = c << 8;
347
                                                                        c = c | TEXT_FIPS_DERIVATED[10];
348
                                                                        c = c << 8;
349
                                                                        c = c | TEXT_FIPS_DERIVATED[11];
350
                                                                        v_ecb.value.integer = c;
351
 
352
                                                                }else if(counter_write == 13 )
353
                                                                {
354
                                                                        d = d | TEXT_FIPS_DERIVATED[12];
355
                                                                        d = d << 8;
356
                                                                        d = d | TEXT_FIPS_DERIVATED[13];
357
                                                                        d = d << 8;
358
                                                                        d = d | TEXT_FIPS_DERIVATED[14];
359
                                                                        d = d << 8;
360
                                                                        d = d | TEXT_FIPS_DERIVATED[15];
361
                                                                        v_ecb.value.integer = d;
362
 
363
                                                                }
364
 
365
                                                        }else if(DATATYPE == TYPE_01)
366 4 redbear
                                                        {
367
 
368 12 redbear
 
369
                                                                if(counter_write == 10)
370
                                                                {
371
                                                                        a = a | TEXT_FIPS_DATATYPE_T01_DERIVATED[0];
372
                                                                        a = a << 8;
373
                                                                        a = a | TEXT_FIPS_DATATYPE_T01_DERIVATED[1];
374
                                                                        a = a << 8;
375
                                                                        a = a | TEXT_FIPS_DATATYPE_T01_DERIVATED[2];
376
                                                                        a = a << 8;
377
                                                                        a = a | TEXT_FIPS_DATATYPE_T01_DERIVATED[3];
378
                                                                        v_ecb.value.integer = a;
379
 
380
                                                                }else if(counter_write == 11)
381
                                                                {
382
                                                                        b = b | TEXT_FIPS_DATATYPE_T01_DERIVATED[4];
383
                                                                        b = b << 8;
384
                                                                        b = b | TEXT_FIPS_DATATYPE_T01_DERIVATED[5];
385
                                                                        b = b << 8;
386
                                                                        b = b | TEXT_FIPS_DATATYPE_T01_DERIVATED[6];
387
                                                                        b = b << 8;
388
                                                                        b = b | TEXT_FIPS_DATATYPE_T01_DERIVATED[7];
389
                                                                        v_ecb.value.integer = b;
390
 
391
                                                                }else if(counter_write == 12 )
392
                                                                {
393
 
394
                                                                        c = c | TEXT_FIPS_DATATYPE_T01_DERIVATED[8];
395
                                                                        c = c << 8;
396
                                                                        c = c | TEXT_FIPS_DATATYPE_T01_DERIVATED[9];
397
                                                                        c = c << 8;
398
                                                                        c = c | TEXT_FIPS_DATATYPE_T01_DERIVATED[10];
399
                                                                        c = c << 8;
400
                                                                        c = c | TEXT_FIPS_DATATYPE_T01_DERIVATED[11];
401
                                                                        v_ecb.value.integer = c;
402
 
403
                                                                }else if(counter_write == 13 )
404
                                                                {
405
                                                                        d = d | TEXT_FIPS_DATATYPE_T01_DERIVATED[12];
406
                                                                        d = d << 8;
407
                                                                        d = d | TEXT_FIPS_DATATYPE_T01_DERIVATED[13];
408
                                                                        d = d << 8;
409
                                                                        d = d | TEXT_FIPS_DATATYPE_T01_DERIVATED[14];
410
                                                                        d = d << 8;
411
                                                                        d = d | TEXT_FIPS_DATATYPE_T01_DERIVATED[15];
412
                                                                        v_ecb.value.integer = d;
413
 
414
                                                                }
415
 
416
                                                        }else if(DATATYPE == TYPE_02)
417 4 redbear
                                                        {
418 12 redbear
                                                                if(counter_write == 10)
419
                                                                {
420
                                                                        a = a | TEXT_FIPS_DATATYPE_T02_DERIVATED[0];
421
                                                                        a = a << 8;
422
                                                                        a = a | TEXT_FIPS_DATATYPE_T02_DERIVATED[1];
423
                                                                        a = a << 8;
424
                                                                        a = a | TEXT_FIPS_DATATYPE_T02_DERIVATED[2];
425
                                                                        a = a << 8;
426
                                                                        a = a | TEXT_FIPS_DATATYPE_T02_DERIVATED[3];
427
                                                                        v_ecb.value.integer = a;
428 4 redbear
 
429 12 redbear
                                                                }else if(counter_write == 11)
430
                                                                {
431
                                                                        b = b | TEXT_FIPS_DATATYPE_T02_DERIVATED[4];
432
                                                                        b = b << 8;
433
                                                                        b = b | TEXT_FIPS_DATATYPE_T02_DERIVATED[5];
434
                                                                        b = b << 8;
435
                                                                        b = b | TEXT_FIPS_DATATYPE_T02_DERIVATED[6];
436
                                                                        b = b << 8;
437
                                                                        b = b | TEXT_FIPS_DATATYPE_T02_DERIVATED[7];
438
                                                                        v_ecb.value.integer = b;
439 4 redbear
 
440 12 redbear
                                                                }else if(counter_write == 12 )
441
                                                                {
442
 
443
                                                                        c = c | TEXT_FIPS_DATATYPE_T02_DERIVATED[8];
444
                                                                        c = c << 8;
445
                                                                        c = c | TEXT_FIPS_DATATYPE_T02_DERIVATED[9];
446
                                                                        c = c << 8;
447
                                                                        c = c | TEXT_FIPS_DATATYPE_T02_DERIVATED[10];
448
                                                                        c = c << 8;
449
                                                                        c = c | TEXT_FIPS_DATATYPE_T02_DERIVATED[11];
450
                                                                        v_ecb.value.integer = c;
451
 
452
                                                                }else if(counter_write == 13 )
453
                                                                {
454
                                                                        d = d | TEXT_FIPS_DATATYPE_T02_DERIVATED[12];
455
                                                                        d = d << 8;
456
                                                                        d = d | TEXT_FIPS_DATATYPE_T02_DERIVATED[13];
457
                                                                        d = d << 8;
458
                                                                        d = d | TEXT_FIPS_DATATYPE_T02_DERIVATED[14];
459
                                                                        d = d << 8;
460
                                                                        d = d | TEXT_FIPS_DATATYPE_T02_DERIVATED[15];
461
                                                                        v_ecb.value.integer = d;
462
 
463
                                                                }
464
 
465
 
466
 
467
                                                        }else if(DATATYPE == TYPE_03)
468 4 redbear
                                                        {
469 12 redbear
                                                                if(counter_write == 10)
470
                                                                {
471
                                                                        a = a | TEXT_FIPS_DATATYPE_T03_DERIVATED[0];
472
                                                                        a = a << 8;
473
                                                                        a = a | TEXT_FIPS_DATATYPE_T03_DERIVATED[1];
474
                                                                        a = a << 8;
475
                                                                        a = a | TEXT_FIPS_DATATYPE_T03_DERIVATED[2];
476
                                                                        a = a << 8;
477
                                                                        a = a | TEXT_FIPS_DATATYPE_T03_DERIVATED[3];
478
                                                                        v_ecb.value.integer = a;
479 4 redbear
 
480 12 redbear
                                                                }else if(counter_write == 11)
481
                                                                {
482
                                                                        b = b | TEXT_FIPS_DATATYPE_T03_DERIVATED[4];
483
                                                                        b = b << 8;
484
                                                                        b = b | TEXT_FIPS_DATATYPE_T03_DERIVATED[5];
485
                                                                        b = b << 8;
486
                                                                        b = b | TEXT_FIPS_DATATYPE_T03_DERIVATED[6];
487
                                                                        b = b << 8;
488
                                                                        b = b | TEXT_FIPS_DATATYPE_T03_DERIVATED[7];
489
                                                                        v_ecb.value.integer = b;
490
 
491
                                                                }else if(counter_write == 12 )
492
                                                                {
493
 
494
                                                                        c = c | TEXT_FIPS_DATATYPE_T03_DERIVATED[8];
495
                                                                        c = c << 8;
496
                                                                        c = c | TEXT_FIPS_DATATYPE_T03_DERIVATED[9];
497
                                                                        c = c << 8;
498
                                                                        c = c | TEXT_FIPS_DATATYPE_T03_DERIVATED[10];
499
                                                                        c = c << 8;
500
                                                                        c = c | TEXT_FIPS_DATATYPE_T03_DERIVATED[11];
501
                                                                        v_ecb.value.integer = c;
502
 
503
                                                                }else if(counter_write == 13 )
504
                                                                {
505
                                                                        d = d | TEXT_FIPS_DATATYPE_T03_DERIVATED[12];
506
                                                                        d = d << 8;
507
                                                                        d = d | TEXT_FIPS_DATATYPE_T03_DERIVATED[13];
508
                                                                        d = d << 8;
509
                                                                        d = d | TEXT_FIPS_DATATYPE_T03_DERIVATED[14];
510
                                                                        d = d << 8;
511
                                                                        d = d | TEXT_FIPS_DATATYPE_T03_DERIVATED[15];
512
                                                                        v_ecb.value.integer = d;
513
 
514
                                                                }
515
 
516
 
517
 
518 4 redbear
                                                        }
519
 
520
                                                }else if(FIPS_ENABLE == RANDOM_DATA)
521
                                                {
522
                                                        v_ecb.value.integer = data_in(rd);
523
                                                }
524
 
525
                                                //vpi_put_value(PWDATA, &v_ecb, NULL, vpiNoDelay);
526
                                                vpi_put_value(PWDATA, &v_ecb, &t_ecb, vpiTransportDelay);
527
 
528
                                                a = 0;
529
                                                b = 0;
530
                                                c = 0;
531
                                                d = 0;
532
 
533
 
534
                                        }
535
 
536
                                        v_ecb.value.integer = 1;
537
                                        vpi_put_value(PSEL, &v_ecb, NULL, vpiNoDelay);
538
 
539
                                        counter=0;
540
                                }
541
 
542
                                if(counter_write == 14)
543
                                {
544
                                        counter_write = 0;
545
 
546
                                        STATE =WAIT_SR;
547
 
548
                                }
549
 
550
                  break;
551
 
552
                  case WAIT_SR:
553
 
554
                                v_ecb.value.integer = ADDR_AES_SR;
555
                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
556
 
557
                                v_ecb.value.integer = 0;
558
                                vpi_put_value(PWRITE, &v_ecb, NULL, vpiNoDelay);
559
 
560
                                if(counter == 0)
561
                                {
562
 
563
                                        counter++;
564
 
565
                                        v_ecb.value.integer = 1;
566
                                        vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
567
 
568
 
569 9 redbear
                                        v_ecb.value.integer = 0;
570
                                        vpi_get_value(PRDATA,&v_ecb);
571
 
572
                                        if(v_ecb.value.integer == 1)
573
                                        {
574
                                                STATE = READ_DOUTR;
575
                                                counter=1;
576
                                        }
577
 
578
 
579 4 redbear
                                }else if(counter == 1)
580
                                {
581
                                        v_ecb.value.integer = 0;
582
                                        vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
583
 
584
                                        counter=0;
585
                                }
586
 
587
 
588
                  break;
589
 
590
 
591
                 case READ_DOUTR:
592
 
593
 
594
 
595
                                if(counter == 0)
596
                                {
597
 
598
                                        v_ecb.value.integer = 1;
599
                                        vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
600
 
601 5 redbear
                                        counter_read++;
602 4 redbear
                                        counter++;
603
 
604
 
605
 
606
                                }else if(counter == 1)
607
                                {
608
                                        v_ecb.value.integer = 0;
609
                                        vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
610
 
611 5 redbear
 
612
                                        if(counter_read < 4)
613
                                        {
614
 
615
                                                v_ecb.value.integer = ADDR_AES_DOUTR;
616
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
617
 
618
                                        }
619
 
620
 
621
                                        if(counter_read == 4)
622
                                        {
623
 
624
                                                v_ecb.value.integer = ADDR_AES_KEYR3;
625
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
626
 
627
                                        }
628
 
629
 
630
                                        if(counter_read == 5)
631
                                        {
632
 
633
                                                v_ecb.value.integer = ADDR_AES_KEYR2;
634
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
635
 
636
                                        }
637
 
638
 
639
 
640
                                        if(counter_read == 6)
641
                                        {
642
 
643
                                                v_ecb.value.integer = ADDR_AES_KEYR1;
644
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
645
 
646
                                        }
647
 
648
 
649
                                        if(counter_read == 7)
650
                                        {
651
 
652
                                                v_ecb.value.integer = ADDR_AES_KEYR0;
653
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
654
 
655
                                        }
656
 
657
 
658
                                        if(counter_read == 8)
659
                                        {
660
 
661
                                                v_ecb.value.integer = ADDR_AES_IVR3;
662
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
663
 
664
                                        }
665
 
666
 
667
                                        if(counter_read == 9)
668
                                        {
669
 
670
                                                v_ecb.value.integer = ADDR_AES_IVR2;
671
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
672
 
673
                                        }
674
 
675
 
676
 
677
                                        if(counter_read == 10)
678
                                        {
679
 
680
                                                v_ecb.value.integer = ADDR_AES_IVR1;
681
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
682
 
683
                                        }
684
 
685
 
686
                                        if(counter_read == 11)
687
                                        {
688
 
689
                                                v_ecb.value.integer = ADDR_AES_IVR0;
690
                                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
691
 
692
                                        }
693
 
694
 
695 4 redbear
                                        counter = 0;
696
                                }
697
 
698 5 redbear
                                if(counter_read == 12)
699 4 redbear
                                {
700
                                        STATE = RESET_SR;
701 5 redbear
                                        counter_read = 0;
702 4 redbear
                                }
703
 
704
                 break;
705
 
706
                case RESET_SR:
707
 
708
                                v_ecb.value.integer = 1;
709
                                vpi_put_value(PWRITE, &v_ecb, NULL, vpiNoDelay);
710
 
711
                                v_ecb.value.integer = 1;
712
                                vpi_put_value(PSEL, &v_ecb, NULL, vpiNoDelay);
713
 
714
                                v_ecb.value.integer = 0;
715
                                vpi_put_value(PADDR, &v_ecb, NULL, vpiNoDelay);
716
 
717
                                v_ecb.value.integer = 128;
718
                                vpi_put_value(PWDATA, &v_ecb, NULL, vpiNoDelay);
719
 
720
 
721
                                if(counter == 0)
722
                                {
723
 
724
                                        counter_write++;
725
                                        counter++;
726
 
727
                                        v_ecb.value.integer = 1;
728
                                        vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
729
 
730
                                }else if(counter == 1)
731
                                {
732
 
733
                                        v_ecb.value.integer = 0;
734
                                        vpi_put_value(PENABLE, &v_ecb, NULL, vpiNoDelay);
735
                                        counter=0;
736
 
737
                                }
738
 
739
                                if(counter_write == 1)
740
                                {
741
                                        STATE =IDLE;
742
                                        counter_write = 0;
743
                                        counter=0;
744
                                        PACKETS_GENERATED = PACKETS_GENERATED + 1;
745
                                }
746
 
747
 
748
 
749
                break;
750
 
751
                }
752
 
753
        }
754
 
755
        return 0;
756
}

powered by: WebSVN 2.1.0

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