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

Subversion Repositories ahbmaster

[/] [ahbmaster/] [trunk/] [test79_AHBmaster/] [simulation/] [coreuart_usertb_include.bfm] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 uson
// ********************************************************************
2
// Actel Corporation Proprietary and Confidential
3
//  Copyright 2009 Actel Corporation   All rights reserved
4
//
5
// ANY USE OR REDISTRIBUTION IN PART OR IN WHOLE MUST BE HANDLED IN
6
// ACCORDANCE WITH THE ACTEL LICENSE AGREEMENT AND MUST BE APPROVED
7
// IN ADVANCE IN WRITING
8
//
9
// Description: User testbench include file for CoreAI - contains
10
//                              various constants  procedures  etc  used by main BFM script
11
//
12
// Revision Information:
13
// Date     Description
14
// 19Jan09              Production Release Version 3 0
15
//
16
// SVN Revision Information:
17
// SVN $Revision: $
18
// SVN $Date: $
19
//
20
// Resolved SARs
21
// SAR      Date     Who   Description
22
//
23
// Notes:
24
// 1  best viewed with tabstops set to "4"
25
//
26
// History:
27
//
28
// *********************************************************************
29
 
30
 
31
 
32
// PSEL[0] HSEL[0] used to access the AHB-to-APB bridge in the BFM_APB mod
33
// (for UART Transmitter)
34
memmap BASE1                    0x10000000
35
// PSEL[1] HSEL[1] used to access the AHB-to-APB bridge in the BFM_APB mod
36
// (for UART Receiver)
37
memmap BASE2                    0x11000000
38
 
39
// variables to store passed parameter values
40
int FAMILY
41
int TX_FIFO
42
int RX_FIFO
43
int FIXEDMODE
44
int BAUD_VALUE
45
int PRG_BIT8
46
int PRG_PARITY
47
int RX_LEGACY_MODE
48
int USE_SOFT_FIFO
49
 
50
// derived parameters
51
int FIFO_DEPTH
52
int TIMEOUT_VAL
53
int BYTE_WAIT_TIME
54
int BYTE_WAIT_256
55
int BYTE_WAIT_16
56
int BYTE_WAIT_8
57
 
58
// data variables
59
int rdata[256]
60
 
61
// other variables
62
int PRINT_VARS
63
int BITVAR
64
int data
65
// temp vars
66
int i j k l w x y z tc rc
67
int cmp
68
 
69
 
70
// CoreGPIO internal addresses
71
constant TXDATA   0x00
72
constant RXDATA   0x04
73
constant CTRL1    0x08
74
constant CTRL2    0x0C
75
constant STA        0x10
76
constant CRTL3    0x14
77
 
78
//BFM GPIN bit defs
79
constant RXRDY1       0
80
constant TXRDY1       1
81
constant PARITY_ERR1  2
82
constant OVERFLOW1    3
83
constant RXRDY2       4
84
constant TXRDY2       5
85
constant PARITY_ERR2  6
86
constant OVERFLOW2    7
87
 
88
//---------------------------------------------------------------------------
89
// procedures
90
//---------------------------------------------------------------------------
91
 
92
//---------------------------------------------------------------------------
93
// initialize local variables from the ARGVALUE* BFM parameters passed
94
// down from the testbench HDL
95
//---------------------------------------------------------------------------
96
procedure init_parameter_vars
97
 
98
  set FAMILY          $ARGVALUE0
99
  set TX_FIFO         $ARGVALUE1
100
  set RX_FIFO         $ARGVALUE2
101
  set FIXEDMODE       $ARGVALUE3
102
  set BAUD_VALUE      $ARGVALUE4
103
  set PRG_BIT8        $ARGVALUE5
104
  set PRG_PARITY      $ARGVALUE6
105
  set RX_LEGACY_MODE  $ARGVALUE7
106
  set USE_SOFT_FIFO   $ARGVALUE8
107
 
108
  // derived parameters
109
  if USE_SOFT_FIFO
110
    set FIFO_DEPTH 15
111
  else
112
    set FIFO_DEPTH 255
113
  endif
114
 
115
  // check for SX or RTSX or RTAXS
116
  // and set FIFO depth accordingly
117
  // (these 3 have soft FIFOs)
118
  set cmp FAMILY == 8
119
  if cmp
120
    set FIFO_DEPTH 15
121
  endif
122
  set cmp FAMILY == 9
123
  if cmp
