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

Subversion Repositories gppd

[/] [gppd/] [trunk/] [stimuli.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ahmed.shah
#include "systemc.h"
2
#include <iostream>
3
#include <fstream>
4
 
5
#define textLength 40 //The length of the bit-stream in the stimuli file
6
 
7
/** This function read in a text file into a local variable and export it
8
    in array format */
9
int* ReadFileData()
10
{
11
        int *values = new int[textLength];
12
        int numValuesRead = 0;
13
 
14
        // open the file
15
        FILE* pFile = fopen("impulse_response.dat","r+t");
16
 
17
        while( ! feof( pFile ) )
18
        {
19
                int currentInt = 0;
20
                fscanf( pFile, "%d", &currentInt);
21
                values[numValuesRead] = currentInt ;
22
                numValuesRead++;
23
        }
24
 
25
        fclose(pFile);
26
 
27
        return values;
28
 
29
        delete pFile;
30
}
31
 
32
/** Read in the text file using the developed previous function
33
    and store the content into the arry called data */
34
static int *data = ReadFileData();
35
 
36
/** This module/block start reading the data from the array data
37
    when the clear signal is set to zero and at each rising edge of the clock */
38
SC_MODULE(stimuli) {
39
        // Input and Output Ports
40
        sc_in_clk       CLK;
41
        sc_in<bool> CLR;
42
        sc_out<double > firIN;
43
 
44
    // Internal variable
45
    unsigned int count;
46
 
47
    // Constructor
48
    SC_CTOR(stimuli)
49
    {
50
        SC_METHOD(bitstream);
51
            sensitive << CLR << CLK.pos();
52
    }
53
 
54
    // Process
55
    void bitstream()
56
    {
57
        if (CLR == true)
58
        {
59
            count = 0;
60
            firIN.write(0);
61
        }
62
        else
63
        {
64
            if (CLK.posedge())
65
            {
66
                if (count < textLength)
67
                {
68
                    firIN.write(data[count]);
69
                    count = count + 1;
70
                }
71
                else
72
                {
73
                    count = 0;
74
                }
75
            }
76
        }
77
    }
78
 
79
 
80
};

powered by: WebSVN 2.1.0

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