problem with creating new levels of logic

From: David Li (mengli_us_at_yahoo.com)
Date: 08/04/04


Date: 3 Aug 2004 15:17:38 -0700

I am having a lot of problem with following code. To start with
I have a working sets of code and the top level SystemC code looks
like this:

----------working main.cpp start here -------------------

#include "C:\SystemC\systemc-2.0.1\src\systemc.h"
#include "stimulus.h"
#include "display.h"
#include "fir.h"
#include "ParametizedDelay.h"

int sc_main (int argc , char *argv[]) {
  sc_clock clock;
  sc_signal<bool> reset;
  sc_signal<bool> input_valid;
  sc_signal<int> ADC_Data;
  sc_signal<int> Filter_Out;
  sc_signal<int> Line1_Out,Line2_Out,Line3_Out,Line4_Out;

  stimulus stimulus("stimulus");
  fir fir("fir");
  fir.SetCoefs(13, 0, "LPF.Coeff");
  display display ("display");

  stimulus.CLK(clock.signal());
  stimulus.reset(reset);
  stimulus.ADC_Data(ADC_Data);

  fir.CLK(clock.signal());
  fir.reset(reset);
  fir.ipData(ADC_Data);
  fir.opData(Filter_Out);

  ParametizedDelay Line1 ("line1");
  ParametizedDelay Line2 ("line2");
  ParametizedDelay Line3 ("line3");
  ParametizedDelay Line4 ("line4");

  Line1.SetDelay(500);
  Line1.CLK(clock.signal());
  Line1.reset(reset);
  Line1.ipData(ADC_Data);
  Line1.opData(Line1_Out);

  Line2.SetDelay(500);
  Line2.CLK(clock.signal());
  Line2.reset(reset);
  Line2.ipData(Line1_Out);
  Line2.opData(Line2_Out);

  Line3.SetDelay(500);
  Line3.CLK(clock.signal());
  Line3.reset(reset);
  Line3.ipData(Line2_Out);
  Line3.opData(Line3_Out);

  Line4.SetDelay(500);
  Line4.CLK(clock.signal());
  Line4.reset(reset);
  Line4.ipData(Line3_Out);
  Line4.opData(Line4_Out);

  display.CLK(clock.signal());
  display.lpf(Filter_Out);
  display.Line1(Line1_Out);
  display.Line2(Line2_Out);
  display.Line3(Line3_Out);
  display.Line4(Line4_Out);

  sc_start(clock, -1);
  return 0;
}
--------------End of main.cpp ------------------

Basically, the stimulus module read in a data file and feed it(the
ADC_Data) to the fir module which is simply a FIR filter(the filter
coefficient is defined by LPF.Coeff text file). At the same time
stimulus also feed into a 4 separate Line delays each with a delay of
500 clocks. Now, the code is working but what I would like to do is to
create a new module that contains only the 4 Lines at the top level.
When done, I like it to look like the following.

-------------the new main.cpp -------------------

#include "C:\SystemC\systemc-2.0.1\src\systemc.h"
#include "stimulus.h"
#include "display.h"
#include "fir.h"
#include "ParametizedDelay.h"
#include "FourInOne.h"

int sc_main (int argc , char *argv[]) {

  sc_clock clock;
  sc_signal<bool> reset;
  sc_signal<bool> input_valid;
  sc_signal<int> ADC_Data;
  sc_signal<int> Filter_Out;
  sc_signal<int> Line1_Out,Line2_Out,Line3_Out,Line4_Out;

  stimulus stimulus("stimulus");
  fir fir("fir");
  fir.SetCoefs(13, 0, "LPF.Coeff");
  display display ("display");
  FourInOne FourInOne("FourInOne"); // This would be the new module
added here.

  stimulus.CLK(clock.signal());
  stimulus.reset(reset);
  stimulus.ADC_Data(ADC_Data);

  fir.CLK(clock.signal());
  fir.reset(reset);
  fir.ipData(ADC_Data);
  fir.opData(Filter_Out);

  ParametizedDelay Line1 ("line1");
  ParametizedDelay Line2 ("line2");
  ParametizedDelay Line3 ("line3");
  ParametizedDelay Line4 ("line4");

  FourInOne.SetDelay(500); //Added
  FourInOne.CLK(clock.signal()); //Added
  FourInOne.reset(reset); //Added
  FourInOne.ipBotLine(ADC_Data); //Added
  FourInOne.opCurLine(Line1_Out); //Added
  FourInOne.opCurLine(Line2_Out); //Added
  FourInOne.opCurLine(Line3_Out); //Added
  FourInOne.opTopLine(Line4_Out); //Added

  display.CLK(clock.signal());
  display.lpf(Filter_Out);
  display.Line1(Line1_Out);
  display.Line2(Line2_Out);
  display.Line3(Line3_Out);
  display.Line4(Line4_Out);

  sc_start(clock, -1);
  return 0;
}