124
    set FIFO_DEPTH 15
125
  endif
126
 
127
//  set cmp FAMILY == 12
128
//  if cmp
129
//    set FIFO_DEPTH 15
130
//  endif
131
 
132
//check for SmartFusion2 or Igloo2 or RTG4
133
//and set FIFO depth accordingly
134
  set cmp FAMILY == 19
135
  if cmp
136
        if USE_SOFT_FIFO
137
                set FIFO_DEPTH 15
138
        else
139
                set FIFO_DEPTH 127
140
        endif
141
  endif
142
  set cmp FAMILY == 24
143
  if cmp
144
        if USE_SOFT_FIFO
145
                set FIFO_DEPTH 15
146
        else
147
                set FIFO_DEPTH 127
148
        endif
149
  endif
150
  set cmp FAMILY == 25
151
  if cmp
152
        if USE_SOFT_FIFO
153
                set FIFO_DEPTH 15
154
        else
155
                set FIFO_DEPTH 127
156
        endif
157
  endif
158
 
159
//check for PolarFire
160
//and set FIFO depth accordingly
161
  set cmp FAMILY == 26
162
  if cmp
163
        if USE_SOFT_FIFO
164
                set FIFO_DEPTH 15
165
        else
166
                set FIFO_DEPTH 255
167
        endif
168
  endif
169
 
170
//check for ProASICplus
171
//and set FIFO depth accordingly
172
    set cmp FAMILY == 14
173
  if cmp
174
    if USE_SOFT_FIFO
175
      set FIFO_DEPTH 15
176
    else
177
      set FIFO_DEPTH 254
178
    endif
179
  endif
180
 
181
  set BYTE_WAIT_TIME BAUD_VALUE * 250
182
  set BYTE_WAIT_256 BYTE_WAIT_TIME * 256
183
  set BYTE_WAIT_16   BYTE_WAIT_TIME * 16
184
  set BYTE_WAIT_8   BYTE_WAIT_TIME * 8
185
 
186
  set TIMEOUT_VAL BYTE_WAIT_256 + 1
187
 
188
  timeout TIMEOUT_VAL
189
 
190
  set PRINT_VARS 1
191
 
192
  if PRINT_VARS
193
    header " Begin printing variables from APB Master BFM Script ..."
194
    print "FAMILY:%0d"            FAMILY
195
    print "TX_FIFO:%0d"           TX_FIFO
196
    print "RX_FIFO:%0d"           RX_FIFO
197
    print "FIXEDMODE:%0d"         FIXEDMODE
198
    print "BAUD_VALUE:%0d"        BAUD_VALUE
199
    print "PRG_BIT8:%0d"          PRG_BIT8
200
    print "PRG_PARITY:%0d"        PRG_PARITY
201
    print "RX_LEGACY_MODE:%0d"    RX_LEGACY_MODE
202
    print "FIFO_DEPTH:%0d"        FIFO_DEPTH
203
    header " Done printing variables from APB Master BFM Script."
204
    header " "
205
  endif
206
return
207
 
208
//---------------------------------------------------------------------------
209
// get bit number (bnum) from given wval integer
210
//---------------------------------------------------------------------------
211
procedure get_bit wval bnum
212
  int d01
213
  set d01 wval >> bnum
214
  // set global BITVAR variable
215
  set BITVAR d01 & 0x1
216
return
217
 
218
//---------------------------------------------------------------------------
219
// print line of underscores
220
//---------------------------------------------------------------------------
221
procedure pr_underscores
222
  print "____________________________________________________________________"
223
  print " "
224
return
225
 
226
//---------------------------------------------------------------------------
227
// test procedures
228
//---------------------------------------------------------------------------
229
 
230
procedure set_config dn pe p bv bn
231
  int dut_num         // 1 = RX(DUT2), 0 = TX(DUT1)
232
  int par_en          // 1 = enabled, 0 = disabled
233
  int par             // 1 = odd, 0 = even
234
  int baud_val        // 13-bit baud-value (split into 2 config registers)
235
  int bit_num         // 1 = 8 bits, 0 = 7 bits
236
 
237
  // temp vars
238
  int baud1
239
  int baud2
240
  int ctrl2_val
241
 
242
  set dut_num   dn
243
  set par_en    pe
244
  set par       p
245
  set baud_val  bv
246
  set bit_num   bn
247
 
248
  print "Configuring UART:%0d with par_en:%0d parity:%0d baud_val:%0d bit_num:%0d" dut_num par_en par baud_val bit_num
