1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#include<systemc-ams.h>
#include<systemc.h>
const double PI=3.1415;
int sc_main(int argc, char *argv[])
{
sca_tdf::sca_in<double>rf, osc;
sc_core::sc_out<sc_int<8>>if_d;
sc_trace_file *wf = sc_create_vcd_trace_file("wave");
sc_trace(wf,rf,"rf");
sc_trace(wf,osc,"osc");
sc_trace(wf,if_d,"if_d");
sc_start(1.0,SC_MS);
getchar();
sc_close_vcd_trace_file(wf);
return 0;
}
SCA_TDF_MODULE(mixer) {
// TDF input and output ports
sca_tdf::sca_in<double> in1, in2;
sca_tdf::sca_out<double> out;
// TDF functions
void set_attributes() {
set_timestep(1.0, SC_US); }
void processing() {
out.write(in1.read() * in2.read()); }
// constructor
SCA_CTOR(mixer) {}
};
SCA_TDF_MODULE(lp_filter_ltf_ctrl) {
sca_tdf::sca_in<double> in; // input
sca_tdf::sca_out<double> out; // output
sca_tdf::sc_in<bool> ctrl; // gain ctrl
sca_tdf::sca_ltf_nd ltf; // LTF object
sca_util::sca_vector<double> num, den;
void initialize() {
num(0) = 1.0;
den(0) = 1.0; den(1) = 1.0/(2.0*PI*1.0e4);}
void processing() {
double tf = ltf(num, den, in.read());
if (ctrl.read()) out.write(2.0*tf);
else out.write(1.0*tf);
}
SCA_CTOR(lp_filter_ltf_ctrl)
{}
};
SCA_TDF_MODULE(ad_converter) {
sca_tdf::sca_in<double> in;
sca_tdf::sc_out<sc_int<8> > out; // DE output
void processing() {
out.write(sc_int<8>(in.read())); }
SCA_CTOR(ad_converter) {}
};
SC_MODULE(front_end) {
sca_tdf::sca_in<double> in,in1,in2,rf, osc;
sca_tdf::sca_out<double> out;
sc_core::sc_out<sc_int<8>> if_d;
sca_tdf::sca_signal<double> if_mxr, if_lpf;
mixer* mxr;
lp_filter_ltf_ctrl* lpf;
ad_converter* adc;
SC_CTOR(front_end)
{
mxr = new mixer("mxr");
mxr->in1(rf),in2(osc),out(if_mxr);
lpf = new lp_filter_ltf_ctrl("lpf");
lpf->in(if_mxr);
lpf->out(if_lpf);
adc = new ad_converter("adc");
adc->in(if_lpf);
adc->out(if_d);
}
};
|