---------------end of desired main.cpp ---------------------

As you can see, my purpose is to be able to create new levels of logic
as design gets bigger. But the code doesn't work and can not compile.

In the following, I listed all the revelent .h and .cpp code.

-----------stimulus.h---------------
SC_MODULE(stimulus) {

  sc_out<bool> reset;
  sc_out<int> ADC_Data;
  sc_in<bool> CLK;

  unsigned CLK_COUNT;
  FILE* ifp;
  char line[80];
  int FileReadData;

  SC_CTOR(stimulus)
  {
      SC_METHOD(Read_Data_File);
      dont_initialize();
      sensitive_pos(CLK);
      CLK_COUNT = 0;
      ifp = fopen("C:/SystemC/Hardware-Model/InputData/cnn1.vec","r");
  }
  void Read_Data_File();
};

-------------- stimulus.cpp -------------------
#include "stdio.h"
#include "C:\SystemC\systemc-2.0.1\src\systemc.h"
#include "stimulus.h"

void stimulus::Read_Data_File() {

  if(fgets(line, 80, ifp)== NULL) {sc_stop();}
  sscanf(line, "%x", &FileReadData);

  CLK_COUNT++;
  if (CLK_COUNT<4){
    reset.write(true);
  } else {
    reset.write(false);
    ADC_Data.write((int)FileReadData);
  }
}

----------fir.h-----------------
SC_MODULE(fir){
  
sc_in_clk CLK;
sc_in<bool> reset;
sc_in<int> ipData;
sc_out<int> opData;

int TAP;
int DELAY;
int *filter_flops;
int *delay_flops;
int *coefs;

SC_CTOR(fir) {
  SC_CTHREAD(filter, CLK.pos());
  watching(reset.delayed() == true);
  TAP = 0;
  DELAY = 0;
  coefs = new int[TAP];
  filter_flops = new int[TAP];
  delay_flops = new int[DELAY];
  }
  
void SetCoefs(int NumTaps, int Delay, char *FileName);
void filter();
};

---------------fir.cpp-------------------
#include "C:\SystemC\systemc-2.0.1\src\systemc.h"
#include "fir.h"

void fir::filter() {
  int acc;
  int DataIn;
  int i;
  int delay_out;

  for(i=0; i<=(TAP-1); i++) filter_flops[i] = 0;
  for(i=0; i<=(DELAY-1); i++) delay_flops[i] = 0;
  opData.write(0);
  wait();

  while(1){
    DataIn = ipData.read();
    acc = ipData*coefs[0];
    for(i=(TAP-2); i>=0; i--) {
      acc += filter_flops[i]*coefs[i+1];
    };
    for(i=(TAP-2); i>=0; i--) {
      filter_flops[i+1] = filter_flops[i];
    };
    filter_flops[0] = DataIn;
    acc /=256;

    delay_out = (DELAY==0) ? acc : delay_flops[0];

    for(i=0; i<DELAY-1; i++) {
      delay_flops[i] = delay_flops[i+1];
    };

    delay_flops[DELAY-1] = acc;
    opData.write(delay_out);

    // opData.write(acc);
    wait();
  };
}

void fir::SetCoefs(int NumTaps, int Delay, char *FileName) {
FILE *ifp;
int i;
char line[80];

TAP = NumTaps;
DELAY = Delay;
coefs = new int[TAP];
filter_flops = new int[TAP-1];
delay_flops = new int[DELAY];
ifp = fopen(FileName, "r");

for (i=0; i<TAP; i++)
  {
  if(fgets(line, 80, ifp) != NULL)
  *(coefs+i)= atoi(line);
  }
}