249
 
250
  // Set config regsiter data
251
  set baud1 baud_val << 8 >> 8    // CONFIG REG 1
252
  set baud2 baud_val >> 8         // CONFIG REG 2
253
  set par par << 2
254
  set par_en par_en << 1
255
  set baud2 baud2 << 3
256
  set ctrl2_val par
257
  set ctrl2_val ctrl2_val | par_en
258
  set ctrl2_val ctrl2_val | baud2
259
  set ctrl2_val ctrl2_val | bit_num
260
 
261
  // set base address based on DUT selected
262
  if dut_num == 1
263
    // write control registers
264
    //print "Writing %0d to CTRL1 and %0d to CTRL2" baud1 ctrl2_val
265
    write b BASE2 CTRL1 baud1
266
    write b BASE2 CTRL2 ctrl2_val
267
  else
268
    // write control registers
269
    //print "Writing %0d to CTRL1 and %0d to CTRL2" baud1 ctrl2_val
270
    write b BASE1 CTRL1 baud1
271
    write b BASE1 CTRL2 ctrl2_val
272
  endif
273
 
274
return
275
 
276
procedure data_stream
277
  call pr_underscores
278
  print "Testing Continuous Data Stream UART1 to UART2"
279
  set rc 0
280
 
281
  loop tc 0 FIFO_DEPTH 1
282
    //print "Sending byte %0d" tc
283
    iowaitbit TXRDY1 1                        // wait until TXRDY
284
    set data tc & 0x7F                        // mask byte
285
    //print "Got TXRDY %0d times" tc
286
    write b BASE1 TXDATA data                 // transmit a byte
287
    ifnot TX_FIFO
288
      iowaitbit TXRDY1 0                      // wait until TXRDY deasserted
289
    endif
290
    ifnot RX_FIFO                             // must read immediately
291
      iowaitbit RXRDY2 1                      // wait until RXRDY
292
      //print "Receiving byte %0d" tc
293
      readstore b BASE2 RXDATA rdata[rc]      // read received byte
294
      set rc rc + 1
295
    endif
296
  endloop
297
 
298
  if RX_FIFO                                   // test out FIFO operation
299
    wait BYTE_WAIT_16                          // wait for data to be received
300
    loop rc 0 FIFO_DEPTH 1
301
      iowaitbit RXRDY2 1                      // wait until RXRDY
302
      readstore b BASE2 RXDATA rdata[rc]      // read received byte
303
    endloop
304
  endif
305
 
306
  // check data
307
  loop i 0 FIFO_DEPTH 1
308
    set j i & 0x7F
309
    if rdata[i] != j
310
      call pr_underscores
311
      print "TEST FAILED"
312
      print "Expected %0d, got %0d" i rdata[i]
313
      setfail
314
    endif
315
  endloop
316
  print "Continuous data stream successfull"
317
  call pr_underscores
318
return
319
 
320
procedure framing_err_test
321
  call pr_underscores
322
  print "Performing framing error test by setting input to DUT2 low"
323
 
324
  // set the input to UART2 RX line low
325
  // (no stop bit)
326
  iowrite 0x01
327
  wait BYTE_WAIT_16
328
  ifnot RX_FIFO
329
    // back to normal:
330
    iowrite 0x00
331
    wait BYTE_WAIT_16
332
    readmask b BASE2 STA 0x10 0x10    // check for framing_err bit set
333
    read b BASE2 RXDATA               // doing a read should clear this
334
    readmask b BASE2 STA 0x00 0x10    // check for framing_err bit cleared
335
  else
336
    readmask b BASE2 STA 0x10 0x10    // check for framing_err bit set
337
    iowrite 0x00
338
    // transmit a byte to clear the framing error
339
    iowaitbit TXRDY1 1                // wait until TXRDY
340
    write b BASE1 TXDATA 0xAA
341
    wait BYTE_WAIT_16
342
    readmask b BASE2 STA 0x00 0x10    // check for framing_err bit cleared
343
    //loop i 0 FIFO_DEPTH 1           // probably caused an overflow,
344
    readstore b BASE2 STA x           // read status
345
    set x x & 0x02
346
    set cmp x == 2
347
    while cmp
348
      iowaitbit RXRDY2 1              // wait until RXRDY
349
      read b BASE2 RXDATA             // need to clear
350
      iowaitbit RXRDY2 0              // wait until RXRDY clear
