SystemC Development with CapsimTMK

Source Code sinesc.h

sinesc.h

/*
Copyright (C) 2006-2007 Silicon DSP Corporation, Portland, Oregon

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

http://capsimtmk.sourceforge.net
*/

 

 

/*

This block generates a sinusoid ( cosine for zero phase).

*/

/*

Programmer: Sasan Ardalan
Date: Nov. 1987

Modified for SystemC July 2006

*/

/*
* SystemC code for block generated by Capsim
*/
#include <stdio.h>
#include <math.h>

 

#define PI 3.141592654
#define PIDIV2 1.570796327
#define PI2 6.283185307

SC_MODULE(sinesc) {

sc_in_clk CLK;
sc_in<bool> rst_n;

 

/*
* Output Signals
*/
sc_out < float > y;

/*
* STATES
*/

float dt;
float phaseRad;
long samples_out;
double angle;

/*
* Parameters
*/
int num_of_samples;
float magnitude;
float fs;
float freq;
float phase;

SC_CTOR(sinesc) {
SC_METHOD(entry);
dont_initialize();

/*
* sensitivity list
*/
sensitive_pos(CLK);
sensitive_neg << rst_n;

}
void entry();

};

/*
* Entry Code
*/
void sinesc::entry() {

 

/*
* Declarations
*/

long i,j;
float yy;

if(!rst_n) {

/*
* User Init Code
*/


samples_out=0;
phaseRad = phase *PI/180.0;
dt = 2.*PI*freq/fs;
angle= -dt;

} else {

/*
* Main Code
*/

angle= angle +dt;
angle=fmod(angle,PI2);
yy = magnitude*cos(angle+phaseRad);
y.write(yy);
samples_out += 1;
if(samples_out > num_of_samples) sc_stop();

 

}
}


Contact | ©2007 Silcon DSP Corporation , Portland, Oregon