------------ParameterizedDelay.h--------------------

SC_MODULE(ParametizedDelay){
  
sc_in_clk CLK;
sc_in<bool> reset;
sc_in<int> ipData;
sc_out<int> opData;
int DELAY;
int *delay_flops;
int rPoint;

SC_CTOR(ParametizedDelay) {
  SC_CTHREAD(DelayIt, CLK.pos());
  watching(reset.delayed() == true);
  DELAY = 0;
  delay_flops = new int[DELAY];
  }
  
void SetDelay(int Delay);
void DelayIt();
};

---------------ParameterizedDelay.cpp--------------------
#include "C:\SystemC\systemc-2.0.1\src\systemc.h"
#include "ParametizedDelay.h"

void ParametizedDelay::DelayIt() {
  int DataIn;
  int delay_out;

  while(1){
    DataIn = ipData.read();
    delay_out = *(delay_flops+rPoint);
    *(delay_flops+rPoint) = DataIn;
    opData.write(delay_out);
    rPoint++;
    rPoint %=DELAY;
    // cout << rPoint <<":"<<DataIn<<endl;
    wait();
  };
}

void ParametizedDelay::SetDelay(int Delay) {
  int i;
  DELAY = Delay-1;
  delay_flops = new int[DELAY];
  for (i=0;i<=DELAY-1; i++)delay_flops[i]=0;
  rPoint = 0;
}

-----------------display.h---------------------
SC_MODULE(display) {
sc_in<int> lpf;
sc_in<int> Line1;
sc_in<int> Line2;
sc_in<int> Line3;
sc_in<int> Line4;
sc_in<bool> CLK;

FILE *ofp_lpf;
FILE *ofp_line1;
FILE *ofp_line2;
FILE *ofp_line3;
FILE *ofp_line4;

  SC_CTOR(display)
    {
      SC_METHOD(Monitor);
      dont_initialize();
      sensitive_pos(CLK);
      ofp_lpf = fopen("lpf.hex","w");
      ofp_line1 = fopen("line1.hex","w");
      ofp_line2 = fopen("line2.hex","w");
      ofp_line3 = fopen("line3.hex","w");
      ofp_line4 = fopen("line4.hex","w");
    }

  void Monitor();
};

-----------display.cpp---------------------

#include "C:\SystemC\systemc-2.0.1\src\systemc.h"
#include "display.h"

void display::Monitor(){
  fprintf(ofp_lpf, "%03x\n", lpf.read());
  fprintf(ofp_line1, "%03x\n", Line1.read());
  fprintf(ofp_line2, "%03x\n", Line2.read());
  fprintf(ofp_line3, "%03x\n", Line3.read());
  fprintf(ofp_line4, "%03x\n", Line4.read());
}

------------LPF.Coeff----------
1
9
12
21
18
33
54
33
18
21
12
9
1

Finally, the FourInOne is the one that I am having problem creating,
can someone help? Thanks



Relevant Pages

  • [PATCH 2/3] Change return value from schedule_work
    ... functions, call WARN_ON if there was a failure, and then return void. ... void usbnet_defer_kevent (struct usbnet *dev, int work) ... @delay: ...
    (Linux-Kernel)
  • Re: "PORTING C" > code for CURR_SYS_OSC
    ... micro-seconds by simply calling a delay function on the fly. ... void set_curr_sys_osc(float extCrys, float fpllidiv, float fpllmul, float ... {return (int) curr_sys_osc;} ...
    (microsoft.public.vc.language)
  • help with msp 430 interface and dip-switches
    ... problem is, when i change baud rate, led stops blinkind. ... void delay(); // delay ... volatile int baud; // msp430 baud speed ...
    (comp.arch.embedded)
  • Help in Java swings(internal Frame)
    ... public int getSize() ... public void valueChanged{ ... private JScrollPane scrollPane1; ... public class PeakContainer extends JInternalFrame ...
    (comp.lang.java.programmer)
  • [PATCH] get rid if __cpuinit and __cpuexit
    ... unsigned long action, void *hcpu) ... unsigned int cpu = hcpu; ... -static int __cpuinit ... __cpu_up(unsigned int cpu) ...
    (Linux-Kernel)