351
      wait 4
352
      readstore b BASE2 STA x           // read status
353
      set x x & 0x02
354
      set cmp x == 2
355
    endwhile
356
 
357
  endif
358
  wait 10
359
 
360
 
361
  print "Framing error test completed"
362
  call pr_underscores
363
return
364
 
365
procedure overflow_test
366
  call pr_underscores
367
  print "Overflow test"
368
 
369
  if RX_FIFO
370
    loop tc 0 FIFO_DEPTH 1
371
      iowaitbit TXRDY1 1                        // wait until TXRDY
372
      set data tc & 0x7F                        // mask byte
373
      write b BASE1 TXDATA data                 // transmit a byte
374
      ifnot TX_FIFO
375
        iowaitbit TXRDY1 0                      // wait until TXRDY deasserted
376
      endif
377
    endloop
378
 
379
    iowaitbit TXRDY1 1                          // wait until TXRDY
380
    wait BYTE_WAIT_256
381
    iotstbit OVERFLOW2 0                        // check that overflow not set
382
    write b BASE1 TXDATA 0xab                   // transmit a byte (0xab)
383
 
384
    wait BYTE_WAIT_256                          // worst case: 3 blocks (BAUD_VAL=1)
385
    wait BYTE_WAIT_256
386
    wait BYTE_WAIT_256
387
 
388
    iotstbit OVERFLOW2 1                        // check that overflow set
389
 
390
    // read RX data
391
    loop rc 0 FIFO_DEPTH 1
392
      if rc == 1
393
        iotstbit OVERFLOW2 0                  // check
394
      endif
395
      iowaitbit RXRDY2 1                      // wait until RXRDY
396
      readstore b BASE2 RXDATA rdata[rc]      // read received byte
397
    endloop
398
 
399
    // check data
400
    loop i 0 FIFO_DEPTH 1
401
      set j i & 0x7F
402
      if rdata[i] != j
403
        call pr_underscores
404
        print "TEST FAILED"
405
        print "Expected %0d, got %0d" i rdata[i]
406
        setfail
407
      endif
408
    endloop
409
  endif
410
 
411
  call pr_underscores
412
 
413
return
414
 
415
procedure parity_err_test
416
  call pr_underscores
417
  print "Performing Parity Error Test"
418
  call set_config 0 1 0 1 1
419
  call set_config 1 1 1 1 1
420
 
421
                                              // -- transmit a byte --
422
  iotstbit PARITY_ERR2 0                      // check that parity error is 0
423
  iowaitbit txrdy1 1                          // wait until txrdy
424
  write b base1 txdata 0xab                   // transmit a byte (0xab)
425
  iowaitbit PARITY_ERR2 1                     // check that parity error asserted
426
 
427
  if RX_FIFO
428
    iowaitbit PARITY_ERR2 0                     // check that parity error deasserted
429
    call set_config 0 1 1 1 1                   // match parity
430
    iowaitbit txrdy1 1                          // wait until txrdy
431
    write b base1 txdata 0xac                   // transmit a new byte (0xab)
432
    iowaitbit RXRDY2 1                          // read byte
433
    iotstbit PARITY_ERR2 0                      // check that parity error NOT asserted
434
    readstore b BASE2 RXDATA x                  // store
435
 
436
    if x != 0xac
437
      call pr_underscores
438
      print "TEST FAILED"
439
      print "Expected 0xac, got %0h" x
440
      setfail
441
    endif
442
  else
443
    // NO RX_FIFO
444
    // clear parity error
445
    read b BASE2 RXDATA                         // read should clear
446
    wait 4
447
    iotstbit PARITY_ERR2 0                      // the parity error
448
    call set_config 0 1 1 1 1                   // match parity
449
    iowaitbit txrdy1 1                          // wait until txrdy
450
    write b base1 txdata 0xac                   // transmit a new byte (0xab)
451
    iowaitbit RXRDY2 1                          // read byte
452
    iotstbit PARITY_ERR2 0                      // check that parity error NOT asserted
453
    readstore b BASE2 RXDATA x                  // store
454
 
455
    if x != 0xac
456
      call pr_underscores
457
      print "TEST FAILED"
458
      print "Expected 0xac, got %0h" x
459
      setfail
460
    endif
461
 
462
  endif
463
 
464
 
465
 
466
  print "Parity Error Test Complete"
467
  call pr_underscores
468
return

powered by: WebSVN 2.1.0

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