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

Subversion Repositories sciir

[/] [sciir/] [trunk/] [SystemC/] [tfii/] [Stimuli.h] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 ahmed.shah
/** This function read in a text file into a local variable and export it
2
    in array format */
3
template<class T> T* ReafFileData(int Size)
4
{
5
        T *values = new T[Size];
6
        int numValuesRead = 0;
7
 
8
        // open the file
9
        FILE* pFile = fopen("Step.txt","r+t");
10
 
11
        while( ! feof( pFile ) )
12
        {
13
                T currentInt = 0;
14
                fscanf( pFile, "%f", &currentInt);
15
                values[numValuesRead] = currentInt ;
16
                numValuesRead++;
17
        }
18
 
19
        fclose(pFile);
20
 
21
        return values;
22
 
23
        delete pFile;
24
}
25
 
26
/** This module/block start reading the data from the array data
27
    when the clear signal is set to zero and at each rising edge of the clock */
28
template<class T>
29
SC_MODULE(Stimuli) {
30
        // Input and Output Ports
31
        sc_in_clk       clk;
32
        sc_in<bool> clr;
33
        sc_out<T >      streamout;
34
 
35
    // Internal variable
36
    unsigned int count;
37
        float *data;
38
 
39
    // Constructor  
40
    SC_HAS_PROCESS(Stimuli);
41
 
42
    Stimuli(sc_module_name name, int _Size):
43
        sc_module(name),
44
        Size(_Size)
45
    {
46
        SC_METHOD(bitstream);
47
            sensitive << clr << clk.pos();
48
 
49
        data = ReafFileData<float> (Size);
50
    }
51
 
52
    // Process
53
    void bitstream()
54
    {
55
        if (clr == true)
56
        {
57
            count = 0;
58
            streamout.write(0.0);
59
        }
60
        else
61
        {
62
            if (clk.posedge())
63
            {
64
                if (count < Size)
65
                {
66
                    streamout.write(data[count]);
67
                    count = count + 1;
68
                }
69
                else
70
                {
71
                    count = 0;
72
                }
73
            }
74
        }
75
    }
76
 
77
        ~Stimuli()
78
        {
79
        }
80
 
81
        int Size;
82
};

powered by: WebSVN 2.1.0

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