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

Subversion Repositories spdif_transmitter

[/] [spdif_transmitter/] [trunk/] [testbench/] [spdif_tb.cpp] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 ultra_embe
#include "spdif_tb.h"
2
 
3
//-----------------------------------------------------------------
4
// sc_main_tb
5
//-----------------------------------------------------------------
6
static int attach_system_c(p_cb_data user_data)
7
{
8
    spdif_tb * u_tb  = new spdif_tb("spdif_tb");
9
 
10
    // Initialize SystemC
11
    sc_start(0, SC_NS);
12
 
13
    // Start clock
14
    u_tb->m_vpi_clk.start();
15
}
16
//-----------------------------------------------------------------
17
// _register
18
//-----------------------------------------------------------------
19
static void _register(void)
20
{
21
    s_cb_data          cb_data_s;
22
    cb_data_s.user_data = NULL;
23
    cb_data_s.reason    = cbStartOfSimulation;
24
    cb_data_s.cb_rtn    = attach_system_c;
25
    cb_data_s.time      = NULL;
26
    cb_data_s.value     = NULL;
27
    vpi_register_cb(&cb_data_s);
28
}
29
 
30
void (*vlog_startup_routines[])() =
31
{
32
    _register,
33
 
34
};
35
 
36
//-----------------------------------------------------------------
37
// audio_clk: Produce audio clock
38
//-----------------------------------------------------------------
39
void spdif_tb::audio_clk(void)
40
{
41
    // Reset
42
    rst_i.write(true);
43
    wait(5);
44
    rst_i.write(false);
45
    wait(1);
46
 
47
    while (1)
48
    {
49
        wait(AUDIO_CLK_DIV/2);
50
        audio_clk_i.write(!audio_clk_i.read());
51
    }
52
}
53
//-----------------------------------------------------------------
54
// drive: Drive input sequence
55
//-----------------------------------------------------------------
56
void spdif_tb::drive(void)
57
{
58
    sc_uint <32> data;
59
    int interations = 2000;
60
 
61
    // Drive input data
62
    while (interations--)
63
    {
64
        data.range(15,0)  = rand();
65
        data.range(31,16) = rand();
66
        m_tx_fifo.write(data.range(15,0));
67
        m_tx_fifo.write(data.range(31,16));
68
 
69
        m_driver.write(data);
70
    }
71
}
72
//-----------------------------------------------------------------
73
// monitor: Check output data
74
//-----------------------------------------------------------------
75
void spdif_tb::monitor(void)
76
{
77
    do
78
    {
79
        wait();
80
    }
81
    while (rst_i.read());
82
 
83
    while (1)
84
    {
85
        sc_uint <16> data    = m_tx_fifo.read();
86
        sc_uint <16> rx_data = m_decoder.read();
87
 
88
        printf("EXPECT: %04x\n", (unsigned)data);
89
        printf("GOT: %04x\n", (unsigned)rx_data);
90
 
91
        sc_assert(rx_data == data);
92
 
93
        if (m_tx_fifo.num_available() == 0)
94
            m_dut.stopSimulation();
95
    }
96
}

powered by: WebSVN 2.1.0

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